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; using System.Collections.Generic; using System.Linq; namespace AtCoder { static class Extensions { public static int LowerBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c > 0) l = m + 1; else r = m; } return l; } public static int UpperBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c >= 0) l = m + 1; else r = m; } return r; } } class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public MaxHeap<T> Copy(Comparison<T> comp = null) { var c = new MaxHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MaxHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } class InputLine { private string[] _inputs; private int _index = 0; InputLine(string input) { _inputs = input.Split(); _index = 0; } public static InputLine Read() { return new InputLine(Console.ReadLine()); } public int NextInt() { return int.Parse(_inputs[_index++]); } public long NextLong() { return long.Parse(_inputs[_index++]); } public double NextDouble() { return double.Parse(_inputs[_index++]); } } public static int GCD(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long GCD(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } static long ModPower(long x, long y, long mod) { var bytes = BitConverter.GetBytes(y); var bits = new System.Collections.BitArray(bytes); var max2 = 0; for (int i = bits.Length - 1; i >= 0; i--) { if (bits[i]) { max2 = i; break; } } long result = 1; for (int i = max2; i >= 0; i--) { result = (result * result) % mod; if (bits[i]) { result = (result * x) % mod; } } return result; } static long ModFact(long n, long mod) { long result = 1; for (int i = 1; i <= n; i++) { result = result * i % mod; } return result; } static long ModAdd(long x, long y, long mod) { return ((x % mod) + (y % mod)) % mod; } static long ModMal(long x, long y, long mod) { return ((x % mod) * (y % mod)) % mod; } static long ModDiv(long x, long y, long mod) { //フェルマーの小定理より、a^(-1) = a^(p-2) return ModMal(x, ModPower(y, mod - 2, mod), mod); } static long ModComb(long n, long r, long mod) { long numerator = 1; for (int i = 0; i < r; i++) { numerator = ModMal(numerator, n - i, mod); } long denominator = ModFact(r, mod); return ModDiv(numerator, denominator, mod); } class Graph { private int _size; private List<int>[] _map; public IEnumerable<int> this[int i] { get { if (_map[i] == null) return Enumerable.Empty<int>(); return _map[i]; } } public Graph(int size) { _size = size; _map = new List<int>[size]; } public void Add(int from, int to) { if (_map[from] == null) { _map[from] = new List<int>(); } _map[from].Add(to); } } static long p1097 = 1000000007; static void Main(string[] args) { //↓ var nm = ReadIntArray(); var n = nm[0]; var m = nm[1]; var aas = ReadIntArray(m); var steps = new long[n + 1]; var j = 0; steps[0] = 1; if (aas[0] == 1) steps[1] = 0; else steps[1] = 1; for (int i = 2; i < n + 1; i++) { while (j < aas.Length - 1 && aas[j] < i) j++; if (aas[j] == i) { steps[i] = 0; if (steps[i - 1] == 0) break; continue; } steps[i] = ModAdd(steps[i - 2], steps[i - 1], p1097); } Console.WriteLine(steps[n]); //↑ } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { static class Extensions { public static int LowerBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c > 0) l = m + 1; else r = m; } return l; } public static int UpperBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c >= 0) l = m + 1; else r = m; } return r; } } class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public MaxHeap<T> Copy(Comparison<T> comp = null) { var c = new MaxHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MaxHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } class InputLine { private string[] _inputs; private int _index = 0; InputLine(string input) { _inputs = input.Split(); _index = 0; } public static InputLine Read() { return new InputLine(Console.ReadLine()); } public int NextInt() { return int.Parse(_inputs[_index++]); } public long NextLong() { return long.Parse(_inputs[_index++]); } public double NextDouble() { return double.Parse(_inputs[_index++]); } } public static int GCD(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long GCD(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } static long ModPower(long x, long y, long mod) { var bytes = BitConverter.GetBytes(y); var bits = new System.Collections.BitArray(bytes); var max2 = 0; for (int i = bits.Length - 1; i >= 0; i--) { if (bits[i]) { max2 = i; break; } } long result = 1; for (int i = max2; i >= 0; i--) { result = (result * result) % mod; if (bits[i]) { result = (result * x) % mod; } } return result; } static long ModFact(long n, long mod) { long result = 1; for (int i = 1; i <= n; i++) { result = result * i % mod; } return result; } static long ModAdd(long x, long y, long mod) { return ((x % mod) + (y % mod)) % mod; } static long ModMal(long x, long y, long mod) { return ((x % mod) * (y % mod)) % mod; } static long ModDiv(long x, long y, long mod) { //フェルマーの小定理より、a^(-1) = a^(p-2) return ModMal(x, ModPower(y, mod - 2, mod), mod); } static long ModComb(long n, long r, long mod) { long numerator = 1; for (int i = 0; i < r; i++) { numerator = ModMal(numerator, n - i, mod); } long denominator = ModFact(r, mod); return ModDiv(numerator, denominator, mod); } class Graph { private int _size; private List<int>[] _map; public IEnumerable<int> this[int i] { get { if (_map[i] == null) return Enumerable.Empty<int>(); return _map[i]; } } public Graph(int size) { _size = size; _map = new List<int>[size]; } public void Add(int from, int to) { if (_map[from] == null) { _map[from] = new List<int>(); } _map[from].Add(to); } } static long p1097 = 1000000007; static void Main(string[] args) { //↓ var nm = ReadIntArray(); var n = nm[0]; var m = nm[1]; var aas = ReadIntArray(m); var steps = new long[n + 1]; var j = 0; steps[0] = 1; if (m > 0 && aas[0] == 1) steps[1] = 0; else steps[1] = 1; for (int i = 2; i < n + 1; i++) { while (j < aas.Length - 1 && aas[j] < i) j++; if (j < m && aas[j] == i) { steps[i] = 0; if (steps[i - 1] == 0) break; continue; } steps[i] = ModAdd(steps[i - 2], steps[i - 1], p1097); } Console.WriteLine(steps[n]); //↑ } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
2,075
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { static class Program { static void Main() { //ここから var vs = IO.ReadLineToIntList(); int N = vs[0]; int M = vs[1]; var a = new List<int>(); for (var i = 0; i < M; i++) { a.Add(IO.ReadLineToInt()); } Dictionary<int, long> ways = new Dictionary<int, long>(); long ans = Recurs(N, ref ways, a) % Func.mod; //ここまで Console.WriteLine(ans); Console.ReadKey(); } static long Recurs(int num, ref Dictionary<int, long> ways, List<int> a) { if (ways.ContainsKey(num)) { return ways[num]; } if (a.Any(l => l == num)) { ways.Add(num, 0); return 0; } if (num == 1) { ways.Add(num, 1); return 1; } if (num == 2) { long secondnum = a.Any(l => l == 1) ? 1 : 2; ways.Add(num, secondnum); return secondnum; } var newway = Recurs(num - 1, ref ways, a) + Recurs(num - 2, ref ways, a); ways.Add(num, newway); return newway; } } static class Func { static public long mod = 1000000007; static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); } static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); } public static double ToAngle(this double radian) { return (double)(radian * 180 / Math.PI); } public static double ToRadian(this double angle) { return (double)(angle * Math.PI / 180); } static public long Conbination(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * Conbination(n - 1, m - 1) / m; } static public void Factoring(long num, ref long[] vs) { if (num == 1) { vs[1]++; } for (long i = 2; i < Math.Sqrt(num); i++) { if (num % i == 0) { vs[i]++; Factoring(num / i, ref vs); } } vs[1]++; } } static class IO { static public string ReadLineToString() { return Console.ReadLine(); } static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace AtCoder { static class Program { static void Main() { //ここから var vs = IO.ReadLineToIntList(); int N = vs[0]; int M = vs[1]; var a = new Dictionary<int, bool>(); for (var i = 0; i < M; i++) { a.Add(IO.ReadLineToInt(), true); } Dictionary<int, long> ways = new Dictionary<int, long>(); long ans = Recurs(N, ref ways, a) % Func.mod; //ここまで Console.WriteLine(ans); Console.ReadKey(); } static long Recurs(int num, ref Dictionary<int, long> ways, Dictionary<int, bool> a) { if (ways.ContainsKey(num)) { return ways[num]; } if (a.ContainsKey(num)) { ways.Add(num, 0); return 0; } if (num == 1) { ways.Add(num, 1); return 1; } if (num == 2) { long secondnum = a.ContainsKey(1) ? 1 : 2; ways.Add(num, secondnum); return secondnum; } var newway = Recurs(num - 2, ref ways, a) + Recurs(num - 1, ref ways, a) % Func.mod; ways.Add(num, newway); return newway; } } static class Func { static public long mod = 1000000007; static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; } static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); } static public int Factorial(int a) { return a == 1 ? a : a * Factorial(a - 1); } public static double ToAngle(this double radian) { return (double)(radian * 180 / Math.PI); } public static double ToRadian(this double angle) { return (double)(angle * Math.PI / 180); } static public long Conbination(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * Conbination(n - 1, m - 1) / m; } static public void Factoring(long num, ref long[] vs) { if (num == 1) { vs[1]++; } for (long i = 2; i < Math.Sqrt(num); i++) { if (num % i == 0) { vs[i]++; Factoring(num / i, ref vs); } } vs[1]++; } } static class IO { static public string ReadLineToString() { return Console.ReadLine(); } static public int ReadLineToInt() { return int.Parse(Console.ReadLine()); } static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); } static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); } static public List<int> ReadLineToIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); } static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); } static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } } } }
[["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 21], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 211, 0, 146], ["-", 0, 195, 54, 55, 0, 220, 39, 236, 141, 22], ["+", 0, 195, 54, 55, 0, 220, 39, 236, 141, 22], ["+", 54, 55, 0, 220, 39, 236, 237, 238, 0, 21], ["+", 54, 55, 0, 220, 39, 236, 237, 238, 0, 199], ["-", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 15, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 16, 17, 60], ["-", 0, 212, 0, 41, 15, 213, 63, 214, 141, 22], ["+", 0, 212, 0, 41, 15, 213, 63, 214, 141, 22], ["-", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 12, 16, 17, 109], ["+", 0, 212, 0, 16, 12, 16, 12, 214, 205, 22], ["+", 0, 212, 0, 16, 12, 16, 12, 214, 0, 131], ["+", 0, 212, 0, 16, 12, 16, 12, 214, 141, 22]]
8
861
30
using System; using System.Collections.Generic; // list用 using System.Text; // StringBuilder用 using System.Collections; using System.Linq; class Program { static List<int> s = new List<int>(); static decimal result; static Hashtable ht = new Hashtable(); static StringBuilder sb = new StringBuilder(); static int N, M, K; static long[,] table; static void Main() { Read4(); Read5(); Modular[] check = new Modular[N]; for (int i = 0; i < N; i++) { check[i] = new Modular(0); } int j = 0; if (K > j && s[j] != 1) { check[0] = 1; } else { j++; } if (N > 1 && K > j && s[j] != 2) { check[1] = check[0] + 1; } else { j++; } for (int i = 2; i < N; i++) { check[i] = check[i - 1] + check[i - 2]; if (j < K && s[j] - 1 == i) { check[i] = 0; j++; } } Console.WriteLine(((int)check[N - 1]).ToString()); } static void Read1() // 1項 { string tmp = Console.ReadLine(); N = int.Parse(tmp); } static void Read2() //複数項(項目数N) { string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); } } static void Read3() // 1行複数項 { string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); } } static void Read4() // NK1行 { string[] tmp = Console.ReadLine().Split(' '); N = int.Parse(tmp[0]); K = int.Parse(tmp[1]); } static void Read5() // N行K項 { for (int i = 0; i < K; i++) { string tmp = Console.ReadLine(); s.Add(int.Parse(tmp)); } } } class Modular { private const int M = 1000000007; private long value; public Modular(long value) { 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) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } private 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 }; private 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 Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } }
using System; using System.Collections.Generic; // list用 using System.Text; // StringBuilder用 using System.Collections; using System.Linq; class Program { static List<int> s = new List<int>(); static decimal result; static Hashtable ht = new Hashtable(); static StringBuilder sb = new StringBuilder(); static int N, M, K; static long[,] table; static void Main() { Read4(); Read5(); Modular[] check = new Modular[N]; for (int i = 0; i < N; i++) { check[i] = new Modular(0); } int j = 0; if (K <= j || s[j] != 1) { check[0] = 1; } else { j++; } if (N > 1) { if (K <= j || s[j] != 2) { check[1] = check[0] + 1; } else { j++; } } for (int i = 2; i < N; i++) { check[i] = check[i - 1] + check[i - 2]; if (j < K && s[j] - 1 == i) { check[i] = 0; j++; } } Console.WriteLine(((int)check[N - 1]).ToString()); } static void Read1() // 1項 { string tmp = Console.ReadLine(); N = int.Parse(tmp); } static void Read2() //複数項(項目数N) { string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); } } static void Read3() // 1行複数項 { string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); } } static void Read4() // NK1行 { string[] tmp = Console.ReadLine().Split(' '); N = int.Parse(tmp[0]); K = int.Parse(tmp[1]); } static void Read5() // N行K項 { for (int i = 0; i < K; i++) { string tmp = Console.ReadLine(); s.Add(int.Parse(tmp)); } } } class Modular { private const int M = 1000000007; private long value; public Modular(long value) { 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) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } private 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 }; private 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 Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 17, 47], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
889
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; public class Contest { public const long MOD1 = 1000000007L; // 10^9+7 public static void Main() { int n, m; int[] a; MyIO.ReadMulti(out n, out m); MyIO.ReadLines(m, out a); long[] dp = new long[n + 1]; dp[0] = 1; dp[1] = a[0] == 1 ? 0 : 1; int ai = 0; for (int i = 2; i <= n; i++) { while ((ai < m) && (a[ai] < i - 2)) ai++; dp[i] = ((((ai < m) && (a[ai] == i - 2)) ? 0 : dp[i - 2]) + ((((ai < m) && (a[ai] == i - 1)) || ((ai < m - 1) && (a[ai + 1] == i - 1))) ? 0 : dp[i - 1])) % MOD1; } MyIO.WriteMulti(dp[n]); } } public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(int n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(int n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(int n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(int n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(int n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) { return t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; } public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.CompilerServices; public class Contest { public const long MOD1 = 1000000007L; // 10^9+7 public static void Main() { int n, m; int[] a; MyIO.ReadMulti(out n, out m); MyIO.ReadLines(m, out a); long[] dp = new long[n + 1]; dp[0] = 1; dp[1] = ((0 < m) && (a[0] == 1)) ? 0 : 1; int ai = 0; for (int i = 2; i <= n; i++) { while ((ai < m) && (a[ai] < i - 2)) ai++; dp[i] = ((((ai < m) && (a[ai] == i - 2)) ? 0 : dp[i - 2]) + ((((ai < m) && (a[ai] == i - 1)) || ((ai + 1 < m) && (a[ai + 1] == i - 1))) ? 0 : dp[i - 1])) % MOD1; } MyIO.WriteMulti(dp[n]); } } public struct VT<T, U> { public T Item1; public U Item2; public VT(T a, U b) { Item1 = a; Item2 = b; } } public struct VT<T, U, V> { public T Item1; public U Item2; public V Item3; public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; } } public struct VT<T, U, V, W> { public T Item1; public U Item2; public V Item3; public W Item4; public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(int n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(int n, out VT<T, U>[] a) { a = new VT<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new VT<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(int n, out VT<T, U, V>[] a) { a = new VT<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new VT<T, U, V>(o, p, q); } return arr; } public static string[][] ReadLines<T, U, V, W>(int n, out VT<T, U, V, W>[] a) { a = new VT<T, U, V, W>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; W r; arr[i] = ReadMulti(out o, out p, out q, out r); a[i] = new VT<T, U, V, W>(o, p, q, r); } return arr; } public static string[][] ReadMatrix<T>(int n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } private static string wfm(Type t) { return t.Equals(typeof(double)) ? "{0:F10}" : "{0}"; } public static void WriteMulti(params object[] a) { wwp(() => { for (int i = 0; i < a.Length; i++) { string fs = wfm(a[i].GetType()) + ((i < a.Length - 1) ? " " : Environment.NewLine); Console.Write(fs, a[i]); } }); } public static void WriteArray<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)); string fs1 = fs + " "; string fs2 = fs + Environment.NewLine; for (int i = 0; i < a.Length; i++) Console.Write(((i < a.Length - 1) ? fs1 : fs2), a[i]); }); } public static void WriteLines<T>(T[] a) { wwp(() => { string fs = wfm(typeof(T)) + Environment.NewLine; foreach (T x in a) Console.Write(fs, x); }); } }
[["+", 0, 1, 0, 11, 12, 41, 15, 23, 0, 24], ["+", 12, 41, 15, 23, 0, 16, 31, 23, 0, 24], ["+", 15, 23, 0, 16, 31, 23, 0, 16, 31, 203], ["+", 15, 23, 0, 16, 31, 23, 0, 16, 17, 18], ["+", 15, 23, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 12, 41, 15, 23, 0, 16, 31, 23, 0, 25], ["+", 0, 11, 12, 41, 15, 23, 0, 16, 17, 98], ["+", 12, 41, 15, 23, 0, 16, 12, 23, 0, 24], ["+", 12, 41, 15, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 41, 15, 23, 0, 25], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 16, 31, 23, 0, 16, 12, 16, 17, 33], ["-", 0, 16, 31, 23, 0, 16, 12, 16, 12, 203]]
8
2,031
14
using System; namespace FibonacciSample { class Program { static void Main(string[] args) { string[] str0 = Console.ReadLine().Split(' '); long n = int.Parse(str0[0]); long m = int.Parse(str0[1]); long[] s = new long[m + 1]; long[] f = new long[n + 1]; if (m != 0) { for (int i = 0; i < m; i++) { s[i] = long.Parse(Console.ReadLine()); } s[m] = 0; int j = 0; if (s[0] == 1 && s[1] != 2) { f[1] = 0; f[2] = 1; j++; } else if (s[0] == 2) { f[1] = 1; f[2] = 0; j++; } else if (s[0] == 1 && s[1] == 2) { f[n] = 0; j += 2; } else { f[2] = 2; f[1] = 1; } for (int i = 3; i <= n; i++) { if (i != s[j]) { f[i] = (f[i - 1] + f[i - 2]) % 1000000007; } else { f[i] = 0; j++; } } Console.WriteLine(f[n]); } else { f[2] = 2; f[1] = 1; for (int i = 3; i <= n; i++) { f[i] = (f[i - 1] + f[i - 2]) % 1000000007; } Console.WriteLine(f[n]); } } } }
using System; namespace FibonacciSample { class Program { static void Main(string[] args) { string[] str0 = Console.ReadLine().Split(' '); long n = int.Parse(str0[0]); long m = int.Parse(str0[1]); long[] s = new long[m + 1]; long[] f = new long[n + 1]; if (n == 1) { Console.WriteLine(1); } else if (m != 0) { for (int i = 0; i < m; i++) { s[i] = long.Parse(Console.ReadLine()); } s[m] = 0; int j = 0; if (s[0] == 1 && s[1] != 2) { f[1] = 0; f[2] = 1; j++; } else if (s[0] == 2) { f[1] = 1; f[2] = 0; j++; } else if (s[0] == 1 && s[1] == 2) { f[n] = 0; j += 2; } else { f[2] = 2; f[1] = 1; } for (int i = 3; i <= n; i++) { if (i != s[j]) { f[i] = (f[i - 1] + f[i - 2]) % 1000000007; } else { f[i] = 0; j++; } } Console.WriteLine(f[n]); } else { f[2] = 2; f[1] = 1; for (int i = 3; i <= n; i++) { f[i] = (f[i - 1] + f[i - 2]) % 1000000007; } Console.WriteLine(f[n]); } } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24]]
8
394
16
using System; using System.Linq; using System.Collections.Generic; namespace C { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var a = new int[nm[1]]; var isStepAble = new bool[nm[0] + 1]; int MOD = 1000000007; a = a.Select(x => x = int.Parse(Console.ReadLine())).ToArray(); for (int i = 0; i < isStepAble.Count(); i++) { isStepAble[i] = true; } foreach (var x in a) { isStepAble[x] = false; } // foreach (var x in a) // { // x = int.Parse(Console.ReadLine()); // isStepAble[x] = false; // } var dp = new int[nm[0] + 1]; dp[0] = 0; dp[1] = isStepAble[1] ? 1 : 0; dp[2] = isStepAble[2] ? dp[1] == 1 ? 2 : 1 : 0; for (int i = 3; i < dp.Count(); i++) { dp[i] = ((dp[i - 1] + dp[i - 2]) % MOD) * (isStepAble[i] ? 1 : 0); } Console.WriteLine(dp.Last()); } } }
using System; using System.Linq; using System.Collections.Generic; namespace C { class Program { static void Main(string[] args) { var nm = Console.ReadLine().Split().Select(int.Parse).ToArray(); var a = new int[nm[1]]; var isStepAble = new bool[nm[0] + 1]; int MOD = 1000000007; a = a.Select(x => x = int.Parse(Console.ReadLine())).ToArray(); for (int i = 0; i < isStepAble.Count(); i++) { isStepAble[i] = true; } foreach (var x in a) { isStepAble[x] = false; } var dp = new int[nm[0] + 1]; dp[0] = 1; dp[1] = isStepAble[1] ? 1 : 0; // dp[2] = isStepAble[2] ? dp[1] == 1 ? 2 : 1 : 0; for (int i = 2; i < dp.Count(); i++) { dp[i] = ((dp[i - 1] + dp[i - 2]) % MOD) * (isStepAble[i] ? 1 : 0); } Console.WriteLine(dp.Last()); } } }
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 1, 0, 11, 12, 41, 15, 204, 205, 22], ["-", 0, 11, 12, 41, 15, 204, 206, 207, 0, 70], ["-", 12, 41, 15, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 11, 12, 41, 15, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 75, 203], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 12, 41, 64, 41, 15, 16, 31, 204, 205, 22], ["-", 64, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 12, 41, 64, 41, 15, 16, 17, 60], ["-", 0, 11, 12, 41, 64, 41, 15, 16, 12, 203], ["-", 0, 1, 0, 11, 12, 41, 64, 41, 64, 203], ["-", 0, 1, 0, 11, 12, 41, 64, 41, 0, 102], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
288
27
using System; using System.Collections.Generic; using System.IO; using System.Linq; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here string L = Cin; const int mod = 1000000007; long countFree = 1, countLimit = 1; for (int i = L.Length - 1; i > 0; i--) { countFree *= 3; countLimit *= L[i] == '1' ? 3 : 1; countFree %= mod; countLimit %= mod; } Coutln((countFree + (2 * countLimit % mod)) % mod); } // Other Functions Here } class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public PriorityQueue() {} public void Push(T item, int priority) { var itemIndex = _list.Count; _list.Add(Tuple.Create(priority, item)); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { var item = _list[0].Item2; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null) { if (_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) _list[index] = _list[childrenIndex.Item1]; else _list[index] = _list[childrenIndex.Item2]; } return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public static void Cout(object o) { _writer.Write(o); } public static void CoutF(object o) { _writer.Write(o); _writer.Flush(); } public static void Coutln(object o) { _writer.WriteLine(o); } public static void CoutlnF(object o) { _writer.WriteLine(o); _writer.Flush(); } public static void Flush() { _writer.Flush(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using Extensions; using static System.Math; using static Extensions.MathExtension; using static Extensions.ConsoleInputExtension; using static Extensions.ConsoleOutputExtension; class Solver { public void Solve() { // Solve Code Here string L = Cin; const int mod = 1000000007; long countFree = 1, countLimit = 1; for (int i = L.Length - 1; i > 0; i--) { countLimit = L[i] == '0' ? countLimit : countLimit * 2 + countFree; countLimit %= mod; countFree *= 3; countFree %= mod; } Coutln((countFree + 2 * countLimit % mod) % mod); } // Other Functions Here } class EntryPoint { static void Main(string[] args) { new Solver().Solve(); Flush(); } } class PriorityQueue<T> { private readonly List<Tuple<int, T>> _list = new List<Tuple<int, T>>(); public PriorityQueue() {} public void Push(T item, int priority) { var itemIndex = _list.Count; _list.Add(Tuple.Create(priority, item)); int parentIndex; while ((parentIndex = GetParentIndex(itemIndex)) != -1 && priority > _list[parentIndex].Item1) { Swap(itemIndex, parentIndex); itemIndex = parentIndex; } } private int GetParentIndex(int index) { if (index == 0) return -1; return ((index + 1) >> 1) - 1; } private Tuple<int, int> GetChildrenIndex(int index) { var item2 = (index + 1) << 1; var item1 = item2 - 1; return item2 >= _list.Count ? null : Tuple.Create(item1, item2); } public T Pop() { var item = _list[0].Item2; Tuple<int, int> childrenIndex; int index = 0; while ((childrenIndex = GetChildrenIndex(index)) != null) { if (_list[childrenIndex.Item1].Item1 > _list[childrenIndex.Item2].Item1) _list[index] = _list[childrenIndex.Item1]; else _list[index] = _list[childrenIndex.Item2]; } return item; } public T Peek() { return _list[0].Item2; } private void Swap(int index1, int index2) { var tmp = _list[index1]; _list[index1] = _list[index2]; _list[index2] = tmp; } } struct Rational { private long _numerator; private long _denominator; public long Numerator => _numerator; public long Denominator => _denominator; public Rational(long numerator, long denominator) { var gcd = GCD(numerator, denominator); _numerator = numerator / gcd; _denominator = denominator / gcd; } public static Rational operator +(Rational a, Rational b) { return new Rational(a._numerator * b._denominator + b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator -(Rational a, Rational b) { return new Rational(a._numerator * b._denominator - b._numerator * a._denominator, a._denominator * b._denominator); } public static Rational operator *(Rational a, Rational b) { return new Rational(a._numerator * b._numerator, a._denominator * b._denominator); } public static Rational operator /(Rational a, Rational b) { return new Rational(a._numerator * b._denominator, a._denominator * b._numerator); } public static explicit operator Rational(int i) { return new Rational(i, 1); } public static explicit operator Rational(long l) { return new Rational(l, 1); } public static explicit operator Rational(double d) { long denominator = 1; while (d % 1 != 0) { denominator *= 2; d *= 2; } return new Rational((long)d, denominator); } public static explicit operator Rational(float f) { long denominator = 1; while (f % 1 != 0) { denominator *= 2; f *= 2; } return new Rational((long)f, denominator); } } class UnionFind { private readonly int[] _array; public UnionFind(int N) { _array = new int[N]; for (int i = 0; i < N; i++) { _array[i] = i; } } public int GetRootNode(int n) { if (_array[n] == n) return n; return _array[n] = GetRootNode(_array[n]); } public void UnionGroup(int a, int b) { var rootA = GetRootNode(a); var rootB = GetRootNode(b); if (rootA == rootB) return; _array[rootA] = rootB; } public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b); public bool IsRoot(int n) => _array[n] == n; } namespace Extensions { public class ConsoleInputExtension { private static readonly ConsoleInputExtension _cin = new ConsoleInputExtension(); public static ConsoleInputExtension Cin => _cin; private static readonly Queue<string> _inputQueue = new Queue<string>(); private ConsoleInputExtension() {} public static implicit operator string(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return _inputQueue.Dequeue(); } public static implicit operator int(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return int.Parse(_inputQueue.Dequeue()); } public static implicit operator long(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return long.Parse(_inputQueue.Dequeue()); } public static implicit operator float(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return float.Parse(_inputQueue.Dequeue()); } public static implicit operator double(ConsoleInputExtension _) { if (_inputQueue.Count == 0) Console.ReadLine().Split(' ').ForEach(val => _inputQueue.Enqueue(val)); return double.Parse(_inputQueue.Dequeue()); } } public static class ConsoleOutputExtension { private static StreamWriter _writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; public static void Cout(object o) { _writer.Write(o); } public static void CoutF(object o) { _writer.Write(o); _writer.Flush(); } public static void Coutln(object o) { _writer.WriteLine(o); } public static void CoutlnF(object o) { _writer.WriteLine(o); _writer.Flush(); } public static void Flush() { _writer.Flush(); } } public static class MathExtension { //最小公倍数 public static int LCM(int num1, int num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } public static long LCM(long num1, long num2) { var gcd = GCD(num1, num2); return num1 * (num2 / gcd); } //最大公約数 public static int GCD(int num1, int num2) { int a = Math.Max(num1, num2); int b = Math.Min(num1, num2); int mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } public static long GCD(long num1, long num2) { long a = Math.Max(num1, num2); long b = Math.Min(num1, num2); long mod; while ((mod = a % b) != 0) { a = b; b = mod; } return b; } } public static class EnumerableExtension { public delegate void Function<in T>(T val); public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function) { foreach (var x in enumerable) { function(x); } } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 11, 12, 41, 15, 16, 12, 252, 0, 253], ["+", 0, 11, 12, 41, 15, 16, 12, 252, 0, 253], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 64, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 75, 203], ["+", 0, 11, 12, 41, 75, 16, 31, 16, 31, 22], ["+", 0, 11, 12, 41, 75, 16, 31, 16, 17, 48], ["+", 0, 11, 12, 41, 75, 16, 31, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 41, 75, 16, 17, 72], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["-", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
8
1,722
26
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static long C(long n, long k) { long bunbo = 1; long bunsi = 1; for (long i = n - k; i <= n; i++) bunsi *= i; for (long i = 1; i <= n - k; i++) bunbo *= i; return bunsi / bunbo; } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var n = input[0]; var a = input[1]; var b = input[2]; var c = input[3]; var d = input[4]; var s = Console.ReadLine().ToCharArray(); var f = true; var ff = false; for (int i = 0; i < s.Length - 1; i++) { if (s[i] == s[i + 1] && s[i] == '#') f = false; if (i > 0 && a - 1 <= i && i <= c - 1 && s[i - 1] == s[i] && s[i] == s[i + 1] && s[i] == '.') ff = true; } if ((c < d && f) || (c > d && ff)) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using System.IO; namespace atcorder2 { class Program { public static long Read() { return long.Parse(Console.ReadLine()); } public static long[] Reads() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); } public static long C(long n, long k) { long bunbo = 1; long bunsi = 1; for (long i = n - k; i <= n; i++) bunsi *= i; for (long i = 1; i <= n - k; i++) bunbo *= i; return bunsi / bunbo; } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var input = Reads(); var n = input[0]; var a = input[1]; var b = input[2]; var c = input[3]; var d = input[4]; var s = Console.ReadLine().ToCharArray(); var f = true; var ff = false; for (int i = 0; i < s.Length - 1; i++) { if (a - 1 <= i && i <= d - 1 && s[i] == s[i + 1] && s[i] == '#') f = false; if (i > 0 && b - 1 <= i && i <= d - 1 && s[i - 1] == s[i] && s[i] == s[i + 1] && s[i] == '.') ff = true; } if ((c < d && f) || (c > d && ff)) Console.WriteLine("Yes"); else Console.WriteLine("No"); Console.Out.Flush(); } } }
[["+", 31, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 33], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 19], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 19], ["+", 31, 16, 31, 16, 12, 16, 12, 16, 31, 22], ["+", 31, 16, 31, 16, 12, 16, 12, 16, 17, 33], ["+", 31, 16, 31, 16, 12, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["-", 31, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["+", 31, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["-", 31, 16, 31, 16, 12, 16, 12, 16, 31, 22]]
8
401
16
using System; using System.Text; using System.Collections.Generic; using System.Collections; using static System.Math; using System.Linq; using static System.Array; namespace ConsoleApp2 { class Program { // static int N; // static long mod = 1000000007; // static char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => // (Char)i).ToArray(); static void Main(string[] args) { // var N = long.Parse(Console.ReadLine()); // var A = Console.ReadLine().Split(' ').Select(x => // long.Parse(x)).ToArray(); var S = Console.ReadLine().ToCharArray(); long ans = 0; var sumA = 0; for (int i = 0; i < S.Length; i++) { if (S[i] == 'A') { while (i < S.Length && S[i] == 'A') { sumA++; i++; } } else if (i < S.Length - 1 && S[i] == 'B' && S[i + 1] == 'C') { ans += sumA; i++; } else { sumA = 0; } } Console.WriteLine(ans); // R = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); // var S = Console.ReadLine(); } } }
using System; using System.Text; using System.Collections.Generic; using System.Collections; using static System.Math; using System.Linq; using static System.Array; namespace ConsoleApp2 { class Program { // static int N; // static long mod = 1000000007; // static char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => // (Char)i).ToArray(); static void Main(string[] args) { // var N = long.Parse(Console.ReadLine()); // var A = Console.ReadLine().Split(' ').Select(x => // long.Parse(x)).ToArray(); var S = Console.ReadLine().ToCharArray(); long ans = 0; var sumA = 0; for (int i = 0; i < S.Length; i++) { if (S[i] == 'A') { sumA++; } else if (i < S.Length - 1 && S[i] == 'B' && S[i + 1] == 'C') { ans += sumA; i++; } else { sumA = 0; } } Console.WriteLine(ans); // R = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); // var S = Console.ReadLine(); } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 52, 0, 89], ["-", 8, 196, 0, 57, 64, 196, 0, 52, 0, 24], ["-", 64, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["-", 64, 196, 0, 52, 15, 16, 31, 16, 17, 18], ["-", 0, 52, 15, 16, 31, 16, 12, 214, 205, 22], ["-", 0, 52, 15, 16, 31, 16, 12, 214, 0, 131], ["-", 0, 52, 15, 16, 31, 16, 12, 214, 141, 22], ["-", 0, 57, 64, 196, 0, 52, 15, 16, 17, 98], ["-", 0, 52, 15, 16, 12, 16, 31, 204, 205, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 52, 15, 16, 12, 16, 17, 60], ["-", 0, 52, 15, 16, 12, 16, 12, 252, 0, 104], ["-", 0, 52, 15, 16, 12, 16, 12, 252, 0, 253], ["-", 8, 196, 0, 57, 64, 196, 0, 52, 0, 25], ["-", 0, 57, 64, 196, 0, 52, 8, 196, 0, 45], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 64, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 52, 8, 196, 0, 46]]
8
198
22
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = rstr(); long a = 0; long ans = 0; for (int i = 0; i < n.Length; i++) { if (n[i] == 'A') { a++; } else if (n[i] == 'B' && i < n.Length - 1) { if (n[i + 1] == 'C') { ans += a; i++; } } else { a = 0; } } WriteLine(ans); } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = rstr(); long a = 0; long ans = 0; for (int i = 0; i < n.Length; i++) { if (n[i] == 'A') { a++; } else if (n[i] == 'B' && i < n.Length - 1) { if (n[i + 1] == 'C') { ans += a; i++; } else { a = 0; } } else { a = 0; } } WriteLine(ans); } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } }
[["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 95], ["+", 75, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46]]
8
1,194
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC034 { class B { static void Main(string[] args) { long numBC = 0; string s = Console.ReadLine(); long sum = 0; char p1 = '0', p2 = '0'; for (int i = 0; i < s.Length; i++) { int j = s.Length - i - 1; if (s[j] == 'B') { if (p1 == 'C') numBC++; else numBC = 0; } else if (s[j] == 'A') { sum += numBC; } else { if (!(p1 == 'A') && !(p1 == 'B' && p2 == 'C')) numBC = 0; } p2 = p1; p1 = s[j]; } Console.WriteLine(sum); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC034 { class B { static void Main(string[] args) { long numBC = 0; string s = Console.ReadLine(); long sum = 0; char p1 = '0', p2 = '0'; for (int i = 0; i < s.Length; i++) { int j = s.Length - i - 1; if (s[j] == 'B') { if (p1 == 'C') numBC++; else numBC = 0; } else if (s[j] == 'A') { if (p1 == 'C') numBC = 0; sum += numBC; } else { if (!(p1 == 'A') && !(p1 == 'B' && p2 == 'C')) numBC = 0; } p2 = p1; p1 = s[j]; } Console.WriteLine(sum); } } }
[["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 121], ["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 24], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["+", 64, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 0, 57, 75, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 75, 57, 64, 196, 0, 57, 64, 1, 0, 35]]
8
205
12
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int32; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var X = rl; var a = Enumerate(n, x => new long[] { rl, rl, rl }); var sum = 0L; foreach (var x in a) sum += x[0] * x[1]; Debug.WriteLine(sum); Array.Sort(a, (l, r) => (l[2] * (X - l[0]) + l[0] * l[1]) .CompareTo(r[2] * (X - r[0]) + r[0] * r[1])); Array.Reverse(a); var b = new long[n + 1]; for (int i = 0; i < n; i++) b[i + 1] = b[i] + a[i][2] * (X - a[i][0]) + a[i][0] * a[i][1]; Debug.WriteLine(b.AsJoinedString()); var min = INF; var k = n - 1; for (int i = 0; i < n; i++) { while (true) { var val = b[k]; var p = a[i][0]; var L = a[i][1]; var R = a[i][2]; if (i < k) { val = b[k + 1]; val -= R * (X - p) + p * L; } val -= sum; if (val >= 0) k--; else { val *= -1; if ((val + L - 1) / L <= p) { min = Min(min, k * X + (val + L - 1) / L); } else { val -= L * p; if ((val + R - 1) / R <= X - p) min = Min(min, k * X + p + (val + R - 1) / R); } break; } } } Console.WriteLine(min); } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = true }); var solver = new Program.Solver(); /* var t = new System.Threading.Thread(solver.Solve, 50000000); t.Start(); t.Join(); */ solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> 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); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> 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); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion #region Binomial Coefficient public class BinomialCoefficient { public ModInt[] fact, ifact; public BinomialCoefficient(int n) { fact = new ModInt[n + 1]; ifact = new ModInt[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; ifact[n] = ModInt.Inverse(fact[n]); for (int i = n - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1); ifact[0] = ifact[1]; } public ModInt this[int n, int r] { get { if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0; return fact[n] * ifact[n - r] * ifact[r]; } } public ModInt RepeatedCombination(int n, int k) { if (k == 0) return 1; return this[n + k - 1, k]; } } #endregion
using System; using System.Linq; using System.Collections.Generic; using System.Diagnostics; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using System.Numerics; using static System.Math; using Number = System.Int32; namespace Program { public class Solver { Random rnd = new Random(); public void Solve() { var n = ri; var X = rl; var a = Enumerate(n, x => new long[] { rl, rl, rl }); var sum = 0L; foreach (var x in a) sum += x[0] * x[1]; if (sum == 0) { Console.WriteLine(0); return; } Debug.WriteLine(sum); Array.Sort(a, (l, r) => (l[2] * (X - l[0]) + l[0] * l[1]) .CompareTo(r[2] * (X - r[0]) + r[0] * r[1])); Array.Reverse(a); var b = new long[n + 1]; for (int i = 0; i < n; i++) b[i + 1] = b[i] + a[i][2] * (X - a[i][0]) + a[i][0] * a[i][1]; Debug.WriteLine(b.AsJoinedString()); var min = INF; var k = n - 1; for (int _ = 0; _ < 2; _++) { for (int i = 0; i < n; i++) { while (true) { var val = b[k]; var p = a[i][0]; var L = a[i][1]; var R = a[i][2]; if (i < k) { val = b[k + 1]; val -= R * (X - p) + p * L; } val -= sum; if (val >= 0) k--; else { val *= -1; if ((val + L - 1) / L <= p) { min = Min(min, k * X + (val + L - 1) / L); } else { val -= L * p; if ((val + R - 1) / R <= X - p) min = Min(min, k * X + p + (val + R - 1) / R); } break; } } } } Debug.WriteLine(k); Console.WriteLine(min); } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput()); static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = true }); var solver = new Program.Solver(); /* var t = new System.Threading.Thread(solver.Solve, 50000000); t.Start(); t.Join(); */ solver.Solve(); Console.Out.Flush(); } } #endregion #region Ex namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { /// <summary> /// 剰余を取る値. /// </summary> public const long Mod = (int)1e9 + 7; /// <summary> /// 実際の数値. /// </summary> public long num; /// <summary> /// 値が <paramref name="n"/> であるようなインスタンスを構築します. /// </summary> /// <param name="n">インスタンスが持つ値</param> /// <remarks>パフォーマンスの問題上,コンストラクタ内では剰余を取りません.そのため,<paramref /// name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> /// を渡してください.このコンストラクタは O(1) で実行されます.</remarks> public ModInt(long n) { num = n; } /// <summary> /// このインスタンスの数値を文字列に変換します. /// </summary> /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 /// 進表記したもの.</returns> 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); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } /// <summary> /// 与えられた 2 つの数値からべき剰余を計算します. /// </summary> /// <param name="v">べき乗の底</param> /// <param name="k">べき指数</param> /// <returns>繰り返し二乗法により O(N log N) で実行されます.</returns> 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); } /// <summary> /// 与えられた数の逆元を計算します. /// </summary> /// <param name="v">逆元を取る対象となる数</param> /// <returns>逆元となるような値</returns> /// <remarks>法が素数であることを仮定して,フェルマーの小定理に従って逆元を /// O(log N) で計算します.</remarks> public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } #endregion #region Binomial Coefficient public class BinomialCoefficient { public ModInt[] fact, ifact; public BinomialCoefficient(int n) { fact = new ModInt[n + 1]; ifact = new ModInt[n + 1]; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i; ifact[n] = ModInt.Inverse(fact[n]); for (int i = n - 1; i >= 0; i--) ifact[i] = ifact[i + 1] * (i + 1); ifact[0] = ifact[1]; } public ModInt this[int n, int r] { get { if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0; return fact[n] * ifact[n - r] * ifact[r]; } } public ModInt RepeatedCombination(int n, int k) { if (k == 0) return 1; return this[n + k - 1, k]; } } #endregion
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 24], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 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], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
1,846
40
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int N = int.Parse(str[0]); long X = long.Parse(str[1]); long[][] A = new long [N][]; for (var i = 0; i < N; i++) { string[] str2 = Console.ReadLine().Split(); A[i] = new long[3]; A[i][0] = long.Parse(str2[0]); A[i][1] = long.Parse(str2[1]); A[i][2] = long.Parse(str2[2]); } Array.Sort(A, (x, y) => ((y[0] * y[1] + (X - y[0]) * y[2])) .CompareTo(x[0] * x[1] + (X - x[0]) * x[2])); long[] S1 = new long[N + 1]; long[] S2 = new long[N + 1]; long[] S3 = new long[N + 1]; long[] S4 = new long[N + 1]; long[] S5 = new long[N + 1]; long[] C = new long[N + 1]; for (var i = 0; i < N; i++) { S1[i + 1] = S1[i] + X * A[i][2]; C[i + 1] = C[i] + X; S2[i + 1] = S2[i] + A[i][0] * A[i][2]; S4[i + 1] = S4[i] + A[i][0] * A[i][1] + (X - A[i][0]) * A[i][2]; S5[i + 1] = S5[i] + A[i][0] * A[i][1]; } for (var i = N - 1; i >= 0; i--) { S3[i] = S3[i + 1] + A[i][0] * A[i][1]; } long ans = 999999999999999999; for (var i = 0; i < N; i++) { int min = 0; int max = N - 1; while (min < max) { int m = (min + max) / 2; long sum; if (m > i) { sum = S4[m + 1] - S5[N]; } else { sum = S4[m] - S5[N]; sum += A[i][0] * A[i][1] + (X - A[i][0]) * A[i][2]; } if (sum >= 0) { max = m; } else { min = m + 1; } } long s; if (min > i) { s = S4[min + 1] - S5[N] - (A[i][0] * A[i][1] + (X - A[i][0]) * A[i][2]); } else { s = S4[min] - S5[N]; } long cs = X * min; if (s > 0) { s = 0; } if (-s > A[i][0] * A[i][1]) { cs += A[i][0] + (-s - A[i][0] * A[i][1] - 1) / A[i][2] + 1; } else { cs += (-s - 1) / A[i][1] + 1; } ans = Math.Min(cs, ans); } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int N = int.Parse(str[0]); long X = long.Parse(str[1]); long[][] A = new long [N][]; for (var i = 0; i < N; i++) { string[] str2 = Console.ReadLine().Split(); A[i] = new long[3]; A[i][0] = long.Parse(str2[0]); A[i][1] = long.Parse(str2[1]); A[i][2] = long.Parse(str2[2]); } Array.Sort(A, (x, y) => ((y[0] * y[1] + (X - y[0]) * y[2])) .CompareTo(x[0] * x[1] + (X - x[0]) * x[2])); long[] S1 = new long[N + 1]; long[] S2 = new long[N + 1]; long[] S3 = new long[N + 1]; long[] S4 = new long[N + 1]; long[] S5 = new long[N + 1]; long[] C = new long[N + 1]; for (var i = 0; i < N; i++) { S1[i + 1] = S1[i] + X * A[i][2]; C[i + 1] = C[i] + X; S2[i + 1] = S2[i] + A[i][0] * A[i][2]; S4[i + 1] = S4[i] + A[i][0] * A[i][1] + (X - A[i][0]) * A[i][2]; S5[i + 1] = S5[i] + A[i][0] * A[i][1]; } for (var i = N - 1; i >= 0; i--) { S3[i] = S3[i + 1] + A[i][0] * A[i][1]; } long ans = 999999999999999999; for (var i = 0; i < N; i++) { int min = 0; int max = N - 1; while (min < max) { int m = (min + max) / 2; long sum; if (m > i) { sum = S4[m + 1] - S5[N]; } else { sum = S4[m] - S5[N]; sum += A[i][0] * A[i][1] + (X - A[i][0]) * A[i][2]; } if (sum >= 0) { max = m; } else { min = m + 1; } } long s; if (min > i) { s = S4[min + 1] - S5[N] - (A[i][0] * A[i][1] + (X - A[i][0]) * A[i][2]); } else { s = S4[min] - S5[N]; } long cs = X * min; if (s < 0) { if (-s > A[i][0] * A[i][1]) { cs += A[i][0] + (-s - A[i][0] * A[i][1] - 1) / A[i][2] + 1; } else { cs += (-s - 1) / A[i][1] + 1; } } ans = Math.Min(cs, ans); } Console.WriteLine(ans); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46]]
8
879
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemB { class Program { static void Main(string[] args) { var str = Console.ReadLine(); var first = int.Parse(str.Substring(0, 2)); Console.WriteLine((first - 2) * 180); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemB { class Program { static void Main(string[] args) { var str = Console.ReadLine(); var first = int.Parse(str); Console.WriteLine((first - 2) * 180); } } }
[["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
85
7
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; namespace ac2 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); var s = Console.ReadLine(); var k = s.Length; var r = (15 - k) + s.Count(x => x == 'o') >= 8 ? "YES" : "NO"; Console.WriteLine(r); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; namespace ac2 { class Program { static void Main(string[] args) { var s = Console.ReadLine(); var k = s.Length; var r = (15 - k) + s.Count(x => x == 'o') >= 8 ? "YES" : "NO"; Console.WriteLine(r); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 104], ["-", 0, 213, 3, 4, 0, 28, 0, 252, 0, 253], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
8
127
18
using System; using System.IO; using System.Linq; class Program { static void Solve() { var S = Read(); var rest = 15 - S.Length; var win = 0; foreach (var s in S) { if (s == 'o') win++; } if (win + rest >= 8) Console.WriteLine(win + rest >= 8 ? "YES" : "NO"); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static string Read() { return Console.ReadLine(); } public static int ReadInt() { return int.Parse(Read()); } public static long ReadLong() { return long.Parse(Read()); } public static double ReadDouble() { return double.Parse(Read()); } public static string[] Reads() { return Console.ReadLine().Split(' '); } public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); } public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); } public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); } }
using System; using System.IO; using System.Linq; class Program { static void Solve() { var S = Read(); var rest = 15 - S.Length; var win = 0; foreach (var s in S) { if (s == 'o') win++; } Console.WriteLine(win + rest >= 8 ? "YES" : "NO"); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static string Read() { return Console.ReadLine(); } public static int ReadInt() { return int.Parse(Read()); } public static long ReadLong() { return long.Parse(Read()); } public static double ReadDouble() { return double.Parse(Read()); } public static string[] Reads() { return Console.ReadLine().Split(' '); } public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); } public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); } public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25]]
8
326
8
using System; using System.Linq; class Program { public static void Main() { var line = Console.ReadLine().Split(' ').Select(p => long.Parse(p)).ToArray(); long N = line[0]; long M = line[1]; long r = 0; long r_ = 1; long r__ = 0; bool k = true; bool[] broken = new bool[N + 1]; for (long i = 0; i < M; i++) { broken[long.Parse(Console.ReadLine())] = true; } for (long i = 1; i <= N; i++) { if (broken[i]) { r = 0; } else { r = r_ + r__; } r__ = r_; r_ = r; } Console.WriteLine(r % 1000000007); } }
using System; using System.Linq; class Program { public static void Main() { var line = Console.ReadLine().Split(' ').Select(p => long.Parse(p)).ToArray(); long N = line[0]; long M = line[1]; long r = 0; long r_ = 1; long r__ = 0; bool k = true; bool[] broken = new bool[N + 1]; for (long i = 0; i < M; i++) { broken[long.Parse(Console.ReadLine())] = true; } for (long i = 1; i <= N; i++) { if (broken[i]) { r = 0; } else { r = r_ + r__; r = r % 1000000007; } r__ = r_; r_ = r; } Console.WriteLine(r); } }
[["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
188
8
using System; public class S { private const bool FINE = true; private const bool BROKEN = false; public static void Main() { var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var stairCount = input[0]; var brokenStairCount = input[1]; var stairs = new bool[stairCount + 1]; var patterns = new long[stairCount + 1]; for (long i = 0; i < stairCount; i++) { stairs[i] = FINE; patterns[i] = 0; } for (long i = 0; i < brokenStairCount; i++) { stairs[long.Parse(Console.ReadLine()) - 1] = BROKEN; } patterns[0] = stairs[0] ? 1 : 0; patterns[1] = stairs[1] ? 1 : 0; patterns[1] += stairs[0] ? 1 : 0; stairs[stairCount] = BROKEN; for (long i = 2; i < stairCount; i++) { if (stairs[i] == FINE) { patterns[i] = patterns[i - 1] + patterns[i - 2]; } else { patterns[i] = 0; } patterns[i] %= 1000000007; } Console.WriteLine(patterns[stairCount - 1] % 1000000007); } }
using System; public class S { private const bool FINE = true; private const bool BROKEN = false; public static void Main() { var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var stairCount = input[0]; var brokenStairCount = input[1]; var stairs = new bool[stairCount + 1]; var patterns = new long[stairCount + 1]; for (long i = 0; i < stairCount; i++) { stairs[i] = FINE; patterns[i] = 0; } for (long i = 0; i < brokenStairCount; i++) { stairs[long.Parse(Console.ReadLine()) - 1] = BROKEN; } patterns[0] = stairs[0] ? 1 : 0; patterns[1] = stairs[1] ? stairs[0] ? 2 : 1 : 0; stairs[stairCount] = BROKEN; for (long i = 2; i < stairCount; i++) { if (stairs[i] == FINE) { patterns[i] = patterns[i - 1] + patterns[i - 2]; } else { patterns[i] = 0; } patterns[i] %= 1000000007; } Console.WriteLine(patterns[stairCount - 1] % 1000000007); } }
[["-", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["-", 8, 196, 0, 1, 0, 11, 12, 41, 75, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 41, 64, 41, 64, 203], ["+", 0, 1, 0, 11, 12, 41, 64, 41, 0, 102]]
8
283
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { class Program { static void Main(string[] args) { var NM = ReadSplitLong(); var n = NM[0]; var m = NM[1]; var a = ReadSplitLongLines(m); var dp = new long[n + 1]; var instrusion = new bool[n + 1]; // 1段目への移動方法数 dp[0] = 1; // 侵入負荷の段数設定(trueが侵入負荷) for (long i = 0; i < m; i++) { instrusion[a[i][0]] = true; } for (long i = 0; i <= n; i++) { // 1段か2段先へ移動 for (long j = 1; j <= 2; j++) { if (i + j <= n) { // 侵入不可への移動はできない if (instrusion[i + j] != true) { // i番目からi+j番目への移動 dp[i + j] += dp[i]; } } } } Console.WriteLine(dp[n] % 1000000007); Console.ReadKey(); } #region MyRegion public static int ReadInt() { return int.Parse(Console.ReadLine()); } /// <summary> /// 空白区切の数値を取得する /// </summary> /// <returns>The read split int.</returns> public static int[] ReadSplitInt() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } /// <summary> /// 空白区切の数値を取得 /// </summary> /// <returns>The read split long.</returns> public static long[] ReadSplitLong() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } public static int[][] ReadSplitIntLines(int n) { return Enumerable.Range(0, n).Select(x => ReadSplitInt()).ToArray(); } public static long[][] ReadSplitLongLines(int n) { return Enumerable.Range(0, n).Select(x => ReadSplitLong()).ToArray(); } public static long[][] ReadSplitLongLines(long n) { var ret = new List<long[]>(); for (long i = 0; i < n; i++) { ret.Add(ReadSplitLong().ToArray()); } return ret.ToArray(); } #endregion } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { class Program { static void Main(string[] args) { var NM = ReadSplitLong(); var n = NM[0]; var m = NM[1]; var a = ReadSplitLongLines(m); var dp = new long[n + 1]; var instrusion = new bool[n + 1]; // 1段目への移動方法数 dp[0] = 1; // 侵入負荷の段数設定(trueが侵入負荷) for (long i = 0; i < m; i++) { instrusion[a[i][0]] = true; } for (long i = 0; i <= n; i++) { // 1段か2段先へ移動 for (long j = 1; j <= 2; j++) { if (i + j <= n) { // 侵入不可への移動はできない if (instrusion[i + j] != true) { // i番目からi+j番目への移動 dp[i + j] += dp[i]; dp[i + j] %= 1000000007; } } } } Console.WriteLine(dp[n]); Console.ReadKey(); } #region MyRegion public static int ReadInt() { return int.Parse(Console.ReadLine()); } /// <summary> /// 空白区切の数値を取得する /// </summary> /// <returns>The read split int.</returns> public static int[] ReadSplitInt() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); } /// <summary> /// 空白区切の数値を取得 /// </summary> /// <returns>The read split long.</returns> public static long[] ReadSplitLong() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); } public static int[][] ReadSplitIntLines(int n) { return Enumerable.Range(0, n).Select(x => ReadSplitInt()).ToArray(); } public static long[][] ReadSplitLongLines(int n) { return Enumerable.Range(0, n).Select(x => ReadSplitLong()).ToArray(); } public static long[][] ReadSplitLongLines(long n) { var ret = new List<long[]>(); for (long i = 0; i < n; i++) { ret.Add(ReadSplitLong().ToArray()); } return ret.ToArray(); } #endregion } }
[["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
475
11
using System; using System.Linq; namespace abc129 { class C2 { const int MOD = 1000000007; static public bool[] isHolls; static void Main(string[] args) { var input = Input.IntArray(); var N = input[0]; var M = input[1]; isHolls = new bool[N + 1]; for (int i = 0; i < M; i++) { isHolls[Input.Int()] = true; } var dp = new long[N + 1]; for (int now = 0; now < N; now++) { for (int next = now + 1; next < Math.Min(N, now + 2); next++) { dp[next] += dp[now]; dp[next] %= MOD; } } Console.WriteLine(dp[N]); } /** Input Class */ internal static class Input { /** input int */ public static int Int() => int.Parse(Console.ReadLine()); /** input str */ public static string Str() => Console.ReadLine(); /** input array of int */ public static int[] IntArray() => Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); /** input array of string */ public static string[] StrArray() => Input.Str().Split(' '); /** input array of char */ public static char[] charArray() => Input.Str().ToCharArray(); } } }
using System; using System.Linq; namespace abc129 { class C2 { const int MOD = 1000000007; static public bool[] isHolls; static void Main(string[] args) { var input = Input.IntArray(); var N = input[0]; var M = input[1]; isHolls = new bool[N + 1]; for (int i = 0; i < M; i++) { isHolls[Input.Int()] = true; } var dp = new long[N + 1]; dp[0] = 1; for (int now = 0; now < N; now++) { for (int next = now + 1; next <= Math.Min(N, now + 2); next++) { if (!isHolls[next]) { dp[next] += dp[now]; dp[next] %= MOD; } } } Console.WriteLine(dp[N]); } /** Input Class */ internal static class Input { /** input int */ public static int Int() => int.Parse(Console.ReadLine()); /** input str */ public static string Str() => Console.ReadLine(); /** input array of int */ public static int[] IntArray() => Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); /** input array of string */ public static string[] StrArray() => Input.Str().Split(' '); /** input array of char */ public static char[] charArray() => Input.Str().ToCharArray(); } } }
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 241, 0, 111], ["+", 8, 196, 0, 57, 15, 241, 0, 204, 205, 22], ["+", 0, 57, 15, 241, 0, 204, 206, 207, 0, 70], ["+", 15, 241, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 241, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
300
19
using System; using System.Collections.Generic; using System.Linq; namespace atcoder { class Program { static long p = 0; static int[] ng; static void Main(string[] args) { string[] inputs = Console.ReadLine().Split(' '); int n = int.Parse(inputs[0]) + 1; int m = int.Parse(inputs[1]); ng = new int[n]; for (int i = 0; i < n; i++) ng[i] = 0; for (int i = 0; i < m; i++) ng[int.Parse(Console.ReadLine())] = 1; long[] nums = new long[n]; nums[0] = 1; for (int i = 0; i < n; i++) { if (ng[i] == 0) { if (i + 1 < n) { nums[i + 1] += nums[i]; nums[i + 1] %= 1000000007; } if (i + 2 < n) { nums[i + 2] += nums[i]; nums[i + 2] %= 1000000007; } } } Console.WriteLine(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace atcoder { class Program { static long p = 0; static int[] ng; static void Main(string[] args) { string[] inputs = Console.ReadLine().Split(' '); int n = int.Parse(inputs[0]) + 1; int m = int.Parse(inputs[1]); ng = new int[n]; for (int i = 0; i < n; i++) ng[i] = 0; for (int i = 0; i < m; i++) ng[int.Parse(Console.ReadLine())] = 1; long[] nums = new long[n]; nums[0] = 1; for (int i = 0; i < n; i++) { if (ng[i] == 0) { if (i + 1 < n) { nums[i + 1] += nums[i]; nums[i + 1] %= 1000000007; } if (i + 2 < n) { nums[i + 2] += nums[i]; nums[i + 2] %= 1000000007; } } } Console.WriteLine(nums[nums.Length - 1]); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 206, 207, 0, 28, 0, 16, 31, 214, 141, 22], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73]]
8
264
8
using System; using System.Collections.Generic; using System.Linq; namespace ProjectContest { class Test { static void Main() { const int mod = 1000000007; var nm = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32); int n = nm[0], m = nm[1]; var F = new int[n + 1]; F[0] = F[1] = 1; var a = new int[m]; for (int i = 0; i < m; i++) a[i] = Convert.ToInt32(Console.ReadLine()); int count = 0; if (a[0] == 1) { F[1] = 0; count = 1; } for (int i = 2; i < n + 1; i++) { if (count < m && i == a[count]) { F[i] = 0; count++; } else { F[i] = (F[i - 1] + F[i - 2]) % mod; } } Console.WriteLine(F[n]); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ProjectContest { class Test { static void Main() { const int mod = 1000000007; var nm = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32); int n = nm[0], m = nm[1]; var F = new int[n + 1]; F[0] = F[1] = 1; var a = new int[m + 1]; for (int i = 0; i < m; i++) a[i] = Convert.ToInt32(Console.ReadLine()); a[m] = 0; int count = 0; if (a[0] == 1) { F[1] = 0; count = 1; } for (int i = 2; i < n + 1; i++) { if (i == a[count]) { F[i] = 0; count++; } else { F[i] = (F[i - 1] + F[i - 2]) % mod; } } Console.WriteLine(F[n]); } } }
[["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
241
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Q3 { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] strs = line.Split(' '); int N = int.Parse(strs[0]); int M = int.Parse(strs[1]); bool[] staris_broken = new bool[N]; for (int i = 0; i < N; i++) staris_broken[i] = false; for (int i = 0; i < M; i++) { staris_broken[int.Parse(Console.ReadLine())] = true; } long[] count = new long[N + 1]; for (int i = 0; i <= N; i++) count[i] = 0; count[0] = 1; for (int i = 0; i < N; i++) { if ((i + 1 < N && !staris_broken[i + 1]) || i + 1 == N) { count[i + 1] += count[i]; } if ((i + 2 < N && !staris_broken[i + 2]) || i + 2 == N) { count[i + 2] += count[i]; } } Console.WriteLine(count[N] % 1000000007); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Q3 { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] strs = line.Split(' '); int N = int.Parse(strs[0]); int M = int.Parse(strs[1]); bool[] staris_broken = new bool[N]; for (int i = 0; i < N; i++) staris_broken[i] = false; for (int i = 0; i < M; i++) { staris_broken[int.Parse(Console.ReadLine())] = true; } long[] count = new long[N + 1]; for (int i = 0; i <= N; i++) count[i] = 0; count[0] = 1; for (int i = 0; i < N; i++) { if ((i + 1 < N && !staris_broken[i + 1]) || i + 1 == N) { count[i + 1] += count[i]; count[i + 1] %= 1000000007; } if ((i + 2 < N && !staris_broken[i + 2]) || i + 2 == N) { count[i + 2] += count[i]; count[i + 2] %= 1000000007; } } Console.WriteLine(count[N]); } } }
[["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 132], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
304
20
using System; using System.Linq; public class Test { public static void Main() { // your code goes here var b = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int n = b[0]; int m = b[1]; bool[] isBroken = new bool[n + 10]; for (int i = 0; i < m; i++) { int input = int.Parse(Console.ReadLine()); isBroken[input] = true; } long[] dp = new long[n + 10]; dp[0] = 1; for (int i = 1; i <= n; i++) { if (isBroken[i]) { dp[i] = 0; } else { if (i == 1) { dp[i] = dp[i - 1]; } else { dp[i] = dp[i - 1] + dp[i - 2]; } } } Console.WriteLine(dp[n]); } }
using System; using System.Linq; public class Test { public static void Main() { // your code goes here var b = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); int n = b[0]; int m = b[1]; bool[] isBroken = new bool[n + 10]; for (int i = 0; i < m; i++) { int input = int.Parse(Console.ReadLine()); isBroken[input] = true; } long[] dp = new long[n + 10]; dp[0] = 1; long mod = 1000000007; for (int i = 1; i <= n; i++) { if (isBroken[i]) { dp[i] = 0; } else { if (i == 1) { dp[i] = dp[i - 1]; dp[i] = dp[i] % mod; } else { dp[i] = dp[i - 1] + dp[i - 2]; dp[i] = dp[i] % mod; } } } Console.WriteLine(dp[n]); } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
224
29
using System; using System.Collections.Generic; class ABC_129_C { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int[] A = new int[M]; for (int i = 0; i < M; i++) { A[i] = int.Parse(Console.ReadLine()); if (i > 0 && A[i - 1] + 1 == A[i]) { Console.WriteLine(0); return; } } int bi = M == 0 ? -1 : 0; ulong[] pattern = new ulong[N + 1]; pattern[0] = 1L; for (int i = 0; i < N; i++) { if (bi >= 0 && bi < M && A[bi] == i) { pattern[i] = 0L; bi++; } pattern[i + 1] += pattern[i]; if (i + 1 < N) pattern[i + 2] += pattern[i]; } Console.WriteLine(pattern[N] % 1000000007L); } }
using System; using System.Collections.Generic; class ABC_129_C { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int M = int.Parse(input[1]); int[] A = new int[M]; for (int i = 0; i < M; i++) { A[i] = int.Parse(Console.ReadLine()); if (i > 0 && A[i - 1] + 1 == A[i]) { Console.WriteLine(0); return; } } int bi = M == 0 ? -1 : 0; ulong[] pattern = new ulong[N + 1]; pattern[0] = 1L; for (int i = 0; i < N; i++) { if (bi >= 0 && bi < M && A[bi] == i) { pattern[i] = 0L; bi++; } pattern[i + 1] += pattern[i] % 1000000007UL; if (i + 1 < N) pattern[i + 2] += pattern[i] % 1000000007UL; } Console.WriteLine(pattern[N] % 1000000007UL); } }
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 109], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
264
6
using System; using System.Collections.Generic; using System.Text; using System.Numerics; namespace SolutionCS { class Program { class modMCalc { public const int M = 1000000007; // 素数(int範囲) // 乗算結果 % Mを求める static public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } // 冪乗(mod M) static public int Pow(int a, int m) { if (0 == m) { return 1; } if (1 == m) { return a; } int result = 1; int param = a; for (; m > 0; m >>= 1) { if ((m & 0x01) == 1) { result = Mul(result, param); } param = Mul(param, param); } return result; } // 除算(mod M) static public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } } class CombinationPermutation { private readonly int[] fac; // コンストラクタ // (mod Mの)階乗テーブル作成する public CombinationPermutation(int n) { fac = new int[n + 1]; fac[0] = 1; for (int i = 1; i <= n; ++i) { fac[i] = modMCalc.Mul(fac[i - 1], i); } } // 階乗求める public int Factorial(int n) { return fac[n]; } // nCr public int nCr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = modMCalc.Div(res, Factorial(r)); res = modMCalc.Div(res, Factorial(n - r)); return res; } } static void Main(string[] args) { string[] inS = Console.ReadLine().Split(' '); int N = int.Parse(inS[0]); int M = int.Parse(inS[1]); int[] b = new int[M + 2]; b[0] = 0; for (int i = 0; i < M; i++) { b[i + 1] = int.Parse(Console.ReadLine()); // 一番最初以外が連続していたら終了 if (i != 0 && (b[i] + 1 == b[i + 1])) { Console.WriteLine(0); return; } } b[M + 1] = N; CombinationPermutation c = new CombinationPermutation(N); int ans = 1; for (int i = 0; i <= M; i++) { int p = 0; int w = b[i + 1] - b[i] - 1; int s = w % 2; while (s <= w) { int a = c.nCr(w, s); p += a; p %= modMCalc.M; s += 2; } ans = modMCalc.Mul(ans, p); } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; namespace SolutionCS { class Program { class modMCalc { public const int M = 1000000007; // 素数(int範囲) // 乗算結果 % Mを求める static public int Mul(int a, int b) { return (int)(Math.BigMul(a, b) % M); } // 冪乗(mod M) static public int Pow(int a, int m) { if (0 == m) { return 1; } if (1 == m) { return a; } int result = 1; int param = a; for (; m > 0; m >>= 1) { if ((m & 0x01) == 1) { result = Mul(result, param); } param = Mul(param, param); } return result; } // 除算(mod M) static public int Div(int a, int b) { return Mul(a, Pow(b, M - 2)); } } class CombinationPermutation { private readonly int[] fac; // コンストラクタ // (mod Mの)階乗テーブル作成する public CombinationPermutation(int n) { fac = new int[n + 1]; fac[0] = 1; for (int i = 1; i <= n; ++i) { fac[i] = modMCalc.Mul(fac[i - 1], i); } } // 階乗求める public int Factorial(int n) { return fac[n]; } // nCr public int nCr(int n, int r) { if (n < r) { return 0; } if (n == r) { return 1; } int res = Factorial(n); res = modMCalc.Div(res, Factorial(r)); res = modMCalc.Div(res, Factorial(n - r)); return res; } } static void Main(string[] args) { string[] inS = Console.ReadLine().Split(' '); int N = int.Parse(inS[0]); int M = int.Parse(inS[1]); int[] b = new int[M + 2]; b[0] = -1; for (int i = 0; i < M; i++) { b[i + 1] = int.Parse(Console.ReadLine()); // 一番最初以外が連続していたら終了 if (i != 0 && (b[i] + 1 == b[i + 1])) { Console.WriteLine(0); return; } } b[M + 1] = N + 1; CombinationPermutation c = new CombinationPermutation(N); int ans = 1; for (int i = 0; i <= M; i++) { int p = 1; int w = b[i + 1] - b[i] - 2; int s = w - 1; int d = 1; while (s >= d) { int a; a = c.nCr(s, d); p += a; p %= modMCalc.M; s -= 1; d += 1; } ans = modMCalc.Mul(ans, p); } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 241, 0, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 52, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 197, 0, 35], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203]]
8
620
34
using System; using System.Linq; namespace CTypicalStairs { class Program { const int LAW = 1000000007; static void Main(string[] args) { // 入力の取得 var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = inputs[0]; var m = inputs[1]; // 壊れている床の一覧を取得 var brokenStairs = new int[m]; for (var i = 0; i < m; i++) { brokenStairs[i] = int.Parse(Console.ReadLine()); } // 連続する壊れていない床の距離を計算 var distances = new int[m + 1]; for (var i = 0; i <= m; i++) { var current = i != m ? brokenStairs[i] : n + 1; var prev = i != 0 ? brokenStairs[i - 1] : -1; // 壊れた階段が連続していたら、0を出力して終了 if (current - prev == 1) { Console.WriteLine(0); return; } distances[i] = (current - 1) - (prev + 1); } // 0 ~ a1 - 1 まで P1 通り、a1 + 1 ~ a2 - 1 まで P2 通り… am + 1 ~ N まで // Pm+1 通り 総数は P1 * P2 * … * Pm+1 通り var maxDistance = distances.Max(); var patternMap = CalcPatternMap(maxDistance); int patternCount = 1; foreach (var distance in distances) { patternCount = (int)(Math.BigMul(patternCount, patternMap[distance]) % LAW); } // 解答の出力 Console.WriteLine(patternCount); } /// <summary> /// 各距離までの経路数 % 1000000007 の一覧を返す /// </summary> /// <param name="maxDistance"></param> /// <returns></returns> static int[] CalcPatternMap(int maxDistance) { var patternMap = new int[maxDistance + 1]; patternMap[0] = 1; patternMap[1] = 1; for (var i = 2; i <= maxDistance; i++) { patternMap[i] = (patternMap[i - 2] + patternMap[i - 1]) % LAW; } return patternMap; } } }
using System; using System.Linq; namespace CTypicalStairs { class Program { const int LAW = 1000000007; static void Main(string[] args) { // 入力の取得 var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = inputs[0]; var m = inputs[1]; // 壊れている床の一覧を取得 var brokenStairs = new int[m]; for (var i = 0; i < m; i++) { brokenStairs[i] = int.Parse(Console.ReadLine()); } // 連続する壊れていない床の距離を計算 var distances = new int[m + 1]; for (var i = 0; i <= m; i++) { var current = i != m ? brokenStairs[i] : n + 1; var prev = i != 0 ? brokenStairs[i - 1] : -1; // 壊れた階段が連続していたら、0を出力して終了 if (current - prev == 1) { Console.WriteLine(0); return; } distances[i] = (current - 1) - (prev + 1); } // 0 ~ a1 - 1 まで P1 通り、a1 + 1 ~ a2 - 1 まで P2 通り… am + 1 ~ N まで // Pm+1 通り 総数は P1 * P2 * … * Pm+1 通り var maxDistance = distances.Max(); var patternMap = CalcPatternMap(Math.Max(maxDistance, 1)); var patternCount = 1; foreach (var distance in distances) { patternCount = (int)(Math.BigMul(patternCount, patternMap[distance]) % LAW); } // 解答の出力 Console.WriteLine(patternCount); } /// <summary> /// 各距離までの経路数 % 1000000007 の一覧を返す /// </summary> /// <param name="maxDistance"></param> /// <returns></returns> static int[] CalcPatternMap(int maxDistance) { var patternMap = new int[maxDistance + 1]; patternMap[0] = 1; patternMap[1] = 1; for (var i = 2; i <= maxDistance; i++) { patternMap[i] = (patternMap[i - 2] + patternMap[i - 1]) % LAW; } return patternMap; } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217]]
8
359
9
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { public class Prog { const int MOD = 1000000007; public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Prog().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var n = cin.ReadInt; var m = cin.ReadInt; var a = cin.ReadIntArray(m); var dp = new UInt64[n]; var index = 0; if (index < m && a[index] == 1) { dp[0] = 0; index++; } else { dp[0] = 1; } if (index < m && a[index] == 2) { dp[1] = 0; index++; } else { dp[1] = dp[0] + 1; } for (int i = 2; i < n; i++) { if (index < m && a[index] == i + 1) { dp[i] = 0; index++; } else { dp[i] = dp[i - 1] % MOD + dp[i - 2] % MOD; } } Console.WriteLine(dp[n - 1] % MOD); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } } } }
using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { public class Prog { const int MOD = 1000000007; public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); new Prog().Solve(new ConsoleInput(Console.In, ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var n = cin.ReadInt; var m = cin.ReadInt; var a = cin.ReadIntArray(m); var dp = new ulong[n + 1]; var index = 0; if (index < m && a[index] == 1) { dp[0] = 0; index++; } else { dp[0] = 1; } if (index < m && a[index] == 2) { dp[1] = 0; index++; } else { dp[1] = dp[0] + 1; } for (int i = 2; i < n; i++) { if (index < m && a[index] == i + 1) { dp[i] = 0; index++; } else { dp[i] = (dp[i - 1] + dp[i - 2]) % MOD; } } Console.WriteLine(dp[n - 1]); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; } } } }
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 22], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 109], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
726
10
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; using System.Text.RegularExpressions; public class Solver { public void Solve() { int n = ri, m = ri, b = 0, t = 0; long p = 0; long[] f = new long[n + 1]; f[0] = 1; f[1] = 1; for (int i = 2; i <= n; i++) { f[i] = (f[i - 2] + f[i - 1]) % mod; } if (m > 0) { t = ri; p = f[t - 1]; } for (int i = 1; i < m; i++) { b = t; t = ri; if (t - b == 1) { p = 0; break; } else { p = (p * f[t - b - 2]) % mod; } } p = (p * f[n - t - 1]) % mod; Write(p); } int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); private const int mod = 1000000007; long Reverse(long n) { return Pow(n, mod - 2); } long Pow(long n, long p) { long t = n, q = 1; while (p > 0) { if (p % 2 == 1) { q = (q * t) % mod; } t = (t * t) % mod; p /= 2; } return q; } int PowUpper(int n, int b) { int p = 1; while (p <= n) { p *= b; } return p; } int Abs(int n) { return (n > 0) ? n : -n; } int Gcd(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); } int Lcm(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } int Lcm(int a, int b) { return a * b / Gcd(a, b); } int Max(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } int Min(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } void Write<T>(T t) { Console.WriteLine(t.ToString()); } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) 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 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 int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan()); } }
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; using System.Text.RegularExpressions; public class Solver { public void Solve() { int n = ri, m = ri, b = 0, t = 0; long p = 0; long[] f = new long[n + 1]; f[0] = 1; f[1] = 1; for (int i = 2; i <= n; i++) { f[i] = (f[i - 2] + f[i - 1]) % mod; } if (m > 0) { t = ri; p = f[t - 1]; for (int i = 1; i < m; i++) { b = t; t = ri; if (t - b == 1) { p = 0; break; } else { p = (p * f[t - b - 2]) % mod; } } p = (p * f[n - t - 1]) % mod; } else { p = f[n]; } Write(p); } int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); private const int mod = 1000000007; long Reverse(long n) { return Pow(n, mod - 2); } long Pow(long n, long p) { long t = n, q = 1; while (p > 0) { if (p % 2 == 1) { q = (q * t) % mod; } t = (t * t) % mod; p /= 2; } return q; } int PowUpper(int n, int b) { int p = 1; while (p <= n) { p *= b; } return p; } int Abs(int n) { return (n > 0) ? n : -n; } int Gcd(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); } int Lcm(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } int Lcm(int a, int b) { return a * b / Gcd(a, b); } int Max(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } int Min(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } void Write<T>(T t) { Console.WriteLine(t.ToString()); } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) 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 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 int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan()); } }
[["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 75, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,238
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC129_C { class Program { static long[] fibo = new long[100001]; static void Main(string[] args) { var mod = 1000000007; var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var a = new int[NM[1]]; var imp = false; for (int i = 0; i < NM[1]; i++) { a[i] = int.Parse(Console.ReadLine()); if (i > 0 && a[i] - a[i - 1] == 1) { imp = true; } } if (imp) { Console.WriteLine(0); } else { long ans = 0; var temp = 0; foreach (var i in a) { if (ans == 0) { ans += CalcFibo(i - 1 - temp); } else ans *= CalcFibo(i - 1 - temp); ans %= mod; temp = i + 1; } if (ans == 0) { ans += CalcFibo(NM[0] - temp); } else ans *= CalcFibo(NM[0] - temp); ans %= mod; Console.WriteLine(ans); } } static long CalcFibo(int n) { if (n <= 1) return 1; if (fibo[n] != 0) return fibo[n]; fibo[n] = CalcFibo(n - 1) + CalcFibo(n - 2); return fibo[n]; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC129_C { class Program { static long[] fibo = new long[100001]; static long mod = 1000000007; static void Main(string[] args) { var NM = Console.ReadLine().Split().Select(int.Parse).ToArray(); var a = new int[NM[1]]; var imp = false; for (int i = 0; i < NM[1]; i++) { a[i] = int.Parse(Console.ReadLine()); if (i > 0 && a[i] - a[i - 1] == 1) { imp = true; } } if (imp) { Console.WriteLine(0); } else { long ans = 0; var temp = 0; foreach (var i in a) { if (ans == 0) { ans += CalcFibo(i - 1 - temp); } else ans *= CalcFibo(i - 1 - temp); ans %= mod; temp = i + 1; } if (ans == 0) { ans += CalcFibo(NM[0] - temp); } else ans *= CalcFibo(NM[0] - temp); ans %= mod; Console.WriteLine(ans); } } static long CalcFibo(int n) { if (n <= 1) return 1; if (fibo[n] != 0) return fibo[n]; fibo[n] = (CalcFibo(n - 1) + CalcFibo(n - 2)) % mod; return fibo[n]; } } }
[["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
343
15
using System; using System.Collections.Generic; using System.Linq; public class Hello { private const int MOD_N = 1000000000 + 7; public static void Main() { var list = Console.ReadLine().Split(' '); var n = int.Parse(list[0]); var m = int.Parse(list[1]); var ass = new int[m]; for (int i = 0; i < ass.Length; ++i) ass[i] = int.Parse(Console.ReadLine()); int pp = 1; int prev = 0; int current = 0; int ai = 0; var a = ass[ai]; if (a == 1) { prev = 0; ++ai; if (ai < ass.Length) a = ass[ai]; } else { prev = pp; } for (int i = 2; i <= n; ++i) { if (i == a) { current = 0; ++ai; if (ai < ass.Length) a = ass[ai]; } else { current = prev + pp; current %= MOD_N; } pp = prev; prev = current; } Console.WriteLine(prev); } private static int Comb(int m, int n) { var t = m - n; if (n > t) n = t; long numerator = 1; for (int i = 0; i < n; ++i) { numerator *= m - i; numerator %= MOD_N; } long denominator = 1; for (; n != 0; --n) { denominator *= n; denominator %= MOD_N; } var inv_denominator = ModInv((int)denominator, MOD_N); var ret = (int)(numerator * inv_denominator % MOD_N); return ret >= 0 ? ret : ret + MOD_N; } private static int ModInv(int a, int m) { int b = m, x = 1, y = 0; while (b != 0) { var t = a / b; a -= t * b; Swap(ref a, ref b); x -= t * y; Swap(ref x, ref y); } x %= m; return x >= 0 ? x : x + m; } private static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } }
using System; using System.Collections.Generic; using System.Linq; public class Hello { private const int MOD_N = 1000000000 + 7; public static void Main() { var list = Console.ReadLine().Split(' '); var n = int.Parse(list[0]); var m = int.Parse(list[1]); var ass = new int[m]; for (int i = 0; i < ass.Length; ++i) ass[i] = int.Parse(Console.ReadLine()); int pp = 1; int prev = 0; int current = 0; int ai = 0; var a = ai < ass.Length ? ass[ai] : -1; if (a == 1) { prev = 0; ++ai; if (ai < ass.Length) a = ass[ai]; } else { prev = pp; } for (int i = 2; i <= n; ++i) { if (i == a) { current = 0; ++ai; if (ai < ass.Length) a = ass[ai]; } else { current = prev + pp; current %= MOD_N; } pp = prev; prev = current; } Console.WriteLine(prev); } private static int Comb(int m, int n) { var t = m - n; if (n > t) n = t; long numerator = 1; for (int i = 0; i < n; ++i) { numerator *= m - i; numerator %= MOD_N; } long denominator = 1; for (; n != 0; --n) { denominator *= n; denominator %= MOD_N; } var inv_denominator = ModInv((int)denominator, MOD_N); var ret = (int)(numerator * inv_denominator % MOD_N); return ret >= 0 ? ret : ret + MOD_N; } private static int ModInv(int a, int m) { int b = m, x = 1, y = 0; while (b != 0) { var t = a / b; a -= t * b; Swap(ref a, ref b); x -= t * y; Swap(ref x, ref y); } x %= m; return x >= 0 ? x : x + m; } private static void Swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } }
[["+", 0, 200, 0, 212, 0, 41, 15, 16, 31, 22], ["+", 0, 200, 0, 212, 0, 41, 15, 16, 17, 18], ["+", 0, 212, 0, 41, 15, 16, 12, 214, 0, 131], ["+", 0, 212, 0, 41, 15, 16, 12, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 200, 0, 212, 0, 41, 64, 204, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 200, 0, 212, 0, 41, 75, 241, 0, 33], ["+", 0, 200, 0, 212, 0, 41, 75, 241, 0, 203]]
8
500
9
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { var input = ReadArrayInt(); var N = input[0]; var M = input[1]; var cnt = new long[N + 1]; for (int i = 0; i < M; i++) cnt[ReadInt()] = -1; var mod = (int)Math.Pow(10, 9) + 7; if (cnt[1] != -1) cnt[1] = 1; if (cnt[2] != -1) cnt[2] = 1; for (int i = 1; i < N - 1; i++) { if (cnt[i] != -1) { if (cnt[i + 1] != -1) { cnt[i + 1] += cnt[i]; cnt[i + 1] %= mod; } if (cnt[i + 2] != -1) { cnt[i + 2] += cnt[i]; cnt[i + 2] %= mod; } } } if (cnt[N - 1] != -1) { cnt[N] += cnt[N - 1]; cnt[N] %= mod; } Console.WriteLine(cnt[N]); 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(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace test { class Program { static void Main(string[] args) { var input = ReadArrayLong(); var N = input[0]; var M = input[1]; var cnt = new long[N + 1]; for (int i = 0; i < M; i++) cnt[ReadInt()] = -1; var mod = (long)Math.Pow(10, 9) + 7; if (N == 1) { Console.WriteLine(cnt[1] != -1 ? 1 : 0); return; } if (cnt[1] != -1) cnt[1] = 1; if (cnt[2] != -1) cnt[2] = 1; for (int i = 1; i < N - 1; i++) { if (cnt[i] != -1) { if (cnt[i + 1] != -1) { cnt[i + 1] += cnt[i]; cnt[i + 1] %= mod; } if (cnt[i + 2] != -1) { cnt[i + 2] += cnt[i]; cnt[i + 2] %= mod; } } } if (cnt[N - 1] != -1) { cnt[N] += cnt[N - 1]; cnt[N] %= mod; } Console.WriteLine(cnt[N]); 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(); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 41, 15, 16, 31, 204, 205, 22], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 41, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 79], ["+", 0, 28, 0, 41, 15, 16, 12, 241, 0, 33], ["+", 0, 28, 0, 41, 15, 16, 12, 241, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
414
31
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var h = ScanInt; var w = ScanInt; bool[,] bs = new bool[2010, 2010]; for (int i = 0; i < h; i++) { var s = ScanStr; for (int j = 0; j < w; j++) { if (s[j] == '.') bs[i + 1, j + 1] = true; } } int[,] hs = new int[2010, 2010]; int[,] ws = new int[2010, 2010]; for (int i = 0; i < 2005; i++) { var bg = -1; for (int j = 0; j < 2005; j++) { if (bs[i, j]) { if (bg < 0) bg = j; } else { if (bg >= 0) { for (int k = bg; k < j - 1; k++) { hs[i, k] = j - bg; } bg = -1; } } } } for (int i = 0; i < 2005; i++) { var bg = -1; for (int j = 0; j < 2005; j++) { if (bs[j, i]) { if (bg < 0) bg = j; } else { if (bg >= 0) { for (int k = bg; k < j - 1; k++) { ws[k, i] = j - bg; } bg = -1; } } } } var res = 0; for (int i = 0; i < 2005; i++) { for (int j = 0; j < 2005; j++) { res = Math.Max(res, hs[i, j] + ws[i, j] - 1); } } return res; } public bool SolveBool() { var n = Scan; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer sw) { this.scanner = sc; this.printer = sw; } private readonly Scanner scanner; private readonly Printer printer; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int ScanInt => scanner.Int; private long Sc => scanner.Long; private long Scan => scanner.Long; private long ScanLong => scanner.Long; private double ScanDouble => scanner.Double; private string Str => scanner.Str; private string ScanStr => scanner.Str; private int[] IntArr(int n) => scanner.Ints(n); private int[] IntArr(long n) => scanner.Ints(n); private long[] Scs(int n) => scanner.Longs(n); private long[] Scs(long n) => scanner.Longs(n); private long[] ScanArr(int n) => scanner.Longs(n); private long[] ScanArr(long n) => scanner.Longs(n); private long[] LongArr(int n) => scanner.Longs(n); private long[] LongArr(long n) => scanner.Longs(n); private double[] DoubleArr(int n) => scanner.Doubles(n); private double[] DoubleArr(long n) => scanner.Doubles(n); private string[] StrArr(int n) => scanner.Strs(n); private string[] StrArr(long n) => scanner.Strs(n); private void Wr(string s) => printer.Write(s); private void Wr(object obj) => printer.Write(obj); private void Wr<T>(IEnumerable<T> ts) => printer.Write(ts); private void Wr(params object[] objs) => printer.Write(objs); private void Write(string s) => printer.Write(s); private void Write(object obj) => printer.Write(obj); private void Write<T>(IEnumerable<T> ts) => printer.Write(ts); private void Write(params object[] objs) => printer.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } class C { public class PriorityQueue<TKey, TValue> { SortedDictionary<TKey, Queue<TValue>> dictionary = new SortedDictionary<TKey, Queue<TValue>>(); int count = 0; public int Count { get { return count; } } public void Add(TKey key, TValue value) { if (!dictionary.ContainsKey(key)) { dictionary[key] = new Queue<TValue>(); } dictionary[key].Enqueue(value); count++; } public KeyValuePair<TKey, TValue> Dequeue() { var queue = dictionary.First(); if (queue.Value.Count <= 1) { dictionary.Remove(queue.Key); } count--; return new KeyValuePair<TKey, TValue>(queue.Key, queue.Value.Dequeue()); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static int GetFirstIndexGreater(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static int GetFirstIndexGreater(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static int GetLastIndexLess(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } public static int GetLastIndexLess(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } 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 static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007; public static void Set998244353() { divider = 998244353; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); private static long PowImpl(long a, long p) { if (p == 0) return 1L; if (p == 1) return a; var halfP = p / 2; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2 == 0 ? powered : powered * a % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache = 0L; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static readonly List<long> facCache = new List<long>() { 1L }; private static long FacImpl(long a) { if (a >= divider) return 0; var val = 1L; var start = 1; for (int i = start; i <= a; i++) { val = (val * i) % divider; } return val; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nr = 1L; for (var i = n; i > n - r; i--) { nr *= i; nr %= divider; } var rr = FacImpl(r); return (nr * InvImpl(rr)) % divider; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var h = ScanInt; var w = ScanInt; bool[,] bs = new bool[2010, 2010]; for (int i = 0; i < h; i++) { var s = ScanStr; for (int j = 0; j < w; j++) { if (s[j] == '.') bs[i + 1, j + 1] = true; } } int[,] hs = new int[2010, 2010]; int[,] ws = new int[2010, 2010]; for (int i = 0; i < 2005; i++) { var bg = -1; for (int j = 0; j < 2005; j++) { if (bs[i, j]) { if (bg < 0) bg = j; } else { if (bg >= 0) { for (int k = bg; k <= j - 1; k++) { hs[i, k] = j - bg; } bg = -1; } } } } for (int i = 0; i < 2005; i++) { var bg = -1; for (int j = 0; j < 2005; j++) { if (bs[j, i]) { if (bg < 0) bg = j; } else { if (bg >= 0) { for (int k = bg; k <= j - 1; k++) { ws[k, i] = j - bg; } bg = -1; } } } } var res = 0; for (int i = 1; i <= h; i++) { var l = new List<int>(); for (int j = 1; j <= w; j++) { var c = Math.Max(0, hs[i, j] + ws[i, j] - 1); l.Add(c); res = Math.Max(res, c); } // Wr(string.Join("", l)); } return res; } public bool SolveBool() { var n = Scan; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer sw) { this.scanner = sc; this.printer = sw; } private readonly Scanner scanner; private readonly Printer printer; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int ScanInt => scanner.Int; private long Sc => scanner.Long; private long Scan => scanner.Long; private long ScanLong => scanner.Long; private double ScanDouble => scanner.Double; private string Str => scanner.Str; private string ScanStr => scanner.Str; private int[] IntArr(int n) => scanner.Ints(n); private int[] IntArr(long n) => scanner.Ints(n); private long[] Scs(int n) => scanner.Longs(n); private long[] Scs(long n) => scanner.Longs(n); private long[] ScanArr(int n) => scanner.Longs(n); private long[] ScanArr(long n) => scanner.Longs(n); private long[] LongArr(int n) => scanner.Longs(n); private long[] LongArr(long n) => scanner.Longs(n); private double[] DoubleArr(int n) => scanner.Doubles(n); private double[] DoubleArr(long n) => scanner.Doubles(n); private string[] StrArr(int n) => scanner.Strs(n); private string[] StrArr(long n) => scanner.Strs(n); private void Wr(string s) => printer.Write(s); private void Wr(object obj) => printer.Write(obj); private void Wr<T>(IEnumerable<T> ts) => printer.Write(ts); private void Wr(params object[] objs) => printer.Write(objs); private void Write(string s) => printer.Write(s); private void Write(object obj) => printer.Write(obj); private void Write<T>(IEnumerable<T> ts) => printer.Write(ts); private void Write(params object[] objs) => printer.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } class C { public class PriorityQueue<TKey, TValue> { SortedDictionary<TKey, Queue<TValue>> dictionary = new SortedDictionary<TKey, Queue<TValue>>(); int count = 0; public int Count { get { return count; } } public void Add(TKey key, TValue value) { if (!dictionary.ContainsKey(key)) { dictionary[key] = new Queue<TValue>(); } dictionary[key].Enqueue(value); count++; } public KeyValuePair<TKey, TValue> Dequeue() { var queue = dictionary.First(); if (queue.Value.Count <= 1) { dictionary.Remove(queue.Key); } count--; return new KeyValuePair<TKey, TValue>(queue.Key, queue.Value.Dequeue()); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static int GetFirstIndexGreater(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static int GetFirstIndexGreater(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static int GetLastIndexLess(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } public static int GetLastIndexLess(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } 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 static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007; public static void Set998244353() { divider = 998244353; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); private static long PowImpl(long a, long p) { if (p == 0) return 1L; if (p == 1) return a; var halfP = p / 2; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2 == 0 ? powered : powered * a % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache = 0L; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static readonly List<long> facCache = new List<long>() { 1L }; private static long FacImpl(long a) { if (a >= divider) return 0; var val = 1L; var start = 1; for (int i = start; i <= a; i++) { val = (val * i) % divider; } return val; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nr = 1L; for (var i = n; i > n - r; i--) { nr *= i; nr %= divider; } var rr = FacImpl(r); return (nr * InvImpl(rr)) % divider; } } }
[["-", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 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], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21]]
8
6,022
50
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { static class Extensions { public static int LowerBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c > 0) l = m + 1; else r = m; } return l; } public static int UpperBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c >= 0) l = m + 1; else r = m; } return r; } } class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public MaxHeap<T> Copy(Comparison<T> comp = null) { var c = new MaxHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MaxHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } class InputLine { private string[] _inputs; private int _index = 0; InputLine(string input) { _inputs = input.Split(); _index = 0; } public static InputLine Read() { return new InputLine(Console.ReadLine()); } public int NextInt() { return int.Parse(_inputs[_index++]); } public long NextLong() { return long.Parse(_inputs[_index++]); } public double NextDouble() { return double.Parse(_inputs[_index++]); } } public static int GCD(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long GCD(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } static long ModPower(long x, long y, long mod) { var bytes = BitConverter.GetBytes(y); var bits = new System.Collections.BitArray(bytes); var max2 = 0; for (int i = bits.Length - 1; i >= 0; i--) { if (bits[i]) { max2 = i; break; } } long result = 1; for (int i = max2; i >= 0; i--) { result = (result * result) % mod; if (bits[i]) { result = (result * x) % mod; } } return result; } static long ModFact(long n, long mod) { long result = 1; for (int i = 1; i <= n; i++) { result = result * i % mod; } return result; } static long ModAdd(long x, long y, long mod) { return ((x % mod) + (y % mod)) % mod; } static long ModMal(long x, long y, long mod) { return ((x % mod) * (y % mod)) % mod; } static long ModDiv(long x, long y, long mod) { //フェルマーの小定理より、a^(-1) = a^(p-2) return ModMal(x, ModPower(y, mod - 2, mod), mod); } static long ModComb(long n, long r, long mod) { long numerator = 1; for (int i = 0; i < r; i++) { numerator = ModMal(numerator, n - i, mod); } long denominator = ModFact(r, mod); return ModDiv(numerator, denominator, mod); } class Graph { private int _size; private List<int>[] _map; public IEnumerable<int> this[int i] { get { if (_map[i] == null) return Enumerable.Empty<int>(); return _map[i]; } } public Graph(int size) { _size = size; _map = new List<int>[size]; } public void Add(int from, int to) { if (_map[from] == null) { _map[from] = new List<int>(); } _map[from].Add(to); } } static long p1097 = 1000000007; static void Main(string[] args) { //↓ var hw = ReadIntArray(); var h = hw[0]; var w = hw[1]; var ss = new string[h]; for (int i = 0; i < h; i++) { ss[i] = Console.ReadLine(); } var row = new int[h + 2, w + 2]; var col = new int[h + 2, w + 2]; for (int i = 1; i < h + 1; i++) { for (int j = 1; j < w + 1; j++) { var s = ss[i - 1][j - 1]; if (s == '#') { col[i, j] = 0; row[i, j] = 0; } else { col[i, j] = col[i - 1, j] + 1; row[i, j] = row[i, j - 1] + 1; } } } var max = int.MinValue; for (int i = h; i >= 1; i--) { for (int j = w; j >= 1; j--) { if (col[i + 1, j] > 0) col[i, j] = col[i + 1, j]; if (row[i, j + 1] > 0) row[i, j] = row[i, j + 1]; max = Math.Max(max, row[i, j] + col[i, j] - 1); } } Console.WriteLine(max); //↑ } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { static class Extensions { public static int LowerBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c > 0) l = m + 1; else r = m; } return l; } public static int UpperBound<T>(this IList<T> list, T value, IComparer<T> comp = null) { if (comp == null) comp = Comparer<T>.Default; var l = 0; var r = list.Count; while (l < r) { var m = (l + r) / 2; var c = comp.Compare(value, list[m]); if (c >= 0) l = m + 1; else r = m; } return r; } } class Program { static int ReadInt() { return int.Parse(Console.ReadLine()); } static long ReadLong() { return long.Parse(Console.ReadLine()); } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static int[] ReadIntArray(int n) { var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = ReadInt(); } return a; } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } static long[] ReadLongArray(int n) { var a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } return a; } public static int[] ZAlgotithm(string s) { var len = s.Length; var a = new int[len]; a[0] = len; var i = 1; var j = 0; while (i < len) { while (i + j < len && s[j] == s[i + j]) j++; a[i] = j; if (j == 0) { i++; continue; } var k = 1; while (i + k < len && k + a[k] < j) { a[i + k] = a[k]; k++; } i += k; j -= k; } return a; } public class MaxHeap<T> : IEnumerable<T> { private List<T> _list; private Comparer<T> _comp; public int Count { get { return _list.Count; } } public MaxHeap() : this(0) {} public MaxHeap(int capacity, Comparison<T> comp = null) { _list = new List<T>(capacity); if (comp == null) { _comp = Comparer<T>.Default; } else { _comp = Comparer<T>.Create(comp); } } public void Push(T elem) { Upheap(elem); } public T Pop() { return Downheap(); } public T Peek() { return _list[0]; } private void Swap(int i, int j) { var a = _list[j]; _list[j] = _list[i]; _list[i] = a; } private void Upheap(T elem) { _list.Add(elem); var i = _list.Count - 1; while (true) { if (i == 0) return; var j = (i - 1) / 2; var e = _list[i]; var p = _list[j]; var c = _comp.Compare(e, p); if (c > 0) { Swap(i, j); i = j; continue; } else { break; } } } private T Downheap() { var result = _list[0]; var last = _list.Count - 1; Swap(0, last); _list.RemoveAt(last); if (_list.Count == 0) return result; var i = 0; while (true) { if (i == _list.Count - 1) return result; var p = _list[i]; var j = i * 2 + 1; if (j >= _list.Count) return result; if (j + 1 < _list.Count && _comp.Compare(_list[j], _list[j + 1]) < 0) { j++; } if (_comp.Compare(_list[i], _list[j]) < 0) { Swap(i, j); i = j; } else { return result; } } } public MaxHeap<T> Copy(Comparison<T> comp = null) { var c = new MaxHeap<T>(0, comp); c._list = _list.ToList(); return c; } public MaxHeap(List<T> list) { _list = list; _comp = Comparer<T>.Default; } public List<T> GetList() { return _list; } public IEnumerator<T> GetEnumerator() { return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } class InputLine { private string[] _inputs; private int _index = 0; InputLine(string input) { _inputs = input.Split(); _index = 0; } public static InputLine Read() { return new InputLine(Console.ReadLine()); } public int NextInt() { return int.Parse(_inputs[_index++]); } public long NextLong() { return long.Parse(_inputs[_index++]); } public double NextDouble() { return double.Parse(_inputs[_index++]); } } public static int GCD(int x, int y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } public static long GCD(long x, long y) { var a = Math.Max(x, y); var b = x + y - a; while (b != 0) { var c = b; b = a % b; a = c; } return a; } static long ModPower(long x, long y, long mod) { var bytes = BitConverter.GetBytes(y); var bits = new System.Collections.BitArray(bytes); var max2 = 0; for (int i = bits.Length - 1; i >= 0; i--) { if (bits[i]) { max2 = i; break; } } long result = 1; for (int i = max2; i >= 0; i--) { result = (result * result) % mod; if (bits[i]) { result = (result * x) % mod; } } return result; } static long ModFact(long n, long mod) { long result = 1; for (int i = 1; i <= n; i++) { result = result * i % mod; } return result; } static long ModAdd(long x, long y, long mod) { return ((x % mod) + (y % mod)) % mod; } static long ModMal(long x, long y, long mod) { return ((x % mod) * (y % mod)) % mod; } static long ModDiv(long x, long y, long mod) { //フェルマーの小定理より、a^(-1) = a^(p-2) return ModMal(x, ModPower(y, mod - 2, mod), mod); } static long ModComb(long n, long r, long mod) { long numerator = 1; for (int i = 0; i < r; i++) { numerator = ModMal(numerator, n - i, mod); } long denominator = ModFact(r, mod); return ModDiv(numerator, denominator, mod); } class Graph { private int _size; private List<int>[] _map; public IEnumerable<int> this[int i] { get { if (_map[i] == null) return Enumerable.Empty<int>(); return _map[i]; } } public Graph(int size) { _size = size; _map = new List<int>[size]; } public void Add(int from, int to) { if (_map[from] == null) { _map[from] = new List<int>(); } _map[from].Add(to); } } static long p1097 = 1000000007; static void Main(string[] args) { //↓ var hw = ReadIntArray(); var h = hw[0]; var w = hw[1]; var ss = new string[h]; for (int i = 0; i < h; i++) { ss[i] = Console.ReadLine(); } var row = new int[h + 2, w + 2]; var col = new int[h + 2, w + 2]; for (int i = 1; i < h + 1; i++) { for (int j = 1; j < w + 1; j++) { var s = ss[i - 1][j - 1]; if (s == '#') { col[i, j] = 0; row[i, j] = 0; } else { col[i, j] = col[i - 1, j] + 1; row[i, j] = row[i, j - 1] + 1; } } } var max = int.MinValue; for (int i = h; i >= 1; i--) { for (int j = w; j >= 1; j--) { if (col[i + 1, j] > 0 && col[i, j] > 0) col[i, j] = col[i + 1, j]; if (row[i, j + 1] > 0 && row[i, j] > 0) row[i, j] = row[i, j + 1]; if (col[i, j] > 0) max = Math.Max(max, row[i, j] + col[i, j] - 1); } } Console.WriteLine(max); //↑ } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 21], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 21], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25]]
8
2,228
29
using System; using System.Linq; using System.Collections.Generic; class c { static void Main() { var hw = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var map = new string[hw[0]]; for (int i = 0; i < hw[0]; i++) { map[i] = Console.ReadLine(); } var ans = new int[hw[0]][]; for (int i = 0; i < hw[0]; i++) { ans[i] = new int[hw[1]]; } for (int i = 0; i < hw[0]; i++) { for (int j = 0; j < hw[1]; j++) { if (map[i][j] == '.') ans[i][j] = 1; } } for (int i = 0; i < hw[0]; i++) { int temp = 0; for (int j = 0; j < hw[1]; j++) { ans[i][j] += temp; if (map[i][j] == '.') { temp++; } else temp = 0; } } for (int i = hw[0] - 1; i >= 0; i--) { int temp = 0; for (int j = hw[1] - 1; j >= 0; j--) { ans[i][j] += temp; if (map[i][j] == '.') { temp++; } else temp = 0; } } for (int i = 0; i < hw[1]; i++) { int temp = 0; for (int j = 0; j < hw[0]; j++) { ans[j][i] += temp; if (map[j][i] == '.') { temp++; } else temp = 0; } } for (int i = hw[1] - 1; i >= 0; i--) { int temp = 0; for (int j = hw[0] - 1; j >= 0; j--) { ans[j][i] += temp; if (map[j][i] == '.') { temp++; } else temp = 0; } } int max = 0; for (int i = 0; i < hw[0]; i++) { max = Math.Max(max, ans[i].Max()); } Console.WriteLine(Math.Max(0, max)); } }
using System; using System.Linq; class c { static void Main() { var hw = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); var map = new string[hw[0]]; for (int i = 0; i < hw[0]; i++) { map[i] = Console.ReadLine(); } var ans = new int[hw[0]][]; for (int i = 0; i < hw[0]; i++) { ans[i] = new int[hw[1]]; } for (int i = 0; i < hw[0]; i++) { for (int j = 0; j < hw[1]; j++) { if (map[i][j] == '.') ans[i][j] = 1; else ans[i][j] = int.MinValue; } } for (int i = 0; i < hw[0]; i++) { int temp = 0; for (int j = 0; j < hw[1]; j++) { ans[i][j] += temp; if (map[i][j] == '.') temp++; else temp = 0; } } for (int i = hw[0] - 1; i >= 0; i--) { int temp = 0; for (int j = hw[1] - 1; j >= 0; j--) { ans[i][j] += temp; if (map[i][j] == '.') temp++; else temp = 0; } } for (int i = 0; i < hw[1]; i++) { int temp = 0; for (int j = 0; j < hw[0]; j++) { ans[j][i] += temp; if (map[j][i] == '.') temp++; else temp = 0; } } for (int i = hw[1] - 1; i >= 0; i--) { int temp = 0; for (int j = hw[0] - 1; j >= 0; j--) { ans[j][i] += temp; if (map[j][i] == '.') temp++; else temp = 0; } } int max = 0; for (int i = 0; i < hw[0]; i++) { max = Math.Max(max, ans[i].Max()); } Console.WriteLine(max); } }
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 234, 22], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 0, 131], ["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 75, 1, 0, 11, 31, 204, 205, 204, 205, 22], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 75, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 1, 0, 11, 12, 214, 205, 199], ["+", 0, 57, 75, 1, 0, 11, 12, 214, 0, 131], ["+", 0, 57, 75, 1, 0, 11, 12, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 75, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
571
35
using System; using System.Linq; using System.Collections.Generic; class Mondai { static void Main() { var HW = Console.ReadLine() .Split(' ') .Select(n => Int32.Parse(n)) .OrderBy(x => x) .ToArray(); var H = HW[0]; var W = HW[1]; var array = new char[H, W]; for (int height = 0; height < H; ++height) { var S = Console.ReadLine().ToCharArray(); for (int width = 0; width < W; ++width) array[height, width] = S[width]; } var yokoArray = new int[H, W]; for (int height = 0; height < H; ++height) { for (int width = 0; width < W; ++width) { if (array[height, width] == '#') continue; if (yokoArray[height, width] != 0) continue; var count = 0; var w = width; while (array[height, w] == '.') { count++; w++; if (W <= w) break; } for (int k = 0; k < count; ++k) yokoArray[height, width + k] = count; } } var tateArray = new int[H, W]; for (int width = 0; width < W; ++width) { for (int height = 0; height < H; ++height) { if (array[height, width] == '#') continue; if (tateArray[height, width] != 0) continue; var count = 0; var h = height; while (array[h, width] == '.') { count++; h++; if (H <= h) break; } for (int k = 0; k < count; ++k) tateArray[height + k, width] = count; } } var max = int.MinValue; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { var rayCount = yokoArray[i, j] + tateArray[i, j] - 1; if (max < rayCount) max = rayCount; } } Console.WriteLine(max); } }
using System; using System.Linq; using System.Collections.Generic; class Mondai { static void Main() { var HW = Console.ReadLine().Split(' ').Select(n => Int32.Parse(n)).ToArray(); var H = HW[0]; var W = HW[1]; var array = new char[H, W]; for (int height = 0; height < H; ++height) { var S = Console.ReadLine().ToCharArray(); for (int width = 0; width < W; ++width) array[height, width] = S[width]; } var yokoArray = new int[H, W]; for (int height = 0; height < H; ++height) { for (int width = 0; width < W; ++width) { if (array[height, width] == '#') continue; if (yokoArray[height, width] != 0) continue; var count = 0; var w = width; while (array[height, w] == '.') { count++; w++; if (W <= w) break; } for (int k = 0; k < count; ++k) yokoArray[height, width + k] = count; } } var tateArray = new int[H, W]; for (int width = 0; width < W; ++width) { for (int height = 0; height < H; ++height) { if (array[height, width] == '#') continue; if (tateArray[height, width] != 0) continue; var count = 0; var h = height; while (array[h, width] == '.') { count++; h++; if (H <= h) break; } for (int k = 0; k < count; ++k) tateArray[height + k, width] = count; } } var max = int.MinValue; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { var rayCount = yokoArray[i, j] + tateArray[i, j] - 1; if (max < rayCount) max = rayCount; } } Console.WriteLine(max); } }
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131]]
8
492
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC129_D { class Program { static void Main(string[] args) { var HW = Console.ReadLine().Split().Select(int.Parse).ToArray(); var H = HW[0]; var W = HW[1]; var S = new string[H]; var tate = new int[H, W]; var yoko = new int[H, W]; for (int h = 0; h < H; h++) { S[h] = Console.ReadLine(); for (int w = 0; w < W; w++) { tate[h, w] = -1; yoko[h, w] = -1; } } var ans = 0; for (int h = 0; h < H; h++) { for (int w = 0; w < W; w++) { if (S[h][w] == '#') continue; var temp = 0; // tate var t = 0; if (tate[h, w] == -1) { for (int h2 = 0; h2 < H; h2++) { if (h + h2 >= H || S[h + h2][w] == '#') break; t++; } for (int h2 = 0; h2 < H; h2++) { if (h + h2 >= H) break; tate[h + h2, w] = t; } } temp += tate[h, w]; // yoko var y = 0; if (yoko[h, w] == -1) { for (int w2 = 0; w2 < W; w2++) { if (w + w2 >= W || S[h][w + w2] == '#') break; y++; } for (int w2 = 0; w2 < W; w2++) { if (w + w2 >= W) break; yoko[h, w + w2] = y; } } temp += yoko[h, w] - 1; ans = Math.Max(temp, ans); } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC129_D { class Program { static void Main(string[] args) { var HW = Console.ReadLine().Split().Select(int.Parse).ToArray(); var H = HW[0]; var W = HW[1]; var S = new string[H]; var tate = new int[H, W]; var yoko = new int[H, W]; for (int h = 0; h < H; h++) { S[h] = Console.ReadLine(); for (int w = 0; w < W; w++) { tate[h, w] = -1; yoko[h, w] = -1; } } var ans = 0; for (int h = 0; h < H; h++) { for (int w = 0; w < W; w++) { if (S[h][w] == '#') continue; var temp = 0; // tate var t = 0; if (tate[h, w] == -1) { for (int h2 = 0; h2 < H; h2++) { if (h + h2 >= H || S[h + h2][w] == '#') break; t++; } for (int h2 = 0; h2 < H; h2++) { if (h + h2 >= H || S[h + h2][w] == '#') break; tate[h + h2, w] = t; } } temp += tate[h, w]; // yoko var y = 0; if (yoko[h, w] == -1) { for (int w2 = 0; w2 < W; w2++) { if (w + w2 >= W || S[h][w + w2] == '#') break; y++; } for (int w2 = 0; w2 < W; w2++) { if (w + w2 >= W || S[h][w + w2] == '#') break; yoko[h, w + w2] = y; } } temp += yoko[h, w] - 1; ans = Math.Max(temp, ans); } } Console.WriteLine(ans); } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 16, 31, 204, 205, 204, 205, 22], ["+", 12, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 12, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 104], ["+", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22]]
8
476
28
using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; class Program { #region Reader static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim()); static int[] ReadInts => Console.ReadLine() .Trim() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim()); static long[] ReadLongs => Console.ReadLine() .Trim() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); static List<int[]> ReadPairs(int N) { List<int[]> ans = new List<int[]>(); for (int i = 0; i < N; i++) { ans.Add(ReadInts); } return ans; } static List<long[]> ReadPairsLong(int N) { List<long[]> ans = new List<long[]>(); for (int i = 0; i < N; i++) { ans.Add(ReadLongs); } return ans; } #endregion #region Method const int mod = 1000000007; public static int Mod(int a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; } public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; } bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); void Multi<T>(out T a) => a = cv<T>(ReadStr); void Multi<T, U>(out(T, U) ans) { var ar = ReadStrs; ans = (cv<T>(ar[0]), cv<U>(ar[1])); } void Multi<T, U, V>(out(T, U, V) ans) { var ar = ReadStrs; ans = (cv<T>(ar[0]), cv<U>(ar[1]), cv<V>(ar[2])); } void Multi<T, U>(out T a, out U b) { var ar = ReadStrs; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } void Multi<T, U, V>(out T a, out U b, out V c) { var ar = ReadStrs; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } #endregion /// <summary> /// とりうる最大値に1を足すこと /// </summary> /// <param name="minLimit"></param> /// <param name="maxLimitPlus1"></param> /// <param name="judge"></param> /// <returns></returns> static long[] BinarySearch(long minLimit, long maxLimitPlus1, Func<long, bool> judge) { long max = maxLimitPlus1; long min = minLimit; long mid = (min + max) / 2; while (max - min > 1) { if (judge(mid)) { min = mid; mid = (mid + max) / 2; } else { max = mid; mid = (mid + min) / 2; } } if (max == maxLimitPlus1) return new long[2] { mid, mid + 1 }; else if (min == minLimit - 1) return new long[2] { -1, 0 }; else { return judge(mid) != judge(mid + 1) ? new long[2] { mid, mid + 1 } : new long[2] { mid - 1, mid }; } } static int[] BinarySearch(IEnumerable<int> numbers, Func<int, bool> judge) { int max = numbers.Count(); int min = -1; int mid = (min + max) / 2; while (max - min > 1) { if (judge(numbers.ElementAt(mid))) { min = mid; mid = (mid + max) / 2; } else { max = mid; mid = (mid + min) / 2; } } if (max == numbers.Count()) return new int[2] { mid, mid + 1 }; else if (min == -1) return new int[2] { -1, 0 }; else { return judge(numbers.ElementAt(mid)) != judge(numbers.ElementAt(mid + 1)) ? new int[2] { mid, mid + 1 } : new int[2] { mid - 1, mid }; } } static void Main() { string s = ReadStr; long ans = 0; long current = 1; long sum = PowerMod(3, s.Length); long pow3 = sum; long inv = GetInv(3); for (int i = 0; i < s.Length; i++) { pow3 *= inv; if (s[i] == '1') { current *= 2; current = Mod(current); } else { long temp = current *= 2; ans += temp * pow3; ans = Mod(ans); } } WriteLine(Mod(sum - Mod(ans))); } #region Mod public static long GetInv(long a, long mod = 1000000007) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod = 1000000007) { if (b < 0 || b > a) return 0; if (b > a / 2) b = a - b; long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } #endregion }
using static System.Math; using static System.Console; using System.Collections.Generic; using System.Linq; using System; class Program { #region Reader static string ReadStr => Console.ReadLine(); static string[] ReadStrs => Console.ReadLine().Split(' '); static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim()); static int[] ReadInts => Console.ReadLine() .Trim() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim()); static long[] ReadLongs => Console.ReadLine() .Trim() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); static List<int[]> ReadPairs(int N) { List<int[]> ans = new List<int[]>(); for (int i = 0; i < N; i++) { ans.Add(ReadInts); } return ans; } static List<long[]> ReadPairsLong(int N) { List<long[]> ans = new List<long[]>(); for (int i = 0; i < N; i++) { ans.Add(ReadLongs); } return ans; } #endregion #region Method const int mod = 1000000007; public static int Mod(int a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; } public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; } bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); void Multi<T>(out T a) => a = cv<T>(ReadStr); void Multi<T, U>(out(T, U) ans) { var ar = ReadStrs; ans = (cv<T>(ar[0]), cv<U>(ar[1])); } void Multi<T, U, V>(out(T, U, V) ans) { var ar = ReadStrs; ans = (cv<T>(ar[0]), cv<U>(ar[1]), cv<V>(ar[2])); } void Multi<T, U>(out T a, out U b) { var ar = ReadStrs; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } void Multi<T, U, V>(out T a, out U b, out V c) { var ar = ReadStrs; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } #endregion /// <summary> /// とりうる最大値に1を足すこと /// </summary> /// <param name="minLimit"></param> /// <param name="maxLimitPlus1"></param> /// <param name="judge"></param> /// <returns></returns> static long[] BinarySearch(long minLimit, long maxLimitPlus1, Func<long, bool> judge) { long max = maxLimitPlus1; long min = minLimit; long mid = (min + max) / 2; while (max - min > 1) { if (judge(mid)) { min = mid; mid = (mid + max) / 2; } else { max = mid; mid = (mid + min) / 2; } } if (max == maxLimitPlus1) return new long[2] { mid, mid + 1 }; else if (min == minLimit - 1) return new long[2] { -1, 0 }; else { return judge(mid) != judge(mid + 1) ? new long[2] { mid, mid + 1 } : new long[2] { mid - 1, mid }; } } static int[] BinarySearch(IEnumerable<int> numbers, Func<int, bool> judge) { int max = numbers.Count(); int min = -1; int mid = (min + max) / 2; while (max - min > 1) { if (judge(numbers.ElementAt(mid))) { min = mid; mid = (mid + max) / 2; } else { max = mid; mid = (mid + min) / 2; } } if (max == numbers.Count()) return new int[2] { mid, mid + 1 }; else if (min == -1) return new int[2] { -1, 0 }; else { return judge(numbers.ElementAt(mid)) != judge(numbers.ElementAt(mid + 1)) ? new int[2] { mid, mid + 1 } : new int[2] { mid - 1, mid }; } } static void Main() { string s = ReadStr; long ans = 0; long current = 1; long sum = PowerMod(3, s.Length); long pow3 = sum; long inv = GetInv(3); for (int i = 0; i < s.Length; i++) { pow3 *= inv; pow3 = Mod(pow3); if (s[i] == '1') { current *= 2; current = Mod(current); } else { long temp = current * 2; ans += temp * pow3; ans = Mod(ans); } } WriteLine(Mod(sum - Mod(ans))); } #region Mod public static long GetInv(long a, long mod = 1000000007) { return PowerMod(a, mod - 2, mod); } public static long Combination(long a, long b, long mod = 1000000007) { if (b < 0 || b > a) return 0; if (b > a / 2) b = a - b; long numerator = Factorial(a, mod); long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod; return (numerator * GetInv(denominator, mod)) % mod; } public static long Factorial(long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return 1; long ans = n; for (int i = 2; i < n; i++) { ans = (ans * i) % mod; } return ans; } private static long PowerMod(long a, long n, long mod = 1000000007) { if (n == 0) return 1; if (n == 1) return a; long p = PowerMod(a, n / 2, mod); if (n % 2 == 1) return ((p * p) % mod * a) % mod; else return (p * p) % mod; } #endregion }
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 200, 0, 212, 0, 11, 0, 202, 0, 108], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48]]
8
1,572
9
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; class MainClass : Scanner { static void Main() { string L = RString(); int M = L.Length; Modular ans = 0; Modular sum = 1; for (int i = 0; i < M; i++) { ans += sum * Modular.Pow(3, M - 1 - i); if (L[i] == '1') sum *= 2; } if (L.Last() == '1') ans += sum; WriteLine((int)ans); } } 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 string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); 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 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 string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<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) ReadTuple<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) ReadTuple<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[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], 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() { string L = RString(); int M = L.Length; Modular ans = 0; Modular sum = 1; for (int i = 0; i < M; i++) { if (L[i] == '1') { ans += sum * Modular.Pow(3, M - 1 - i); sum *= 2; } } ans += sum; WriteLine((int)ans); } } 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 string RString() => Console.ReadLine(); public static int RInt() => ReadTuple<int>(); public static long RLong() => ReadTuple<long>(); public static double RDouble() => ReadTuple<double>(); public static string[] RStrings() => Console.ReadLine().Split(); 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 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 string[] RStrings(Func<string, string> func) => // Console.ReadLine().Split().Select(func).ToArray(); public static T1 ReadTuple<T1>() { var r = RString(); var r1 = (T1)Convert.ChangeType(r, typeof(T1)); return r1; } public static (T1, T2) ReadTuple<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) ReadTuple<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) ReadTuple<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[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["+", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 104], ["-", 8, 196, 0, 57, 15, 16, 12, 252, 0, 253], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
1,182
36
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var s = Str; var res = new Mint(1); for (long i = 0; i < s.Length - 1; i++) { res += Mint.Pow(3, i) * 2; } var add = new Mint(2); for (long i = 1; i < s.Length; i++) { if (s[(int)i] == '1') add *= 3; } res += add; return res.Value; } public bool SolveBool() { long n = Read; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { public static bool TryRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } public static void SafeAdd<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); public static long ToDigit(this char c) => (long)(c - '0'); public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); } class C { public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; //[MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { //[MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static long GetFirstIndexGreater(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetFirstIndexGreater(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetLastIndexLess(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } public static long GetLastIndexLess(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } 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 static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; public static void Set998244353() { divider = 998244353L; } public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : (powered * a) % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace V { partial class Solver { public void Solve() { Write(SolveLong()); // YesNo(SolveBool()); } public long SolveLong() { var s = Str; var res = new Mint(1); for (long i = 0; i < s.Length - 1; i++) { res += Mint.Pow(3, i) * 2; } var add = new Mint(2); for (long i = 1; i < s.Length; i++) { if (s[(int)i] == '1') { res += Mint.Pow(3, s.Length - i - 1) * add; add *= 2; } } res += add; return res.Value; } public bool SolveBool() { long n = Read; return false; } } } namespace V { class StartingPoint { static void Main(string[] args) { try { var streamReader = args.Any() ? new StreamReader(args[0]) : new StreamReader(Console.OpenStandardInput()); var streamWriter = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; var scanner = new Scanner(streamReader); var printer = new Printer(streamWriter); var solver = new Solver(scanner, printer); solver.Solve(); streamWriter.Flush(); } catch (Exception e) { Console.WriteLine(e); if (args.Any() == false) throw e; } if (args.Any()) Console.ReadKey(); } } } namespace V { partial class Solver { public Solver(Scanner sc, Printer pr) { this.sc = sc; this.pr = pr; } private readonly Scanner sc; private readonly Printer pr; private IEnumerable<int> Loop(int n) => C.Loop(n); private IEnumerable<long> Loop(long n) => C.Loop(n); private int RdInt => sc.Int; private int ReadInt => sc.Int; private long Rd => sc.Long; private long Read => sc.Long; private long ReadLong => sc.Long; private double RdDouble => sc.Double; private double ReadDouble => sc.Double; private string Str => sc.Str; private string RdStr => sc.Str; private string ReadStr => sc.Str; private int[] ArrInt(int n) => sc.Ints(n); private int[] ArrInt(long n) => sc.Ints(n); private long[] Arr(int n) => sc.Longs(n); private long[] Arr(long n) => sc.Longs(n); private long[] ArrLong(int n) => sc.Longs(n); private long[] ArrLong(long n) => sc.Longs(n); private double[] ArrDouble(int n) => sc.Doubles(n); private double[] ArrDouble(long n) => sc.Doubles(n); private string[] ArrStr(int n) => sc.Strs(n); private string[] ArrStr(long n) => sc.Strs(n); private void Wr(string s) => pr.Write(s); private void Wr(object obj) => pr.Write(obj); private void Wr<T>(IEnumerable<T> ts) => pr.Write(ts); private void Wr(params object[] objs) => pr.Write(objs); private void Write(string s) => pr.Write(s); private void Write(object obj) => pr.Write(obj); private void Write<T>(IEnumerable<T> ts) => pr.Write(ts); private void Write(params object[] objs) => pr.Write(objs); private void YesNo(bool b) => Write(b ? "Yes" : "No"); private void YESNO(bool b) => Write(b ? "YES" : "NO"); } class Scanner { private readonly TextReader reader; public Scanner(TextReader reader) { this.reader = reader; } private Queue<string> strQueue = new Queue<string>(); public string Str { get { if (strQueue.Count > 0) return strQueue.Dequeue(); string[] strs = null; do { strs = reader.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } while (strs.Any() == false); foreach (var s in strs.Skip(1)) strQueue.Enqueue(s); return strs[0]; } } public int Int => int.Parse(this.Str); public long Long => long.Parse(this.Str); public double Double => double.Parse(this.Str); public static bool TypeEquals<T1, T2>() => typeof(T1).Equals(typeof(T2)); public static T1 ChangeTypes<T1, T2>(T2 t2) => (T1)System.Convert.ChangeType(t2, typeof(T1)); public static T1 Convert<T1>(string s) => TypeEquals<T1, int>() ? ChangeTypes<T1, int>(int.Parse(s)) : TypeEquals<T1, long>() ? ChangeTypes<T1, long>(long.Parse(s)) : TypeEquals<T1, double>() ? ChangeTypes<T1, double>(int.Parse(s)) : TypeEquals<T1, char>() ? ChangeTypes<T1, char>(s[0]) : ChangeTypes<T1, string>(s); public Pair<TX, TY> P2<TX, TY>() => new Pair<TX, TY>(Convert<TX>(this.Str), Convert<TY>(this.Str)); public Pair3<TX, TY, TZ> P3<TX, TY, TZ>() => new Pair3<TX, TY, TZ>( Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str)); public Pair4<TX, TY, TZ, TW> P4<TX, TY, TZ, TW>() => new Pair4<TX, TY, TZ, TW>(Convert<TX>(this.Str), Convert<TY>(this.Str), Convert<TZ>(this.Str), Convert<TW>(this.Str)); } static class ScannerExtension { public static int[] Ints(this Scanner scanner, int n) => scanner.Ints((long)n); public static int[] Ints(this Scanner scanner, long n) => scanner.ScanStrs<int>(n).ToArray(); public static long[] Longs(this Scanner scanner, int n) => scanner.Longs((long)n); public static long[] Longs(this Scanner scanner, long n) => scanner.ScanStrs<long>(n).ToArray(); public static double[] Doubles(this Scanner scanner, int n) => scanner.Doubles((long)n); public static double[] Doubles(this Scanner scanner, long n) => scanner.ScanStrs<double>(n).ToArray(); public static string[] Strs(this Scanner scanner, int n) => scanner.Strs((long)n); public static string[] Strs(this Scanner scanner, long n) => scanner.ScanStrs<string>(n).ToArray(); private static IEnumerable<T> ScanStrs<T>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return Scanner.Convert<T>(scanner.Str); } public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, int n) => scanner.Pairs<TX, TY>((long)n); public static Pair<TX, TY>[] Pairs<TX, TY>(this Scanner scanner, long n) => scanner.ScanPairs<TX, TY>(n).ToArray(); public static Pair<long, long>[] Pairs(this Scanner scanner, int n) => scanner.Pairs((long)n); public static Pair<long, long>[] Pairs(this Scanner scanner, long n) => scanner.ScanPairs<long, long>(n).ToArray(); public static Pair<int, int>[] PairsInt(this Scanner scanner, int n) => scanner.PairsInt((long)n); public static Pair<int, int>[] PairsInt(this Scanner scanner, long n) => scanner.ScanPairs<int, int>(n).ToArray(); private static IEnumerable<Pair<TX, TY>> ScanPairs<TX, TY>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P2<TX, TY>(); } public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>( this Scanner scanner, int n) => scanner.Pairs3<TX, TY, TZ>((long)n); public static Pair3<TX, TY, TZ>[] Pairs3<TX, TY, TZ>(this Scanner scanner, long n) => scanner.ScanPairs3<TX, TY, TZ>(n).ToArray(); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, int n) => scanner.Pairs3((long)n); public static Pair3<long, long, long>[] Pairs3(this Scanner scanner, long n) => scanner.ScanPairs3<long, long, long>(n).ToArray(); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, int n) => scanner.Pairs3Int((long)n); public static Pair3<int, int, int>[] Pairs3Int(this Scanner scanner, long n) => scanner.ScanPairs3<int, int, int>(n).ToArray(); private static IEnumerable<Pair3<TX, TY, TZ>> ScanPairs3<TX, TY, TZ>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P3<TX, TY, TZ>(); } public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, int n) => scanner.Pairs4<TX, TY, TZ, TW>((long)n); public static Pair4<TX, TY, TZ, TW>[] Pairs4<TX, TY, TZ, TW>( this Scanner scanner, long n) => scanner.ScanPairs4<TX, TY, TZ, TW>(n).ToArray(); public static Pair4<long, long, long, long>[] Pairs4( this Scanner scanner, int n) => scanner.Pairs4((long)n); public static Pair4<long, long, long, long>[] Pairs4(this Scanner scanner, long n) => scanner.ScanPairs4<long, long, long, long>(n).ToArray(); public static Pair4<int, int, int, int>[] Pairs4Int( this Scanner scanner, int n) => scanner.Pairs4Int((long)n); public static Pair4<int, int, int, int>[] Pairs4Int(this Scanner scanner, long n) => scanner.ScanPairs4<int, int, int, int>(n).ToArray(); private static IEnumerable<Pair4<TX, TY, TZ, TW>> ScanPairs4<TX, TY, TZ, TW>(this Scanner scanner, long n) { for (long i = 0; i < n; i++) yield return scanner.P4<TX, TY, TZ, TW>(); } } class Pair<TX, TY> { public TX X { get; } public TY Y { get; } public Pair(TX x, TY y) { this.X = x; this.Y = y; } } class Pair : Pair<long, long> { public Pair(long x, long y) : base(x, y) {} } class PairInt : Pair<int, int> { public PairInt(int x, int y) : base(x, y) {} } class Pair3<TX, TY, TZ> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public Pair3(TX x, TY y, TZ z) { this.X = x; this.Y = y; this.Z = z; } } class Pair3 : Pair3<long, long, long> { public Pair3(long x, long y, long z) : base(x, y, z) {} } class Pair3Int : Pair3<int, int, int> { public Pair3Int(int x, int y, int z) : base(x, y, z) {} } class Pair4<TX, TY, TZ, TW> { public TX X { get; } public TY Y { get; } public TZ Z { get; } public TW W { get; } public Pair4(TX x, TY y, TZ z, TW w) { this.X = x; this.Y = y; this.Z = z; this.W = w; } } class Pair4 : Pair4<long, long, long, long> { public Pair4(long x, long y, long z, long w) : base(x, y, z, w) {} } class Pair4Int : Pair4<int, int, int, int> { public Pair4Int(int x, int y, int z, int w) : base(x, y, z, w) {} } class Printer { private readonly TextWriter writer; public Printer(TextWriter writer) { this.writer = writer; } public void Write(string obj) { writer.WriteLine(obj); } public void Write(object obj) { writer.WriteLine(obj); } public void Write<T>(IEnumerable<T> ts) { writer.WriteLine(string.Join(" ", ts)); } public void Write(params object[] objs) { writer.WriteLine(string.Join(" ", objs)); } } static class Extension { public static bool TryRemove<T>(this HashSet<T> ts, T t) { if (ts.Contains(t)) { ts.Remove(t); return true; } else { return false; } } public static void SafeSet<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] = value; else ts.Add(t, value); } public static void SafeAdd<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] += value; else ts.Add(t, value); } public static void SafeSub<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] -= value; else ts.Add(t, value); } public static void SafeMult<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] *= value; else ts.Add(t, value); } public static void SafeDiv<T>(this Dictionary<T, long> ts, T t, long value) { if (ts.ContainsKey(t)) ts[t] /= value; else ts.Add(t, value); } public static HashSet<T> ToHashSet<T>(this IEnumerable<T> ts) => new HashSet<T>(ts.Distinct()); public static long ToDigit(this char c) => (long)(c - '0'); public static long ToSmallAbcIndex(this char c) => (long)(c - 'a'); public static long ToLargeAbcIndex(this char c) => (long)(c - 'A'); public static long Count<T1, T2>(this IGrouping<T1, T2> gs) => gs.LongCount(); } class C { public class IterTools { /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<long>> Combinations(long n, long k) { if (k <= 0) yield break; long[] indices = new long[k]; long pointer = 0; while (pointer >= 0) { if (indices[pointer] < n) { if (pointer >= k - 1) { yield return indices; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複なし) /// n = 4, k = 3 => (0,1,2) (0,1,3) (0,2,3) (1,2,3) /// </summary> public static IEnumerable<IReadOnlyList<T>> Combinations<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = indices[pointer] + 1; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<long>> CombinationsWithReplacement(long n, long k) { if (k <= 0) yield break; long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (pointer >= k - 1) { yield return container; container[pointer]++; } else { container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) container[pointer]++; } } } /// <summary> /// 組み合わせ(重複あり) /// n = 3, k = 2 => (0,0) (0,1) (0,2) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2) /// </summary> public static IEnumerable<IReadOnlyList<T>> CombinationsWithReplacement<T>(T[] ts, long k) { if (k <= 0) yield break; long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { container[pointer] = ts[indices[pointer]]; if (pointer >= k - 1) { yield return container; indices[pointer]++; } else { indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) indices[pointer]++; } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<long>> Permutations(long n, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] container = new long[k]; long pointer = 0; while (pointer >= 0) { if (container[pointer] < n) { if (enumed.Contains(container[pointer])) { container[pointer]++; } else if (pointer >= k - 1) { yield return container; container[pointer]++; } else { enumed.Add(container[pointer]); container[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(container[pointer]); container[pointer]++; } } } } /// <summary> /// 順列 /// n = 3, k = 2 => (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) /// </summary> public static IEnumerable<IReadOnlyList<T>> Permutations<T>(T[] ts, long k) { if (k <= 0) yield break; HashSet<long> enumed = new HashSet<long>(); long[] indices = new long[k]; T[] container = new T[k]; long pointer = 0; long n = ts.LongLength; while (pointer >= 0) { if (indices[pointer] < n) { if (enumed.Contains(indices[pointer])) { indices[pointer]++; } else if (pointer >= k - 1) { container[pointer] = ts[indices[pointer]]; yield return container; indices[pointer]++; } else { container[pointer] = ts[indices[pointer]]; enumed.Add(indices[pointer]); indices[pointer + 1] = 0; pointer++; } } else { pointer--; if (pointer >= 0) { enumed.Remove(indices[pointer]); indices[pointer]++; } } } } } public class Tree { public Tree() { toNodes = new Dictionary<long, long[]>(); } public Tree(Scanner sc, long n, bool base1 = true, bool singleDirection = false) { Adjust(sc.Pairs(n), base1, singleDirection); } public Tree(Pair<long, long>[] edges, bool base1 = true, bool singleDirection = false) { Adjust(edges, base1, singleDirection); } public Tree(IEnumerable<long> ps, IEnumerable<long> qs, bool base1 = true, bool singleDirection = false) { Adjust(ps.Zip(qs, (p, q) => new Pair<long, long>(p, q)).ToArray(), base1, singleDirection); } private void Adjust(Pair<long, long>[] edges, bool base1, bool singleDirection) { var arrows = base1 ? edges.Select(x => new { from = x.X - 1, to = x.Y - 1 }) : edges.Select(x => new { from = x.X, to = x.Y }); if (singleDirection == false) arrows = arrows.Concat(arrows.Select(x => new { from = x.to, to = x.from })); toNodes = arrows.GroupBy(x => x.from) .ToDictionary(x => x.Key, x => x.Select(xs => xs.to).ToArray()); } private long[] empty = new long[0]; private Dictionary<long, long[]> toNodes; public long[] To(long from) { long[] res = null; if (toNodes.TryGetValue(from, out res)) return res; else return empty; } public IEnumerable<Pair<long, long>> GetRouteEdges(long from, long to) { return GetRouteEdgesImpl(from, to).Skip(1); } private IEnumerable<Pair<long, long>> GetRouteEdgesImpl(long from, long to) { var routeNodes = GetRouteNodes(from, to); var current = -1L; foreach (var next in routeNodes) { yield return new Pair<long, long>(current, next); current = next; } } public IEnumerable<long> GetRouteNodes(long from, long to) { Stack<long> routeNodes = new Stack<long>(); HashSet<long> checkedNodes = new HashSet<long>(); GetRouteNodes(from, to, routeNodes, checkedNodes); return routeNodes.Reverse(); } private bool GetRouteNodes(long current, long dest, Stack<long> routeNodes, HashSet<long> checkedNodes) { routeNodes.Push(current); checkedNodes.Add(current); if (current == dest) return true; foreach (var next in toNodes[current]) { if (checkedNodes.Contains(next)) continue; if (GetRouteNodes(next, dest, routeNodes, checkedNodes)) return true; } routeNodes.Pop(); return false; } } public class PriorityQueue<TKey, TState> where TKey : IComparable<TKey> { public int Count { get; private set; } private readonly Func<TState, TKey> keySelector; private readonly bool desc; private TState[] states = new TState[65536]; private TKey[] keys = new TKey[65536]; //[MethodImpl(MethodImplOptions.AggressiveInlining)] public PriorityQueue(Func<TState, TKey> keySelector, bool desc = false) { this.keySelector = keySelector; this.desc = desc; } public TState Top { //[MethodImpl(MethodImplOptions.AggressiveInlining)] get { ValidateNonEmpty(); return states[1]; } } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public TState Dequeue() { var top = Top; var item = states[Count]; var key = keys[Count]; Count--; int index = 1; while (true) { if ((index << 1) >= Count) { if (index << 1 > Count) break; if (key.CompareTo(keys[index << 1]) <= 0 ^ desc) break; states[index] = states[index << 1]; keys[index] = keys[index << 1]; index <<= 1; } else { var nextIndex = keys[index << 1].CompareTo(keys[(index << 1) + 1]) <= 0 ^ desc ? (index << 1) : (index << 1) + 1; if (key.CompareTo(keys[nextIndex]) <= 0 ^ desc) break; states[index] = states[nextIndex]; keys[index] = keys[nextIndex]; index = nextIndex; } } states[index] = item; keys[index] = key; return top; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] public void Enqueue(TState state) { var key = keySelector.Invoke(state); Count++; int index = Count; if (states.Length == Count) Extend(states.Length * 2); while ((index >> 1) != 0) { if (keys[index >> 1].CompareTo(key) <= 0 ^ desc) break; states[index] = states[index >> 1]; keys[index] = keys[index >> 1]; index >>= 1; } states[index] = state; keys[index] = key; } //[MethodImpl(MethodImplOptions.AggressiveInlining)] private void Extend(int newSize) { TState[] newStates = new TState[newSize]; TKey[] newKeys = new TKey[newSize]; states.CopyTo(newStates, 0); keys.CopyTo(newKeys, 0); states = newStates; keys = newKeys; } private void ValidateNonEmpty() { if (Count == 0) throw new IndexOutOfRangeException(); } } public class BinaryIndexTree { long length; long[] binaryIndexedTree; public BinaryIndexTree(long length) { this.length = length; binaryIndexedTree = new long[length + 1]; } public void Add(long indexZeroBase, long additional) { // i += i & -i // 1が立っている最下位ビットを足す、の意味 for (long i = indexZeroBase + 1; i <= length; i += i & -i) { binaryIndexedTree[i] += additional; } } public long Sum(long indexZeroBase) { long result = 0; // i += i & -i // 1が立っている最下位ビットを引く、の意味 for (long i = indexZeroBase + 1; i > 0; i -= i & -i) { result += binaryIndexedTree[i]; } return result; } } public static class BinarySearch { public static long GetFirstIndexGreater(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetFirstIndexGreater(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } public static long GetLastIndexLess(long x, IReadOnlyList<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } public static long GetLastIndexLess(int x, IReadOnlyList<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } 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 static long Gcd(int a, int b) => Gcd((long)a, (long)b); public static long Gcd(long a, long b) { if (a < b) return GcdImpl(b, a); else return GcdImpl(a, b); } private static long GcdImpl(long a, long b) { var remainder = a % b; if (remainder == 0) return b; else return GcdImpl(b, remainder); } public static long Lcm(int a, int b) => Lcm((long)a, (long)b); public static long Lcm(long a, long b) { return a / Gcd(a, b) * b; } public static long Pow(int n, int p) => Pow((long)n, (long)p); public static long Pow(long n, long p) { var res = 1L; for (long i = 0; i < p; i++) res *= n; return res; } public static Dictionary<long, long> Factorize(int n) => Factorize((long)n); public static Dictionary<long, long> Factorize(long n) { var res = new Dictionary<long, long>(); var r = n; for (long i = 2; i * i <= r; i++) { var c = 0L; while (r % i == 0) { c++; r /= i; } if (c > 0) res.Add(i, c); } if (r > 1) res.Add(r, 1); return res; } public static IEnumerable<long> Divisors(int n) => Divisors((long)n); public static IEnumerable<long> Divisors(long n) { var cache = new Stack<long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; cache.Push(i); } } var r = cache.Peek(); if (r * r == n) cache.Pop(); while (cache.Count > 0) { var i = cache.Pop(); yield return n / i; } } public static IEnumerable<int> Loop(int n) { for (int i = 0; i < n; i++) yield return i; } public static IEnumerable<long> Loop(long n) { for (long i = 0L; i < n; i++) yield return i; } } struct Mint { public static long Divider { set { divider = value; } } private static long divider = 1000000007L; public static void Set998244353() { divider = 998244353L; } public static void Set1000000009() { divider = 1000000009L; } public long Value { get; } public override string ToString() => this.Value.ToString(); public Mint(long value) { this.Value = value; } // public static implicit operator Mint(long a) => new Mint(a % divider); // public static implicit operator Mint(int a) => new Mint(a % divider); // public static explicit operator long(Mint a) => a.Value; // public static explicit operator int(Mint a) => (int)a.Value; public static Mint operator +(Mint a, Mint b) => new Mint((a.Value + b.Value) % divider); public static Mint operator +(Mint a, long b) => a + new Mint(b); public static Mint operator +(Mint a, int b) => a + new Mint(b); public static Mint operator -(Mint a, Mint b) { var t = (a.Value - b.Value) % divider; if (t < 0L) t += divider; return new Mint(t); } public static Mint operator -(Mint a, long b) => a - new Mint(b); public static Mint operator -(Mint a, int b) => a - new Mint(b); public static Mint operator *(Mint a, Mint b) => new Mint((a.Value * b.Value) % divider); public static Mint operator *(Mint a, long b) => a * new Mint(b); public static Mint operator *(Mint a, int b) => a * new Mint(b); public static Mint operator /(Mint a, Mint b) => new Mint((a.Value * InvImpl(b.Value)) % divider); public static Mint operator /(Mint a, long b) => a / new Mint(b); public static Mint operator /(Mint a, int b) => a / new Mint(b); public Mint Pow(long p) => new Mint(PowImpl(Value, p)); public static Mint Pow(long a, long p) => new Mint(PowImpl(a, p)); private static long PowImpl(long a, long p) { if (p == 0L) return 1L; if (p == 1L) return a; var halfP = p / 2L; var halfPowered = PowImpl(a, halfP); var powered = halfPowered * halfPowered % divider; return p % 2L == 0L ? powered : (powered * a) % divider; } public static Mint Inv(long a) => new Mint(InvImpl(a)); private static readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); private static long InvImpl(long a) { long cache; if (invCache.TryGetValue(a, out cache)) return cache; var result = PowImpl(a, divider - 2L); invCache.Add(a, result); return result; } public static Mint Fac(long a) => new Mint(FacImpl(a)); private static long[] facCache = new long[262144]; private static long cachedFac = 0L; private static long FacImpl(long a) { if (a >= divider) return 0L; facCache[0] = 1L; if (facCache.LongLength <= a) { long newSize = facCache.LongLength; while (newSize <= a) { newSize *= 2; } ExtendFacCache(newSize); } if (cachedFac < a) { var val = facCache[cachedFac]; var start = cachedFac + 1L; for (long i = start; i <= a; i++) { val = (val * i) % divider; facCache[i] = val; } cachedFac = a; } return facCache[a]; } private static void ExtendFacCache(long newSize) { long[] newFacCache = new long[newSize]; facCache.CopyTo(newFacCache, 0); facCache = newFacCache; } public static Mint Perm(long n, long r) => new Mint(PermImpl(n, r)); private static long PermImpl(long n, long r) { if (n < r) return 0L; if (r <= 0L) return 1L; var nn = FacImpl(n); var nr = FacImpl(n - r); return (nn * InvImpl(nr)) % divider; } public static Mint Comb(long n, long r) => new Mint(CombImpl(n, r)); private static long CombImpl(long n, long r) { if (n < r) return 0L; if (n == r) return 1L; if (n - r < r) return CombImpl(n, n - r); var nn = FacImpl(n); var nr = FacImpl(n - r); var rr = FacImpl(r); var nrrr = (nr * rr) % divider; return (nn * InvImpl(nrrr)) % divider; } } }
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 11, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 11, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 11, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 12, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 11, 12, 16, 31, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 28, 0, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 28, 0, 16, 31, 16, 31, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 11, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
8,242
23
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramE { static void Main() { var l = Line; var dp = new long[l.Length + 1, 2]; dp[0, 0] = 1; for (int i = 0; i < l.Length; i++) { if (l[i] == '1') { dp[i + 1, 0] = (dp[i, 0] * 2) % Modular.mod; dp[i + 1, 1] = dp[i, 0]; } else { dp[i + 1, 0] = dp[i, 0]; } dp[i + 1, 1] = (dp[i + 1, 1] + dp[i, 1] * 3) % Modular.mod; } System.Console.WriteLine(dp[l.Length, 0] + dp[l.Length, 1]); } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } } namespace Library { class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return 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, mod - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % mod)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramE { static void Main() { var l = Line; var dp = new long[l.Length + 1, 2]; dp[0, 0] = 1; for (int i = 0; i < l.Length; i++) { if (l[i] == '1') { dp[i + 1, 0] = dp[i, 0] * 2 % Modular.mod; dp[i + 1, 1] = dp[i, 0]; } else { dp[i + 1, 0] = dp[i, 0]; } dp[i + 1, 1] = (dp[i + 1, 1] + dp[i, 1] * 3) % Modular.mod; } System.Console.WriteLine((dp[l.Length, 0] + dp[l.Length, 1]) % Modular.mod); } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } } namespace Library { class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return 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, mod - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % mod)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } } }
[["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 3, 4, 0, 28, 0, 16, 12, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 12, 214, 141, 22]]
8
808
8
using System; using System.Collections.Generic; // list用 using System.Text; // StringBuilder用 using System.Collections; using System.Linq; class Program { static string s; static decimal result; static void Main() { Read5(); var mo = new Modular(1); var mo2 = new Modular(1); bool f = false; for (int i = 0; i < s.Length; i++) { // 0なら,ここまでに(0,0)がなければならない。なければここが(0,0)で確定 if (s[i] == '0' && f == false) { mo = (mo - mo2) * 3 + mo2; f = true; continue; } mo *= 3; //(0,0)(0,1)(1,0)で条件を満たす mo2 *= 2; //(1,0)(0,1)のみのパターンを集計しておく } Console.WriteLine(((int)mo).ToString()); } static void Read5() // N行K項 { s = Console.ReadLine(); } } class Modular { private const int M = 1000000007; private long value; public Modular(long value) { 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) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } private 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 }; private 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 Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } }
using System; using System.Collections.Generic; // list用 using System.Text; // StringBuilder用 using System.Collections; using System.Linq; class Program { static string s; static decimal result; static void Main() { Read5(); var mo = new Modular(1); var mo2 = new Modular(1); for (int i = 0; i < s.Length; i++) { // 0なら,ここまでに(0,0)がなければならない。なければここが(0,0)で確定 if (s[i] == '0') { mo = (mo - mo2) * 3 + mo2; continue; } mo *= 3; //(0,0)(0,1)(1,0)で条件を満たす mo2 *= 2; //(1,0)(0,1)のみのパターンを集計しておく } Console.WriteLine(((int)mo).ToString()); } static void Read5() // N行K項 { s = Console.ReadLine(); } } class Modular { private const int M = 1000000007; private long value; public Modular(long value) { 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) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } private 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 }; private 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 Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 57, 15, 16, 12, 16, 12, 211, 0, 147], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146]]
8
532
13
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { Scanner cin = new Scanner(); string l = cin.Next(); int n = l.Length; var dpl = new ModInt[n]; var dp = new ModInt[n]; for (int i = 0; i < n; i++) { if (i == 0) { dpl[i] = 2; dp[i] = 1; } else { if (l[i] == '1') { dpl[i] = (dpl[i - 1]) * 2; dp[i] = (dp[i - 1]) * 3 + dpl[i - 1]; } else { dpl[i] = dpl[i - 1]; dp[i] = dpl[i - 1] * 3 + dp[i - 1]; } } } Console.WriteLine(dp[n - 1] + dpl[n - 1]); } } public struct ModInt { public static long Mod { get; set; } = (long)1e9 + 7; public static ModInt Pow(ModInt value, long k) { return Pow(value.Value, k); } public static ModInt Pow(long value, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, value = value * value % Mod) { if ((k & 1) == 1) { ret = ret * value % Mod; } } return new ModInt(ret); } public static ModInt Inverse(ModInt value) { return Pow(value, Mod - 2); } public long Value; public ModInt(long value) { Value = value; } public static ModInt operator +(ModInt lhs, ModInt rhs) { lhs.Value += rhs.Value; if (lhs.Value >= Mod) { lhs.Value -= Mod; } return lhs; } public static ModInt operator -(ModInt lhs, ModInt rhs) { lhs.Value -= rhs.Value; if (lhs.Value < 0) { lhs.Value += Mod; } return lhs; } public static ModInt operator *(ModInt lhs, ModInt rhs) { return new ModInt(lhs.Value * rhs.Value % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) { n += Mod; } return new ModInt(n); } public override string ToString() { return Value.ToString(); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { Scanner cin = new Scanner(); string l = cin.Next(); int n = l.Length; var dpl = new ModInt[n]; var dp = new ModInt[n]; for (int i = 0; i < n; i++) { if (i == 0) { dpl[i] = 2; dp[i] = 1; } else { if (l[i] == '1') { dpl[i] = (dpl[i - 1]) * 2; dp[i] = (dp[i - 1]) * 3 + dpl[i - 1]; } else { dpl[i] = dpl[i - 1]; dp[i] = dp[i - 1] * 3; } } } Console.WriteLine(dp[n - 1] + dpl[n - 1]); } } public struct ModInt { public static long Mod { get; set; } = (long)1e9 + 7; public static ModInt Pow(ModInt value, long k) { return Pow(value.Value, k); } public static ModInt Pow(long value, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, value = value * value % Mod) { if ((k & 1) == 1) { ret = ret * value % Mod; } } return new ModInt(ret); } public static ModInt Inverse(ModInt value) { return Pow(value, Mod - 2); } public long Value; public ModInt(long value) { Value = value; } public static ModInt operator +(ModInt lhs, ModInt rhs) { lhs.Value += rhs.Value; if (lhs.Value >= Mod) { lhs.Value -= Mod; } return lhs; } public static ModInt operator -(ModInt lhs, ModInt rhs) { lhs.Value -= rhs.Value; if (lhs.Value < 0) { lhs.Value += Mod; } return lhs; } public static ModInt operator *(ModInt lhs, ModInt rhs) { return new ModInt(lhs.Value * rhs.Value % Mod); } public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) { n += Mod; } return new ModInt(n); } public override string ToString() { return Value.ToString(); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
[["-", 0, 11, 12, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["-", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73]]
8
917
9
using System; using System.Collections.Generic; public class CSharp { public static void Main() { Kyopuro chokudai = new Kyopuro(); chokudai.AtCoder(); } } public class Kyopuro { int n, m; int[] a, b, c; int x; long ans; public void AtCoder() { string[] input; input = Console.ReadLine().Split(' '); n = int.Parse(input[0]); m = int.Parse(input[1]); a = new int[n]; b = new int[n]; c = new int[n]; input = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) a[i] = int.Parse(input[i]); for (int i = 0; i < m; i++) { input = Console.ReadLine().Split(' '); b[i] = int.Parse(input[0]); c[i] = int.Parse(input[1]); } Array.Sort(a); Array.Sort(c, b); x = 0; ans = 0; for (int i = n - 1; i > -1; i--) { for (int j = 0; j < b[i]; j++) { if (x >= n) { i = -1; return; } if (c[i] > a[x]) { a[x] = c[i]; x++; } else { i = -1; break; } } } for (int i = 0; i < n; i++) ans += a[i]; Console.WriteLine(ans); } public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); } }
using System; using System.Collections.Generic; public class CSharp { public static void Main() { Kyopuro chokudai = new Kyopuro(); chokudai.AtCoder(); } } public class Kyopuro { int n, m; int[] a, b, c; int x; long ans; public void AtCoder() { string[] input; input = Console.ReadLine().Split(' '); n = int.Parse(input[0]); m = int.Parse(input[1]); a = new int[n]; b = new int[m]; c = new int[m]; input = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) a[i] = int.Parse(input[i]); for (int i = 0; i < m; i++) { input = Console.ReadLine().Split(' '); b[i] = int.Parse(input[0]); c[i] = int.Parse(input[1]); } Array.Sort(a); Array.Sort(c, b); x = 0; ans = 0; for (int i = m - 1; i > -1; i--) { for (int j = 0; j < b[i]; j++) { if (x >= n) { i = -1; break; } if (c[i] > a[x]) { a[x] = c[i]; x++; } else { i = -1; break; } } } for (int i = 0; i < n; i++) { ans += a[i]; DebugWL(a[i]); } Console.WriteLine(ans); } public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); } }
[["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
405
18
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; namespace Program { public static class ABC127E { static public void Solve() { var N = NextInt; var M = NextInt; var K = NextInt; var pat = Mod.Comb(N * M - 2, K - 2); Mod ansm = 0; for (Mod i = 1; i < M; ++i) { ansm += i * (M - i); } ansm *= pat * N * N; Mod ansn = 0; for (Mod i = 1; i < N; ++i) { ansn += i * (N - i); } ansn *= pat * M * M; Console.WriteLine(ansn + ansm); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { private static Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => int.Parse(Console_.NextString()); static long NextLong => long.Parse(Console_.NextString()); static double NextDouble => double.Parse(Console_.NextString()); static string NextString => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<int> NextIntList(long N) => Enumerable.Repeat(0, (int)N).Select(_ => NextInt).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<long> NextLongList(long N) => Enumerable.Repeat(0, (int)N).Select(_ => NextLong).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<double> NextDoubleList(long N) => Enumerable.Repeat(0, (int)N).Select(_ => NextDouble).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<string> NextStringList(long N) => Enumerable.Repeat(0, (int)N).Select(_ => NextString).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> Sort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> Sort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, comp); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> RevSort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => y.CompareTo(x)); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> RevSort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => comp(y, x)); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } class PQ<T> where T : IComparable { private List<T> h; private Comparison<T> c; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Peek => h[0]; public int Count => h.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TKey, TValue> where TKey : IComparable { private PQ<Tuple<TKey, TValue>> q; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v)); public Tuple<TKey, TValue> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TKey, TValue> Pop() => q.Pop(); } struct Mod : IEquatable<object> { static public long _mod = 1000000007; private long _val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mod(long x) { if (x < _mod && x >= 0) _val = x; else if ((_val = x % _mod) < 0) _val += _mod; } static public implicit operator Mod(long x) => new Mod(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator long(Mod x) => x._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(Mod x, Mod y) => x._val + y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) => x._val - y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(Mod x, Mod y) => x._val == y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(Mod x, Mod y) => x._val != y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] bool IEquatable<object>.Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() => _val.GetHashCode(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => _val.ToString(); static private List<Mod> _fact = new List<Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[n - k] / _fact[k]; } } struct Mat<T> { private T[,] m; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mat(T[,] v) { m = (T[,])v.Clone(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mod Pow(Mod x, long y) => Mod.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Comb(int n, int k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[k] / _fact[n - k]; } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; namespace Program { public static class ABC127E { static public void Solve() { var N = NextInt; var M = NextInt; var K = NextInt; var pat = Mod.Comb(N * M - 2, K - 2); Mod ansm = 0; for (Mod i = 1; i < M; ++i) { ansm += i * (M - i); } ansm *= pat * N * N; Mod ansn = 0; for (Mod i = 1; i < N; ++i) { ansn += i * (N - i); } ansn *= pat * M * M; Console.WriteLine(ansn + ansm); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } Solve(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { private static Queue<string> param = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } } static int NextInt => int.Parse(Console_.NextString()); static long NextLong => long.Parse(Console_.NextString()); static double NextDouble => double.Parse(Console_.NextString()); static string NextString => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<int> NextIntList(long N) => Enumerable.Repeat(0, (int)N).Select(_ => NextInt).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<long> NextLongList(long N) => Enumerable.Repeat(0, (int)N).Select(_ => NextLong).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<double> NextDoubleList(long N) => Enumerable.Repeat(0, (int)N).Select(_ => NextDouble).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<string> NextStringList(long N) => Enumerable.Repeat(0, (int)N).Select(_ => NextString).ToList(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => rand.Next()); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> Sort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> Sort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, comp); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> RevSort<T>(List<T> l) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => y.CompareTo(x)); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static List<T> RevSort<T>(List<T> l, Comparison<T> comp) where T : IComparable { var tmp = l.ToArray(); Array.Sort(tmp, (x, y) => comp(y, x)); return tmp.ToList(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Primes(long x) { if (x < 2) yield break; yield return 2; var halfx = x / 2; var table = new bool[halfx + 1]; var max = (long)(Math.Sqrt(x) / 2); for (long i = 1; i <= max; ++i) { if (table[i]) continue; var add = 2 * i + 1; yield return add; for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true; } for (long i = max + 1; i <= halfx; ++i) if (!table[i] && 2 * i + 1 <= x) yield return 2 * i + 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Factors(long x) { if (x < 2) yield break; while (x % 2 == 0) { x /= 2; yield return 2; } var max = (long)Math.Sqrt(x); for (long i = 3; i <= max; i += 2) while (x % i == 0) { x /= i; yield return i; } if (x != 1) yield return x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerable<long> Divisor(long x) { if (x < 1) yield break; var max = (long)Math.Sqrt(x); for (long i = 1; i <= max; ++i) { if (x % i != 0) continue; yield return i; if (i != x / i) yield return x / i; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GCD(long a, long b) { while (b > 0) { var tmp = b; b = a % b; a = tmp; } return a; } class PQ<T> where T : IComparable { private List<T> h; private Comparison<T> c; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<T> c, bool asc = true) { h = new List<T>(cap); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<T> c, bool asc = true) { h = new List<T>(); this.c = asc ? c : (x, y) => c(y, x); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(T v) { var i = h.Count; h.Add(v); while (i > 0) { var ni = (i - 1) / 2; if (c(v, h[ni]) >= 0) break; h[i] = h[ni]; i = ni; } h[i] = v; } public T Peek => h[0]; public int Count => h.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Pop() { var r = h[0]; var v = h[h.Count - 1]; h.RemoveAt(h.Count - 1); if (h.Count == 0) return r; var i = 0; while (i * 2 + 1 < h.Count) { var i1 = i * 2 + 1; var i2 = i * 2 + 2; if (i2 < h.Count && c(h[i1], h[i2]) > 0) i1 = i2; if (c(v, h[i1]) <= 0) break; h[i] = h[i1]; i = i1; } h[i] = v; return r; } } class PQ<TKey, TValue> where TKey : IComparable { private PQ<Tuple<TKey, TValue>> q; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TKey> c, bool asc = true) { q = new PQ<Tuple<TKey, TValue>>((x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, bool asc = true) : this(cap, (x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(bool asc = true) : this((x, y) => x.CompareTo(y), asc) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Push(TKey k, TValue v) => q.Push(Tuple.Create(k, v)); public Tuple<TKey, TValue> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TKey, TValue> Pop() => q.Pop(); } struct Mod : IEquatable<object> { static public long _mod = 1000000007; private long _val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mod(long x) { if (x < _mod && x >= 0) _val = x; else if ((_val = x % _mod) < 0) _val += _mod; } static public implicit operator Mod(long x) => new Mod(x); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator long(Mod x) => x._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator +(Mod x, Mod y) => x._val + y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) => x._val - y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator *(Mod x, Mod y) => x._val * y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator /(Mod x, Mod y) => x._val * Inverse(y._val); [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator ==(Mod x, Mod y) => x._val == y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public bool operator !=(Mod x, Mod y) => x._val != y._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Pow(Mod x, long y) { Mod a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public long Inverse(long x) { long b = _mod, r = 1, u = 0, t = 0; while (b > 0) { var q = x / b; t = u; u = r - q * u; r = t; t = b; b = x - q * b; x = t; } return r < 0 ? r + _mod : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] bool IEquatable<object>.Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(object obj) => obj == null ? false : Equals((Mod)obj); [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(Mod obj) => obj == null ? false : _val == obj._val; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() => _val.GetHashCode(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => _val.ToString(); static private List<Mod> _fact = new List<Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static private void Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Comb(int n, int k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[n - k] / _fact[k]; } } struct Mat<T> { private T[,] m; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Mat(T[,] v) { m = (T[,])v.Clone(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public implicit operator Mat<T>(T[,] v) => new Mat<T>(v); public T this[int r, int c] { get { return m[r, c]; } set { m[r, c] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator +(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] += (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator -(Mat<T> a, Mat<T> b) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] -= (dynamic)b[r, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, T x) { var tm = (T[,])a.m.Clone(); for (int r = 0; r < tm.GetLength(0); ++r) for (int c = 0; c < tm.GetLength(1); ++c) tm[r, c] *= (dynamic)x; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> operator *(Mat<T> a, Mat<T> b) { var nr = a.m.GetLength(0); var nc = b.m.GetLength(1); var tm = new T[nr, nc]; for (int i = 0; i < nr; ++i) for (int j = 0; j < nc; ++j) tm[i, j] = (dynamic)0; for (int r = 0; r < nr; ++r) for (int c = 0; c < nc; ++c) for (int i = 0; i < a.m.GetLength(1); ++i) tm[r, c] += a[r, i] * (dynamic)b[i, c]; return tm; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mat<T> Pow(Mat<T> x, long y) { var n = x.m.GetLength(0); var t = (Mat<T>)new T[n, n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) t[i, j] = (dynamic)(i == j ? 1 : 0); while (y != 0) { if ((y & 1) == 1) t *= x; x *= x; y >>= 1; } return t; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mat<T> Pow<T>(Mat<T> x, long y) => Mat<T>.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static Mod Pow(Mod x, long y) => Mod.Pow(x, y); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Pow(long x, long y) { long a = 1; while (y != 0) { if ((y & 1) == 1) a *= x; x *= x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _Build(int n) { if (n >= _fact.Count) for (int i = _fact.Count; i <= n; ++i) _fact.Add(_fact[i - 1] * i); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Comb(int n, int k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[n] / _fact[k] / _fact[n - k]; } } }
[["+", 8, 201, 0, 270, 8, 201, 0, 315, 17, 48], ["+", 0, 270, 8, 201, 0, 315, 54, 55, 0, 24], ["+", 8, 201, 0, 315, 54, 55, 0, 220, 39, 22], ["+", 8, 201, 0, 315, 54, 55, 0, 220, 141, 22], ["+", 0, 270, 8, 201, 0, 315, 54, 55, 0, 21], ["+", 0, 270, 8, 201, 0, 315, 54, 55, 0, 25], ["+", 0, 270, 8, 201, 0, 315, 8, 306, 0, 221], ["+", 0, 315, 8, 306, 0, 16, 31, 214, 205, 22], ["+", 0, 315, 8, 306, 0, 16, 31, 214, 0, 131], ["+", 0, 315, 8, 306, 0, 16, 31, 214, 141, 22], ["+", 8, 201, 0, 315, 8, 306, 0, 16, 17, 48], ["+", 0, 315, 8, 306, 0, 16, 12, 214, 205, 22], ["+", 0, 315, 8, 306, 0, 16, 12, 214, 0, 131], ["+", 0, 315, 8, 306, 0, 16, 12, 214, 141, 22], ["+", 8, 201, 0, 270, 8, 201, 0, 315, 0, 35], ["+", 0, 270, 8, 201, 0, 315, 0, 318, 0, 70], ["+", 8, 201, 0, 315, 0, 318, 0, 319, 141, 22], ["+", 0, 315, 0, 318, 0, 319, 0, 320, 0, 24], ["+", 0, 319, 0, 320, 0, 321, 0, 214, 205, 22], ["+", 0, 319, 0, 320, 0, 321, 0, 214, 0, 131], ["+", 0, 319, 0, 320, 0, 321, 0, 214, 141, 22], ["+", 0, 315, 0, 318, 0, 319, 0, 320, 0, 25], ["+", 0, 270, 8, 201, 0, 315, 0, 318, 0, 73], ["+", 0, 270, 8, 201, 0, 315, 0, 251, 0, 115], ["+", 0, 270, 8, 201, 0, 315, 0, 251, 0, 259], ["+", 8, 201, 0, 270, 8, 201, 0, 315, 39, 22], ["+", 8, 201, 0, 270, 8, 201, 0, 315, 0, 17]]
8
3,960
29
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; static class Program { const int mod = (int)1e9 + 7; static long[] r; static void Main() { Sc sc = new Sc(); long[] s = sc.La; r = new long[s[0] * s[1]]; r[0] = 1; long ans = 0; for (int i = 1; i < s[0] * s[1]; i++) { r[i] = (r[i - 1] * i) % mod; } long p = (((s[1] * s[1]) % mod) * Cb1(s[0] * s[1] - 2, 2)) % mod; for (int i = 1; i < s[0]; i++) { ans = (ans + (((p * i) % mod) * (s[0] - i)) % mod) % mod; } p = (((s[0] * s[0]) % mod) * Cb1(s[0] * s[1] - 2, 2)) % mod; for (int i = 1; i < s[1]; i++) { ans = (ans + (((p * i) % mod) * (s[1] - i)) % mod) % mod; } Console.WriteLine("{0}", ans); } static long Cb1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; } static long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Sc { private string[] a; private int n = -1, m = 0; public int I { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return int.Parse(a[n]); } } public long L { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return long.Parse(a[n]); } } public double D { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return double.Parse(a[n]); } } public string S { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return a[n]; } } public string Sz { get { return Console.ReadLine(); } } public int[] Ia { get { if (n != -1 && n != a.Length - 1) { m = n; n = -1; return Array.ConvertAll(a.Skip(m + 1).ToArray(), int.Parse); } return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2(int b) { return Array.ConvertAll((((b & 1) != 0 ? "0 " : "") + Console.ReadLine() + ((b & 2) != 0 ? " 0" : "")) .Split(), int.Parse); } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public string[] Sa2 { get { return (Console.ReadLine() + " 0").Split(); } } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; static class Program { const int mod = (int)1e9 + 7; static long[] r; static void Main() { Sc sc = new Sc(); long[] s = sc.La; r = new long[s[0] * s[1]]; r[0] = 1; long ans = 0; for (int i = 1; i < s[0] * s[1]; i++) { r[i] = (r[i - 1] * i) % mod; } long p = (((s[1] * s[1]) % mod) * Cb1(s[0] * s[1] - 2, s[2] - 2)) % mod; for (int i = 1; i < s[0]; i++) { ans = (ans + (((p * i) % mod) * (s[0] - i)) % mod) % mod; } p = (((s[0] * s[0]) % mod) * Cb1(s[0] * s[1] - 2, s[2] - 2)) % mod; for (int i = 1; i < s[1]; i++) { ans = (ans + (((p * i) % mod) * (s[1] - i)) % mod) % mod; } Console.WriteLine("{0}", ans); } static long Cb1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; } static long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; a ^= b; b ^= a; a ^= b; u -= t * v; u ^= v; v ^= u; u ^= v; } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Sc { private string[] a; private int n = -1, m = 0; public int I { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return int.Parse(a[n]); } } public long L { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return long.Parse(a[n]); } } public double D { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return double.Parse(a[n]); } } public string S { get { if (n == -1 || n == a.Length - 1) { n = -1; a = Console.ReadLine().Split(); } n++; return a[n]; } } public string Sz { get { return Console.ReadLine(); } } public int[] Ia { get { if (n != -1 && n != a.Length - 1) { m = n; n = -1; return Array.ConvertAll(a.Skip(m + 1).ToArray(), int.Parse); } return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public int[] Ia2(int b) { return Array.ConvertAll((((b & 1) != 0 ? "0 " : "") + Console.ReadLine() + ((b & 2) != 0 ? " 0" : "")) .Split(), int.Parse); } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public string[] Sa2 { get { return (Console.ReadLine() + " 0").Split(); } } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } }
[["+", 3, 4, 0, 28, 0, 16, 31, 204, 205, 22], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33]]
8
1,115
10
using System; class P { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); char[] c = Console.ReadLine().ToCharArray(); int N = int.Parse(str[0]); int K = int.Parse(str[1]); c[K - 1] = Char.ToLower(c[K - 1]); } }
using System; class P { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); char[] c = Console.ReadLine().ToCharArray(); int N = int.Parse(str[0]); int K = int.Parse(str[1]); c[K - 1] = Char.ToLower(c[K - 1]); Console.WriteLine(c); } }
[["+", 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], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
96
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace AtcoderC { class Program { /*static void Main(string[] args) { }*/ // ABC132C //全探索法 /*static void Main() { BigInteger N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int min = input.Min(); int max = input.Max(); int countARC = 0; int countABC = 0; int Answer = 0; for (int i = min; i <= max; i++) { countABC = 0; countARC = 0; foreach (int n in input) { if (n > i) { countARC++; } else { countABC++; } } if (countABC == countARC) { Answer++; } } Console.WriteLine(Answer); }*/ // 2回目 /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(input); int min = input[(N / 2) - 1]; int max = input[N / 2]; Console.WriteLine(max - min); }*/ // ABC131C //ユーグリッドの互除法の応用 /*static void Main() { BigInteger[] input = Console.ReadLine().Split().Select(BigInteger.Parse).ToArray(); BigInteger A = input[0]; BigInteger B = input[1]; BigInteger C = input[2]; BigInteger D = input[3]; BigInteger ans = (B / C) + (B / D); //最小公倍数 var ans2 = C * D / lcm(C, D); BigInteger ans3 = B / ans2; var BB = B - ans + ans3; ans = (A - 1) / C + (A - 1) / D; ans3 = (A - 1) / ans2; var AA = (A - 1) - ans + ans3; Console.WriteLine(BB - AA); } static public BigInteger lcm(BigInteger a, BigInteger b) { var r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; }*/ // 129C //動的計画法 // TLEになる時間がかかり過ぎる /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int> ttt = new List<int>(); for (int i = 0;i < M;i++) { var temp = int.Parse(Console.ReadLine()); ttt.Add(temp); } int[] dparray = new int[N+2]; dparray[N] = 1; dparray[N - 1] = 1; for (int i = N-1; i >= 0; i--) { if (ttt.Contains(i)) { dparray[i] = 0; } dparray[i] = (dparray[i + 1] + dparray[i + 2]) % 1000000007; } Console.WriteLine(dparray[0]); }*/ // ABC128 /*static void Main() { }*/ // ABC134A /*static void Main() { int r = int.Parse(Console.ReadLine()); var ans = 3 * r * r; Console.WriteLine(ans); }*/ // ABC134B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int D = input[1]; int count = 0; int ans = N; while (true) { ans = ans - (D * 2 + 1); count++; if (ans <= 0) { break; } } Console.WriteLine(count); }*/ // ABC134C /*static void Main() { int N = int.Parse(Console.ReadLine()); List<int> array = new List<int>(); for (int i =0;i<N; i++) { array.Add(int.Parse(Console.ReadLine())); } List<int> ans = new List<int>(); int max = array.Max(); var temp = new List<int>(); foreach (int n in array) { temp.Add(n); } temp.Sort(); temp.Reverse(); int second = temp[1]; foreach (int nn in array) { if (nn == max) { Console.WriteLine(second); } else { Console.WriteLine(max); } } }*/ // 134ABCD /*static void Main() { int N = int.Parse(Console.ReadLine()); int count = 0; int ans = 0; int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0;i<N;i++) { for (int j =0;j<N; j++) { if ((j+1)%(i+1)==0) { count += input[j]; } } if (count % 2 == input[i]) { ans++; } count = 0; } if (ans != 0) { } }*/ // AGC036 /*static void Main() { long S = long.Parse(Console.ReadLine()); long X1 = 1000000000; long Y1 = 0; /*while (true) { Y1 = S / X1 + S % X1; } Y1 = S / X1 + S % X1; Console.WriteLine("0 0 " + X1 + " 0 0 " + Y1); /*int tempX = 0; List<long> ss = new List<long>(); while (tempX < S) { var ans = S % tempX; if (ans == 0) { ss.Add(ans); } tempX++; } Console.WriteLine(tempX);*/ /*long X1 = 0; long Y1 = 1; while (true) { X1 = S % Y1; if (X1 <= 1000000000) { break; } Y1++; } Console.WriteLine("0 0 "+X1+" 0 0 "+Y1); }*/ // ABC82A /*static void Main() { double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray(); double a = input[0]; double b = input[1]; double sum = (a + b) / 2; Console.WriteLine(Math.Ceiling(sum)); }*/ // ABC128C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int ans = 0; List<int[]> K = new List<int[]>(); for (int i = 0;i<M;i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); K.Add(temp); } int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] light = new int[M]; for (int i = 0;i < Math.Pow(2,N);i++) { var isrow = 0; var temp = int.Parse(Convert.ToString(i, 2)).ToString("0000000000"); for (int j =0;j < M;j++) { var ison = 0; for (int k = 0; k < K[j][0];k++) { var index = K[j][k] - 1; if (temp[9-index] == '1') { ison++; } } if (ison % 2 == P[j]) { isrow++; } else { break; } } if (isrow == M) { ans++; } } Console.WriteLine(ans);*/ /*nt[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = input[0]; int b = input[1]; var temp = a * b % 2; if (temp == 0) { Console.WriteLine("even"); } else { Console.WriteLine("odd"); } }*/ // ABC127C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } if (M == 1) { Console.WriteLine(N); } else { List<int> card = new List<int>(); for (int i = gate[0][0]; i <= gate[0][1]; i++) { card.Add(i); } for (int j = 1; j < gate.Count; j++) { List<int> ans = new List<int>(); var count = 0; for (int i = gate[j][0]; i <= gate[j][1]; i++) { if (card.Contains(i)) { count++; ans.Add(i); } } if (count == 0) { break; } card = new List<int>(ans); } Console.WriteLine(card.Count()); } }*/ // 127C Revenge TLE /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } int Ans = 0; for (int i =1;i<=N;i++) { var count = 0; for (int j = 0;j < gate.Count;j++) { if (gate[j][0] <= i && i <= gate[j][1]) { count++; } } if (count == gate.Count) { Ans++; } } Console.WriteLine(Ans); }*/ // 127C RevengeVer2 /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } List<int> Max = new List<int>(); List<int> Min = new List<int>(); for (int i =0;i< M;i++) { Max.Add(gate[i][1]); Min.Add(gate[i][0]); } int max = Max.Min(); int min = Min.Max(); if (min <= max) { Console.WriteLine(max - min + 1); } else { Console.WriteLine("0"); } }*/ // ABC126C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; double ans = 0.0; for (int i = 1; i<= N;i++) { double tempP = (double)1 / N; int point = i; while (point<M) { tempP = tempP * 1 / 2; point *= 2; } ans += tempP; } Console.WriteLine(ans); }*/ // ABC125C ユーグリッド互除法 /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(A); int lcmr, lcml = 0; List<int> answer = new List<int>(); for (int i =0;i<A.Length;i++) { lcmr = 0; for (int x = 0;x < i;x++) { if (lcmr - A[x] >= 0) { lcmr = lcm(lcmr, A[x]); } else { lcmr = lcm(A[x], lcmr); } } lcml = 0; for (int y = i+1; y < A.Length; y++) { if (lcml - A[y] >= 0) { lcml = lcm(lcml, A[y]); } else { lcml = lcm(A[y],lcml); } } var tempans = 0; if (lcmr > lcml) { tempans = lcm(lcmr, lcml); } else { tempans = lcm(lcml, lcmr); } answer.Add(tempans); } Console.WriteLine(answer.Max()); } static public int lcm(int a, int b) { if (b == 0) { return a; } var r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; }*/ // 124C /*static void Main() { string inputstr = Console.ReadLine(); int count = 0; if (inputstr[0] == '0') { for (int i = 0; i < inputstr.Length; i++) { if (i % 2 == 0) { if (inputstr[i] == '1') { count++; } } else { if (inputstr[i] == '0') { count++; } } } } else { for (int i = 0; i < inputstr.Length; i++) { if (i % 2 == 1) { if (inputstr[i] == '1') { count++; } } else { if (inputstr[i] == '0') { count++; } } } } Console.WriteLine(count); }*/ // 123C /*static void Main() { double N = double.Parse(Console.ReadLine()); List<double> city = new List<double>(); for (int i = 0; i < 5; i++) { city.Add(double.Parse(Console.ReadLine())); } var ans = Math.Ceiling(N / city.Min()) + 4; Console.WriteLine(ans); }*/ // 82C /*static void Main() { double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray(); double a = input[0]; double b = input[1]; double answer = (a + b) / 2; Console.WriteLine(Math.Ceiling(answer)); }*/ // 128B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int P = input[1]; var ans = (P + A * 3) / 2; Console.WriteLine(ans); int a,b cin << a << b; cout >> (P + A * 3) / 2 >> endl; }*/ // 119A /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; if (B % A == 0) { Console.WriteLine(A + B); } else { Console.WriteLine(B-A); } }*/ // 116A /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; int C = input[2]; Console.WriteLine((A*B)/2); }*/ // ABC31B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = int.Parse(Console.ReadLine()); List<int> array = new List<int>(); for (int i =0;i<N;i++) { array.Add(int.Parse(Console.ReadLine())); } foreach (int a in array) { if (a < input[0]) { Console.WriteLine(input[0] - a); } else if (input[1] < a) { Console.WriteLine("-1"); } else { Console.WriteLine("0"); } } }*/ // ABC36B /*static void Main() { int N = int.Parse(Console.ReadLine()); List<string> map = new List<string>(); for (int i =0;i< N;i++) { map.Add(Console.ReadLine()); } List<string> ans = new List<string>(); for(int j = 0; j < N;j++) { var temp = ""; for (int i = N-1; i >= 0; i--) { temp += map[i][j]; } ans.Add(temp); } foreach (string a in ans) { Console.WriteLine(a); } }*/ // ABC40B /*static void Main() { int N = int.Parse(Console.ReadLine()); int A = 0; int temp = N; if (N == 1) { Console.WriteLine("0"); } else { while (true) { double root = Math.Sqrt(N); if (root != (int)root) { N--; } else { A = (int)root; break; } } List<int> answer = new List<int>(); bool flag = false; while (A > 0) { var a = A; while (A * a <= temp) { var ans = temp - (A * a) + Math.Abs(A - a); if (ans == 0) { flag = true; break; } a++; answer.Add(ans); } if (flag == true) { break; } A--; } if (flag) { Console.WriteLine("0"); } else { Console.WriteLine(answer.Min()); } } }*/ // ABC122C // TLE /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); string S = Console.ReadLine(); List<int[]> array = new List<int[]>(); for (int i = 0; i < input[1]; i++) { array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray()); } List<int> answer = new List<int>(); foreach (int[] n in array) { var tempstr = S.Substring(n[0]-1,n[1]-n[0]+1); var count = tempstr.Length - tempstr.Replace("AC","").Length; var ans = count / 2; answer.Add(ans); } foreach (int a in answer) { Console.WriteLine(a); } }*/ /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); string S = Console.ReadLine(); List<int[]> array = new List<int[]>(); for (int i = 0; i < input[1]; i++) { array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray()); } for (int i = 0;i < S.Length-1;i++) { if (S[i] == 'A') { if (S[i + 1] == 'C') { S = S.Replace(S[i],'a'); } } } int count = 0; List<int> ansstr = new List<int>(); for (int i = 0; i < S.Length;i++) { count = 0; for (int j = 0;j <= i;j++) { if (S[j] == 'a') { count++; } } ansstr.Add(count); } List<int> anss = new List<int>(); for (int i = 0; i < input[1];i++) { anss.Add(ansstr[array[i][1]-2] - ansstr[array[i][0]-1]); } foreach (int a in anss) { Console.WriteLine(a); } }*/ // ABC39B /*static void Main() { int X = int.Parse(Console.ReadLine()); var ans = Math.Sqrt(X); var ans2 = Math.Sqrt(ans); Console.WriteLine(ans2); }*/ // ABC38B /*static void Main() { int[] input1 = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] input2 = Console.ReadLine().Split().Select(int.Parse).ToArray(); bool flag1 = false; foreach (int a in input1) { foreach (int b in input2) { if (a == b) { flag1 = true; } } } if (flag1 == true) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } }*/ // ABC35B /*static void Main() { string S = Console.ReadLine(); int T = int.Parse(Console.ReadLine()); int[] pos = { 0, 0 }; foreach (char a in S) { } }*/ // ABC34B /*static void Main() { }*/ //技術ProgramContest4Day1 // A /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); }*/ // ABC135A /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; var temp = B - A; if (temp % 2 == 0) { Console.WriteLine(A + (temp/2)); } else { Console.WriteLine("IMPOSSIBLE"); } }*/ // ABC135B /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] AnsN = new int[N]; for (int i = 0;i <N;i++) { AnsN[i] = i + 1; } int count = 0; for(int i = 0;i < N;i++) { if (P[i] != AnsN[i]) { count++; } } if (count <= 2) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } }*/ // ABC135C /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray(); /*int count = 0; for (int i = N;i>0;i--) { var tempA = A[i] + A[i - 1]; if (tempA <= B[i - 1]) { A[i - 1] = 0; count += tempA; } else { if (A[i] <= B[i - 1]) { A[i - 1] = tempA - B[i - 1]; count += B[i - 1]; } else { count += B[i - 1]; } } }*/ /*int count = 0; for (int i = 0;i < N;i++) { var tempA = A[i] + A[i + 1]; if (tempA <= B[i]) { A[i + 1] = 0; count += tempA; } else { if (B[i] >= A[i]) { A[i + 1] = A[i + 1] - (B[i] - A[i]); count += B[i]; } else { count += B[i]; } } } //このやり方 int count = 0; for (int i = 0; i < N;i++) { List<int> temp = new List<int>(); temp.Add(A[i]); temp.Add(B[i]); count += temp.Min(); } Console.WriteLine(count); }*/ // ABC135D // ABC127A static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); string inputstr = Console.ReadLine(); inputstr = inputstr.Replace(inputstr[input[1] - 1], Char.ToLower(inputstr[input[1] - 1])); Console.WriteLine(inputstr); } } } // 125C難しい /*namespace CSharp { class Program { static IEnumerable<long> EnumerateDivisors(long n) { for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; if (n / i != i) { yield return n / i; } } } } static void Main(string[] args) { ReadString(); long[] A = ReadLongArray(); long[] divisors = Enumerable.Concat(EnumerateDivisors(A[0]), EnumerateDivisors(A[1])) .Distinct().ToArray(); long ans = divisors.Select(x => new { Value = x, Count = A.Count(v => v % x == 0) }) .Where(x => x.Count >= A.Length - 1) .OrderByDescending(x => x.Value) .First().Value; Console.WriteLine(ans); } #region Helpers static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray(); static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray(); static string ReadString() => Console.ReadLine(); static int ReadInt() => int.Parse(Console.ReadLine()); static long ReadLong() => long.Parse(Console.ReadLine()); static void ReadInt(out int first) { var array = ReadIntArray(); first = array[0]; } static void ReadInt(out int first, out int second) { var array = ReadIntArray(); first = array[0]; second = array[1]; } static void ReadInt(out int first, out int second, out int third) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadInt(out int first, out int second, out int third, out int fourth) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static void ReadLong(out long first) { var array = ReadLongArray(); first = array[0]; } static void ReadLong(out long first, out long second) { var array = ReadLongArray(); first = array[0]; second = array[1]; } static void ReadLong(out long first, out long second, out long third) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadLong(out long first, out long second, out long third, out long fourth) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } #endregion } }*/
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace AtcoderC { class Program { /*static void Main(string[] args) { }*/ // ABC132C //全探索法 /*static void Main() { BigInteger N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int min = input.Min(); int max = input.Max(); int countARC = 0; int countABC = 0; int Answer = 0; for (int i = min; i <= max; i++) { countABC = 0; countARC = 0; foreach (int n in input) { if (n > i) { countARC++; } else { countABC++; } } if (countABC == countARC) { Answer++; } } Console.WriteLine(Answer); }*/ // 2回目 /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(input); int min = input[(N / 2) - 1]; int max = input[N / 2]; Console.WriteLine(max - min); }*/ // ABC131C //ユーグリッドの互除法の応用 /*static void Main() { BigInteger[] input = Console.ReadLine().Split().Select(BigInteger.Parse).ToArray(); BigInteger A = input[0]; BigInteger B = input[1]; BigInteger C = input[2]; BigInteger D = input[3]; BigInteger ans = (B / C) + (B / D); //最小公倍数 var ans2 = C * D / lcm(C, D); BigInteger ans3 = B / ans2; var BB = B - ans + ans3; ans = (A - 1) / C + (A - 1) / D; ans3 = (A - 1) / ans2; var AA = (A - 1) - ans + ans3; Console.WriteLine(BB - AA); } static public BigInteger lcm(BigInteger a, BigInteger b) { var r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; }*/ // 129C //動的計画法 // TLEになる時間がかかり過ぎる /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int> ttt = new List<int>(); for (int i = 0;i < M;i++) { var temp = int.Parse(Console.ReadLine()); ttt.Add(temp); } int[] dparray = new int[N+2]; dparray[N] = 1; dparray[N - 1] = 1; for (int i = N-1; i >= 0; i--) { if (ttt.Contains(i)) { dparray[i] = 0; } dparray[i] = (dparray[i + 1] + dparray[i + 2]) % 1000000007; } Console.WriteLine(dparray[0]); }*/ // ABC128 /*static void Main() { }*/ // ABC134A /*static void Main() { int r = int.Parse(Console.ReadLine()); var ans = 3 * r * r; Console.WriteLine(ans); }*/ // ABC134B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int D = input[1]; int count = 0; int ans = N; while (true) { ans = ans - (D * 2 + 1); count++; if (ans <= 0) { break; } } Console.WriteLine(count); }*/ // ABC134C /*static void Main() { int N = int.Parse(Console.ReadLine()); List<int> array = new List<int>(); for (int i =0;i<N; i++) { array.Add(int.Parse(Console.ReadLine())); } List<int> ans = new List<int>(); int max = array.Max(); var temp = new List<int>(); foreach (int n in array) { temp.Add(n); } temp.Sort(); temp.Reverse(); int second = temp[1]; foreach (int nn in array) { if (nn == max) { Console.WriteLine(second); } else { Console.WriteLine(max); } } }*/ // 134ABCD /*static void Main() { int N = int.Parse(Console.ReadLine()); int count = 0; int ans = 0; int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0;i<N;i++) { for (int j =0;j<N; j++) { if ((j+1)%(i+1)==0) { count += input[j]; } } if (count % 2 == input[i]) { ans++; } count = 0; } if (ans != 0) { } }*/ // AGC036 /*static void Main() { long S = long.Parse(Console.ReadLine()); long X1 = 1000000000; long Y1 = 0; /*while (true) { Y1 = S / X1 + S % X1; } Y1 = S / X1 + S % X1; Console.WriteLine("0 0 " + X1 + " 0 0 " + Y1); /*int tempX = 0; List<long> ss = new List<long>(); while (tempX < S) { var ans = S % tempX; if (ans == 0) { ss.Add(ans); } tempX++; } Console.WriteLine(tempX);*/ /*long X1 = 0; long Y1 = 1; while (true) { X1 = S % Y1; if (X1 <= 1000000000) { break; } Y1++; } Console.WriteLine("0 0 "+X1+" 0 0 "+Y1); }*/ // ABC82A /*static void Main() { double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray(); double a = input[0]; double b = input[1]; double sum = (a + b) / 2; Console.WriteLine(Math.Ceiling(sum)); }*/ // ABC128C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; int ans = 0; List<int[]> K = new List<int[]>(); for (int i = 0;i<M;i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); K.Add(temp); } int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] light = new int[M]; for (int i = 0;i < Math.Pow(2,N);i++) { var isrow = 0; var temp = int.Parse(Convert.ToString(i, 2)).ToString("0000000000"); for (int j =0;j < M;j++) { var ison = 0; for (int k = 0; k < K[j][0];k++) { var index = K[j][k] - 1; if (temp[9-index] == '1') { ison++; } } if (ison % 2 == P[j]) { isrow++; } else { break; } } if (isrow == M) { ans++; } } Console.WriteLine(ans);*/ /*nt[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a = input[0]; int b = input[1]; var temp = a * b % 2; if (temp == 0) { Console.WriteLine("even"); } else { Console.WriteLine("odd"); } }*/ // ABC127C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } if (M == 1) { Console.WriteLine(N); } else { List<int> card = new List<int>(); for (int i = gate[0][0]; i <= gate[0][1]; i++) { card.Add(i); } for (int j = 1; j < gate.Count; j++) { List<int> ans = new List<int>(); var count = 0; for (int i = gate[j][0]; i <= gate[j][1]; i++) { if (card.Contains(i)) { count++; ans.Add(i); } } if (count == 0) { break; } card = new List<int>(ans); } Console.WriteLine(card.Count()); } }*/ // 127C Revenge TLE /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } int Ans = 0; for (int i =1;i<=N;i++) { var count = 0; for (int j = 0;j < gate.Count;j++) { if (gate[j][0] <= i && i <= gate[j][1]) { count++; } } if (count == gate.Count) { Ans++; } } Console.WriteLine(Ans); }*/ // 127C RevengeVer2 /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; List<int[]> gate = new List<int[]>(); for (int i = 0; i < M; i++) { var temp = Console.ReadLine().Split().Select(int.Parse).ToArray(); gate.Add(temp); } List<int> Max = new List<int>(); List<int> Min = new List<int>(); for (int i =0;i< M;i++) { Max.Add(gate[i][1]); Min.Add(gate[i][0]); } int max = Max.Min(); int min = Min.Max(); if (min <= max) { Console.WriteLine(max - min + 1); } else { Console.WriteLine("0"); } }*/ // ABC126C /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = input[0]; int M = input[1]; double ans = 0.0; for (int i = 1; i<= N;i++) { double tempP = (double)1 / N; int point = i; while (point<M) { tempP = tempP * 1 / 2; point *= 2; } ans += tempP; } Console.WriteLine(ans); }*/ // ABC125C ユーグリッド互除法 /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray(); Array.Sort(A); int lcmr, lcml = 0; List<int> answer = new List<int>(); for (int i =0;i<A.Length;i++) { lcmr = 0; for (int x = 0;x < i;x++) { if (lcmr - A[x] >= 0) { lcmr = lcm(lcmr, A[x]); } else { lcmr = lcm(A[x], lcmr); } } lcml = 0; for (int y = i+1; y < A.Length; y++) { if (lcml - A[y] >= 0) { lcml = lcm(lcml, A[y]); } else { lcml = lcm(A[y],lcml); } } var tempans = 0; if (lcmr > lcml) { tempans = lcm(lcmr, lcml); } else { tempans = lcm(lcml, lcmr); } answer.Add(tempans); } Console.WriteLine(answer.Max()); } static public int lcm(int a, int b) { if (b == 0) { return a; } var r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; }*/ // 124C /*static void Main() { string inputstr = Console.ReadLine(); int count = 0; if (inputstr[0] == '0') { for (int i = 0; i < inputstr.Length; i++) { if (i % 2 == 0) { if (inputstr[i] == '1') { count++; } } else { if (inputstr[i] == '0') { count++; } } } } else { for (int i = 0; i < inputstr.Length; i++) { if (i % 2 == 1) { if (inputstr[i] == '1') { count++; } } else { if (inputstr[i] == '0') { count++; } } } } Console.WriteLine(count); }*/ // 123C /*static void Main() { double N = double.Parse(Console.ReadLine()); List<double> city = new List<double>(); for (int i = 0; i < 5; i++) { city.Add(double.Parse(Console.ReadLine())); } var ans = Math.Ceiling(N / city.Min()) + 4; Console.WriteLine(ans); }*/ // 82C /*static void Main() { double[] input = Console.ReadLine().Split().Select(double.Parse).ToArray(); double a = input[0]; double b = input[1]; double answer = (a + b) / 2; Console.WriteLine(Math.Ceiling(answer)); }*/ // 128B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int P = input[1]; var ans = (P + A * 3) / 2; Console.WriteLine(ans); int a,b cin << a << b; cout >> (P + A * 3) / 2 >> endl; }*/ // 119A /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; if (B % A == 0) { Console.WriteLine(A + B); } else { Console.WriteLine(B-A); } }*/ // 116A /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; int C = input[2]; Console.WriteLine((A*B)/2); }*/ // ABC31B /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int N = int.Parse(Console.ReadLine()); List<int> array = new List<int>(); for (int i =0;i<N;i++) { array.Add(int.Parse(Console.ReadLine())); } foreach (int a in array) { if (a < input[0]) { Console.WriteLine(input[0] - a); } else if (input[1] < a) { Console.WriteLine("-1"); } else { Console.WriteLine("0"); } } }*/ // ABC36B /*static void Main() { int N = int.Parse(Console.ReadLine()); List<string> map = new List<string>(); for (int i =0;i< N;i++) { map.Add(Console.ReadLine()); } List<string> ans = new List<string>(); for(int j = 0; j < N;j++) { var temp = ""; for (int i = N-1; i >= 0; i--) { temp += map[i][j]; } ans.Add(temp); } foreach (string a in ans) { Console.WriteLine(a); } }*/ // ABC40B /*static void Main() { int N = int.Parse(Console.ReadLine()); int A = 0; int temp = N; if (N == 1) { Console.WriteLine("0"); } else { while (true) { double root = Math.Sqrt(N); if (root != (int)root) { N--; } else { A = (int)root; break; } } List<int> answer = new List<int>(); bool flag = false; while (A > 0) { var a = A; while (A * a <= temp) { var ans = temp - (A * a) + Math.Abs(A - a); if (ans == 0) { flag = true; break; } a++; answer.Add(ans); } if (flag == true) { break; } A--; } if (flag) { Console.WriteLine("0"); } else { Console.WriteLine(answer.Min()); } } }*/ // ABC122C // TLE /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); string S = Console.ReadLine(); List<int[]> array = new List<int[]>(); for (int i = 0; i < input[1]; i++) { array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray()); } List<int> answer = new List<int>(); foreach (int[] n in array) { var tempstr = S.Substring(n[0]-1,n[1]-n[0]+1); var count = tempstr.Length - tempstr.Replace("AC","").Length; var ans = count / 2; answer.Add(ans); } foreach (int a in answer) { Console.WriteLine(a); } }*/ /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); string S = Console.ReadLine(); List<int[]> array = new List<int[]>(); for (int i = 0; i < input[1]; i++) { array.Add(Console.ReadLine().Split().Select(int.Parse).ToArray()); } for (int i = 0;i < S.Length-1;i++) { if (S[i] == 'A') { if (S[i + 1] == 'C') { S = S.Replace(S[i],'a'); } } } int count = 0; List<int> ansstr = new List<int>(); for (int i = 0; i < S.Length;i++) { count = 0; for (int j = 0;j <= i;j++) { if (S[j] == 'a') { count++; } } ansstr.Add(count); } List<int> anss = new List<int>(); for (int i = 0; i < input[1];i++) { anss.Add(ansstr[array[i][1]-2] - ansstr[array[i][0]-1]); } foreach (int a in anss) { Console.WriteLine(a); } }*/ // ABC39B /*static void Main() { int X = int.Parse(Console.ReadLine()); var ans = Math.Sqrt(X); var ans2 = Math.Sqrt(ans); Console.WriteLine(ans2); }*/ // ABC38B /*static void Main() { int[] input1 = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] input2 = Console.ReadLine().Split().Select(int.Parse).ToArray(); bool flag1 = false; foreach (int a in input1) { foreach (int b in input2) { if (a == b) { flag1 = true; } } } if (flag1 == true) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } }*/ // ABC35B /*static void Main() { string S = Console.ReadLine(); int T = int.Parse(Console.ReadLine()); int[] pos = { 0, 0 }; foreach (char a in S) { } }*/ // ABC34B /*static void Main() { }*/ //技術ProgramContest4Day1 // A /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); }*/ // ABC135A /*static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = input[0]; int B = input[1]; var temp = B - A; if (temp % 2 == 0) { Console.WriteLine(A + (temp/2)); } else { Console.WriteLine("IMPOSSIBLE"); } }*/ // ABC135B /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] AnsN = new int[N]; for (int i = 0;i <N;i++) { AnsN[i] = i + 1; } int count = 0; for(int i = 0;i < N;i++) { if (P[i] != AnsN[i]) { count++; } } if (count <= 2) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } }*/ // ABC135C /*static void Main() { int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray(); /*int count = 0; for (int i = N;i>0;i--) { var tempA = A[i] + A[i - 1]; if (tempA <= B[i - 1]) { A[i - 1] = 0; count += tempA; } else { if (A[i] <= B[i - 1]) { A[i - 1] = tempA - B[i - 1]; count += B[i - 1]; } else { count += B[i - 1]; } } }*/ /*int count = 0; for (int i = 0;i < N;i++) { var tempA = A[i] + A[i + 1]; if (tempA <= B[i]) { A[i + 1] = 0; count += tempA; } else { if (B[i] >= A[i]) { A[i + 1] = A[i + 1] - (B[i] - A[i]); count += B[i]; } else { count += B[i]; } } } //このやり方 int count = 0; for (int i = 0; i < N;i++) { List<int> temp = new List<int>(); temp.Add(A[i]); temp.Add(B[i]); count += temp.Min(); } Console.WriteLine(count); }*/ // ABC135D // ABC127A static void Main() { int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray(); string inputstr = Console.ReadLine(); char[] temp = inputstr.ToCharArray(); temp[input[1] - 1] = Char.ToLower(temp[input[1] - 1]); inputstr = new string(temp); Console.WriteLine(inputstr); } // } } // 125C難しい /*namespace CSharp { class Program { static IEnumerable<long> EnumerateDivisors(long n) { for (long i = 1; i * i <= n; i++) { if (n % i == 0) { yield return i; if (n / i != i) { yield return n / i; } } } } static void Main(string[] args) { ReadString(); long[] A = ReadLongArray(); long[] divisors = Enumerable.Concat(EnumerateDivisors(A[0]), EnumerateDivisors(A[1])) .Distinct().ToArray(); long ans = divisors.Select(x => new { Value = x, Count = A.Count(v => v % x == 0) }) .Where(x => x.Count >= A.Length - 1) .OrderByDescending(x => x.Value) .First().Value; Console.WriteLine(ans); } #region Helpers static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray(); static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray(); static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray(); static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray(); static string ReadString() => Console.ReadLine(); static int ReadInt() => int.Parse(Console.ReadLine()); static long ReadLong() => long.Parse(Console.ReadLine()); static void ReadInt(out int first) { var array = ReadIntArray(); first = array[0]; } static void ReadInt(out int first, out int second) { var array = ReadIntArray(); first = array[0]; second = array[1]; } static void ReadInt(out int first, out int second, out int third) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadInt(out int first, out int second, out int third, out int fourth) { var array = ReadIntArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } static void ReadLong(out long first) { var array = ReadLongArray(); first = array[0]; } static void ReadLong(out long first, out long second) { var array = ReadLongArray(); first = array[0]; second = array[1]; } static void ReadLong(out long first, out long second, out long third) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; } static void ReadLong(out long first, out long second, out long third, out long fourth) { var array = ReadLongArray(); first = array[0]; second = array[1]; third = array[2]; fourth = array[3]; } #endregion } }*/
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 230, 0, 228], ["+", 8, 196, 0, 1, 0, 11, 12, 230, 39, 199], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 24], ["+", 0, 11, 12, 230, 3, 4, 0, 28, 0, 22]]
8
206
22
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int r = 0; static int c = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static long mod = 1000000007; static long[] arr; static char[,] map; static int[,] imap; static Queue<int> qx = new Queue<int>(); static Queue<int> qy = new Queue<int>(); public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void ShowArray() { for (int i = 0; i < arr.Length; i++) { if (i > 0) w(" "); w(arr[i]); } wl(); } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(int def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } static void ShowMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(map[i, j]); } wl(); } } static void ShowIMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(imap[i, j]); } wl(); } } #endregion #region main static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); try { Solve(); } catch (Exception ex) { wl(ex); } Console.Out.Flush(); } public static void Solve() { s = Text(); int st = int.Parse(s.Substring(0, 2)); int ed = int.Parse(s.Substring(2)); bool yyS = (st > 0); bool mmS = (1 <= st && st <= 12); bool yyE = (ed > 0); bool mmE = (1 <= ed && ed <= 12); if (yyS && mmS && yyE && mmE) wl("AMBIGUOUS"); else if (yyS && mmE) wl("YYMM"); else if (mmS && yyE) wl("MMYY"); else wl("NA"); } #endregion }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int r = 0; static int c = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static long mod = 1000000007; static long[] arr; static char[,] map; static int[,] imap; static Queue<int> qx = new Queue<int>(); static Queue<int> qy = new Queue<int>(); public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void ShowArray() { for (int i = 0; i < arr.Length; i++) { if (i > 0) w(" "); w(arr[i]); } wl(); } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(int def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } static void ShowMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(map[i, j]); } wl(); } } static void ShowIMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(imap[i, j]); } wl(); } } #endregion #region main static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); try { Solve(); } catch (Exception ex) { wl(ex); } Console.Out.Flush(); } public static void Solve() { s = Text(); int st = int.Parse(s.Substring(0, 2)); int ed = int.Parse(s.Substring(2)); bool flgS = (1 <= st && st <= 12); bool flgE = (1 <= ed && ed <= 12); if (flgS && flgE) wl("AMBIGUOUS"); else if (flgE) wl("YYMM"); else if (flgS) wl("MMYY"); else wl("NA"); } #endregion }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 23, 0, 24], ["-", 0, 200, 0, 212, 0, 23, 0, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 23, 0, 16, 17, 47], ["-", 0, 200, 0, 212, 0, 23, 0, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 23, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 15, 22], ["-", 0, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["-", 0, 57, 75, 57, 75, 57, 15, 16, 17, 98], ["-", 0, 57, 75, 57, 75, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 57, 75, 57, 15, 22]]
8
1,544
38
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace KyoPro { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string first = S.Substring(0, 2); string last = S.Substring(2, 2); if (IsYearString(first)) { if (IsYearString(last)) { Console.WriteLine("NA"); } else { Console.WriteLine("YYMM"); } } else if (IsYearString(last)) { Console.WriteLine("MMYY"); } else { Console.WriteLine("AMBIGUOUS"); } } static bool IsYearString(string s) { char first = s[0]; char last = s[1]; if (first != '0' && first != '1') { return true; } else { return false; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace KyoPro { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string first = S.Substring(0, 2); string last = S.Substring(2, 2); if (IsYearString(first)) { if (IsYearString(last)) { Console.WriteLine("NA"); } else { Console.WriteLine("YYMM"); } } else if (IsYearString(last)) { Console.WriteLine("MMYY"); } else { Console.WriteLine("AMBIGUOUS"); } } static bool IsYearString(string s) { int n = Convert.ToInt32(s); if (0 < n && n < 13) { return false; } else { return true; } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["-", 0, 57, 15, 16, 31, 16, 12, 252, 0, 104], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["-", 0, 57, 15, 16, 12, 16, 12, 252, 0, 104], ["-", 0, 57, 15, 16, 12, 16, 12, 252, 0, 253], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 64, 196, 0, 37, 0, 211, 0, 146], ["+", 0, 57, 64, 196, 0, 37, 0, 211, 0, 147], ["-", 0, 57, 75, 196, 0, 37, 0, 211, 0, 147], ["+", 0, 57, 75, 196, 0, 37, 0, 211, 0, 146]]
8
199
38
using System; using System.Linq; namespace abc126A { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); int a2 = a % 100; int a1 = (a - a2) / 100; bool ym = false; bool my = false; if (a1 <= 12) ym = true; if (a2 <= 12) my = true; if (ym == true && my == true) Console.WriteLine("AMBIGUOUS"); if (ym == true && my == false) Console.WriteLine("MMYY"); if (ym == false && my == true) Console.WriteLine("YYMM"); if (ym == false && my == false) Console.WriteLine("NA"); } } }
using System; using System.Linq; namespace abc126A { class Program { static void Main(string[] args) { int a = int.Parse(Console.ReadLine()); int a2 = a % 100; int a1 = (a - a2) / 100; bool ym = false; bool my = false; if (a1 <= 12 && a1 > 0) ym = true; if (a2 <= 12 && a2 > 0) my = true; if (ym == true && my == true) Console.WriteLine("AMBIGUOUS"); if (ym == true && my == false) Console.WriteLine("MMYY"); if (ym == false && my == true) Console.WriteLine("YYMM"); if (ym == false && my == false) Console.WriteLine("NA"); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
165
8
using System; using System.Linq; using System.Collections.Generic; namespace ABC126_1 { class B { static void Main(string[] args) { var s = Console.ReadLine(); var s1 = int.Parse(s.Substring(0, 2)); var s2 = int.Parse(s.Substring(2, 2)); if ((1 <= s1 && s1 <= 12) && (1 <= s2 && s2 <= 12)) Console.WriteLine("AMBIGUOUS"); else if ((1 <= s1 && s1 <= 12) && (12 < s2)) Console.WriteLine("MMYY"); else if ((12 < s1) && (1 <= s2 && s2 <= 12)) Console.WriteLine("YYMM"); else Console.WriteLine("NA"); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC126_1 { class B { static void Main(string[] args) { var s = Console.ReadLine(); var s1 = int.Parse(s.Substring(0, 2)); var s2 = int.Parse(s.Substring(2, 2)); if ((1 <= s1 && s1 <= 12) && (1 <= s2 && s2 <= 12)) Console.WriteLine("AMBIGUOUS"); else if ((1 <= s1 && s1 <= 12) && (s2 == 0 || 12 < s2)) Console.WriteLine("MMYY"); else if ((s1 == 0 || 12 < s1) && (1 <= s2 && s2 <= 12)) Console.WriteLine("YYMM"); else Console.WriteLine("NA"); } } }
[["+", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["+", 75, 57, 15, 16, 12, 23, 0, 16, 17, 106], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 17, 60], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 12, 203], ["+", 75, 57, 15, 16, 31, 23, 0, 16, 17, 106]]
8
174
8
using System; using System.Linq; using System.Collections.Generic; namespace abc081b { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string[] month = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", }; var onetwo = s[0] + s[1]; var thrfour = s[2] + s[3]; string ans; if (!month.Contains(onetwo.ToString()) && month.Contains(thrfour.ToString())) ans = "YYMM"; else if (month.Contains(onetwo.ToString()) && !month.Contains(thrfour.ToString())) ans = "MMYY"; else if (month.Contains(onetwo.ToString()) && month.Contains(thrfour.ToString())) ans = "AMBIGUOUS"; else ans = "NA"; Console.Write(ans); } } }
using System; using System.Linq; using System.Collections.Generic; namespace abc126 { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string[] month = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", }; string onetwo = s.Substring(0, 2); string thrfour = s.Substring(2, 2); string ans; if (!month.Contains(onetwo.ToString()) && month.Contains(thrfour.ToString())) ans = "YYMM"; else if (month.Contains(onetwo.ToString()) && !month.Contains(thrfour.ToString())) ans = "MMYY"; else if (month.Contains(onetwo.ToString()) && month.Contains(thrfour.ToString())) ans = "AMBIGUOUS"; else ans = "NA"; Console.Write(ans); } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 70], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 212, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 212, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
236
32
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var front = int.Parse(S.Substring(0, 2)); var back = int.Parse(S.Substring(2, 2)); if (front > 12) { if (back > 12) { Console.WriteLine("NA"); } else { Console.WriteLine("YYMM"); } } else { if (back > 12) { Console.WriteLine("MMYY"); } else { Console.WriteLine("AMBINGUOUS"); } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var front = int.Parse(S.Substring(0, 2)); var back = int.Parse(S.Substring(2, 2)); if (front > 12 || front == 0) { if (back > 12 || back == 0) { Console.WriteLine("NA"); } else { Console.WriteLine("YYMM"); } } else { if (back > 12 || back == 0) { Console.WriteLine("MMYY"); } else { Console.WriteLine("AMBIGUOUS"); } } } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 106], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 106], ["+", 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, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
158
14
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); int l = int.Parse(s.Substring(0, 2)); int r = int.Parse(s.Substring(2, 2)); if (l == 0 || r == 0) { Console.WriteLine("NA"); } else if ((1 <= l && l <= 12) && !(1 <= r && r <= 12)) { Console.WriteLine("MMYY"); } else if (!(1 <= l && l <= 12) && (1 <= r && r <= 12)) { Console.WriteLine("YYMM"); } else { Console.WriteLine("AMBIGUOUS"); } } }
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); int l = int.Parse(s.Substring(0, 2)); int r = int.Parse(s.Substring(2, 2)); if ((1 <= l && l <= 12) && (1 <= r && r <= 12)) { Console.WriteLine("AMBIGUOUS"); } else if ((1 <= l && l <= 12) && !(1 <= r && r <= 12)) { Console.WriteLine("MMYY"); } else if (!(1 <= l && l <= 12) && (1 <= r && r <= 12)) { Console.WriteLine("YYMM"); } else { Console.WriteLine("NA"); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 31, 203], ["+", 15, 16, 31, 23, 0, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 98], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 17, 19], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 31, 203], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 19], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
164
26
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 s = Console.ReadLine(); var first = int.Parse(new string(s.Take(2).ToArray())); var second = int.Parse(new string(s.Skip(2).ToArray())); string msg; if (canMonth(first) && canMonth(second)) { msg = "AMBIGUOUS"; } else if (canMonth(first)) { msg = "MMYY"; } else if (canMonth(second)) { msg = "YYMM"; } else { msg = "NA"; } Console.WriteLine(msg); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } private static bool canMonth(int s) { return s <= 12; } } 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() { return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); } public static long[] ReadAsLongArray() { return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).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) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine())) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray()).ToArray(); } }
using System; 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 s = Console.ReadLine(); var first = int.Parse(new string(s.Take(2).ToArray())); var second = int.Parse(new string(s.Skip(2).ToArray())); string msg; if (canMonth(first) && canMonth(second)) { msg = "AMBIGUOUS"; } else if (canMonth(first)) { msg = "MMYY"; } else if (canMonth(second)) { msg = "YYMM"; } else { msg = "NA"; } Console.WriteLine(msg); #region Flush #if !DEBUG Console.Out.Flush(); sw.Close(); #endif #endregion } private static bool canMonth(int s) { return 1 <= s && s <= 12; } } 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() { return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); } public static long[] ReadAsLongArray() { return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).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) { return Enumerable.Range(1, n) .Select(s => int.Parse(Console.ReadLine())) .ToArray(); } public static int[][] ReadNTimesAsIntArray(int n) { return Enumerable.Range(1, n).Select(s => ReadAsIntArray()).ToArray(); } }
[["-", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 8, 196, 0, 37, 0, 16, 31, 16, 31, 203], ["+", 8, 196, 0, 37, 0, 16, 31, 16, 17, 19], ["+", 8, 196, 0, 37, 0, 16, 31, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 98]]
8
509
11
using System; class Plogram { static void Main() { int S = int.Parse(Console.ReadLine()); int pre = S / 100; int last = S % 100; int p = 0; int l = 0; if (1 <= pre && pre <= 12) { p = 1; } else if (0 <= pre && pre <= 19) { p = 2; } if (1 <= last && last <= 12) { l = 1; } else if (0 <= last && last <= 19) { l = 2; } if (p == 1 && l == 1) { Console.WriteLine("AMBIGUOUS"); } else if (p == 2 && l == 1) { Console.WriteLine("YYMM"); } else if (p == 1 && l == 2) { Console.WriteLine("MMYY"); } else { Console.WriteLine("NA"); } } }
using System; class Plogram { static void Main() { int S = int.Parse(Console.ReadLine()); int pre = S / 100; int last = S % 100; int p = 0; int l = 0; if (1 <= pre && pre <= 12) { p = 1; } if (1 <= last && last <= 12) { l = 1; } if (p == 1 && l == 1) { Console.WriteLine("AMBIGUOUS"); } else if (p == 0 && l == 1) { Console.WriteLine("YYMM"); } else if (p == 1 && l == 0) { Console.WriteLine("MMYY"); } else { Console.WriteLine("NA"); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 31, 203], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 17, 19], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 12, 22], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 17, 19], ["-", 0, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["-", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 75, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["-", 75, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 12, 203]]
8
195
38
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { string S = Console.ReadLine(); string A = S.Substring(0, 2); string B = S.Substring(2, 2); int a = int.Parse(A); int b = int.Parse(B); if ((a == 0 || a > 12) && (b == 0 || b > 12)) { Console.WriteLine("NA"); return; } if (a <= 12 && b <= 12) { Console.WriteLine("AMBIGUOUS"); } else if (a <= 12) { Console.WriteLine("MMYY"); } else if (b <= 12) { Console.WriteLine("YYMM"); } } static long calcGCD(long num1, long num2) { if (num1 < num2) { var tmp = num1; num1 = num2; num2 = tmp; } while (true) { long res; long div = Math.DivRem(num1, num2, out res); if (res == 0) { return num2; } else { num1 = num2; num2 = res; } } } } static class MathUtil { public static T Max<T>(params T[] datas) { return datas.Max(); } public static T Min<T>(params T[] datas) { return datas.Min(); } public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { string S = Console.ReadLine(); string A = S.Substring(0, 2); string B = S.Substring(2, 2); int a = int.Parse(A); int b = int.Parse(B); if ((a == 0 || a > 12) && (b == 0 || b > 12)) { Console.WriteLine("NA"); return; } if ((a != 0 && a <= 12 && b != 0 && b <= 12)) { Console.WriteLine("AMBIGUOUS"); } else if (a != 0 && a <= 12) { Console.WriteLine("MMYY"); } else if (b != 0 && b <= 12) { Console.WriteLine("YYMM"); } } static long calcGCD(long num1, long num2) { if (num1 < num2) { var tmp = num1; num1 = num2; num2 = tmp; } while (true) { long res; long div = Math.DivRem(num1, num2, out res); if (res == 0) { return num2; } else { num1 = num2; num2 = res; } } } } static class MathUtil { public static T Max<T>(params T[] datas) { return datas.Max(); } public static T Min<T>(params T[] datas) { return datas.Min(); } public static IEnumerable<IEnumerable<int>> GetPermutation(int n) { if (n == 0) { yield return Single(0); yield break; } for (int i = 0; i <= n; i++) { foreach (var x in GetPermutation(n - 1)) { yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1)); } } } private static IEnumerable<int> Single(int x) { yield return x; } public static IEnumerable<int> EnumeratePrimeNumbers() { List<int> primes = new List<int>() { 2 }; yield return 2; for (int i = 3; i < int.MaxValue; i++) { bool isPrime = true; int Sqrt = (int)Math.Sqrt(i) + 1; foreach (var prime in primes) { if (prime > Sqrt) { break; } if (i % prime == 0) { isPrime = false; break; } } if (isPrime) { primes.Add(i); yield return i; } } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 17, 79], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["+", 15, 23, 0, 16, 31, 16, 31, 16, 17, 98], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 23, 0, 16, 31, 16, 17, 98], ["+", 15, 23, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 23, 0, 16, 31, 16, 12, 16, 17, 79], ["+", 15, 23, 0, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 23, 0, 25], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 17, 79], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 98], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 79], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 75, 57, 75, 57, 15, 16, 17, 98]]
8
555
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var first = int.Parse(S[0].ToString() + S[1].ToString()); var second = int.Parse(S[2].ToString() + S[3].ToString()); if (0 < first && first < 13 && 0 < second && second < 13) { Console.WriteLine("AMBIGUOUS"); return; } if (0 >= first || first >= 13 && 0 >= second || second >= 13) { Console.WriteLine("NA"); return; } if (0 < first && first < 13) { Console.WriteLine("MMYY"); return; } Console.WriteLine("YYMM"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Numerics; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var first = int.Parse(S[0].ToString() + S[1].ToString()); var second = int.Parse(S[2].ToString() + S[3].ToString()); if ((0 < first && first < 13) && (0 < second && second < 13)) { Console.WriteLine("AMBIGUOUS"); return; } if ((0 >= first || first >= 13) && (0 >= second || second >= 13)) { Console.WriteLine("NA"); return; } if (0 < first && first < 13) { Console.WriteLine("MMYY"); return; } Console.WriteLine("YYMM"); } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24]]
8
206
8
using System; using System.Linq; class Program { static void Main(string[] args) { string s = Console.ReadLine(); int front = int.Parse(s[0].ToString()) * 10 + int.Parse(s[1].ToString()); int back = int.Parse(s[2].ToString()) * 10 + int.Parse(s[3].ToString()); bool isYYMM = false; bool isMMYY = false; if (front != 0 && back >= 1 && back <= 12) isYYMM = true; if (back != 0 && front >= 1 && front <= 12) isMMYY = true; string ans = ""; if (isYYMM && isMMYY) ans += "AMBIGUOUS"; else if (!isYYMM && !isMMYY) ans += "NA"; else if (isYYMM) ans += "YYMM"; else ans += "MMYY"; Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main(string[] args) { string s = Console.ReadLine(); int front = int.Parse(s[0].ToString()) * 10 + int.Parse(s[1].ToString()); int back = int.Parse(s[2].ToString()) * 10 + int.Parse(s[3].ToString()); bool isYYMM = false; bool isMMYY = false; if (back >= 1 && back <= 12) isYYMM = true; if (front >= 1 && front <= 12) isMMYY = true; string ans = ""; if (isYYMM && isMMYY) ans += "AMBIGUOUS"; else if (!isYYMM && !isMMYY) ans += "NA"; else if (isYYMM) ans += "YYMM"; else ans += "MMYY"; Console.WriteLine(ans); } }
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 79], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98]]
8
202
8
using System; using System.Collections.Generic; public class ABC126B { public static void Main() { string str = System.Console.ReadLine(); int all = int.Parse(str); bool YYMM = false, MMYY = false; int first = all / 100; int second = all - first * 100; if (first != 0 && second != 0 && second <= 12) YYMM = true; if (first != 0 && second != 0 && first <= 12) MMYY = true; if (YYMM) { if (MMYY) System.Console.WriteLine("AMBIGUOUS"); else System.Console.WriteLine("YYMM"); } else { if (MMYY) System.Console.WriteLine("MMYY"); else System.Console.WriteLine("NA"); } } }
using System; using System.Collections.Generic; public class ABC126B { public static void Main() { string str = System.Console.ReadLine(); int all = int.Parse(str); bool YYMM = false, MMYY = false; int first = all / 100; int second = all - first * 100; if (second != 0 && second <= 12) YYMM = true; if (first != 0 && first <= 12) MMYY = true; if (YYMM) { if (MMYY) System.Console.WriteLine("AMBIGUOUS"); else System.Console.WriteLine("YYMM"); } else { if (MMYY) System.Console.WriteLine("MMYY"); else System.Console.WriteLine("NA"); } } }
[["-", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 17, 79], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["-", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22]]
8
168
8
using System; namespace A { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var s1 = int.Parse(S.Substring(0, 2)); var s2 = int.Parse(S.Substring(2, 2)); var isYYMM = s1 > 0 && s2 > 0 && s2 < 13; var isMMYY = s1 > 0 && s1 < 13 && s2 > 0; if (isYYMM) { if (isMMYY) { Console.WriteLine("AMBIGUOUS"); } else { Console.WriteLine("YYMM"); } } else { if (isMMYY) { Console.WriteLine("MMYY"); } else { Console.WriteLine("NA"); } } } static int NumberOfDigits(long x) { if (x < 10) return 1; var result = 0; while (x > 0) { result++; x /= 10; } return result; } static int SumOfDigits(int x) { var sum = 0; while (x > 0) { sum += x % 10; x /= 10; } return sum; } } }
using System; namespace B { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var s1 = int.Parse(S.Substring(0, 2)); var s2 = int.Parse(S.Substring(2, 2)); var isYYMM = s2 > 0 && s2 < 13; var isMMYY = s1 > 0 && s1 < 13; if (isYYMM) { if (isMMYY) { Console.WriteLine("AMBIGUOUS"); } else { Console.WriteLine("YYMM"); } } else { if (isMMYY) { Console.WriteLine("MMYY"); } else { Console.WriteLine("NA"); } } } static int NumberOfDigits(long x) { if (x < 10) return 1; var result = 0; while (x > 0) { result++; x /= 10; } return result; } static int SumOfDigits(int x) { var sum = 0; while (x > 0) { sum += x % 10; x /= 10; } return sum; } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 17, 47], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 98], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 98], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 17, 47], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 12, 203]]
8
234
10
using Atcoder; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var A = int.Parse(S.Substring(0, 2)); var B = int.Parse(S.Substring(2, 2)); if (A < 13 && B < 13 && A != 0 && B != 0) { Console.Write("AMBIGUOUS"); return; } if ((A >= 13 && B >= 13) || (A == 0 && B >= 13) || (A >= 13 && B == 0)) { Console.Write("NA"); return; } if (A != 0 && A < 13) { Console.Write("MMYY"); return; } if (B != 0 && B < 13) { Console.Write("YYMM"); return; } } } // var N = int.Parse(Console.ReadLine()); // var S = Console.ReadLine(); // var K = Console.ReadLine().Split(' '); }
using Atcoder; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var A = int.Parse(S.Substring(0, 2)); var B = int.Parse(S.Substring(2, 2)); if (A < 13 && B < 13 && A != 0 && B != 0) { Console.Write("AMBIGUOUS"); return; } if ((A >= 13 && B >= 13) || (A == 0 && B >= 13) || (A >= 13 && B == 0) || (A == 0 && B == 0)) { Console.Write("NA"); return; } if (A != 0 && A < 13) { Console.Write("MMYY"); return; } if (B != 0 && B < 13) { Console.Write("YYMM"); return; } } } // var N = int.Parse(Console.ReadLine()); // var S = Console.ReadLine(); // var K = Console.ReadLine().Split(' '); }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 60], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25]]
8
217
10
using System; using System.Collections.Generic; using System.Linq; 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) { Solve(); // WriteLine(Solve()); } static void Solve() { /*var nk = Input.ar;var res = 0L; for(var i = 1; i <= nk[0]; i++) { var ct = 0;var k = i; while (nk[1] > k) { k *= 2;ct++; } if(ct!=0) res += ct + 1; } WriteLine(((double) / res).ToString("F10"));*/ var s = ReadLine(); var q = ToInt32(s.Substring(0, 2)); var w = ToInt32(s.Substring(2)); if (q > 12 && w > 12) WriteLine("NA"); else if (q == 0 && w > 12) WriteLine("NA"); else if (w == 0 && q > 12) { WriteLine("NA"); } else if (q == 0 && w == 0) { WriteLine("NA"); } else if (q < 13 && w < 13) { WriteLine("AMBIGUOUS"); } else if (q > 12) WriteLine("YYMM"); else WriteLine("MMYY"); } }
using System; using System.Collections.Generic; using System.Linq; 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) { Solve(); // WriteLine(Solve()); } static void Solve() { /*var nk = Input.ar;var res = 0L; for(var i = 1; i <= nk[0]; i++) { var ct = 0;var k = i; while (nk[1] > k) { k *= 2;ct++; } if(ct!=0) res += ct + 1; } WriteLine(((double) / res).ToString("F10"));*/ var s = ReadLine(); var q = ToInt32(s.Substring(0, 2)); var w = ToInt32(s.Substring(2)); if (q > 12 && w > 12) WriteLine("NA"); else if (q == 0 && w > 12) WriteLine("NA"); else if (w == 0 && q > 12) { WriteLine("NA"); } else if (q == 0 && w == 0) { WriteLine("NA"); } else if (q < 12 && w == 0) WriteLine("MMYY"); else if (w < 12 && q == 0) { WriteLine("YYMM"); } else if (q < 13 && w < 13) { WriteLine("AMBIGUOUS"); } else if (q > 12) WriteLine("YYMM"); else WriteLine("MMYY"); } }
[["+", 75, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 17, 98], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 31, 22], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 17, 60], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 25], ["+", 75, 57, 75, 57, 64, 1, 0, 213, 63, 22], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 75, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 75, 57, 75, 57, 64, 1, 0, 35], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 95], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 121], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 31, 22], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 17, 18], ["+", 75, 57, 75, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 75, 57, 75, 57, 64, 196, 0, 46]]
8
221
38
using System; using System.Text; namespace ABC126 { class Program { static int Main(string[] args) { ProblemB(); return 0; } static void ProblemB() { int input = int.Parse(System.Console.ReadLine()); string answer; int ba, dc; ba = input % 100; dc = (input - ba) / 100; // YYMM if (ba <= 12) { if (dc <= 12) { answer = "AMBIGUOUS"; } else { answer = "YYMM"; } } // notYYMM else { if (dc <= 12) { answer = "MMYY"; } else { answer = "NA"; } } Console.WriteLine(answer); } static int ProblemA() { string[] K = System.Console.ReadLine().Split(' '); string S = System.Console.ReadLine(); string L = S.ToLower(); char[] Answer = new char[S.Length]; for (int i = 0; i < S.Length; i++) { if (i == int.Parse(K[1]) - 1) { Answer[i] = L[i]; } else { Answer[i] = S[i]; } } Console.WriteLine(Answer); return 0; } } }
using System; using System.Text; namespace ABC126 { class Program { static int Main(string[] args) { ProblemB(); return 0; } static void ProblemB() { int input = int.Parse(System.Console.ReadLine()); string answer; int ba, dc; ba = input % 100; dc = (input - ba) / 100; // YYMM if (ba <= 12 && ba >= 1) { if (dc <= 12 && dc >= 1) { answer = "AMBIGUOUS"; } else { answer = "YYMM"; } } // notYYMM else { if (dc <= 12 && dc >= 1) { answer = "MMYY"; } else { answer = "NA"; } } Console.WriteLine(answer); } static int ProblemA() { string[] K = System.Console.ReadLine().Split(' '); string S = System.Console.ReadLine(); string L = S.ToLower(); char[] Answer = new char[S.Length]; for (int i = 0; i < S.Length; i++) { if (i == int.Parse(K[1]) - 1) { Answer[i] = L[i]; } else { Answer[i] = S[i]; } } Console.WriteLine(Answer); return 0; } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 75, 196, 0, 57, 15, 16, 17, 98], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 75, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
276
12
using System; using System.Linq; using System.Collections.Generic; class Mondai { static void Main() { var S = Console.ReadLine(); var mae = string.Empty; var ushiro = string.Empty; for (int i = 0; i < 4; ++i) { if (i < 2) mae += S[i]; else ushiro += S[i]; } var ans = "AMBIGUOUS"; var maeNum = Int32.Parse(mae); var ushiroNum = Int32.Parse(ushiro); if ((12 < maeNum && 12 < ushiroNum) || (maeNum <= 0 && ushiroNum <= 0)) ans = "NA"; else if (maeNum <= 0 || 12 < maeNum) ans = "YYMM"; else if (ushiroNum <= 0 || 12 < ushiroNum) ans = "MMYY"; Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Mondai { static void Main() { var S = Console.ReadLine(); var mae = string.Empty; var ushiro = string.Empty; for (int i = 0; i < 4; ++i) { if (i < 2) mae += S[i]; else ushiro += S[i]; } var ans = "AMBIGUOUS"; var maeNum = Int32.Parse(mae); var ushiroNum = Int32.Parse(ushiro); if ((12 < maeNum && 12 < ushiroNum) || (maeNum <= 0 && ushiroNum <= 0) || (12 < maeNum && ushiroNum <= 0) || (12 < ushiroNum && maeNum <= 0)) ans = "NA"; else if (maeNum <= 0 || 12 < maeNum) ans = "YYMM"; else if (ushiroNum <= 0 || 12 < ushiroNum) ans = "MMYY"; Console.WriteLine(ans); } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 23, 0, 16, 31, 16, 31, 203], ["+", 31, 16, 12, 23, 0, 16, 31, 16, 17, 18], ["+", 31, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 98], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 17, 19], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 31, 203], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 17, 18], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 19], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25]]
8
182
20
using System; using System.Linq; namespace ABC126B { class Program { static void Main(string[] args) { string S = CIN.String(); int Y = int.Parse(S.Substring(0, 2)); int M = int.Parse(S.Substring(2, 2)); if (Y == 0) { Console.WriteLine("NA"); return; } if (M == 0) { Console.WriteLine("NA"); return; } if (Y > 12) { if (M > 12) { Console.WriteLine("NA"); return; } Console.WriteLine("YYMM"); return; } if (M > 12) { Console.WriteLine("MMYY"); return; } Console.WriteLine("AMBIGUOUS"); } } internal static class CIN { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
using System; using System.Linq; namespace ABC126B { class Program { static void Main(string[] args) { string S = CIN.String(); int Y = int.Parse(S.Substring(0, 2)); int M = int.Parse(S.Substring(2, 2)); if (Y == 0 && M == 0) { Console.WriteLine("NA"); return; } if (Y > 12 || Y == 0) { if (M > 12 || M == 0) { Console.WriteLine("NA"); return; } Console.WriteLine("YYMM"); return; } if (M > 12 || M == 0) { Console.WriteLine("MMYY"); return; } Console.WriteLine("AMBIGUOUS"); } } internal static class CIN { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 106], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
340
29
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Solver { Scanner sc = new Scanner(); public void Solve() { var S = sc.next(); var mae = Convert.ToInt32(S.Substring(0, 2)); var ato = Convert.ToInt32(S.Substring(2, 2)); if (mae == 0 && ato <= 12) { WriteLine("YYMM"); return; } if (mae <= 12 && ato == 0) { WriteLine("MMYY"); return; } if (mae == 0 || ato == 0) { WriteLine("NA"); return; } if (mae <= 12 && ato <= 12) { WriteLine("AMBIGUOUS"); } else if (mae <= 12 && ato > 12) { WriteLine("MMYY"); } else if (mae > 12 && ato <= 12) { WriteLine("YYMM"); } else { WriteLine("NA"); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] args) { Solver s = new Solver(); s.Solve(); } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; class Solver { Scanner sc = new Scanner(); public void Solve() { var S = sc.next(); var mae = Convert.ToInt32(S.Substring(0, 2)); var ato = Convert.ToInt32(S.Substring(2, 2)); if (mae == 0 && ato > 0 && ato <= 12) { WriteLine("YYMM"); return; } if (mae > 0 && mae <= 12 && ato == 0) { WriteLine("MMYY"); return; } if (mae == 0 || ato == 0) { WriteLine("NA"); return; } if (mae <= 12 && ato <= 12) { WriteLine("AMBIGUOUS"); } else if (mae <= 12 && ato > 12) { WriteLine("MMYY"); } else if (mae > 12 && ato <= 12) { WriteLine("YYMM"); } else { WriteLine("NA"); } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] args) { Solver s = new Solver(); s.Solve(); } }
[["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 47], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98]]
8
594
8
using System; using System.Collections.Generic; using System.Text; using System.Numerics; namespace SolutionCS { class Program { static void Main(string[] args) { string strIn = Console.ReadLine(); string str0 = strIn.Substring(0, 2); string str1 = strIn.Substring(2, 2); int int0 = int.Parse(str0); int int1 = int.Parse(str1); if (int0 == 0) { if (int1 > 12) { Console.WriteLine("NA"); } else { Console.WriteLine("YYMM"); } } else if (int1 == 0) { if (int0 > 12) { Console.WriteLine("NA"); } else { Console.WriteLine("MMYY"); } } else if (int0 <= 12 && int1 <= 12) { Console.WriteLine("AMBIGUOUS"); } else if (int0 <= 12) { Console.WriteLine("MMYY"); } else { Console.WriteLine("YYMM"); } } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; namespace SolutionCS { class Program { static void Main(string[] args) { string strIn = Console.ReadLine(); string str0 = strIn.Substring(0, 2); string str1 = strIn.Substring(2, 2); int int0 = int.Parse(str0); int int1 = int.Parse(str1); if (int0 == 0) { if (int1 > 12 || int1 == 0) { Console.WriteLine("NA"); } else { Console.WriteLine("YYMM"); } } else if (int1 == 0) { if (int0 > 12 || int0 == 0) { Console.WriteLine("NA"); } else { Console.WriteLine("MMYY"); } } else if (int0 <= 12 && int1 <= 12) { Console.WriteLine("AMBIGUOUS"); } else if (int0 <= 12) { Console.WriteLine("MMYY"); } else if (int1 <= 12) { Console.WriteLine("YYMM"); } else { Console.WriteLine("NA"); } } } }
[["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 106], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 75, 57, 64, 196, 0, 57, 15, 16, 17, 106], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 121], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 24], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 17, 19], ["+", 75, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 75, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 75, 57, 75, 57, 75, 57, 64, 196, 0, 46], ["+", 75, 57, 75, 57, 75, 57, 75, 57, 0, 95], ["+", 75, 57, 75, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
219
26
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class B { public static void Main() { string S = GetString(); int first = int.Parse(S.Substring(0, 2)); int last = int.Parse(S.Substring(2, 2)); if (first == 0 || last == 0) { Console.WriteLine("NA"); } else if (!canMM(first) && canMM(last)) { Console.WriteLine("YYMM"); } else if (canMM(first) && !canMM(last)) { Console.WriteLine("MMYY"); } else { Console.WriteLine("AMBIGUOUS"); } } private static bool canMM(int x) { return ((x >= 1) && (x <= 12)); } } 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 B { public static void Main() { string S = GetString(); int first = int.Parse(S.Substring(0, 2)); int last = int.Parse(S.Substring(2, 2)); if (canMM(first) && canMM(last)) { Console.WriteLine("AMBIGUOUS"); } else if (!canMM(first) && canMM(last)) { Console.WriteLine("YYMM"); } else if (canMM(first) && !canMM(last)) { Console.WriteLine("MMYY"); } else { Console.WriteLine("NA"); } } private static bool canMM(int x) { return ((x >= 1) && (x <= 12)); } } 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(); } }
[["+", 8, 196, 0, 57, 15, 16, 31, 213, 63, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 213, 63, 22], ["+", 0, 57, 15, 16, 12, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
337
16
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 { class Program { static void Main(string[] args) { new ABC128().SolveC(new ConsoleInput(Console.In, ' ')); } } 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; } } class ABC128 { public void SolveC(ConsoleInput cin) { var n = cin.ReadInt; var m = cin.ReadInt; var S = new List<int[]>(); for (int k = 0; k < m; k++) { int m_k = cin.ReadInt; S.Add(cin.ReadIntArray(m_k)); } var P = cin.ReadIntArray(m); var lamp = new int[m]; int count = 0; int countOfOnSwitch = 0; for (int bit = 0; bit < 1 << n; bit++) //全スイッチ状態ループ { for (int k = 0; k < m; k++) //各ランプのループ { foreach (int s in S[k]) { if ((bit & (1 << s - 1)) != 0) { countOfOnSwitch++; } } if (countOfOnSwitch % 2 == P[k]) { lamp[k] = 1; } else { lamp[k] = 0; } } if (lamp.Sum() == m) { count++; } countOfOnSwitch = 0; } /* WriteLine($"{n} {m}"); for (int i = 0; i < m; i++) { foreach (int k in S[i]) { Write($"{k} "); } WriteLine(); } foreach (int p in P) { Write($"{p} "); } WriteLine(); */ WriteLine(count); ReadLine(); } } }
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 { class Program { static void Main(string[] args) { new ABC128().SolveC(new ConsoleInput(Console.In, ' ')); } } 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; } } class ABC128 { public void SolveC(ConsoleInput cin) { var n = cin.ReadInt; var m = cin.ReadInt; var S = new List<int[]>(); for (int k = 0; k < m; k++) { int m_k = cin.ReadInt; S.Add(cin.ReadIntArray(m_k)); } var P = cin.ReadIntArray(m); var lamp = new int[m]; int count = 0; int countOfOnSwitch = 0; for (int bit = 0; bit < 1 << n; bit++) //全スイッチ状態ループ { for (int k = 0; k < m; k++) //各ランプのループ { foreach (int s in S[k]) { if ((bit & (1 << s - 1)) != 0) { countOfOnSwitch++; } } if (countOfOnSwitch % 2 == P[k]) { lamp[k] = 1; } else { lamp[k] = 0; } countOfOnSwitch = 0; } if (lamp.Sum() == m) { count++; } } /* WriteLine($"{n} {m}"); for (int i = 0; i < m; i++) { foreach (int k in S[i]) { Write($"{k} "); } WriteLine(); } foreach (int p in P) { Write($"{p} "); } WriteLine(); */ WriteLine(count); ReadLine(); } } }
[["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
645
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128_C_Switches { class Program { static void Main(string[] args) { string[] nm = Console.ReadLine().Split(' '); int n = int.Parse(nm[0]); int m = int.Parse(nm[1]); int[] k = new int[m]; List<int[]> switcheList = new List<int[]>(); for (int i = 0; i < m; i++) { int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); k[i] = input[0]; int[] switches = new int[k[i]]; for (int j = 0; j < k[i]; j++) { switches[j] = input[j + 1]; } switcheList.Add(switches); } int[] p = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int ans = 0; for (int i = 0; i < Math.Pow(2, n); i++) { int lightCnt = 0; char[] status = Convert.ToString(i, 2).PadLeft(n, '0').ToCharArray(); for (int j = 0; j < m; j++) { int onCnt = 0; foreach (int x in switcheList[j]) { if (status[x - 1] == '1') { onCnt++; } } if (onCnt % 2 == p[m - 1]) { lightCnt++; } } if (lightCnt == m) { ans++; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128_C_Switches { class Program { static void Main(string[] args) { string[] nm = Console.ReadLine().Split(' '); int n = int.Parse(nm[0]); int m = int.Parse(nm[1]); int[] k = new int[m]; List<int[]> switcheList = new List<int[]>(); for (int i = 0; i < m; i++) { int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); k[i] = input[0]; int[] switches = new int[k[i]]; for (int j = 0; j < k[i]; j++) { switches[j] = input[j + 1] - 1; } switcheList.Add(switches); } int[] p = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int ans = 0; for (int i = 0; i < Math.Pow(2, n); i++) { int lightCnt = 0; char[] status = Convert.ToString(i, 2).PadLeft(n, '0').ToCharArray(); for (int j = 0; j < m; j++) { int onCnt = 0; foreach (int x in switcheList[j]) { if (status[x] == '1') { onCnt++; } } if (onCnt % 2 == p[j]) { lightCnt++; } } if (lightCnt == m) { ans++; } } Console.WriteLine(ans); } } }
[["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
8
412
8
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); // スイッチの数 int m = int.Parse(input[1]); // 電球の数 var lights = new List<Light>(m); for (int i = 0; i < m; i++) { var arg = Console.ReadLine(); lights.Add(new Light(n, arg)); } var rems = Console.ReadLine().Split(' '); for (int i = 0; i < m; i++) { lights[i].SetRemainder(int.Parse(rems[i])); } int maxSwitchPattern = (int)Math.Pow(2, n) - 1; int countAllLightOn = 0; for (int i = 0; i <= maxSwitchPattern; i++) { bool isLightOn = true; // 各電球について確認 for (int j = 0; j < m; j++) { if (!lights[j].IsLightOn(i)) { isLightOn = false; break; } } if (isLightOn) { countAllLightOn++; } } Console.WriteLine(countAllLightOn); } public class Light { int mTotalSw = 0; int mRemainder = 0; int mSwitch = 0; public Light(int totalSw, string input) { mTotalSw = totalSw; var args = input.Split(' '); int switchCount = int.Parse(args[0]); var switchIndex = new List<int>(switchCount); for (int i = 0; i < switchCount; i++) { switchIndex.Add(int.Parse(args[i + 1]) - 1); } for (int i = 0; i < mTotalSw; i++) { mSwitch <<= 1; if (switchIndex.Contains(i)) { mSwitch |= 1; } } } public void SetRemainder(int remainder) { mRemainder = remainder; } public bool IsLightOn( int switchState) // switchState : N(<=10)ビットの整数. S1, S2, .... SN // の状態を表すもの。ON ならビットを立てる { if (switchState == 0) { return false; // 全てOFFの場合は余りの数に関係なく非点灯? } var state = switchState & mSwitch; // 関連づいていてONになっているビットが立つ int onSwitchCount = 0; for (int i = 0; i < mTotalSw; i++) { if ((state & 1) == 1) { onSwitchCount++; } state >>= 1; } return (onSwitchCount % 2 == mRemainder); } } } }
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); // スイッチの数 int m = int.Parse(input[1]); // 電球の数 var lights = new List<Light>(m); for (int i = 0; i < m; i++) { var arg = Console.ReadLine(); lights.Add(new Light(n, arg)); } var rems = Console.ReadLine().Split(' '); for (int i = 0; i < m; i++) { lights[i].SetRemainder(int.Parse(rems[i])); } int maxSwitchPattern = (int)Math.Pow(2, n) - 1; int countAllLightOn = 0; for (int i = 0; i <= maxSwitchPattern; i++) { bool isLightOn = true; // 各電球について確認 for (int j = 0; j < m; j++) { if (!lights[j].IsLightOn(i)) { isLightOn = false; break; } } if (isLightOn) { countAllLightOn++; } } Console.WriteLine(countAllLightOn); } public class Light { int mTotalSw = 0; int mRemainder = 0; int mSwitch = 0; public Light(int totalSw, string input) { mTotalSw = totalSw; var args = input.Split(' '); int switchCount = int.Parse(args[0]); var switchIndex = new List<int>(switchCount); for (int i = 0; i < switchCount; i++) { switchIndex.Add(int.Parse(args[i + 1]) - 1); } for (int i = 0; i < mTotalSw; i++) { mSwitch <<= 1; if (switchIndex.Contains(i)) { mSwitch |= 1; } } } public void SetRemainder(int remainder) { mRemainder = remainder; } public bool IsLightOn( int switchState) // switchState : N(<=10)ビットの整数. S1, S2, .... SN // の状態を表すもの。ON ならビットを立てる { var state = switchState & mSwitch; // 関連づいていてONになっているビットが立つ int onSwitchCount = 0; for (int i = 0; i < mTotalSw; i++) { if ((state & 1) == 1) { onSwitchCount++; } state >>= 1; } return (onSwitchCount % 2 == mRemainder); } } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["-", 0, 57, 64, 196, 0, 37, 0, 211, 0, 147], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
510
11
using System; using static System.Console; using System.Text; using System.Linq; using static System.Math; using System.Collections.Generic; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { public static cp alg; public static int[] P; public static int[][] KS; public static int N; public static int M; public static double num = 0; static void Main(string[] args) { alg = new cp(); var temp = alg.inputSplitInt(); N = temp[0]; M = temp[1]; KS = alg.inputJaggedArrayInt(M); P = alg.inputSplitInt(); long kumi = 0; for (int a = 0; a < (1 << N); a++) { var use = new List<int>(); for (int b = 0; b < N; b++) { if ((a & (1 << b)) > 0) { use.Insert(0, 1); } else { use.Insert(0, 0); } } int count = 0; bool f = true; for (int b = 0; b < M; b++) { for (int c = 0; c < KS[b][0]; c++) { int sIndex = KS[b][c + 1] - 1; if (use[sIndex] == 1) { count++; } } if (count % 2 != P[b]) { f = false; } } if (f) { kumi++; } } WriteLine(kumi); } } class cp { public cp() {} public int GCD(int a, int b) { return a % b == 0 ? b : GCD(b, a % b); } public int LCM(int a, int b) { return a * b / GCD(a, b); } public int countString(string s, string key) { return (s.Length - s.Replace(key, "").Length) / key.Length; } public string Yn(bool f) { if (f) { return "Yes"; } else { return "No"; } } public string YN(bool f) { if (f) { return "YES"; } else { return "NO"; } } public string yn(bool f) { if (f) { return "yes"; } else { return "no"; } } public void inputSkip() { ReadLine(); return; } public string inputString() { return ReadLine(); } public string[] inputSplitString() { return ReadLine().Split(); } public string[] inputLinesString(int len) { var arr = new string[len]; for (int a = 0; a < len; a++) { arr[a] = ReadLine(); } return arr; } public string[][] inputJaggedArrayString(int len) { var arr = new string[len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split(); } return arr; } public int inputInt() { return int.Parse(ReadLine()); } public int[] inputSplitInt() { return ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } public int[] inputLinesInt(int len) { var arr = new int[len]; for (int a = 0; a < len; a++) { arr[a] = int.Parse(ReadLine()); } return arr; } public int[][] inputJaggedArrayInt(int len) { var arr = new int [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } return arr; } public long inputLong() { return long.Parse(ReadLine()); } public long[] inputSplitLong() { return ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } public long[] inputLinesLong(long len) { var arr = new long[len]; for (int a = 0; a < len; a++) { arr[a] = long.Parse(ReadLine()); } return arr; } public long[][] inputJaggedArrayLong(int len) { var arr = new long [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } return arr; } public double inputDouble() { return double.Parse(ReadLine()); } public double[] inputSplitDouble() { return ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } public double[] inputLinesDouble(int len) { var arr = new double[len]; for (int a = 0; a < len; a++) { arr[a] = double.Parse(ReadLine()); } return arr; } public double[][] inputJaggedArrayDouble(int len) { var arr = new double [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } return arr; } }
using System; using static System.Console; using System.Text; using System.Linq; using static System.Math; using System.Collections.Generic; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Program { public static cp alg; public static int[] P; public static int[][] KS; public static int N; public static int M; public static double num = 0; static void Main(string[] args) { alg = new cp(); var temp = alg.inputSplitInt(); N = temp[0]; M = temp[1]; KS = alg.inputJaggedArrayInt(M); P = alg.inputSplitInt(); int kumi = 0; for (int a = 0; a < (1 << N); a++) { var use = new List<int>(); for (int b = 0; b < N; b++) { if ((a & (1 << b)) > 0) { use.Insert(0, 1); } else { use.Insert(0, 0); } } int lcount = 0; for (int b = 0; b < M; b++) { int scount = 0; for (int c = 0; c < KS[b][0]; c++) { int index = KS[b][c + 1] - 1; if (use[index] == 1) { scount++; } } if ((double)scount % 2 == P[b]) { lcount++; } } if (lcount == M) { kumi++; } } WriteLine(kumi); } } class cp { public cp() {} public int GCD(int a, int b) { return a % b == 0 ? b : GCD(b, a % b); } public int LCM(int a, int b) { return a * b / GCD(a, b); } public int countChar(string s, string key) { return (s.Length - s.Replace(key, "").Length); } public string Yn(bool f) { if (f) { return "Yes"; } else { return "No"; } } public string YN(bool f) { if (f) { return "YES"; } else { return "NO"; } } public string yn(bool f) { if (f) { return "yes"; } else { return "no"; } } public void inputSkip() { ReadLine(); return; } public string inputString() { return ReadLine(); } public string[] inputSplitString() { return ReadLine().Split(); } public string[] inputLinesString(int len) { var arr = new string[len]; for (int a = 0; a < len; a++) { arr[a] = ReadLine(); } return arr; } public string[][] inputJaggedArrayString(int len) { var arr = new string[len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split(); } return arr; } public int inputInt() { return int.Parse(ReadLine()); } public int[] inputSplitInt() { return ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } public int[] inputLinesInt(int len) { var arr = new int[len]; for (int a = 0; a < len; a++) { arr[a] = int.Parse(ReadLine()); } return arr; } public int[][] inputJaggedArrayInt(int len) { var arr = new int [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => int.Parse(i)).ToArray(); } return arr; } public long inputLong() { return long.Parse(ReadLine()); } public long[] inputSplitLong() { return ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } public long[] inputLinesLong(long len) { var arr = new long[len]; for (int a = 0; a < len; a++) { arr[a] = long.Parse(ReadLine()); } return arr; } public long[][] inputJaggedArrayLong(int len) { var arr = new long [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => long.Parse(i)).ToArray(); } return arr; } public double inputDouble() { return double.Parse(ReadLine()); } public double[] inputSplitDouble() { return ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } public double[] inputLinesDouble(int len) { var arr = new double[len]; for (int a = 0; a < len; a++) { arr[a] = double.Parse(ReadLine()); } return arr; } public double[][] inputJaggedArrayDouble(int len) { var arr = new double [len][]; for (int a = 0; a < len; a++) { arr[a] = ReadLine().Split().Select(i => double.Parse(i)).ToArray(); } return arr; } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 57, 15, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 57, 15, 16, 31, 16, 31, 74, 51, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 15, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["-", 0, 195, 8, 196, 0, 37, 0, 16, 17, 85], ["-", 8, 196, 0, 37, 0, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 37, 0, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 37, 0, 16, 12, 214, 141, 22]]
8
1,204
42
using System; namespace AtCoderABC128C { class Program { static void Main(string[] args) { int ans = 0; string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); // Switch int M = int.Parse(s[1]); // Lamp int[][] X = new int [M][]; // Lamp毎のSwitch bool[] sw = new bool[N]; // Swichのオンオフ for (int i = 0; i < M; i++) { s = Console.ReadLine().Split(' '); X[i] = new int[s.Length - 1]; for (int j = 1; j < s.Length; j++) { X[i][j - 1] = int.Parse(s[j]) - 1; } } s = Console.ReadLine().Split(' '); int[] lt = new int[M]; for (int i = 0; i < M; i++) { lt[i] = int.Parse(s[i]); } do { int count = 0; bool temp = true; for (int i = 0; i < M; i++) { for (int j = 0; j < X[i].Length; j++) { if (sw[X[i][j]]) count++; } if (count % 2 != lt[i]) { temp = false; break; } } if (temp) ans++; } while ((sw = nextsw(sw)) != null); Console.WriteLine(ans.ToString()); } static bool[] nextsw(bool[] sw) { for (int i = 0; i < sw.Length; i++) { if (!sw[i]) { sw[i] = true; for (int j = 0; j < i; j++) { sw[j] = false; } return sw; } } return null; } } }
using System; namespace AtCoderABC128C { class Program { static void Main(string[] args) { int ans = 0; string[] s = Console.ReadLine().Split(' '); int N = int.Parse(s[0]); // Switch int M = int.Parse(s[1]); // Lamp int[][] X = new int [M][]; // Lamp毎のSwitch bool[] sw = new bool[N]; // Swichのオンオフ for (int i = 0; i < M; i++) { s = Console.ReadLine().Split(' '); X[i] = new int[int.Parse(s[0])]; for (int j = 0; j < X[i].Length; j++) { X[i][j] = int.Parse(s[j + 1]) - 1; } } s = Console.ReadLine().Split(' '); int[] lt = new int[M]; for (int i = 0; i < M; i++) { lt[i] = int.Parse(s[i]); } do { bool temp = true; for (int i = 0; i < M; i++) { int count = 0; for (int j = 0; j < X[i].Length; j++) { if (sw[X[i][j]]) count++; } if (count % 2 != lt[i]) { temp = false; break; } } if (temp) ans++; } while ((sw = nextsw(sw)) != null); Console.WriteLine(ans.ToString()); } static bool[] nextsw(bool[] sw) { for (int i = 0; i < sw.Length; i++) { if (!sw[i]) { sw[i] = true; for (int j = 0; j < i; j++) { sw[j] = false; } return sw; } } return null; } } }
[["-", 39, 224, 225, 226, 0, 16, 31, 214, 205, 22], ["+", 39, 224, 225, 226, 0, 213, 63, 214, 205, 199], ["-", 39, 224, 225, 226, 0, 16, 31, 214, 141, 22], ["-", 12, 227, 39, 224, 225, 226, 0, 16, 17, 33], ["-", 12, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 39, 224, 225, 226, 0, 213, 63, 214, 141, 22], ["+", 39, 224, 225, 226, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 39, 224, 225, 226, 0, 213, 3, 4, 0, 25], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 73], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 214, 205, 204, 205, 22], ["+", 15, 16, 12, 214, 205, 204, 206, 207, 0, 70], ["+", 12, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 214, 205, 204, 206, 207, 0, 73], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 82, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 82, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35]]
8
438
33
using AtCoderBeginnerContest128.Questions; using AtCoderBeginnerContest128.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace AtCoderBeginnerContest128.Questions { public class QuestionD : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var nk = inputStream.ReadIntArray(); var jewelCount = nk[0]; var operationCount = nk[1]; var jewels = inputStream.ReadIntArray(); var maxValue = int.MinValue; for (int left = 0; left <= operationCount; left++) { for (int right = 0; left + right <= operationCount; right++) { var aquiredJewels = new PriorityQueue<int>(false); foreach (var leftJewel in jewels.Take(left)) { aquiredJewels.Enqueue(leftJewel); } foreach (var rightJewel in jewels.Reverse().Take(right)) { aquiredJewels.Enqueue(rightJewel); } var op = operationCount - (left + right); for (int i = 0; i < op; i++) { if (aquiredJewels.Any() && aquiredJewels.Peek() < 0) { aquiredJewels.Dequeue(); } else { break; } } var value = aquiredJewels.Sum(); maxValue = Math.Max(maxValue, value); } } yield return maxValue; } public class PriorityQueue<T> : IEnumerable<T> where T : IComparable<T> { private List<T> _heap = new List<T>(); private readonly int _reverseFactor; public int Count => _heap.Count; public bool IsDescending => _reverseFactor == 1; public PriorityQueue() : this(null, true) {} public PriorityQueue(IEnumerable<T> collection) : this(collection, true) {} public PriorityQueue(bool descending) : this(null, descending) {} public PriorityQueue(IEnumerable<T> collection, bool descending) { _reverseFactor = descending ? 1 : -1; _heap = new List<T>(); if (collection != null) { foreach (var item in collection) { Enqueue(item); } } } public void Enqueue(T item) { _heap.Add(item); UpHeap(); } public T Dequeue() { var item = _heap[0]; DownHeap(); return item; } public T Peek() => _heap[0]; private void UpHeap() { var child = Count - 1; while (child > 0) { int parent = (child - 1) / 2; if (Compare(_heap[child], _heap[parent]) > 0) { SwapAt(child, parent); child = parent; } else { break; } } } private void DownHeap() { _heap[0] = _heap[Count - 1]; _heap.RemoveAt(Count - 1); var parent = 0; while (true) { var leftChild = 2 * parent + 1; if (leftChild > Count - 1) { break; } var target = (leftChild < Count - 1) && (Compare(_heap[leftChild], _heap[leftChild + 1]) < 0) ? leftChild + 1 : leftChild; if (Compare(_heap[parent], _heap[target]) < 0) { SwapAt(parent, target); } else { break; } parent = target; } } private int Compare(T a, T b) => _reverseFactor * a.CompareTo(b); private void SwapAt(int n, int m) { var temp = _heap[n]; _heap[n] = _heap[m]; _heap[m] = temp; } public IEnumerator<T> GetEnumerator() { var copy = new List<T>(_heap); try { while (Count > 0) { yield return Dequeue(); } } finally { _heap = copy; } } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); } } } namespace AtCoderBeginnerContest128 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace AtCoderBeginnerContest128.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace AtCoderBeginnerContest128.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
using AtCoderBeginnerContest128.Questions; using AtCoderBeginnerContest128.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace AtCoderBeginnerContest128.Questions { public class QuestionD : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var nk = inputStream.ReadIntArray(); var jewelCount = nk[0]; var operationCount = nk[1]; var jewels = inputStream.ReadIntArray(); var maxValue = int.MinValue; for (int left = 0; left <= Math.Min(operationCount, jewelCount); left++) { for (int right = 0; left + right <= Math.Min(operationCount, jewelCount); right++) { var aquiredJewels = new PriorityQueue<int>(false); foreach (var leftJewel in jewels.Take(left)) { aquiredJewels.Enqueue(leftJewel); } foreach (var rightJewel in jewels.Reverse().Take(right)) { aquiredJewels.Enqueue(rightJewel); } var op = operationCount - (left + right); for (int i = 0; i < op; i++) { if (aquiredJewels.Any() && aquiredJewels.Peek() < 0) { aquiredJewels.Dequeue(); } else { break; } } var value = aquiredJewels.Sum(); maxValue = Math.Max(maxValue, value); } } yield return maxValue; } public class PriorityQueue<T> : IEnumerable<T> where T : IComparable<T> { private List<T> _heap = new List<T>(); private readonly int _reverseFactor; public int Count => _heap.Count; public bool IsDescending => _reverseFactor == 1; public PriorityQueue() : this(null, true) {} public PriorityQueue(IEnumerable<T> collection) : this(collection, true) {} public PriorityQueue(bool descending) : this(null, descending) {} public PriorityQueue(IEnumerable<T> collection, bool descending) { _reverseFactor = descending ? 1 : -1; _heap = new List<T>(); if (collection != null) { foreach (var item in collection) { Enqueue(item); } } } public void Enqueue(T item) { _heap.Add(item); UpHeap(); } public T Dequeue() { var item = _heap[0]; DownHeap(); return item; } public T Peek() => _heap[0]; private void UpHeap() { var child = Count - 1; while (child > 0) { int parent = (child - 1) / 2; if (Compare(_heap[child], _heap[parent]) > 0) { SwapAt(child, parent); child = parent; } else { break; } } } private void DownHeap() { _heap[0] = _heap[Count - 1]; _heap.RemoveAt(Count - 1); var parent = 0; while (true) { var leftChild = 2 * parent + 1; if (leftChild > Count - 1) { break; } var target = (leftChild < Count - 1) && (Compare(_heap[leftChild], _heap[leftChild + 1]) < 0) ? leftChild + 1 : leftChild; if (Compare(_heap[parent], _heap[target]) < 0) { SwapAt(parent, target); } else { break; } parent = target; } } private int Compare(T a, T b) => _reverseFactor * a.CompareTo(b); private void SwapAt(int n, int m) { var temp = _heap[n]; _heap[n] = _heap[m]; _heap[m] = temp; } public IEnumerator<T> GetEnumerator() { var copy = new List<T>(_heap); try { while (Count > 0) { yield return Dequeue(); } } finally { _heap = copy; } } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); } } } namespace AtCoderBeginnerContest128 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace AtCoderBeginnerContest128.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace AtCoderBeginnerContest128.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
[["+", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 21], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25]]
8
1,198
14
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128_D { class Program { static void Main(string[] args) { var NK = Console.ReadLine().Split().Select(long.Parse).ToArray(); var N = NK[0]; var K = NK[1]; var V = Console.ReadLine().Split().Select(long.Parse).ToArray(); var revV = V.Reverse(); var max = V.Length <= K ? V.Length : K; long ans = 0; for (int left = 0; left < max; left++) { for (int right = 0; right < max; right++) { if (left + right > max) break; var lis = V.Take(left).ToList(); lis.AddRange(revV.Take(right)); lis.Sort(); var rest = K - left - right; while (rest > 0 && lis.Any()) { if (lis[0] < 0) { lis.RemoveAt(0); rest--; } else { break; } } ans = Math.Max(ans, lis.Sum()); } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128_D { class Program { static void Main(string[] args) { var NK = Console.ReadLine().Split().Select(int.Parse).ToArray(); var N = NK[0]; var K = NK[1]; var V = Console.ReadLine().Split().Select(long.Parse).ToArray(); var revV = V.Reverse(); var max = Math.Min(V.Length, K); long ans = 0; for (int left = 0; left <= max; left++) { for (int right = 0; right <= max; right++) { if (left + right > max) break; var lis = V.Take(left).ToList(); lis.AddRange(revV.Take(right)); lis.Sort(); var rest = K - left - right; while (rest > 0 && lis.Any() && lis[0] < 0) { lis.RemoveAt(0); rest--; } ans = Math.Max(ans, lis.Sum()); } } Console.WriteLine(ans); } } }
[["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 212, 0, 41, 15, 16, 31, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 212, 0, 41, 15, 16, 31, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 41, 15, 16, 17, 19], ["-", 0, 200, 0, 212, 0, 41, 15, 16, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 41, 0, 101], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 52, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 7, 8, 196, 0, 52, 8, 196, 0, 45], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 98], ["-", 0, 52, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 52, 8, 196, 0, 57, 0, 95], ["-", 0, 52, 8, 196, 0, 57, 75, 196, 0, 45], ["-", 8, 196, 0, 57, 75, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 57, 75, 196, 0, 93, 0, 35], ["-", 0, 52, 8, 196, 0, 57, 75, 196, 0, 46]]
8
284
28
using System; using System.Linq; using System.Collections.Generic; class Mondai { static void Main() { var nk = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var N = nk[0]; var K = nk[1]; var V = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var ans = 0; //捨てられる宝石の数 for (int i = 0; i <= K / 2; ++i) { var count = K - i; //左 for (int j = 0; j <= count; ++j) { //右 for (int k = 0; k <= count - j; ++k) { var jewels = new List<int>(); jewels.AddRange(V.Take(j)); jewels.AddRange(V.Skip(N - k)); jewels.Sort(); var sum = 0; for (int l = 0; l < jewels.Count; ++l) { if (l < i && jewels[l] < 0) continue; sum += jewels[l]; } if (ans < sum) ans = sum; } } } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Mondai { static void Main() { var nk = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var N = nk[0]; var K = nk[1]; var V = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var ans = 0; //捨てられる宝石の数 for (int i = 0; i <= K / 2; ++i) { var count = K - i; //左 for (int j = 0; j <= count; ++j) { //右 for (int k = 0; k <= count - j; ++k) { if (N < j + k) break; var jewels = new List<int>(); jewels.AddRange(V.Take(j)); jewels.AddRange(V.Skip(N - k)); jewels.Sort(); var sum = 0; for (int l = 0; l < jewels.Count; ++l) { if (l < i && jewels[l] < 0) continue; sum += jewels[l]; } if (ans < sum) ans = sum; } } } Console.WriteLine(ans); } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35]]
8
278
10
using System; using System.Collections.Generic; using System.Linq; namespace ABC128 { class Program { static void Main(string[] args) { var nk = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var N = nk[0]; var K = nk[1] + 1; var V = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var ans = 0; foreach (var a in Enumerable.Range(0, K)) { var queueA = V.Take(a); foreach (var b in Enumerable.Range(0, K - a)) { var queueB = queueA.Concat(V.Skip(N - b)); foreach (var c in Enumerable.Range( 0, Math.Min(K - (a + b), queueB.Count() + 1))) { var queueC = queueB.OrderBy(x => x).Skip(c); ans = Math.Max(ans, queueC.Sum()); } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ABC128 { class Program { static void Main(string[] args) { var nk = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var N = nk[0]; var K = nk[1] + 1; var V = Console.ReadLine().Split(' ').Select(int.Parse).ToList(); var ans = 0; foreach (var a in Enumerable.Range(0, K)) { var queueA = V.Take(a); foreach (var b in Enumerable.Range(0, K - a)) { var queueB = queueA.Concat(V.Skip(Math.Max(a, N - b))); foreach (var c in Enumerable.Range( 0, Math.Min(K - (a + b), queueB.Count() + 1))) { var queueC = queueB.OrderBy(x => x).Skip(c); ans = Math.Max(ans, queueC.Sum()); } } } Console.WriteLine(ans); } } }
[["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
246
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128D { class Program { static void Main(string[] args) { var nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); var n = nums[0]; var k = nums[1]; var q = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); var qr = q.AsEnumerable().Reverse().ToList(); var opc = Math.Min(n, k); var maxValue = int.MinValue; foreach (var i in Enumerable.Range(0, opc)) { foreach (var j in Enumerable.Range(0, opc - i)) { var list = q.Take(i).Concat(qr.Take(j)); var plus = list.Where(x => x >= 0); var minus = list.Where(x => x < 0).OrderBy(x => x); // 捨ててよいカウント var dc = k - (i + j); var result = plus.Sum() + minus.Skip(dc).Sum(); if (result > maxValue) maxValue = result; } } Console.WriteLine(maxValue); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128D { class Program { static void Main(string[] args) { var nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); var n = nums[0]; var k = nums[1]; var q = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); var qr = q.AsEnumerable().Reverse().ToList(); var opc = Math.Min(n, k) + 1; var maxValue = int.MinValue; foreach (var i in Enumerable.Range(0, opc)) { foreach (var j in Enumerable.Range(0, opc - i)) { var list = new List<int>(); list.AddRange(q.Take(i)); list.AddRange(qr.Take(j)); var plus = list.Where(x => x >= 0); var minus = list.Where(x => x < 0).OrderBy(x => x); // 捨ててよいカウント var dc = k - (i + j); var result = plus.Sum() + minus.Skip(dc).Sum(); if (result > maxValue) maxValue = result; } } Console.WriteLine(maxValue); } } }
[["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 8, 196, 0, 210, 8, 196, 0, 197, 0, 35], ["+", 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, 196, 0, 210, 8, 196, 0, 1, 0, 35], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
300
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128 { class D { static void Main(string[] args) { int[] a = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray(); int N = a[0], K = a[1]; int[] V = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray(); int max = int.MinValue; for (int i = 0; i <= K / 2; i++) { int np = K - i; for (int j = 0; j <= np; j++) { for (int m = 0; m <= np - j; m++) { List<int> jewels = new List<int>(); jewels.AddRange(V.Take(j)); jewels.AddRange(V.Skip(N - m)); jewels.Sort(); int sum = 0; for (int k = 0; k < jewels.Count; k++) { if (k < i && jewels[k] < 0) continue; sum += jewels[k]; } if (sum > max) max = sum; } } } Console.WriteLine(max); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC128 { class D { static void Main(string[] args) { int[] a = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray(); int N = a[0], K = a[1]; int[] V = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray(); int max = int.MinValue; for (int i = 0; i <= K / 2; i++) { int np = K - i; for (int j = 0; j <= np; j++) { for (int m = 0; m <= np - j; m++) { if (j + m > N) continue; List<int> jewels = new List<int>(); jewels.AddRange(V.Take(j)); jewels.AddRange(V.Skip(N - m)); jewels.Sort(); int sum = 0; for (int k = 0; k < jewels.Count; k++) { if (k < i && jewels[k] < 0) continue; sum += jewels[k]; } if (sum > max) max = sum; } } } Console.WriteLine(max); } } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 117], ["+", 0, 7, 8, 196, 0, 57, 64, 116, 0, 35]]
8
303
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { int[] nk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = nk[0]; int K = nk[1]; var vList = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var vListRev = vList.Reverse().ToArray(); //「左からA回, 右からB回, 取り出して、残りを突っ込む」をシミュレート int max = int.MinValue; for (int A = 0; A <= K; A++) { if (vList.Length < A) break; for (int B = 0; B <= K - A; B++) { if (vList.Length < (A + B)) break; int remain = K - A - B; var left = vList.Take(A); var right = vListRev.Take(B); var val = left.Concat(right).OrderBy(n => n).Skip(remain).Sum(); max = Math.Max(val, max); } } Console.WriteLine(max); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; class Program { static void Main() { int[] nk = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int N = nk[0]; int K = nk[1]; var vList = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); var vListRev = vList.Reverse().ToArray(); //「左からA回, 右からB回, 取り出して、残りを突っ込む」をシミュレート int max = int.MinValue; for (int A = 0; A <= K; A++) { if (vList.Length < A) break; for (int B = 0; B <= K - A; B++) { if (vList.Length < (A + B)) break; int remain = K - A - B; var left = vList.Take(A); var right = vListRev.Take(B); var val = 0; int cnt = 0; foreach (var x in left.Concat(right).OrderBy(n => n)) { //都合の悪いのは回数分だけSumから除外可能 if (x < 0 && cnt < remain) { cnt++; continue; } val += x; } max = Math.Max(val, max); } } Console.WriteLine(max); } }
[["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 196, 0, 7, 8, 196, 0, 210, 0, 266], ["+", 8, 196, 0, 7, 8, 196, 0, 210, 0, 24], ["+", 0, 7, 8, 196, 0, 210, 39, 216, 0, 217], ["+", 8, 196, 0, 7, 8, 196, 0, 210, 31, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 210, 0, 267], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 210, 8, 196, 0, 45], ["+", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 210, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35], ["+", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 210, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 210, 8, 196, 0, 46]]
8
284
38
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; static class P { static void Main() { var nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); var k = nk[1]; var v = Console.ReadLine().Split().Select(int.Parse).ToArray(); int max = 0; for (int i = 0; i <= v.Length; i++) { for (int j = 0; j <= v.Length; j++) { var remainOps = k - (i + j); if (remainOps < 0) continue; List<int> gems = new List<int>(); for (int front = 0, count = 0; count < i; front++, count++) gems.Add(v[front]); for (int back = v.Length - 1, count = 0; count < j; back--, count++) gems.Add(v[back]); var taked = gems.OrderBy(x => x).TakeWhile(x => x < 0).Take(remainOps).Sum(); max = Max(max, gems.Sum() - taked); } } Console.WriteLine(max); } }
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; static class P { static void Main() { var nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); var k = nk[1]; var v = Console.ReadLine().Split().Select(int.Parse).ToArray(); long max = 0; for (int i = 0; i <= v.Length; i++) { for (int j = 0; j <= v.Length; j++) { var remainOps = k - (i + j); if (remainOps < 0 || v.Length < i + j) continue; List<long> gems = new List<long>(); for (int front = 0, count = 0; count < i; front++, count++) gems.Add(v[front]); for (int back = v.Length - 1, count = 0; count < j; back--, count++) gems.Add(v[back]); var taked = gems.OrderBy(x => x).TakeWhile(x => x < 0).Take(remainOps).Sum(); max = Max(max, gems.Sum() - taked); } } Console.WriteLine(max); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 22], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
319
14
using System; using System.Collections.Generic; using System.Linq; 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) { Solve(); // WriteLine(Solve()); } static int[] nq; static Dictionary<int, List<int[]>> dic; static int[] keys; static int qu; static void Solve() { var nq = Input.ar; var stx = Input.ar2D(nq[0]); for (var i = 0; i < nq[0]; i++) { stx[i][0] -= stx[i][2]; stx[i][1] -= stx[i][2]; } stx = stx.OrderBy(v => v[2]).ToArray(); var ds = Input.ar1D(nq[1]); var bit = new SegmentTree<int>(nq[1], int.MaxValue, (a, b) => Min(a, b)); for (var i = 0; i < nq[0]; i++) { var ind = Search.LowerBound(ds, stx[i][0]); var ind2 = Search.LowerBound(ds, stx[i][1]); bit.Update(ind, ind2, stx[i][2]); } var res = new List<int>(nq[1]); for (var j = 0; j < nq[1]; j++) res.Add(bit.Query(j)); WriteLine(string.Join("\n", res.Select(v => v == int.MaxValue ? -1 : v))); } } 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 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 const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class Search { public static int UpperBound<T>(IList<T> array, T value) where T : IComparable<T> { var low = 0; var high = array.Count; while (high > low) { var mid = (high + low) / 2; if (array[mid].CompareTo(value) == 1) high = mid; else low = mid + 1; } return low; } public static int LowerBound<T>(IList<T> array, T value) where T : IComparable<T> { var low = 0; var high = array.Count; while (high > low) { var mid = (high + low) / 2; if (array[mid].CompareTo(value) != -1) high = mid; else low = mid + 1; } return low; } public static T Max<T>(params T[] array) => array.Max(); public static T Min<T>(params T[] array) => array.Min(); public static bool Inside(int h, int w, int[] hw) => 0 <= h && h < hw[0] && 0 <= w && w < hw[1]; public static bool IsPrime(long num) { if (num % 2 == 0 || num == 1) return num == 2; for (var i = 3L; i * i <= num; i += 2) if (num % i == 0) return false; return true; } } 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) / 2, value); Update(left, right, Right(k), (l + r) / 2, 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) / 2), Query(left, right, Right(k), (l + r) / 2, r)); } }
using System; using System.Collections.Generic; using System.Linq; 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) { Solve(); // WriteLine(Solve()); } static int[] nq; static Dictionary<int, List<int[]>> dic; static int[] keys; static int qu; static void Solve() { var nq = Input.ar; var stx = Input.ar2D(nq[0]); for (var i = 0; i < nq[0]; i++) { stx[i][0] -= stx[i][2]; stx[i][1] -= stx[i][2]; } stx = stx.OrderBy(v => v[2]).ToArray(); var ds = Input.ar1D(nq[1]); var bit = new SegmentTree<int>(nq[1], int.MaxValue, (a, b) => Min(a, b), (a, b) => Min(a, b)); for (var i = 0; i < nq[0]; i++) { var ind = Search.LowerBound(ds, stx[i][0]); var ind2 = Search.LowerBound(ds, stx[i][1]); bit.Update(ind, ind2, stx[i][2]); } var res = new List<int>(nq[1]); for (var j = 0; j < nq[1]; j++) res.Add(bit.Query(j)); WriteLine(string.Join("\n", res.Select(v => v == int.MaxValue ? -1 : v))); } } 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 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 const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class Search { public static int UpperBound<T>(IList<T> array, T value) where T : IComparable<T> { var low = 0; var high = array.Count; while (high > low) { var mid = (high + low) / 2; if (array[mid].CompareTo(value) == 1) high = mid; else low = mid + 1; } return low; } public static int LowerBound<T>(IList<T> array, T value) where T : IComparable<T> { var low = 0; var high = array.Count; while (high > low) { var mid = (high + low) / 2; if (array[mid].CompareTo(value) != -1) high = mid; else low = mid + 1; } return low; } public static T Max<T>(params T[] array) => array.Max(); public static T Min<T>(params T[] array) => array.Min(); public static bool Inside(int h, int w, int[] hw) => 0 <= h && h < hw[0] && 0 <= w && w < hw[1]; public static bool IsPrime(long num) { if (num % 2 == 0 || num == 1) return num == 2; for (var i = 3L; i * i <= num; i += 2) if (num % i == 0) return false; return true; } } 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) / 2), Query(left, right, Right(k), (l + r) / 2, r)); } }
[["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 21], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 24], ["+", 0, 28, 0, 218, 54, 55, 0, 220, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 21], ["+", 0, 230, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 213, 63, 22], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 24], ["+", 0, 218, 8, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 218, 8, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 152], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
1,828
21
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; //using static System.Globalization.CultureInfo; using System.Text; class Program { private static void chmin<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == 1 ? val : num; private static void chmax<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == -1 ? val : num; private static void swap<T>(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } static void Main(string[] args) { var pr = new Program(); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); pr.Solve(); Console.Out.Flush(); } void Solve() { var num = Input.num; var ss = Input.arL; var res = 0L; for(var i = 1; i < num; i++) { var calc = 0L; if ((num - 1) % i != 0) for (int k = 0, q = num - 1; k < num-1 && q > i; k += i, q -= i) calc += ss[k] + ss[q]; else for (int k = 0, q = num - 1; k < q; k += i, q -= i) calc += ss[k] + ss[q]; chmax(ref res, calc); } WriteLine(res); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] grid(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object)int.Parse(g); if (t == typeof(long)) return (T)(object)long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object)char.Parse(g); if (t == typeof(double)) return (T)(object)double.Parse(g); if (t == typeof(bool)) return (T)(object)bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>() { sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item); return GetValue<T>(sc.Dequeue()); } public static void Next<T>(ref T val) => val = Next<T>(); public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1 { get; set; } public T2 v2 { get; set; } public Pair() { v1 = Input.Next<T1>(); v2 = Input.Next<T2>(); } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public override bool Equals(object obj) => this == (Pair<T1, T2>)obj; public override int GetHashCode() => v1.GetHashCode() ^ v2.GetHashCode(); public static bool operator ==(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 0; public static bool operator !=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 0; public static bool operator >(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 1; public static bool operator >=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != -1; public static bool operator <(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == -1; public static bool operator <=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 1; } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3 { get; set; } public Pair() : base() { v3 = Input.Next<T3>(); } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; //using static System.Globalization.CultureInfo; using System.Text; class Program { private static void chmin<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == 1 ? val : num; private static void chmax<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == -1 ? val : num; private static void swap<T>(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } static void Main(string[] args) { var pr = new Program(); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); pr.Solve(); Console.Out.Flush(); } void Solve() { var num = Input.num; var ss = Input.arL; var res = 0L; for(var i = 1; i < num; i++) { var calc = 0L; var max = 0L; if ((num - 1) % i != 0) for (int k = 0, q = num - 1; k < num-1 && q > i; k += i, q -= i) chmax(ref max, calc += ss[k] + ss[q]); else for (int k = 0, q = num - 1; k < q; k += i, q -= i) chmax(ref max, calc += ss[k] + ss[q]); chmax(ref res,max); } WriteLine(res); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] grid(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object)int.Parse(g); if (t == typeof(long)) return (T)(object)long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object)char.Parse(g); if (t == typeof(double)) return (T)(object)double.Parse(g); if (t == typeof(bool)) return (T)(object)bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>() { sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item); return GetValue<T>(sc.Dequeue()); } public static void Next<T>(ref T val) => val = Next<T>(); public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1 { get; set; } public T2 v2 { get; set; } public Pair() { v1 = Input.Next<T1>(); v2 = Input.Next<T2>(); } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public override bool Equals(object obj) => this == (Pair<T1, T2>)obj; public override int GetHashCode() => v1.GetHashCode() ^ v2.GetHashCode(); public static bool operator ==(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 0; public static bool operator !=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 0; public static bool operator >(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 1; public static bool operator >=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != -1; public static bool operator <(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == -1; public static bool operator <=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 1; } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3 { get; set; } public Pair() : base() { v3 = Input.Next<T3>(); } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 57, 64, 7, 8, 1, 0, 213, 63, 22], ["+", 64, 7, 8, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 1, 0, 213, 3, 4, 0, 28, 0, 275], ["+", 8, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 7, 8, 1, 0, 213, 3, 4, 0, 21], ["+", 64, 7, 8, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 7, 8, 1, 0, 213, 63, 22], ["+", 75, 7, 8, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 7, 8, 1, 0, 213, 3, 4, 0, 21], ["+", 75, 7, 8, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
1,790
19
using System; using System.IO; namespace AtCoder { class Program { static void Main(string[] args) { new Program().Solve(); } public void Solve() { var sc = new Scanner(); // 0 // A // A-B // A-B+A // ... // N - 1 - A // N - 1 // 偶数ターンは(A-B)*(i/2)にいる // 奇数ターンは(A-B)*(i/2) + A // はみ出るとすっごいマイナスなのではみ出ることは考えない // なのでゴールは奇数ターン かつ A > B // A - B = Cとすると // 移動する蓮は C * jと(N-1) - C*k // Cを固定して使う蓮を累積和で足していく // 計算量はO(NlogN) int N = sc.NextInt(); long[] s = sc.LongArray(); long ans = long.MinValue; // Cの範囲は1 ~ N - 1 for (int c = 1; c < N - 1; c++) { long left = 0; long right = 0; for (int t = 0; t < N; t += c) { int lpos = t; int rpos = N - 1 - t; if (rpos <= lpos) break; // Console.WriteLine($"{c} {lpos} {rpos}"); left += s[lpos]; right += s[rpos]; ans = Math.Max(ans, left + right); } } Console.WriteLine(ans); } } } class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; } const char Separator = ' '; private readonly StreamReader _stream; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = _stream.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = _stream.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; using System.IO; namespace AtCoder { class Program { static void Main(string[] args) { new Program().Solve(); } public void Solve() { var sc = new Scanner(); // 0 // A // A-B // A-B+A // ... // N - 1 - A // N - 1 // 偶数ターンは(A-B)*(i/2)にいる // 奇数ターンは(A-B)*(i/2) + A // はみ出るとすっごいマイナスなのではみ出ることは考えない // なのでゴールは奇数ターン かつ A > B // A - B = Cとすると // 移動する蓮は C * jと(N-1) - C*k // Cを固定して使う蓮を累積和で足していく // 計算量はO(NlogN) int N = sc.NextInt(); long[] s = sc.LongArray(); long ans = 0; // Cの範囲は1 ~ N - 1 for (int c = 1; c < N - 1; c++) { long left = 0; long right = 0; for (int t = 0; t < N - 1; t += c) { int lpos = t; int rpos = N - 1 - t; if ((N - 1) % c == 0) { if (rpos <= lpos) break; } if (rpos <= c) { break; } // Console.WriteLine($"{c} {lpos} {rpos}"); left += s[lpos]; right += s[rpos]; ans = Math.Max(ans, left + right); } } Console.WriteLine(ans); } } } class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; } const char Separator = ' '; private readonly StreamReader _stream; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = _stream.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = _stream.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 15, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 93, 0, 94], ["+", 0, 57, 64, 196, 0, 57, 64, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22]]
8
630
30
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] S = new int[N]; string[] str = Console.ReadLine().Split(); for (var i = 0; i < N; i++) { S[i] = int.Parse(str[i]); } long ans = 0; for (var i = 1; i <= N; i++) { long a = 0; for (var k = 1; k <= N; k++) { if (k * i >= N - 1 || (N - 1 - k * i <= k * i && (N - 1) % i == 0)) { break; } a += S[N - 1 - k * i]; a += S[k * i]; ans = Math.Max(ans, a); } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { long N = int.Parse(Console.ReadLine()); long[] S = new long[N]; string[] str = Console.ReadLine().Split(); for (var i = 0; i < N; i++) { S[i] = long.Parse(str[i]); } long ans = 0; for (long i = 1; i <= N; i++) { long a = 0; for (long k = 1; k <= N; k++) { if (k * i >= N - 1 || (N - 1 - k * i <= k * i && (N - 1) % i == 0) || N - 1 - k * i <= i) { break; } a += S[N - 1 - k * i]; a += S[k * i]; ans = Math.Max(ans, a); } } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 17, 33], ["+", 15, 16, 12, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 15, 16, 12, 16, 31, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 16, 31, 16, 12, 16, 17, 48], ["+", 15, 16, 12, 16, 31, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
216
22
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; private struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void Solve() { int N = NextInt(); List<long> has = Enumerable.Range(0, N).Select(v => NextLong()).ToList(); // X = B - A //双方からXで進むと考える long ans = 0; for (int x = 1; x < N; x++) { long sum = 0; int L = 0, R = N - 1; if ((N - 1) % x == 0) { //落ちるので L < R を保つ while (L < R) { sum += has[L] + has[R]; ans = Math.Max(sum, ans); L += x; R -= x; } } else { //交わらないので L < R じゃなくてok while (L < N - 1) { sum += has[L] + has[R]; ans = Math.Max(sum, ans); L += x; R -= x; } } } Console.WriteLine(ans); } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; private struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void Solve() { int N = NextInt(); List<long> has = Enumerable.Range(0, N).Select(v => NextLong()).ToList(); // X = B - A //双方からXで進むと考える long ans = 0; for (int x = 1; x < N; x++) { long sum = 0; int L = 0, R = N - 1; if ((N - 1) % x == 0) { //落ちるので L < R を保つ while (L < R) { sum += has[L] + has[R]; ans = Math.Max(sum, ans); L += x; R -= x; } } else { //交わらないので L < R じゃなくてok int A = (N - 1) - L; while (x < A) { sum += has[L] + has[R]; ans = Math.Max(sum, ans); L += x; R -= x; A = (N - 1) - L; } } } Console.WriteLine(ans); } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public class Input { private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }
[["-", 8, 196, 0, 57, 75, 196, 0, 52, 0, 89], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 75, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 57, 75, 196, 0, 52, 15, 16, 31, 22], ["-", 0, 57, 75, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 57, 75, 196, 0, 52, 0, 89], ["+", 8, 196, 0, 57, 75, 196, 0, 52, 0, 24], ["+", 0, 57, 75, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 57, 75, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 52, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 75, 196, 0, 52, 0, 25], ["+", 75, 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, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
612
25
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; using static System.Array; class MainClass : Scanner { static void Main() { var (A, B) = ReadStream<int, int>(); if (A < 5) WriteLine(0); else if (A <= 12) WriteLine(B / 2); else WriteLine(B); } } 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 int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> 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[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], 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 (A, B) = ReadStream<int, int>(); if (A <= 5) WriteLine(0); else if (A <= 12) WriteLine(B / 2); else WriteLine(B); } } 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 int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray(); public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray(); public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse); public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray(); public static string[] RStrings() => Console.ReadLine().Split(); // public static string[] RStrings(Func<string, string> 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[2], typeof(T3)); var r4 = (T4)Convert.ChangeType(r[3], typeof(T4)); return (r1, r2, r3, r4); } }
[["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 115], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19]]
8
716
8
using System; using System.Collections.Generic; using System.Linq; namespace Asakatsu20200313F { class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public void String(out string s) { s = Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public void String(long rowNumber, out string[] s) { s = new String[rowNumber]; for (long i = 0; i < rowNumber; i++) { String(out s[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public void Int(out int i) { string s; String(out s); i = int.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <param name="a"></param> public void Long(out long a) { string s; String(out s); a = long.Parse(s); } /// <summary> /// 2つの整数が1行に書かれている入力を、2つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> public void Long(out long a, out long b) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; } /// <summary> /// 3つの整数が1行に書かれている入力を、3つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(out long a, out long b, out long c) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; } /// <summary> /// 4つの整数が1行に書かれている入力を、4つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(out long a, out long b, out long c, out long d) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; d = lArr[3]; } public void Long(out long[] lArr) { lArr = Split().Select(long.Parse).ToArray(); } public void Long(long rowNumber, out long[] lArr) { lArr = new long[rowNumber]; for (long i = 0; i < rowNumber; i++) { Long(out lArr[i]); } } /// <summary> /// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> public void Long(long rowNumber, out long[] a, out long[] b) { a = new long[rowNumber]; b = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i]); } } /// <summary> /// 3つの整数が複数行に書かれている入力を、3つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i]); } } /// <summary> /// 4つの整数が複数行に書かれている入力を、4つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c, out long[] d) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; d = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i], out d[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public void Double(out double d) { string s; String(out s); d = double.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public void Double(out double[] dArr) { dArr = Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { string s; String(out s); return s.Split(' '); } } class Program { public static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { private Input input; public Solver() { input = new Input(); input.Long(out A); input.Long(out B); } private long A; private long B; public void Solve() { if (A <= 5) { Console.WriteLine(0); return; } if (A <= 12) { Console.WriteLine(B / 2); return; } Console.WriteLine(B); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Asakatsu20200313A { class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public void String(out string s) { s = Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public void String(long rowNumber, out string[] s) { s = new String[rowNumber]; for (long i = 0; i < rowNumber; i++) { String(out s[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public void Int(out int i) { string s; String(out s); i = int.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <param name="a"></param> public void Long(out long a) { string s; String(out s); a = long.Parse(s); } /// <summary> /// 2つの整数が1行に書かれている入力を、2つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> public void Long(out long a, out long b) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; } /// <summary> /// 3つの整数が1行に書かれている入力を、3つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(out long a, out long b, out long c) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; } /// <summary> /// 4つの整数が1行に書かれている入力を、4つのlongで受け取る /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(out long a, out long b, out long c, out long d) { long[] lArr; Long(out lArr); a = lArr[0]; b = lArr[1]; c = lArr[2]; d = lArr[3]; } public void Long(out long[] lArr) { lArr = Split().Select(long.Parse).ToArray(); } public void Long(long rowNumber, out long[] lArr) { lArr = new long[rowNumber]; for (long i = 0; i < rowNumber; i++) { Long(out lArr[i]); } } /// <summary> /// 2つの整数が複数行に書かれている入力を、2つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> public void Long(long rowNumber, out long[] a, out long[] b) { a = new long[rowNumber]; b = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i]); } } /// <summary> /// 3つの整数が複数行に書かれている入力を、3つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i]); } } /// <summary> /// 4つの整数が複数行に書かれている入力を、4つのlong[]で受け取る /// </summary> /// <param name="rowNumber"></param> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <param name="d"></param> public void Long(long rowNumber, out long[] a, out long[] b, out long[] c, out long[] d) { a = new long[rowNumber]; b = new long[rowNumber]; c = new long[rowNumber]; d = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { Long(out a[i], out b[i], out c[i], out d[i]); } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public void Double(out double d) { string s; String(out s); d = double.Parse(s); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public void Double(out double[] dArr) { dArr = Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { string s; String(out s); return s.Split(' '); } } class Program { public static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { private Input input; public Solver() { input = new Input(); input.Long(out A, out B); } private long A; private long B; public void Solve() { if (A <= 5) { Console.WriteLine(0); return; } if (A <= 12) { Console.WriteLine(B / 2); return; } Console.WriteLine(B); } } }
[["-", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 263, 8, 196, 0, 1, 0, 35], ["-", 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, 21]]
8
910
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_127A { class Program { static void Main(string[] args) { int a, b, x; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); x = int.Parse(word[1]); if (a >= 13) { x = b; } else if (a >= 6 && 6 <= 12) { x = b / 2; } else if (a <= 5) { x = 0; } Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC_127A { class Program { static void Main(string[] args) { int a, b, x; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); x = int.Parse(word[1]); if (a >= 13) { x = b; } else if (a >= 6 && 6 <= 12) { x = b / 2; } else if (a <= 5) { x = 0; } Console.WriteLine(x); Console.ReadLine(); } } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131]]
8
155
7
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]); if (A >= 13) { Console.WriteLine(B); } else { Console.WriteLine(B / 2); } } }
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]); if (A >= 13) { Console.WriteLine(B); } else if (A <= 5) { Console.WriteLine(0); } else { Console.WriteLine(B / 2); } } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95]]
8
89
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); int[] N = cin.ArrayInt(2, 0); int ans = 0; if (6 <= N[0] && 12 >= N[0]) ans = N[1] / 2; else ans = N[1]; Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); int[] N = cin.ArrayInt(2, 0); int ans = N[1]; if (6 <= N[0] && 12 >= N[0]) ans = N[1] / 2; else if (N[0] < 6) ans = 0; Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 0, 57, 75, 57, 64, 1, 0, 11, 31, 22], ["+", 75, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 57, 64, 1, 0, 11, 12, 203]]
8
745
17
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { public class MainClass { public static void Main(string[] args) { // if (args.Length > 0 && args[0] == "debug") if (true) { var inputs = new[] { @" 30 100 ", @" 12 100 ", @" 0 100 " }; foreach (var str in inputs) { var text = str.Trim(); if (text.Length == 0) continue; var reader = new System.IO.StringReader(text); Console.SetIn(reader); Main2(args); Console.WriteLine(); Console.WriteLine("----------------------------------"); Console.WriteLine(); } } else Main2(args); } public static void Main2(string[] args) { checked { var list = Console.ReadLine().Split(' ').ToList(); int a = int.Parse(list[0]); int b = int.Parse(list[1]); if (a <= 5) Console.WriteLine("0"); else if (a <= 12) Console.WriteLine(b / 2); else Console.WriteLine(b); } } } public static class EnumerablePlus { ///< summary>出力文字列に変換。</summary> public static string MkString<T>(this IEnumerable<T> list) { return list .Aggregate(new System.Text.StringBuilder(), (a, b) => ((a.Length > 0) ? a.Append(' ') : a).Append(b)) .ToString(); } ///< summary>添字付きfor。</summary> public static void ForEach<T>(this IEnumerable<T> list, Action<T, int> a) { int i = 0; foreach (var item in list) { a(item, i); } } ///< summary>指定回数デリゲートを呼び出す。</summary> public static IEnumerable<T> Repeat<T>(int n, Func<T> f) { for (int i = 0; i < n; i++) { yield return f(); } } } public static class MathPlus { ///< summary>約数。順番は不定。</summary> public static List<long> Divisor(long n) { var list = Prime(n) .GroupBy(id => id) .Select(pair => new { prime = pair.Key, power = pair.Count() }) .ToList(); var result = list.Aggregate(new List<long>(), (left, pair) => { var list2 = Enumerable.Range(0, pair.power + 1) .Aggregate(new List<long>(), (res, l) => { var next = res.Count > 0 ? res.Last() * pair.prime : 1L; res.Add(next); return res; }); if (left.Count == 0) return list2.ToList(); return list2.SelectMany(l => left.Select(m => l * m)).ToList(); }); return result; } ///< summary>順列の数。</summary> public static long Permutation(long n, long r) => Factorial(n, r); ///< summary>組合せの数。</summary> public static long Combination(long n, long r) { if (r == 0) return 1; return Factorial(n, r) / Factorial(r); } ///< summary>階乗。カウントも指定可能。</summary> public static long Factorial(long a, long count = long.MaxValue) { long res = 1; for (long i = 0; a > 0 && i < count; i++) { checked { res *= a; } --a; } return res; } ///< summary>素因数分解。昇順。</summary> public static List<long> Prime(long a) { var res = new List<long>(); for (long b = 2, c = (long)Math.Ceiling(Math.Sqrt(a)); b <= c; ++b) { while (a % b == 0) { res.Add(b); a = a / b; } } return res; } ///< summary>最小公倍数。</summary> public static long Lcm(IEnumerable<long> list) { return list.Aggregate((a, b) => Lcm(a, b)); } ///< summary>最小公倍数。</summary> public static long Lcm(long a, long b) { return checked(a * b) / Gcd(a, b); } ///< summary>最大公約数。</summary> public static long Gcd(IEnumerable<long> list) { return list.Aggregate((a, b) => Gcd(a, b)); } ///< summary>最大公約数。</summary> public static long Gcd(long a, long b) { if (a < b) Gcd(b, a); while (b != 0) { var rem = a % b; a = b; b = rem; } return a; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { public class MainClass { public static void Main(string[] args) { if (args.Length > 0 && args[0] == "debug") { var inputs = new[] { @" 30 100 ", @" 12 100 ", @" 0 100 " }; foreach (var str in inputs) { var text = str.Trim(); if (text.Length == 0) continue; var reader = new System.IO.StringReader(text); Console.SetIn(reader); Main2(args); Console.WriteLine(); Console.WriteLine("----------------------------------"); Console.WriteLine(); } } else Main2(args); } public static void Main2(string[] args) { checked { var list = Console.ReadLine().Split(' ').ToList(); int a = int.Parse(list[0]); int b = int.Parse(list[1]); if (a <= 5) Console.WriteLine("0"); else if (a <= 12) Console.WriteLine(b / 2); else Console.WriteLine(b); } } } public static class EnumerablePlus { ///< summary>出力文字列に変換。</summary> public static string MkString<T>(this IEnumerable<T> list) { return list .Aggregate(new System.Text.StringBuilder(), (a, b) => ((a.Length > 0) ? a.Append(' ') : a).Append(b)) .ToString(); } ///< summary>添字付きfor。</summary> public static void ForEach<T>(this IEnumerable<T> list, Action<T, int> a) { int i = 0; foreach (var item in list) { a(item, i); } } ///< summary>指定回数デリゲートを呼び出す。</summary> public static IEnumerable<T> Repeat<T>(int n, Func<T> f) { for (int i = 0; i < n; i++) { yield return f(); } } } public static class MathPlus { ///< summary>約数。順番は不定。</summary> public static List<long> Divisor(long n) { var list = Prime(n) .GroupBy(id => id) .Select(pair => new { prime = pair.Key, power = pair.Count() }) .ToList(); var result = list.Aggregate(new List<long>(), (left, pair) => { var list2 = Enumerable.Range(0, pair.power + 1) .Aggregate(new List<long>(), (res, l) => { var next = res.Count > 0 ? res.Last() * pair.prime : 1L; res.Add(next); return res; }); if (left.Count == 0) return list2.ToList(); return list2.SelectMany(l => left.Select(m => l * m)).ToList(); }); return result; } ///< summary>順列の数。</summary> public static long Permutation(long n, long r) => Factorial(n, r); ///< summary>組合せの数。</summary> public static long Combination(long n, long r) { if (r == 0) return 1; return Factorial(n, r) / Factorial(r); } ///< summary>階乗。カウントも指定可能。</summary> public static long Factorial(long a, long count = long.MaxValue) { long res = 1; for (long i = 0; a > 0 && i < count; i++) { checked { res *= a; } --a; } return res; } ///< summary>素因数分解。昇順。</summary> public static List<long> Prime(long a) { var res = new List<long>(); for (long b = 2, c = (long)Math.Ceiling(Math.Sqrt(a)); b <= c; ++b) { while (a % b == 0) { res.Add(b); a = a / b; } } return res; } ///< summary>最小公倍数。</summary> public static long Lcm(IEnumerable<long> list) { return list.Aggregate((a, b) => Lcm(a, b)); } ///< summary>最小公倍数。</summary> public static long Lcm(long a, long b) { return checked(a * b) / Gcd(a, b); } ///< summary>最大公約数。</summary> public static long Gcd(IEnumerable<long> list) { return list.Aggregate((a, b) => Gcd(a, b)); } ///< summary>最大公約数。</summary> public static long Gcd(long a, long b) { if (a < b) Gcd(b, a); while (b != 0) { var rem = a % b; a = b; b = rem; } return a; } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 211, 0, 146], ["+", 0, 57, 15, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 31, 16, 31, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 204, 205, 22], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 5, 0, 62], ["+", 0, 57, 15, 16, 12, 16, 12, 5, 0, 222]]
8
947
15
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using static System.Console; namespace ABC127B { static class Program { static void Main(string[] args) { var n = ReadLine().SplitTryParseToList<int>(); int[] a = new int[11]; a[0] = n[2]; foreach (var i in Enumerable.Range(0, 10)) { a[i + 1] = a[i] * n[0] - n[1]; } foreach (var i in a) { WriteLine(i); } } public static T TryParse<T>(this String input) { try { var converter = TypeDescriptor.GetConverter(typeof(T)); if (converter != null) { return (T)converter.ConvertFromString(input); } else { throw new InvalidCastException(""); } } catch { throw new InvalidCastException(typeof(T) + " is not supported."); } } public static List<T> SplitTryParseToList<T>(this String input) { return input.Split().Select(n => n.TryParse<T>()).ToList(); } public static List<T> ListSwap<T>(this List<T> list, Int32 index1, Int32 index2) { var t = list[index1]; list[index1] = list[index2]; list[index2] = t; return list; } public static List<Tuple<T, int>> DuplicateCount<T>(this IEnumerable<T> list) { return list.GroupBy(i => i) .Where(g => g.Any()) .Select(g => Tuple.Create(g.Key, g.Count())) .ToList(); } public static List<Tuple<T, int>> DuplicateSort<T>(this IEnumerable<Tuple<T, int>> list) { return list.OrderByDescending((x) => x.Item2).ToList(); } public static List<T> ReadLineOne<T>(int n) { var list = new List<T>(); foreach (var i in Enumerable.Range(1, n)) { list.Add(Console.ReadLine().TryParse<T>()); } return list; } public static void PrintAll<T>(this IEnumerable<T> list) { foreach (var i in list) { Console.Write($"{i} "); } Console.WriteLine(); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using static System.Console; namespace ABC127B { static class Program { static void Main(string[] args) { var n = ReadLine().SplitTryParseToList<int>(); int[] a = new int[11]; a[0] = n[2]; foreach (var i in Enumerable.Range(0, 10)) { a[i + 1] = a[i] * n[0] - n[1]; } foreach (var i in Enumerable.Range(1, 10)) { WriteLine(a[i]); } } public static T TryParse<T>(this String input) { try { var converter = TypeDescriptor.GetConverter(typeof(T)); if (converter != null) { return (T)converter.ConvertFromString(input); } else { throw new InvalidCastException(""); } } catch { throw new InvalidCastException(typeof(T) + " is not supported."); } } public static List<T> SplitTryParseToList<T>(this String input) { return input.Split().Select(n => n.TryParse<T>()).ToList(); } public static List<T> ListSwap<T>(this List<T> list, Int32 index1, Int32 index2) { var t = list[index1]; list[index1] = list[index2]; list[index2] = t; return list; } public static List<Tuple<T, int>> DuplicateCount<T>(this IEnumerable<T> list) { return list.GroupBy(i => i) .Where(g => g.Any()) .Select(g => Tuple.Create(g.Key, g.Count())) .ToList(); } public static List<Tuple<T, int>> DuplicateSort<T>(this IEnumerable<Tuple<T, int>> list) { return list.OrderByDescending((x) => x.Item2).ToList(); } public static List<T> ReadLineOne<T>(int n) { var list = new List<T>(); foreach (var i in Enumerable.Range(1, n)) { list.Add(Console.ReadLine().TryParse<T>()); } return list; } public static void PrintAll<T>(this IEnumerable<T> list) { foreach (var i in list) { Console.Write($"{i} "); } Console.WriteLine(); } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 210, 12, 22], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 24], ["+", 0, 210, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 210, 12, 213, 3, 4, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73]]
8
537
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder0525 { class Class1 { static void Main(string[] args) { string line = Console.ReadLine(); string[] arr = line.Split(' '); int r = int.Parse(arr[0]); int D = int.Parse(arr[1]); int x2000 = int.Parse(arr[2]); int x = x2000; for (int i = 2001; i <= 2010; i++) { x = r * x - D; Console.Write(x); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder0525 { class Class1 { static void Main(string[] args) { string line = Console.ReadLine(); string[] arr = line.Split(' '); long r = long.Parse(arr[0]); long D = long.Parse(arr[1]); long x2000 = long.Parse(arr[2]); long x = x2000; for (int i = 2001; i <= 2010; i++) { x = r * x - D; Console.WriteLine(x); } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22]]
8
144
16
using System; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int r, D; int[] seq = new int[10]; r = int.Parse(str[0]); D = int.Parse(str[1]); seq[0] = int.Parse(str[2]); for (int i = 0; i < seq.Length - 1; i++) { seq[i + 1] = r * seq[i] - D; } foreach (int x in seq) { Console.WriteLine(x); } } }
using System; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int r, D, x; int[] seq = new int[10]; r = int.Parse(str[0]); D = int.Parse(str[1]); x = int.Parse(str[2]); seq[0] = r * x - D; for (int i = 0; i < seq.Length - 1; ++i) { seq[i + 1] = r * seq[i] - D; } foreach (int s in seq) { Console.WriteLine(s); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 0, 21], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 241, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 31, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
143
24
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int r = 0; static int c = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static long mod = 1000000007; static long[] arr; static char[,] map; static int[,] imap; static Queue<int> qx = new Queue<int>(); static Queue<int> qy = new Queue<int>(); public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void ShowArray() { for (int i = 0; i < arr.Length; i++) { if (i > 0) w(" "); w(arr[i]); } wl(); } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(int def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } static void ShowMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(map[i, j]); } wl(); } } static void ShowIMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(imap[i, j]); } wl(); } } #endregion #region main static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); try { Solve(); } catch (Exception ex) { wl(ex); } Console.Out.Flush(); } public static void Solve() { n = Int(); int m = Int(); for (int i = 0; i < m; i++) { max = Math.Max(Int(), max); min = Math.Min(Int(), min); } wl(min - max + 1); } #endregion }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int r = 0; static int c = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static long mod = 1000000007; static long[] arr; static char[,] map; static int[,] imap; static Queue<int> qx = new Queue<int>(); static Queue<int> qy = new Queue<int>(); public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void ShowArray() { for (int i = 0; i < arr.Length; i++) { if (i > 0) w(" "); w(arr[i]); } wl(); } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(int def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } static void ShowMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(map[i, j]); } wl(); } } static void ShowIMap() { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { w(imap[i, j]); } wl(); } } #endregion #region main static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); try { Solve(); } catch (Exception ex) { wl(ex); } Console.Out.Flush(); } public static void Solve() { n = Int(); int m = Int(); for (int i = 0; i < m; i++) { max = Math.Max(Int(), max); min = Math.Min(Int(), min); } if (min >= max) wl(min - max + 1); else wl(0); } #endregion }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 213, 63, 22], ["+", 0, 57, 75, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
1,473
12
using System; using System.Linq; class C { public static void Main() { int[] inp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int M = inp[1]; int[] L = new int[M]; int[] R = new int[M]; int[] Te = new int[2]; for (int i = 0; i < M; i++) { Te = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); L[i] = Te[0]; R[i] = Te[1]; } int ans = R.Min() - L.Max(); Console.WriteLine(ans); } }
using System; using System.Linq; class C { public static void Main() { int[] inp = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); int M = inp[1]; int[] L = new int[M]; int[] R = new int[M]; int[] Te = new int[2]; for (int i = 0; i < M; i++) { Te = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); L[i] = Te[0]; R[i] = Te[1]; } int ans = R.Min() - L.Max(); if (ans >= 0) ans++; else ans = 0; Console.WriteLine(ans); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 1, 0, 35]]
8
170
14
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; using static System.Console; namespace ConsoleApp2 { class Program { static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { var NM = Sarray(); var N = NM[0]; var M = NM[1]; var left = 0; var right = N; for (var i = 0; i < M; i++) { var tmp = Sarray(); if (left < tmp[0]) left = tmp[0]; if (tmp[1] < right) right = tmp[1]; } WriteLine(right + 1 - left); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; using static System.Console; namespace ConsoleApp2 { class Program { static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { var NM = Sarray(); var N = NM[0]; var M = NM[1]; var left = 0; var right = N; for (var i = 0; i < M; i++) { var tmp = Sarray(); if (left < tmp[0]) left = tmp[0]; if (tmp[1] < right) right = tmp[1]; } var ans = right + 1 - left; WriteLine(ans < 0 ? 0 : ans); } } }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 18], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 22]]
8
230
15