buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC098A { class Program { static void Main(string[] args) { int a, b, max; var word = Console.ReadLine().Split(); a = int.Parse(word[0]); b = int.Parse(word[1]); max = a + b; max = a - b; max = a * b; if (max < a - b) max = a - b; if (max < a * b) max = a * b; Console.WriteLine(max); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC098A { class Program { static void Main(string[] args) { int a, b, max; var word = Console.ReadLine().Split(); a = int.Parse(word[0]); b = int.Parse(word[1]); max = a + b; if (max < a - b) max = a - b; if (max < a * b) max = a * b; Console.WriteLine(max); Console.ReadKey(); } } }
[["-", 0, 195, 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, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48]]
8
149
12
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 imp = Console.ReadLine().Split(' '); int plus = (int.Parse(imp[0])) + (int.Parse(imp[1])); int minus = Math.Abs((int.Parse(imp[0])) - (int.Parse(imp[1]))); int ast = (int.Parse(imp[0])) * (int.Parse(imp[1])); int[] ans = { plus, minus, ast }; Array.Sort(ans); Console.Write(ans[2]); } } }
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 imp = Console.ReadLine().Split(' '); int plus = (int.Parse(imp[0])) + (int.Parse(imp[1])); int minus1 = (int.Parse(imp[0])) - (int.Parse(imp[1])); // int minus2 = (int.Parse(imp[1])) - (int.Parse(imp[0])); int ast = (int.Parse(imp[0])) * (int.Parse(imp[1])); int[] ans = { plus, minus1, /*minus2 ,*/ ast }; Array.Sort(ans); Console.Write(ans[2]); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 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], ["-", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["-", 0, 16, 12, 23, 0, 213, 3, 4, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 229, 0, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 229, 0, 22]]
8
178
9
using System; namespace atcoder { class Program { static void Main(string[] args) { string a = Console.ReadLine(); string b = a.Replace(" ", ""); int c = b[0]; int d = b[1]; int e = c + d; int f = c - d; int g = c * d; int[] numbers = { e, f, g }; var h = Max(numbers); Console.WriteLine(h); } static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; // Minの場合は不等号を逆にすればOK } return max; } } }
using System; namespace atcoder { class Program { static void Main(string[] args) { string a = Console.ReadLine(); var b = a.Split(null); int c = int.Parse(b[0]); int d = int.Parse(b[1]); int e = c + d; int f = c - d; int g = c * d; int[] numbers = { e, f, g }; var h = Max(numbers); Console.WriteLine(h); } static T Max<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T max = nums[0]; for (int i = 1; i < nums.Length; i++) { max = max.CompareTo(nums[i]) > 0 ? max : nums[i]; // Minの場合は不等号を逆にすればOK } return max; } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 215], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25]]
8
195
21
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Numerics; #if DEBUG using Microsoft.VisualStudio.TestTools.UnitTesting; #endif namespace competitive_programming { public class Program { static void Main(string[] args) { #if DEBUG var scanner = new IO.StreamScanner(File.Open("input.txt", FileMode.Open)); #else var scanner = new IO.StreamScanner(Console.OpenStandardInput()); #endif var n = scanner.Integer(); var s = scanner.ScanLine(); IO.Printer.Out.WriteLine(GetAns(n, s)); IO.Printer.Out.Flush(); } static int GetAns(int n, string s) { var ret = 0; for (int i = 1; i < n - 1; i++) { var a = new HashSet<char>(s.Substring(0, i)); var b = new HashSet<char>(s.Substring(i, n - i)); for (int j = 0; j < 26; j++) { if (a.Contains((char)('a' + j)) && b.Contains((char)('a' + j))) ret++; } } return ret; } } #if DEBUG #endif namespace IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } 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; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; 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 = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Numerics; #if DEBUG using Microsoft.VisualStudio.TestTools.UnitTesting; #endif namespace competitive_programming { public class Program { static void Main(string[] args) { #if DEBUG var scanner = new IO.StreamScanner(File.Open("input.txt", FileMode.Open)); #else var scanner = new IO.StreamScanner(Console.OpenStandardInput()); #endif var n = scanner.Integer(); var s = scanner.ScanLine(); IO.Printer.Out.WriteLine(GetAns(s)); IO.Printer.Out.Flush(); } static int GetAns(string s) { var ret = 0; for (int i = 1; i < s.Length - 1; i++) { var a = new HashSet<char>(s.Substring(0, i)); var b = new HashSet<char>(s.Substring(i, s.Length - i)); var cnt = 0; for (int j = 0; j < 26; j++) { if (a.Contains((char)('a' + j)) && b.Contains((char)('a' + j))) cnt++; } ret = Math.Max(ret, cnt); } return ret; } } #if DEBUG #endif namespace IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } 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; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; 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 = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } }
[["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 141, 22], ["-", 0, 235, 8, 201, 0, 195, 54, 55, 0, 21], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 7, 15, 16, 12, 16, 31, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 0, 131], ["+", 3, 4, 0, 28, 0, 16, 31, 214, 141, 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, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 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], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
1,113
31
using System; namespace AtCoder { public class ProblemA { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int eastCount = 0; for (int i = 0; i < n; i++) { if (s[i] == 'E') eastCount++; } int number = int.MaxValue; int east2 = 0; for (int i = 0; i < n; i++) { char c = s[i]; int tmpAns = i - east2; if (c == 'E') { east2++; } tmpAns += (n - i - 2) - (eastCount - east2); if (tmpAns < number) { number = tmpAns; } } Console.WriteLine(number); } } }
using System; namespace AtCoder { public class ProblemA { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int eastCount = 0; for (int i = 0; i < n; i++) { if (s[i] == 'E') eastCount++; } int number = int.MaxValue; int east2 = 0; for (int i = 0; i < n; i++) { char c = s[i]; // 左は西を向いている人が振り向く int tmpAns = i - east2; if (c == 'E') { east2++; } // 右は東を向ている人が振り向く tmpAns += eastCount - east2; if (tmpAns < number) { number = tmpAns; } } Console.WriteLine(number); } } }
[["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 12, 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], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
8
173
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); string s = sc.Next(); int[] sumW = new int[n]; int tmpSumW = 0; for (int i = 0; i < n; i++) { if (s[i] == 'W') { tmpSumW++; } sumW[i] = tmpSumW; } int answer = int.MaxValue; for (int i = 0; i < n; i++) { int leftAnswer = 0; if (i > 0) { leftAnswer = n - i - sumW[n - 1]; } int rightAnswer = sumW[n - 1] - sumW[i]; answer = Math.Min(answer, leftAnswer + rightAnswer); } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); int n = sc.NextInt(); string s = sc.Next(); int[] sumW = new int[n]; int[] sumE = new int[n]; int tmpSumW = 0; int tmpSumE = 0; for (int i = 0; i < n; i++) { if (s[i] == 'W') { tmpSumW++; } else { tmpSumE++; } sumW[i] = tmpSumW; sumE[i] = tmpSumE; } int answer = int.MaxValue; for (int i = 0; i < n; i++) { int leftAnswer = 0; if (i > 0) { leftAnswer = sumW[i - 1]; } int rightAnswer = sumE[n - 1] - sumE[i]; answer = Math.Min(answer, leftAnswer + rightAnswer); } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["+", 0, 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, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 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, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 33], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22], ["+", 0, 200, 0, 212, 0, 16, 12, 204, 205, 22]]
8
491
39
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 ABC098C { static public void Solve() { var N = NN; var S = NS; var ruiseki1 = new long[N + 1]; for (var i = 1; i <= N; i++) { ruiseki1[i] = ruiseki1[i - 1] + (S[i - 1] == 'W' ? 1 : 0); } S = new string(S.Reverse().ToArray()); var ruiseki2 = new long[N + 1]; for (var i = 1; i <= N; i++) { ruiseki2[i] = ruiseki2[i - 1] + (S[i - 1] == 'E' ? 1 : 0); } ruiseki2 = ruiseki2.Reverse().ToArray(); var min = long.MaxValue; for (var i = 1; i <= N; i++) { min = Min(min, ruiseki1[i - 1] + ruiseki2[i - 1]); } Console.WriteLine(min); } //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // TEST _/ //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ class BT<T> where T : IComparable { private class Node { public Node left; public Node right; public T val; public bool isBlack; } private Comparison<T> c; private Node root; private bool change; public BT(Comparison<T> _c) { c = _c; } public BT() : this((x, y) => x.CompareTo(y)) {} private bool Red(Node n) => n != null && !n.isBlack; private bool Black(Node n) => n != null && n.isBlack; private Node RotateL(Node n) { Node m = n.right, t = m.left; m.left = n; n.right = t; return m; } private Node RotateR(Node n) { Node m = n.left, t = m.right; m.right = n; n.left = t; return m; } private Node RotateLR(Node n) { n.left = RotateL(n.left); return RotateR(n); } private Node RotateRL(Node n) { n.right = RotateR(n.right); return RotateL(n); } public void Add(T x) { root = Add(root, x); root.isBlack = true; } private Node Add(Node n, T x) { if (n == null) { change = true; return new Node() { val = x }; } var r = c(x, n.val); if (r < 0) { n.left = Add(n.left, x); return Balance(n); } if (r > 0) { n.right = Add(n.right, x); return Balance(n); } change = false; return n; } private Node Balance(Node n) { if (!change) return n; if (!Black(n)) return n; if (Red(n.left) && Red(n.left.left)) { n = RotateR(n); n.left.isBlack = true; } else if (Red(n.left) && Red(n.left.right)) { n = RotateLR(n); n.left.isBlack = true; } else if (Red(n.right) && Red(n.right.left)) { n = RotateRL(n); n.right.isBlack = true; } else if (Red(n.right) && Red(n.right.right)) { n = RotateL(n); n.right.isBlack = true; } else { change = false; } return n; } public void Remove(T x) { root = Remove(root, x); if (root != null) root.isBlack = true; } private Node Remove(Node n, T x) { if (n == null) { change = false; return n; } var r = c(x, n.val); if (r < 0) { n.left = Remove(n.left, x); return BalanceL(n); } if (r > 0) { n.right = Remove(n.right, x); return BalanceR(n); } if (n.left == null) { change = n.isBlack; return n.right; } n.left = RemoveMax(n.left); n.val = lmax; return BalanceL(n); } private T lmax; private Node RemoveMax(Node n) { if (n.right != null) { n.right = RemoveMax(n.right); return BalanceR(n); } lmax = n.val; change = n.isBlack; return n.left; } private Node BalanceL(Node n) { if (!change) return n; if (Black(n.right) && Red(n.right.left)) { var b = n.isBlack; n = RotateRL(n); n.isBlack = b; n.left.isBlack = true; change = false; } else if (Black(n.right) && Red(n.right.right)) { var b = n.isBlack; n = RotateL(n); n.isBlack = b; n.right.isBlack = true; n.left.isBlack = true; change = false; } else if (Black(n.right)) { change = n.isBlack; n.isBlack = true; n.right.isBlack = false; } else { n = RotateL(n); n.isBlack = true; n.left.isBlack = false; n.left = BalanceL(n.left); change = false; } return n; } private Node BalanceR(Node n) { if (!change) return n; if (Black(n.left) && Red(n.left.right)) { var b = n.isBlack; n = RotateLR(n); n.isBlack = b; n.right.isBlack = true; change = false; } else if (Black(n.left) && Red(n.left.left)) { var b = n.isBlack; n = RotateR(n); n.isBlack = b; n.left.isBlack = true; n.right.isBlack = true; change = false; } else if (Black(n.left)) { change = n.isBlack; n.isBlack = true; n.left.isBlack = false; } else { n = RotateR(n); n.isBlack = true; n.right.isBlack = false; n.right = BalanceR(n.right); change = false; } return n; } public Tuple<bool, T> FindUpper(T x) { var v = FindUpper(root, x); if (v == null) return Tuple.Create(false, default(T)); return v; } private Tuple<bool, T> FindUpper(Node n, T x) { if (n == null) return null; var r = c(x, n.val); if (r < 0) { var v = FindUpper(n.left, x); if (v == null) return Tuple.Create(true, n.val); return v; } else if (r > 0) return FindUpper(n.right, x); else return Tuple.Create(true, x); } public Tuple<bool, T> FindLower(T x) { var v = FindLower(root, x); if (v == null) return Tuple.Create(false, default(T)); return v; } private Tuple<bool, T> FindLower(Node n, T x) { if (n == null) return null; var r = c(x, n.val); if (r < 0) return FindLower(n.left, x); else if (r > 0) { var v = FindLower(n.right, x); if (v == null) return Tuple.Create(true, n.val); return v; } else return Tuple.Create(true, x); } public T Min() { Node n = root, p = null; while (n != null) { p = n; n = n.left; } return p == null ? default(T) : p.val; } public T Max() { Node n = root, p = null; while (n != null) { p = n; n = n.right; } return p == null ? default(T) : p.val; } public bool Any() => root != null; public int CountSlow() => List(root).Count(); public IEnumerable<T> List() => List(root); private IEnumerable<T> List(Node n) { if (n == null) yield break; foreach (var i in List(n.left)) yield return i; yield return n.val; foreach (var i in List(n.right)) yield return i; } } //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // TEST END _/ //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ 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 long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); [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 IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l, Comparison<T> comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); } [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; } static long LCM(long a, long b) => a * b / GCD(a, b); 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 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(long 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(long n, long k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)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 T Pow<T>(T x, long y) { T a = (dynamic)1; while (y != 0) { if ((y & 1) == 1) a *= (dynamic)x; x *= (dynamic)x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _Build(long 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(long n, long k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)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 ABC098C { static public void Solve() { var N = NN; var S = NS; var ruiseki1 = new long[N + 1]; for (var i = 1; i <= N; i++) { ruiseki1[i] = ruiseki1[i - 1] + (S[i - 1] == 'W' ? 1 : 0); } S = new string(S.Reverse().ToArray()); var ruiseki2 = new long[N + 1]; for (var i = 1; i <= N; i++) { ruiseki2[i] = ruiseki2[i - 1] + (S[i - 1] == 'E' ? 1 : 0); } var min = long.MaxValue; for (var i = 1; i <= N; i++) { min = Min(min, ruiseki1[i - 1] + ruiseki2[N - i]); } Console.WriteLine(min); } //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // TEST _/ //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ class BT<T> where T : IComparable { private class Node { public Node left; public Node right; public T val; public bool isBlack; } private Comparison<T> c; private Node root; private bool change; public BT(Comparison<T> _c) { c = _c; } public BT() : this((x, y) => x.CompareTo(y)) {} private bool Red(Node n) => n != null && !n.isBlack; private bool Black(Node n) => n != null && n.isBlack; private Node RotateL(Node n) { Node m = n.right, t = m.left; m.left = n; n.right = t; return m; } private Node RotateR(Node n) { Node m = n.left, t = m.right; m.right = n; n.left = t; return m; } private Node RotateLR(Node n) { n.left = RotateL(n.left); return RotateR(n); } private Node RotateRL(Node n) { n.right = RotateR(n.right); return RotateL(n); } public void Add(T x) { root = Add(root, x); root.isBlack = true; } private Node Add(Node n, T x) { if (n == null) { change = true; return new Node() { val = x }; } var r = c(x, n.val); if (r < 0) { n.left = Add(n.left, x); return Balance(n); } if (r > 0) { n.right = Add(n.right, x); return Balance(n); } change = false; return n; } private Node Balance(Node n) { if (!change) return n; if (!Black(n)) return n; if (Red(n.left) && Red(n.left.left)) { n = RotateR(n); n.left.isBlack = true; } else if (Red(n.left) && Red(n.left.right)) { n = RotateLR(n); n.left.isBlack = true; } else if (Red(n.right) && Red(n.right.left)) { n = RotateRL(n); n.right.isBlack = true; } else if (Red(n.right) && Red(n.right.right)) { n = RotateL(n); n.right.isBlack = true; } else { change = false; } return n; } public void Remove(T x) { root = Remove(root, x); if (root != null) root.isBlack = true; } private Node Remove(Node n, T x) { if (n == null) { change = false; return n; } var r = c(x, n.val); if (r < 0) { n.left = Remove(n.left, x); return BalanceL(n); } if (r > 0) { n.right = Remove(n.right, x); return BalanceR(n); } if (n.left == null) { change = n.isBlack; return n.right; } n.left = RemoveMax(n.left); n.val = lmax; return BalanceL(n); } private T lmax; private Node RemoveMax(Node n) { if (n.right != null) { n.right = RemoveMax(n.right); return BalanceR(n); } lmax = n.val; change = n.isBlack; return n.left; } private Node BalanceL(Node n) { if (!change) return n; if (Black(n.right) && Red(n.right.left)) { var b = n.isBlack; n = RotateRL(n); n.isBlack = b; n.left.isBlack = true; change = false; } else if (Black(n.right) && Red(n.right.right)) { var b = n.isBlack; n = RotateL(n); n.isBlack = b; n.right.isBlack = true; n.left.isBlack = true; change = false; } else if (Black(n.right)) { change = n.isBlack; n.isBlack = true; n.right.isBlack = false; } else { n = RotateL(n); n.isBlack = true; n.left.isBlack = false; n.left = BalanceL(n.left); change = false; } return n; } private Node BalanceR(Node n) { if (!change) return n; if (Black(n.left) && Red(n.left.right)) { var b = n.isBlack; n = RotateLR(n); n.isBlack = b; n.right.isBlack = true; change = false; } else if (Black(n.left) && Red(n.left.left)) { var b = n.isBlack; n = RotateR(n); n.isBlack = b; n.left.isBlack = true; n.right.isBlack = true; change = false; } else if (Black(n.left)) { change = n.isBlack; n.isBlack = true; n.left.isBlack = false; } else { n = RotateR(n); n.isBlack = true; n.right.isBlack = false; n.right = BalanceR(n.right); change = false; } return n; } public Tuple<bool, T> FindUpper(T x) { var v = FindUpper(root, x); if (v == null) return Tuple.Create(false, default(T)); return v; } private Tuple<bool, T> FindUpper(Node n, T x) { if (n == null) return null; var r = c(x, n.val); if (r < 0) { var v = FindUpper(n.left, x); if (v == null) return Tuple.Create(true, n.val); return v; } else if (r > 0) return FindUpper(n.right, x); else return Tuple.Create(true, x); } public Tuple<bool, T> FindLower(T x) { var v = FindLower(root, x); if (v == null) return Tuple.Create(false, default(T)); return v; } private Tuple<bool, T> FindLower(Node n, T x) { if (n == null) return null; var r = c(x, n.val); if (r < 0) return FindLower(n.left, x); else if (r > 0) { var v = FindLower(n.right, x); if (v == null) return Tuple.Create(true, n.val); return v; } else return Tuple.Create(true, x); } public T Min() { Node n = root, p = null; while (n != null) { p = n; n = n.left; } return p == null ? default(T) : p.val; } public T Max() { Node n = root, p = null; while (n != null) { p = n; n = n.right; } return p == null ? default(T) : p.val; } public bool Any() => root != null; public int CountSlow() => List(root).Count(); public IEnumerable<T> List() => List(root); private IEnumerable<T> List(Node n) { if (n == null) yield break; foreach (var i in List(n.left)) yield return i; yield return n.val; foreach (var i in List(n.right)) yield return i; } } //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // TEST END _/ //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ 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 long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); [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 IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l, Comparison<T> comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); } [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; } static long LCM(long a, long b) => a * b / GCD(a, b); 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 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(long 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(long n, long k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)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 T Pow<T>(T x, long y) { T a = (dynamic)1; while (y != 0) { if ((y & 1) == 1) a *= (dynamic)x; x *= (dynamic)x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _Build(long 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(long n, long k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } } }
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 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, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 22]]
8
5,541
16
using System; class Program { static void Main(string[] args) { Console.ReadLine(); var s = Console.ReadLine(); var left = new int[s.Length + 1]; for (int i = 1; i < s.Length + 1; i++) { if (s[i - 1] == 'W') { left[i] = left[i - 1] + 1; } else { left[i] = left[i - 1]; } } var right = new int[s.Length + 1]; for (int i = s.Length - 1; i >= 0; i--) { if (s[i] == 'E') { right[i] = right[i + 1] + 1; } else { right[i] = right[i + 1]; } } var min = int.MaxValue; for (int i = 0; i < s.Length; i++) { min = Math.Min(min, left[i] + right[i]); } Console.WriteLine(min); } }
using System; class Program { static void Main(string[] args) { var len = int.Parse(Console.ReadLine()); var S = Console.ReadLine(); var left = new int[len]; for (int i = 1; i < len; i++) { if (S[i - 1] == 'W') { left[i] = left[i - 1] + 1; } else { left[i] = left[i - 1]; } } var right = new int[len]; for (int i = len - 2; i >= 0; i--) { if (S[i + 1] == 'E') { right[i] = right[i + 1] + 1; } else { right[i] = right[i + 1]; } } var min = int.MaxValue; for (int i = 0; i < len; i++) { min = Math.Min(min, left[i] + right[i]); } Console.WriteLine(min); } }
[["+", 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, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 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], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 39, 224, 225, 226, 0, 16, 31, 214, 205, 22], ["-", 39, 224, 225, 226, 0, 16, 31, 214, 0, 131], ["-", 39, 224, 225, 226, 0, 16, 31, 214, 141, 22], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 205, 22], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 0, 131], ["-", 0, 7, 15, 16, 12, 16, 31, 214, 141, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 16, 31, 214, 141, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22]]
8
236
44
using System; using System.Linq; class c { static void Main() { Console.ReadLine(); var s = Console.ReadLine(); int min = s.Count(f => f == 'E'); int now = min; for (int i = 1; i < s.Length; i++) { if (s[i - 1] == 'W') now++; if (s[i] == 'E') now--; min = Math.Min(now, min); } Console.WriteLine(min); } }
using System; using System.Linq; class c { static void Main() { Console.ReadLine(); var s = Console.ReadLine(); int min = s.Where((f, g) => g > 0).Count(f => f == 'E'); int now = min; for (int i = 1; i < s.Length; i++) { if (s[i - 1] == 'W') now++; if (s[i] == 'E') now--; min = Math.Min(now, min); } Console.WriteLine(min); } }
[["+", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 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], ["+", 3, 4, 0, 28, 0, 218, 54, 55, 0, 25], ["+", 205, 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, 47], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131]]
8
121
13
using System; using System.Linq; using System.Collections.Generic; namespace MyApp { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int[] west = new int[n]; int[] east = new int[n]; int min = 10000000; for (int i = 0; i < n; i++) { int countWest = 0; int countEast = 0; if ((i - 1) >= 0 && s[i] == 'W') countWest++; if ((i - 1) >= 0 && s[i] == 'E') countEast++; west[i] = countWest; east[i] = countEast; } for (int i = 0; i < n; i++) { int left = (i - 1 >= 0) ? west[i - 1] : 0; int right = east[n - 1] - east[i]; int count = left + right; min = Math.Min(min, count); } Console.WriteLine(min); } } }
using System; using System.Linq; using System.Collections.Generic; namespace MyApp { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int[] west = new int[n]; int[] east = new int[n]; int min = 10000000; int countWest = 0; int countEast = 0; for (int i = 0; i < n; i++) { if (s[i] == 'W') countWest++; if (s[i] == 'E') countEast++; west[i] = countWest; east[i] = countEast; } for (int i = 0; i < n; i++) { int left = (i - 1 >= 0) ? west[i - 1] : 0; int right = east[n - 1] - east[i]; int count = left + right; min = Math.Min(min, count); } Console.WriteLine(min); } } }
[["+", 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], ["-", 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, 196, 0, 7, 8, 196, 0, 57, 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, 20], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24]]
8
244
36
using System; namespace AtCoder.ABC098 { class c { static void Main(string[] args) { var line = Console.ReadLine().Trim(); var N = int.Parse(line); var S = Console.ReadLine().Trim(); var max = 0; var cnt = 0; var pointer = 0; for (var i = 0; i < N; ++i) { if (S[i] == 'E') ++cnt; else --cnt; if (cnt > max) pointer = i; } cnt = 0; for (var i = 0; i < N; ++i) { if (i == pointer) continue; else if (i < pointer) { if (S[i] == 'W') ++cnt; } else { if (S[i] == 'E') ++cnt; } } Console.WriteLine(cnt); } } }
using System; namespace AtCoder.ABC098 { class c { static void Main(string[] args) { var line = Console.ReadLine().Trim(); var N = int.Parse(line); var S = Console.ReadLine().Trim(); var max = 0; var cnt = 0; var pointer = 0; for (var i = 0; i < N; ++i) { if (S[i] == 'E') ++cnt; else --cnt; if (cnt > max) { max = cnt; pointer = i + 1; } } cnt = 0; for (var i = 0; i < N; ++i) { if (i == pointer) continue; else if (i < pointer) { if (S[i] == 'W') ++cnt; } else { if (S[i] == 'E') ++cnt; } } Console.WriteLine(cnt); } } }
[["+", 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, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
194
8
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection.Emit; using System.Text; using static System.Console; using static System.Math; //using CS_Contest.Graph; using CS_Contest.Loop; using CS_Contest.Utils; using static Nakov.IO.Cin; using static CS_Contest.IO.IO; using static CS_Contest.Utils.MyMath; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; using ti3 = Tuple<int, int, int>; using ti2 = Tuple<int, int>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { // ABC098 C int N = NextInt(); var S = ReadLine(); var W = new int[N]; var E = new int[N]; S.ForeachWith((i, c) => { if (c == 'W') { W[i]++; } else { E[i]++; } }); for (int i = 0; i < N-1; i++) { W[i + 1] += W[i]; E[i + 1] += E[i]; } var ans = int.MaxValue; for (int i = 0; i < N; i++) { var item = S[i] == 'E'; var next = 0; //西むかないといけない人 next += E[N - 1] - (E[i]-(item?1:0)); //東むかいないといけないひと next += W[i] - (!item ? 1 : 0); if (next<0) continue; ans = Min(ans, next); } ans.WL(); return; } } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } } namespace CS_Contest.Loop { [DebuggerStepThrough] public static class Loop { public static void REP(this int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) { var i = 0; foreach (var item in ie) { act(i, item); i++; } } public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) { foreach (var item in ie) { act(item); } } } public class Generate { public static IEnumerable<int> Seq(int e) => Seq(0, e, 1); public static IEnumerable<int> Seq(int s, int e) => Seq(s, e, 1); public static IEnumerable<int> Seq(int s, int e, int a) { while (s != e) { yield return s; s += a; } } public static List<T> Repeat<T>(Func<int, T> result, int range) => Enumerable.Range(0, range).Select(result).ToList(); } } namespace CS_Contest.IO { using Li = List<int>; using Ll = List<long>; public static class IO { public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList(); public static Li NextIntList(int n) => Enumerable.Repeat(0, n).Select(x => ReadLine()).Select(int.Parse).ToList(); public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList(); public static T Tee<T>(this T t, Func<T, string> formatter = null) { if (formatter == null) formatter = arg => arg.ToString(); formatter(t).WL(); return t; } public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL(); public static void W(this object @this) => Write(@this); public static T[,] GetBox<T>(int h, int w, Func<int, int, T> getFunc) { var rt = new T[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { rt[i, j] = getFunc(i, j); } } return rt; } } } namespace CS_Contest.Utils { using Li = List<int>; using Ll = List<long>; [DebuggerStepThrough] public static class Utils { public static bool AnyOf<T>(this T @this, params T[] these) where T:IComparable { return these.Contains(@this); } public static bool Within(int x, int y, int lx, int ly) => !(x < 0 || x >= lx || y < 0 || y >= ly); public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2)); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static List<Tuple<TKey, TValue>> ToTupleList<TKey, TValue>(this Map<TKey, TValue> @this) => @this.Select(x => Tuple.Create(x.Key, x.Value)).ToList(); public static Map<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Map<TKey, int>(); foreach (var item in l) { dic[item]++; } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) { var enumerable = @this as T[] ?? @this.ToArray(); for (var i = 0; i < enumerable.Count(); i++) { if (i == at) continue; yield return enumerable.ElementAt(i); } } public static int LowerBound<T>(this List<T> @this, T x) where T : IComparable { int lb = -1, ub = @this.Count; while (ub - lb > 1) { int mid = (ub + lb) >> 1; if (@this[mid].CompareTo(x) >= 0) ub = mid; else lb = mid; } return ub; } public static int UpperBound<T>(this List<T> @this, T x) where T : IComparable { int lb = -1, ub = @this.Count; while (ub - lb > 1) { int mid = (ub + lb) >> 1; if (@this[mid].CompareTo(x) > 0) ub = mid; else lb = mid; } return ub; } } public class Map<TKey, TValue> : Dictionary<TKey, TValue> { public Map() : base() { } public Map(int capacity) : base(capacity) { } public new TValue this[TKey index] { get { TValue v; return this.TryGetValue(index, out v) ? v : base[index] = default(TValue); } set { base[index] = value; } } } public static class MyMath { public static T EMin<T>(params T[] a) where T : IComparable<T> => a.Min(); public static T EMax<T>(params T[] a) where T : IComparable<T> => a.Max(); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection.Emit; using System.Text; using static System.Console; using static System.Math; //using CS_Contest.Graph; using CS_Contest.Loop; using CS_Contest.Utils; using static Nakov.IO.Cin; using static CS_Contest.IO.IO; using static CS_Contest.Utils.MyMath; namespace CS_Contest { using Li = List<int>; using LLi = List<List<int>>; using Ll = List<long>; using ti3 = Tuple<int, int, int>; using ti2 = Tuple<int, int>; internal class Program { private static void Main(string[] args) { var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); new Calc().Solve(); Out.Flush(); } public class Calc { public void Solve() { // ABC098 C int N = NextInt(); var S = ReadLine(); var W = new int[N]; var E = new int[N]; S.ForeachWith((i, c) => { if (c == 'W') { W[i]++; } else { E[i]++; } }); for (int i = 0; i < N-1; i++) { W[i + 1] += W[i]; E[i + 1] += E[i]; } var ans = int.MaxValue; for (int i = 0; i < N; i++) { var item = S[i] == 'E'; var next = 0; //西むかないといけない人 next += E[N - 1] - (E[Max(0,i-1)])-(item?1:0); //東むかいないといけないひと next += W[i] - (!item ? 1 : 0); if (next<0) continue; ans = Min(ans, next); } ans.WL(); return; } } } } namespace Nakov.IO { using System; using System.Text; using System.Globalization; public static class Cin { public static string NextToken() { StringBuilder tokenChars = new StringBuilder(); bool tokenFinished = false; bool skipWhiteSpaceMode = true; while (!tokenFinished) { int nextChar = Console.Read(); if (nextChar == -1) { tokenFinished = true; } else { char ch = (char)nextChar; if (char.IsWhiteSpace(ch)) { if (!skipWhiteSpaceMode) { tokenFinished = true; if (ch == '\r' && (Environment.NewLine == "\r\n")) { Console.Read(); } } } else { skipWhiteSpaceMode = false; tokenChars.Append(ch); } } } string token = tokenChars.ToString(); return token; } public static int NextInt() { string token = Cin.NextToken(); return int.Parse(token); } public static long NextLong() { string token = Cin.NextToken(); return long.Parse(token); } public static double NextDouble(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); double result = double.Parse(token, CultureInfo.InvariantCulture); return result; } else { double result = double.Parse(token); return result; } } public static decimal NextDecimal(bool acceptAnyDecimalSeparator = true) { string token = Cin.NextToken(); if (acceptAnyDecimalSeparator) { token = token.Replace(',', '.'); decimal result = decimal.Parse(token, CultureInfo.InvariantCulture); return result; } else { decimal result = decimal.Parse(token); return result; } } } } namespace CS_Contest.Loop { [DebuggerStepThrough] public static class Loop { public static void REP(this int n, Action<int> act) { for (var i = 0; i < n; i++) { act(i); } } public static void ForeachWith<T>(this IEnumerable<T> ie, Action<int, T> act) { var i = 0; foreach (var item in ie) { act(i, item); i++; } } public static void Foreach<T>(this IEnumerable<T> ie, Action<T> act) { foreach (var item in ie) { act(item); } } } public class Generate { public static IEnumerable<int> Seq(int e) => Seq(0, e, 1); public static IEnumerable<int> Seq(int s, int e) => Seq(s, e, 1); public static IEnumerable<int> Seq(int s, int e, int a) { while (s != e) { yield return s; s += a; } } public static List<T> Repeat<T>(Func<int, T> result, int range) => Enumerable.Range(0, range).Select(result).ToList(); } } namespace CS_Contest.IO { using Li = List<int>; using Ll = List<long>; public static class IO { public static void WL(this object obj) => WriteLine(obj); public static void WL(this string obj) => WriteLine(obj); public static void WL<T>(this IEnumerable<T> list) => list.ToList().ForEach(x => x.WL()); public static Li NextIntList() => ReadLine().Split().Select(int.Parse).ToList(); public static Li NextIntList(int n) => Enumerable.Repeat(0, n).Select(x => ReadLine()).Select(int.Parse).ToList(); public static Ll NextLongList() => ReadLine().Split().Select(long.Parse).ToList(); public static T Tee<T>(this T t, Func<T, string> formatter = null) { if (formatter == null) formatter = arg => arg.ToString(); formatter(t).WL(); return t; } public static void JoinWL<T>(this IEnumerable<T> @this, string sp = " ") => @this.StringJoin(sp).WL(); public static void W(this object @this) => Write(@this); public static T[,] GetBox<T>(int h, int w, Func<int, int, T> getFunc) { var rt = new T[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { rt[i, j] = getFunc(i, j); } } return rt; } } } namespace CS_Contest.Utils { using Li = List<int>; using Ll = List<long>; [DebuggerStepThrough] public static class Utils { public static bool AnyOf<T>(this T @this, params T[] these) where T:IComparable { return these.Contains(@this); } public static bool Within(int x, int y, int lx, int ly) => !(x < 0 || x >= lx || y < 0 || y >= ly); public static void Add<T1, T2>(this List<Tuple<T1, T2>> list, T1 t1, T2 t2) => list.Add(new Tuple<T1, T2>(t1, t2)); public static string StringJoin<T>(this IEnumerable<T> l, string separator = "") => string.Join(separator, l); public static Queue<T> ToQueue<T>(this IEnumerable<T> iEnumerable) { var rt = new Queue<T>(); foreach (var item in iEnumerable) { rt.Enqueue(item); } return rt; } public static void Swap<T>(ref T x, ref T y) { var tmp = x; x = y; y = tmp; } public static List<Tuple<TKey, TValue>> ToTupleList<TKey, TValue>(this Map<TKey, TValue> @this) => @this.Select(x => Tuple.Create(x.Key, x.Value)).ToList(); public static Map<TKey, int> CountUp<TKey>(this IEnumerable<TKey> l) { var dic = new Map<TKey, int>(); foreach (var item in l) { dic[item]++; } return dic; } public static int Count<T>(this IEnumerable<T> l, T target) => l.Count(x => x.Equals(target)); public static IEnumerable<T> SkipAt<T>(this IEnumerable<T> @this, int at) { var enumerable = @this as T[] ?? @this.ToArray(); for (var i = 0; i < enumerable.Count(); i++) { if (i == at) continue; yield return enumerable.ElementAt(i); } } public static int LowerBound<T>(this List<T> @this, T x) where T : IComparable { int lb = -1, ub = @this.Count; while (ub - lb > 1) { int mid = (ub + lb) >> 1; if (@this[mid].CompareTo(x) >= 0) ub = mid; else lb = mid; } return ub; } public static int UpperBound<T>(this List<T> @this, T x) where T : IComparable { int lb = -1, ub = @this.Count; while (ub - lb > 1) { int mid = (ub + lb) >> 1; if (@this[mid].CompareTo(x) > 0) ub = mid; else lb = mid; } return ub; } } public class Map<TKey, TValue> : Dictionary<TKey, TValue> { public Map() : base() { } public Map(int capacity) : base(capacity) { } public new TValue this[TKey index] { get { TValue v; return this.TryGetValue(index, out v) ? v : base[index] = default(TValue); } set { base[index] = value; } } } public static class MyMath { public static T EMin<T>(params T[] a) where T : IComparable<T> => a.Min(); public static T EMax<T>(params T[] a) where T : IComparable<T> => a.Max(); } }
[["+", 0, 204, 206, 207, 0, 28, 0, 213, 63, 22], ["+", 206, 207, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 206, 207, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 11, 12, 16, 31, 16, 12, 23, 0, 25], ["-", 12, 16, 12, 23, 0, 16, 12, 23, 0, 25]]
8
2,219
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp36 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string S = Console.ReadLine(); //半開区間[0, i)のWの和 int[] VW = new int[N + 1]; VW[0] = 0; //半開区間[0, i)のEの和 int[] VE = new int[N + 1]; VE[0] = 0; // VWとVEを計算する for (int i = 0; i < N; i++) { if (S[i] == 'W') { VW[i + 1] = VW[i] + 1; VE[i + 1] = VE[i]; } else if (S[i] == 'E') { VW[i + 1] = VW[i]; VE[i + 1] = VE[i] + 1; } } Console.WriteLine(string.Join(" ", VW)); Console.WriteLine(string.Join(" ", VE)); int ans = N; for (int i = 0; i < N; i++) { ans = Math.Min(ans, VW[i] + VE[N] - VE[i + 1]); } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp36 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string S = Console.ReadLine(); //半開区間[0, i)のWの和 int[] VW = new int[N + 1]; VW[0] = 0; //半開区間[0, i)のEの和 int[] VE = new int[N + 1]; VE[0] = 0; // VWとVEを計算する for (int i = 0; i < N; i++) { if (S[i] == 'W') { VW[i + 1] = VW[i] + 1; VE[i + 1] = VE[i]; } else if (S[i] == 'E') { VW[i + 1] = VW[i]; VE[i + 1] = VE[i] + 1; } } // Console.WriteLine(string.Join(" ", VW)); // Console.WriteLine(string.Join(" ", VE)); int ans = N; for (int i = 0; i < N; i++) { ans = Math.Min(ans, VW[i] + VE[N] - VE[i + 1]); } Console.WriteLine(ans); } } }
[["-", 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], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["-", 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
293
32
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { string inpt = Reader.ReadLine(); int idx = int.Parse(Reader.ReadLine()); List<char> charlist = inpt.Distinct().OrderBy(a => a).ToList(); List<string> list = new List<string>(); for (int i = 0; i < 5; i++) { for (int j = 0; j < inpt.Length; j++) { if (inpt[j] != charlist[i]) { continue; } for (int k = 1; k <= 5; k++) { if (j + k > inpt.Length) { break; } string tmp = inpt.Substring(j, k); if (!list.Contains(tmp)) { list.Add(tmp); } } } if (list.Count >= 5) { break; } } list.Sort(); string ans = list[idx - 1]; Console.WriteLine(ans); } public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" aba 4 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { string inpt = Reader.ReadLine(); int idx = int.Parse(Reader.ReadLine()); List<char> charlist = inpt.Distinct().OrderBy(a => a).ToList(); List<string> list = new List<string>(); for (int i = 0; i < Math.Min(charlist.Count, 5); i++) { for (int j = 0; j < inpt.Length; j++) { if (inpt[j] != charlist[i]) { continue; } for (int k = 1; k <= 5; k++) { if (j + k > inpt.Length) { break; } string tmp = inpt.Substring(j, k); if (!list.Contains(tmp)) { list.Add(tmp); } } } if (list.Count >= 5) { break; } } list.Sort(); string ans = list[idx - 1]; Console.WriteLine(ans); } public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" z 1 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["+", 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], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 12, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
8
354
11
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var S = sc.ReadStr(); var K = sc.ReadInt(); var set = new HashSet<string>(); for (int i = 1; i <= K; i++) { for (int j = 0; j < S.Length - i; j++) { var s = S.Substring(j, i); set.Add(s); } } var a = set.ToArray(); Array.Sort(a); var ans = a[K - 1]; Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var S = sc.ReadStr(); var K = sc.ReadInt(); var set = new HashSet<string>(); for (int i = 0; i < S.Length; i++) { for (int j = i + 1; j < Math.Min(i + K + 1, S.Length + 1); j++) { var sub = S.Substring(i, j - i); set.Add(sub); } } var array = set.ToArray(); Array.Sort(array, string.CompareOrdinal); var ans = array[K - 1]; Console.WriteLine(ans); } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 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], ["-", 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, 19], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 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], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 21], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22]]
8
1,167
2
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; // const int M = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n = sc.Int; edge = new List<int>[n]; for (int i = 0; i < n; i++) { edge[i] = new List<int>(); } for (int i = 0; i < n - 1; i++) { int a, b; sc.Multi(out a, out b); --a; --b; edge[a].Add(b); edge[b].Add(a); } isw = sc.Str.Select(x => x == 'W').ToArray(); var wlis = new List<int>(); for (int i = 0; i < n; i++) { if (isw[i]) wlis.Add(i); } if (wlis.Count == 0) { DBG(0); return; } if (wlis.Count == 1) { DBG(1); return; } use = new bool[n]; dfs(wlis[0], -1); cost = new int[n]; int ans = 0; for (int i = 0; i < n; i++) { if (!use[i]) continue; int c = 0; foreach (var item in edge[i]) { if (use[item]) ++c; } if ((c % 2 == 1) == isw[i]) ans += c; else { ans += c + 1; cost[i] = 2; } } Prt(ans - calcchildmax(wlis[0], -1)); sw.Flush(); } static List<int>[] edge; static bool[] isw; static bool[] use; static bool dfs(int p, int par) { bool ret = isw[p]; foreach (var item in edge[p]) { if (item == par) continue; ret = dfs(item, p) | ret; } return use[p] = ret; } static int pathmax; static int[] cost; static int calcchildmax(int p, int par) { int max = 0, sec = 0; foreach (var item in edge[p]) { if (item == par) continue; int c = calcchildmax(item, p); if (c > max) { sec = max; max = c; } else if (c > sec) { sec = c; } } pathmax = Math.Max(pathmax, max + sec + cost[p]); return max + cost[p]; } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2); public override string ToString() => v1 + " " + v2; } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2); public static T sqr<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long[n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double[n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double a, double[] x) { int n = x.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i]; return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static double[][] mul(double a, double[][] A) { int n = A.Length; var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static long[][] mul(long a, long[][] A) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long[n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; // const int M = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n = sc.Int; edge = new List<int>[n]; for (int i = 0; i < n; i++) { edge[i] = new List<int>(); } for (int i = 0; i < n - 1; i++) { int a, b; sc.Multi(out a, out b); --a; --b; edge[a].Add(b); edge[b].Add(a); } isw = sc.Str.Select(x => x == 'W').ToArray(); var wlis = new List<int>(); for (int i = 0; i < n; i++) { if (isw[i]) wlis.Add(i); } if (wlis.Count == 0) { DBG(0); return; } if (wlis.Count == 1) { DBG(1); return; } use = new bool[n]; dfs(wlis[0], -1); cost = new int[n]; int ans = 0; for (int i = 0; i < n; i++) { if (!use[i]) continue; int c = 0; foreach (var item in edge[i]) { if (use[item]) ++c; } if ((c % 2 == 1) == isw[i]) ans += c; else { ans += c + 1; cost[i] = 2; } } calcchildmax(wlis[0], -1); Prt(ans - pathmax); sw.Flush(); } static List<int>[] edge; static bool[] isw; static bool[] use; static bool dfs(int p, int par) { bool ret = isw[p]; foreach (var item in edge[p]) { if (item == par) continue; ret = dfs(item, p) | ret; } return use[p] = ret; } static int pathmax; static int[] cost; static int calcchildmax(int p, int par) { int max = 0, sec = 0; foreach (var item in edge[p]) { if (item == par) continue; int c = calcchildmax(item, p); if (c > max) { sec = max; max = c; } else if (c > sec) { sec = c; } } pathmax = Math.Max(pathmax, max + sec + cost[p]); return max + cost[p]; } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2); public override string ToString() => v1 + " " + v2; } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2); public static T sqr<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long[n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double[n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double a, double[] x) { int n = x.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i]; return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static double[][] mul(double a, double[][] A) { int n = A.Length; var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static long[][] mul(long a, long[][] A) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long[n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
[["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
4,738
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC096 { class Program { public static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int a = input[0]; int b = input[1]; int result = 0; if (a > 1) { if (a <= b) { result = a; } else { result = a - 1; } } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC096 { class Program { public static void Main(string[] args) { var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int a = input[0]; int b = input[1]; int result = 0; if (a == 1 && a < b) { result++; } else { if (a <= b) { result = a; } else { result = a - 1; } } Console.WriteLine(result); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 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, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 0, 195, 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], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95]]
8
131
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace At { class Program { static void Main(string[] args) { var s = ReadInts(); if (s[0] == 1) WriteLine("1"); else if (s[1] < 11) WriteLine(s[0] - 1); else WriteLine(s[0]); } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace At { class Program { static void Main(string[] args) { var s = ReadInts(); if (s[0] <= s[1]) WriteLine(s[0]); else { WriteLine(s[0] - 1); } } private static string Read() { return ReadLine(); } private static string[] Reads() { return (Read().Split()); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 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, 213, 63, 22], ["-", 0, 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], ["-", 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], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["-", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
275
22
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; using System.Collections; namespace debug { class main { static void Main(string[] args) { //問題クラスを展開 ProgramB a = new ProgramB(); a.main(); //実行する } } // ABC096 class ProgramA { public void main() { //入力 string[] s = Console.ReadLine().Split(' '); int a = int.Parse(s[0]); int b = int.Parse(s[1]); if (a <= b) Console.WriteLine(a); else Console.WriteLine(a - 1); } } class ProgramB { public void main() { //入力 string[] s = Console.ReadLine().Split(' '); int[] num = new int[3]; for (int i = 0; i < 3; i++) num[i] = int.Parse(s[i]); Array.Sort(num); int k = int.Parse(Console.ReadLine()); Console.WriteLine(num[0] + num[1] + Math.Pow(num[2], k)); } } class ProgramC { public void main() { //入力 string s = Console.ReadLine(); int k = int.Parse(Console.ReadLine()); List<string> ans = new List<string>(); // kが5文字以下が答えの候補なので入れて考えてみる for (int j = 1; j <= 5; j++) for (int i = 0; i < s.Length + 1 - j; i++) { if (!ans.Contains(s.Substring(i, j))) ans.Add(s.Substring(i, j)); } //ソートする ans.Sort(); //答え出力 Console.WriteLine(ans[k - 1]); } } class ProgramD { public void main() { //入力 int n = int.Parse(Console.ReadLine()); List<int> a = new List<int>(10000); for (int i = 0; i < 10000; i++) a.Add(i + 2); // 10000までの素数を出す for (int i = 2; i <= Math.Sqrt(10000); i++) { List<int> t = new List<int>(10000); foreach (var s in a) { if (s % i == 0 && s / i != 1) t.Add(s); } foreach (var s in t) { a.Remove(s); } } // 5で割ったあまりが1だけのものを出す int count = 0; foreach (var s in a) { if (s % 5 == 1) { Console.Write(s + " "); count++; } if (count == n) break; } } } }
using System; using System.Numerics; using System.Linq; using System.Collections.Generic; using System.Text; using System.Collections; namespace debug { class main { static void Main(string[] args) { //問題クラスを展開 ProgramB a = new ProgramB(); a.main(); //実行する } } // ABC096 class ProgramA { public void main() { //入力 string[] s = Console.ReadLine().Split(' '); int a = int.Parse(s[0]); int b = int.Parse(s[1]); if (a <= b) Console.WriteLine(a); else Console.WriteLine(a - 1); } } class ProgramB { public void main() { //入力 string[] s = Console.ReadLine().Split(' '); int[] num = new int[3]; for (int i = 0; i < 3; i++) num[i] = int.Parse(s[i]); Array.Sort(num); int k = int.Parse(Console.ReadLine()); Console.WriteLine(num[0] + num[1] + num[2] * Math.Pow(2, k)); } } class ProgramC { public void main() { //入力 string s = Console.ReadLine(); int k = int.Parse(Console.ReadLine()); List<string> ans = new List<string>(); // kが5文字以下が答えの候補なので入れて考えてみる for (int j = 1; j <= 5; j++) for (int i = 0; i < s.Length + 1 - j; i++) { if (!ans.Contains(s.Substring(i, j))) ans.Add(s.Substring(i, j)); } //ソートする ans.Sort(); //答え出力 Console.WriteLine(ans[k - 1]); } } class ProgramD { public void main() { //入力 int n = int.Parse(Console.ReadLine()); List<int> a = new List<int>(10000); for (int i = 0; i < 10000; i++) a.Add(i + 2); // 10000までの素数を出す for (int i = 2; i <= Math.Sqrt(10000); i++) { List<int> t = new List<int>(10000); foreach (var s in a) { if (s % i == 0 && s / i != 1) t.Add(s); } foreach (var s in t) { a.Remove(s); } } // 5で割ったあまりが1だけのものを出す int count = 0; foreach (var s in a) { if (s % 5 == 1) { Console.Write(s + " "); count++; } if (count == n) break; } } } }
[["+", 0, 28, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["-", 12, 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
594
8
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static ABC167.abc167_b.Cin; using static ABC167.abc167_b.Util; using Pair = ABC167.abc167_b.VTuple<long, long>; /// <summary> /// ABC167 /// B - Easy Linear Programming /// https://atcoder.jp/contests/ABC167/tasks/abc167_b /// </summary> namespace ABC167.abc167_b { public class Program { public static void Main(string[] args) { int A = ri; int B = ri; int C = ri; int K = ri; int max = Max(A, Max(B, C)); int ans = A + B + C + max * (K - 1); } } /// <summary> /// 競プロライブラリ /// https://github.com/ha2ne2/ABC/tree/master/Lib /// </summary> public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long val) { Value = val % MOD; if (Value < 0) Value += MOD; } private static Mint Ctor(long val) { return new Mint() { Value = val }; } public static Mint operator +(Mint a, Mint b) { long res = a.Value + b.Value; if (res > MOD) res -= MOD; return Ctor(res); } public static Mint operator -(Mint a, Mint b) { long res = a.Value - b.Value; if (res < 0) res += MOD; return Ctor(res); } public static Mint operator *(Mint a, Mint b) { long res = a.Value * b.Value; if (res > MOD) res %= MOD; return Ctor(res); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object obj) { return obj is Mint && Value == ((Mint)obj).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public override string ToString() { return Value.ToString(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long n) { if (n == 0) return new Mint(1); Mint b = Pow(a, n >> 1); b *= b; if ((n & 1) == 1) b *= a; return b; } public static Mint Inv(Mint n) { long a = n.Value; long b = MOD; long x = 1; long u = 0; while (b != 0) { long k = a / b; long _x = u; u = x - k * u; x = _x; long _a = a; a = b; b = _a - (k * b); } return new Mint(x); } public bool Equals(Mint other) { return Value == other.Value; } public int CompareTo(Mint other) { return Comparer<long>.Default.Compare(Value, other.Value); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { private V DefaultValue; private static Func<V> CreateInstance = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V defaultValue) { DefaultValue = defaultValue; } new public V this[K i] { get { V v; if (TryGetValue(i, out v)) { return v; } else { return base[i] = DefaultValue != null ? DefaultValue : CreateInstance(); } } set { base[i] = value; } } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 item1, T2 item2) { Item1 = item1; Item2 = item2; } public override bool Equals(object obj) { return obj is VTuple<T1, T2> && Equals((VTuple<T1, T2>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ")"; } public bool Equals(VTuple<T1, T2> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2); } public int CompareTo(VTuple<T1, T2> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; return Comparer<T2>.Default.Compare(Item2, other.Item2); } } public struct VTuple3<T1, T2, T3> : System.IComparable<VTuple3<T1, T2, T3>>, System.IEquatable<VTuple3<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple3(T1 item1, T2 item2, T3 item3) { Item1 = item1; Item2 = item2; Item3 = item3; } public override bool Equals(object obj) { return obj is VTuple3<T1, T2, T3> && Equals((VTuple3<T1, T2, T3>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ")"; } public bool Equals(VTuple3<T1, T2, T3> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3); } public int CompareTo(VTuple3<T1, T2, T3> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; return Comparer<T3>.Default.Compare(Item3, other.Item3); } } public struct VTuple4<T1, T2, T3, T4> : System.IComparable<VTuple4<T1, T2, T3, T4>>, System.IEquatable<VTuple4<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple4(T1 item1, T2 item2, T3 item3, T4 item4) { Item1 = item1; Item2 = item2; Item3 = item3; Item4 = item4; } public override bool Equals(object obj) { return obj is VTuple4<T1, T2, T3, T4> && Equals((VTuple4<T1, T2, T3, T4>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; int h4 = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3, h4); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ")"; } public bool Equals(VTuple4<T1, T2, T3, T4> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3) && EqualityComparer<T4>.Default.Equals(Item4, other.Item4); } public int CompareTo(VTuple4<T1, T2, T3, T4> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; c = Comparer<T3>.Default.Compare(Item3, other.Item3); if (c != 0) return c; return Comparer<T4>.Default.Compare(Item4, other.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int h1, int h2) { uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27); return ((int)rol5 + h1) ^ h2; } public static int CombineHashCodes(int h1, int h2) { return Combine(Combine(RandomSeed, h1), h2); } public static int CombineHashCodes(int h1, int h2, int h3) { return Combine(CombineHashCodes(h1, h2), h3); } public static int CombineHashCodes(int h1, int h2, int h3, int h4) { return Combine(CombineHashCodes(h1, h2, h3), h4); } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static string ReadString() { return Next(); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { Tokens = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long N) { a = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[,] ReadIntTable(int h, int w) { Tokens = null; int[,] ret = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadInt(); } } return ret; } public static long[,] ReadLongTable(long h, long w) { Tokens = null; long[,] ret = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadLong(); } } return ret; } public static char[,] ReadCharTable(int h, int w) { Tokens = null; char[,] res = new char[h, w]; for (int i = 0; i < h; i++) { string s = ReadString(); for (int j = 0; j < w; j++) { res[i, j] = s[j]; } } return res; } private static string[] Tokens; private static int Pointer; private static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { if (Console.IsOutputRedirected) return; var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } public static long GCD(long a, long b) { while (b != 0) { long _a = a; a = b; b = _a % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } public static long[] Accumulate(long[] array) { long[] acc = new long[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } public static double[] Accumulate(double[] array) { double[] acc = new double[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static ABC167.abc167_b.Cin; using static ABC167.abc167_b.Util; using Pair = ABC167.abc167_b.VTuple<long, long>; /// <summary> /// ABC167 /// B - Easy Linear Programming /// https://atcoder.jp/contests/ABC167/tasks/abc167_b /// </summary> namespace ABC167.abc167_b { public class Program { public static void Main(string[] args) { int A = ri; int B = ri; int C = ri; int K = ri; int max = Max(A, Max(B, C)); int twiced = max; for (int i = 0; i < K; i++) { twiced *= 2; } int ans = A + B + C - max + twiced; Console.WriteLine(ans); } } /// <summary> /// 競プロライブラリ /// https://github.com/ha2ne2/ABC/tree/master/Lib /// </summary> public struct Mint : System.IComparable<Mint>, System.IEquatable<Mint> { public static readonly long MOD = (long)1e9 + 7; public long Value; public Mint(long val) { Value = val % MOD; if (Value < 0) Value += MOD; } private static Mint Ctor(long val) { return new Mint() { Value = val }; } public static Mint operator +(Mint a, Mint b) { long res = a.Value + b.Value; if (res > MOD) res -= MOD; return Ctor(res); } public static Mint operator -(Mint a, Mint b) { long res = a.Value - b.Value; if (res < 0) res += MOD; return Ctor(res); } public static Mint operator *(Mint a, Mint b) { long res = a.Value * b.Value; if (res > MOD) res %= MOD; return Ctor(res); } public static Mint operator /(Mint a, Mint b) { return a * Inv(b); } public override bool Equals(object obj) { return obj is Mint && Value == ((Mint)obj).Value; } public override int GetHashCode() { return Value.GetHashCode(); } public override string ToString() { return Value.ToString(); } public static implicit operator Mint(long a) { return new Mint(a); } public static explicit operator long(Mint a) { return a.Value; } public static Mint Pow(Mint a, long n) { if (n == 0) return new Mint(1); Mint b = Pow(a, n >> 1); b *= b; if ((n & 1) == 1) b *= a; return b; } public static Mint Inv(Mint n) { long a = n.Value; long b = MOD; long x = 1; long u = 0; while (b != 0) { long k = a / b; long _x = u; u = x - k * u; x = _x; long _a = a; a = b; b = _a - (k * b); } return new Mint(x); } public bool Equals(Mint other) { return Value == other.Value; } public int CompareTo(Mint other) { return Comparer<long>.Default.Compare(Value, other.Value); } } public class HashMap<K, V> : System.Collections.Generic.Dictionary<K, V> { private V DefaultValue; private static Func<V> CreateInstance = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V defaultValue) { DefaultValue = defaultValue; } new public V this[K i] { get { V v; if (TryGetValue(i, out v)) { return v; } else { return base[i] = DefaultValue != null ? DefaultValue : CreateInstance(); } } set { base[i] = value; } } } public struct VTuple<T1, T2> : System.IComparable<VTuple<T1, T2>>, System.IEquatable<VTuple<T1, T2>> { public T1 Item1; public T2 Item2; public T1 First { get { return Item1; } } public T2 Second { get { return Item2; } } public VTuple(T1 item1, T2 item2) { Item1 = item1; Item2 = item2; } public override bool Equals(object obj) { return obj is VTuple<T1, T2> && Equals((VTuple<T1, T2>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ")"; } public bool Equals(VTuple<T1, T2> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2); } public int CompareTo(VTuple<T1, T2> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; return Comparer<T2>.Default.Compare(Item2, other.Item2); } } public struct VTuple3<T1, T2, T3> : System.IComparable<VTuple3<T1, T2, T3>>, System.IEquatable<VTuple3<T1, T2, T3>> { public T1 Item1; public T2 Item2; public T3 Item3; public VTuple3(T1 item1, T2 item2, T3 item3) { Item1 = item1; Item2 = item2; Item3 = item3; } public override bool Equals(object obj) { return obj is VTuple3<T1, T2, T3> && Equals((VTuple3<T1, T2, T3>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ")"; } public bool Equals(VTuple3<T1, T2, T3> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3); } public int CompareTo(VTuple3<T1, T2, T3> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; return Comparer<T3>.Default.Compare(Item3, other.Item3); } } public struct VTuple4<T1, T2, T3, T4> : System.IComparable<VTuple4<T1, T2, T3, T4>>, System.IEquatable<VTuple4<T1, T2, T3, T4>> { public T1 Item1; public T2 Item2; public T3 Item3; public T4 Item4; public VTuple4(T1 item1, T2 item2, T3 item3, T4 item4) { Item1 = item1; Item2 = item2; Item3 = item3; Item4 = item4; } public override bool Equals(object obj) { return obj is VTuple4<T1, T2, T3, T4> && Equals((VTuple4<T1, T2, T3, T4>)obj); } public override int GetHashCode() { int h1 = Item1 != null ? Item1.GetHashCode() : 0; int h2 = Item2 != null ? Item2.GetHashCode() : 0; int h3 = Item3 != null ? Item3.GetHashCode() : 0; int h4 = Item3 != null ? Item4.GetHashCode() : 0; return HashHelpers.CombineHashCodes(h1, h2, h3, h4); } public override string ToString() { return "(" + Item1?.ToString() + ", " + Item2?.ToString() + ", " + Item3?.ToString() + ", " + Item4?.ToString() + ")"; } public bool Equals(VTuple4<T1, T2, T3, T4> other) { return EqualityComparer<T1>.Default.Equals(Item1, other.Item1) && EqualityComparer<T2>.Default.Equals(Item2, other.Item2) && EqualityComparer<T3>.Default.Equals(Item3, other.Item3) && EqualityComparer<T4>.Default.Equals(Item4, other.Item4); } public int CompareTo(VTuple4<T1, T2, T3, T4> other) { int c = Comparer<T1>.Default.Compare(Item1, other.Item1); if (c != 0) return c; c = Comparer<T2>.Default.Compare(Item2, other.Item2); if (c != 0) return c; c = Comparer<T3>.Default.Compare(Item3, other.Item3); if (c != 0) return c; return Comparer<T4>.Default.Compare(Item4, other.Item4); } } public static class HashHelpers { public static readonly int RandomSeed = new System.Random().Next(int.MinValue, int.MaxValue); public static int Combine(int h1, int h2) { uint rol5 = ((uint)h1 << 5) | ((uint)h1 >> 27); return ((int)rol5 + h1) ^ h2; } public static int CombineHashCodes(int h1, int h2) { return Combine(Combine(RandomSeed, h1), h2); } public static int CombineHashCodes(int h1, int h2, int h3) { return Combine(CombineHashCodes(h1, h2), h3); } public static int CombineHashCodes(int h1, int h2, int h3, int h4) { return Combine(CombineHashCodes(h1, h2, h3), h4); } } public static class Cin { public static int ri { get { return ReadInt(); } } public static int[] ria { get { return ReadIntArray(); } } public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static string[] rsa { get { return ReadStringArray(); } } public static int ReadInt() { return int.Parse(Next()); } public static long ReadLong() { return long.Parse(Next()); } public static double ReadDouble() { return double.Parse(Next()); } public static string ReadString() { return Next(); } public static int[] ReadIntArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { Tokens = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static string[] ReadStringArray() { Tokens = null; return Console.ReadLine().Split(' '); } public static void ReadCol(out long[] a, long N) { a = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, long N) { a = new long[N]; b = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long N) { a = new long[N]; b = new long[N]; c = new long[N]; for (int i = 0; i < N; i++) { a[i] = ReadLong(); b[i] = ReadLong(); c[i] = ReadLong(); } } public static int[,] ReadIntTable(int h, int w) { Tokens = null; int[,] ret = new int[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadInt(); } } return ret; } public static long[,] ReadLongTable(long h, long w) { Tokens = null; long[,] ret = new long[h, w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ret[i, j] = ReadLong(); } } return ret; } public static char[,] ReadCharTable(int h, int w) { Tokens = null; char[,] res = new char[h, w]; for (int i = 0; i < h; i++) { string s = ReadString(); for (int j = 0; j < w; j++) { res[i, j] = s[j]; } } return res; } private static string[] Tokens; private static int Pointer; private static string Next() { if (Tokens == null || Tokens.Length <= Pointer) { Tokens = Console.ReadLine().Split(' '); Pointer = 0; } return Tokens[Pointer++]; } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { if (Console.IsOutputRedirected) return; var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] array) { Array.Sort<T>(array); return array; } public static T[] SortDecend<T>(T[] array) { Array.Sort<T>(array); Array.Reverse(array); return array; } public static void Swap<T>(ref T a, ref T b) { T _a = a; a = b; b = _a; } public static long GCD(long a, long b) { while (b != 0) { long _a = a; a = b; b = _a % b; } return a; } public static long LCM(long a, long b) { if (a == 0 || b == 0) return 0; return a * b / GCD(a, b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static void ChMax(ref int a, int b) { if (a < b) a = b; } public static void ChMin(ref int a, int b) { if (a > b) a = b; } public static void FillArray<T>(T[] array, T value) { int max = array.Length; for (int i = 0; i < max; i++) { array[i] = value; } } public static void FillArray<T>(T[,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { array[i, j] = value; } } } public static void FillArray<T>(T[,,] array, T value) { int max0 = array.GetLength(0); int max1 = array.GetLength(1); int max2 = array.GetLength(2); for (int i = 0; i < max0; i++) { for (int j = 0; j < max1; j++) { for (int k = 0; k < max2; k++) { array[i, j, k] = value; } } } } public static long[] Accumulate(long[] array) { long[] acc = new long[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } public static double[] Accumulate(double[] array) { double[] acc = new double[array.Length + 1]; for (int i = 0; i < array.Length; i++) { acc[i + 1] = acc[i] + array[i]; } return acc; } } }
[["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 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], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 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, 22], ["+", 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, 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], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["-", 0, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["-", 0, 16, 12, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
3,757
38
using System; using System.Linq; using System.Text.RegularExpressions; using System.Collections.Generic; using static System.Console; using static Program.Input; using static Program.MyMath; using static Program.Const; namespace Program { static class Const { public static string alp = "abcdefghijklmnopqrstuvwxyz"; public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const long MOD = 1000000007; public static int INF = int.MaxValue; public static long INFL = long.MaxValue; } public class Program { public static void Main() { var a = ScanLongArray(); var k = ScanLong(); WriteLine(a.Sum() - a.Max() + (long)Math.Pow(a.Max(), k)); } } static class Input { public static void InputLine(out int a, out int b) { var input = ScanIntArray(); a = input[0]; b = input[1]; } public static void InputLine(out int a, out int b, out int c) { var input = ScanIntArray(); a = input[0]; b = input[1]; c = input[2]; } public static void InputLine(out int a, out int b, out int c, out int d) { var input = ScanIntArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void InputLine(out long a, out long b) { var input = ScanLongArray(); a = input[0]; b = input[1]; } public static void InputLine(out long a, out long b, out long c) { var input = ScanLongArray(); a = input[0]; b = input[1]; c = input[2]; } public static void InputLine(out long a, out long b, out long c, out long d) { var input = ScanLongArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void InputLine(out string a, out string b) { var input = ScanStrArray(); a = input[0]; b = input[1]; } public static int ScanInt() { return int.Parse(ReadLine()); } static public uint ScanUint() { return uint.Parse(ReadLine()); } static public double ScanDouble() { return double.Parse(ReadLine()); } static public long ScanLong() { return long.Parse(ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(ReadLine()); } static public int[] ScanIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return ReadLine().Split().Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return ReadLine().Split().Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(); } static public string RegaxReplace(this string arg1, string pattern, string replacement) { return Regex.Replace(arg1, pattern, replacement); } } static class MyMath { static public int CountBit(this long a) { if (a == 0) return 0; int c = 1; for (; a > 1; a /= 2) if (a % 2 == 1) c++; return c; } static public int Floor2(this int a) { int N = 1; while (N < a) N *= 2; return N / 2; } static public long Floor2(this long a) { long N = 1; while (N < a) N *= 2; return N / 2; } static public int Ceiling2(this int a) { int N = 1; while (N < a) N *= 2; return N; } static public long Ceiling2(this long a) { long N = 1; while (N < a) N *= 2; return N; } static public long[] CumSum(this long[] a) { var res = new long[a.Length]; long s = 0; for (int i = 0; i < a.Length; i++) res[i] = (s += a[i]); return res; } static public IEnumerable<int> PrimeFactors(this int n) { int tmp = n; for (int i = 2; i * i <= n; i++) while (tmp % i == 0) { tmp /= i; yield return i; } if (tmp != 1) yield return tmp; } static public IEnumerable<long> PrimeFactors(this long n) { var tmp = n; for (long i = 2; i * i <= n; i++) while (tmp % i == 0) { tmp /= i; yield return i; } if (tmp != 1) yield return tmp; } static public int Digit(this int n, int d) { if (d < 0) return 0; return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d); } static public int Length(this int n) { if (n < 0) return 0; return (int)Math.Log10(n) + 1; } static public int Top(this int n) { return n.Digit(n.Length() - 1); } public static bool isPrime(this int p) { if (p <= 1) return false; for (int i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static bool isPrime(this long p) { if (p <= 1) return false; for (long i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static long GCD(long a, long b) { Func<long, long, long> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) { if (b == 0) { x = 1; y = 0; return a; } var d = extGCD(b, a % b, ref y, ref x); y -= a / b * x; return d; } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } public static long Inv(this long a, long m = MOD) { long b = m, u = 1, v = 0; while (b != 0) { long t = a / b; a -= t * b; swap(ref a, ref b); u -= t * v; swap(ref u, ref v); } u %= m; if (u < 0) u += m; return u; } private static void swap(ref long a, ref long b) { var t = a; a = b; b = t; } public static long ModPow(long a, long n, long m = MOD) { long res = 1; while (n > 0) { if (n % 2 == 1) res = (res * a) % m; a = (a * a) % m; n >>= 1; } return res; } } static class MyLinq { public static void Sort(this string[] array) { Array.Sort(array, StringComparer.OrdinalIgnoreCase); } public static void StringSort(this List<string> list) { list.Sort(StringComparer.OrdinalIgnoreCase); } public static string Join<T>(this IEnumerable<T> source, string separator) { return string.Join(separator, source); } public static IEnumerable<TItem> Distinct<TItem, TKey>(this IEnumerable<TItem> source, Func<TItem, TKey> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); var set = new HashSet<TKey>(); foreach (var item in source) if (set.Add(keySelector(item))) yield return item; } } }
using System; using System.Linq; using System.Text.RegularExpressions; using System.Collections.Generic; using static System.Console; using static Program.Input; using static Program.MyMath; using static Program.Const; namespace Program { static class Const { public static string alp = "abcdefghijklmnopqrstuvwxyz"; public static string Alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const long MOD = 1000000007; public static int INF = int.MaxValue; public static long INFL = long.MaxValue; } public class Program { public static void Main() { var a = ScanLongArray(); var k = ScanLong(); WriteLine(a.Sum() - a.Max() + a.Max() * (long)Math.Pow(2, k)); } } static class Input { public static void InputLine(out int a, out int b) { var input = ScanIntArray(); a = input[0]; b = input[1]; } public static void InputLine(out int a, out int b, out int c) { var input = ScanIntArray(); a = input[0]; b = input[1]; c = input[2]; } public static void InputLine(out int a, out int b, out int c, out int d) { var input = ScanIntArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void InputLine(out long a, out long b) { var input = ScanLongArray(); a = input[0]; b = input[1]; } public static void InputLine(out long a, out long b, out long c) { var input = ScanLongArray(); a = input[0]; b = input[1]; c = input[2]; } public static void InputLine(out long a, out long b, out long c, out long d) { var input = ScanLongArray(); a = input[0]; b = input[1]; c = input[2]; d = input[3]; } public static void InputLine(out string a, out string b) { var input = ScanStrArray(); a = input[0]; b = input[1]; } public static int ScanInt() { return int.Parse(ReadLine()); } static public uint ScanUint() { return uint.Parse(ReadLine()); } static public double ScanDouble() { return double.Parse(ReadLine()); } static public long ScanLong() { return long.Parse(ReadLine()); } static public ulong ScanUlong() { return ulong.Parse(ReadLine()); } static public int[] ScanIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } static public uint[] ScanUintArray() { return ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); } static public double[] ScanDoubleArray() { return ReadLine().Split().Select(x => double.Parse(x)).ToArray(); } static public long[] ScanLongArray() { return ReadLine().Split().Select(x => long.Parse(x)).ToArray(); } static public ulong[] ScanUlongArray() { return ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); } static public string ScanStr() { return ReadLine(); } static public string[] ScanStrArray() { return ScanStr().Split(); } static public string RegaxReplace(this string arg1, string pattern, string replacement) { return Regex.Replace(arg1, pattern, replacement); } } static class MyMath { static public int CountBit(this long a) { if (a == 0) return 0; int c = 1; for (; a > 1; a /= 2) if (a % 2 == 1) c++; return c; } static public int Floor2(this int a) { int N = 1; while (N < a) N *= 2; return N / 2; } static public long Floor2(this long a) { long N = 1; while (N < a) N *= 2; return N / 2; } static public int Ceiling2(this int a) { int N = 1; while (N < a) N *= 2; return N; } static public long Ceiling2(this long a) { long N = 1; while (N < a) N *= 2; return N; } static public long[] CumSum(this long[] a) { var res = new long[a.Length]; long s = 0; for (int i = 0; i < a.Length; i++) res[i] = (s += a[i]); return res; } static public IEnumerable<int> PrimeFactors(this int n) { int tmp = n; for (int i = 2; i * i <= n; i++) while (tmp % i == 0) { tmp /= i; yield return i; } if (tmp != 1) yield return tmp; } static public IEnumerable<long> PrimeFactors(this long n) { var tmp = n; for (long i = 2; i * i <= n; i++) while (tmp % i == 0) { tmp /= i; yield return i; } if (tmp != 1) yield return tmp; } static public int Digit(this int n, int d) { if (d < 0) return 0; return (n % (int)Math.Pow(10, d + 1)) / (int)Math.Pow(10, d); } static public int Length(this int n) { if (n < 0) return 0; return (int)Math.Log10(n) + 1; } static public int Top(this int n) { return n.Digit(n.Length() - 1); } public static bool isPrime(this int p) { if (p <= 1) return false; for (int i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static bool isPrime(this long p) { if (p <= 1) return false; for (long i = 2; i * i <= p; i++) if (p % i == 0) return false; return true; } public static int GCD(int a, int b) { Func<int, int, int> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static long GCD(long a, long b) { Func<long, long, long> gcd = null; gcd = (x, y) => y == 0 ? x : gcd(y, x % y); return a > b ? gcd(a, b) : gcd(b, a); } public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) { if (b == 0) { x = 1; y = 0; return a; } var d = extGCD(b, a % b, ref y, ref x); y -= a / b * x; return d; } public static int LCM(int a, int b) { return a * b / GCD(a, b); } public static long LCM(long a, long b) { return a * b / GCD(a, b); } public static long Inv(this long a, long m = MOD) { long b = m, u = 1, v = 0; while (b != 0) { long t = a / b; a -= t * b; swap(ref a, ref b); u -= t * v; swap(ref u, ref v); } u %= m; if (u < 0) u += m; return u; } private static void swap(ref long a, ref long b) { var t = a; a = b; b = t; } public static long ModPow(long a, long n, long m = MOD) { long res = 1; while (n > 0) { if (n % 2 == 1) res = (res * a) % m; a = (a * a) % m; n >>= 1; } return res; } } static class MyLinq { public static void Sort(this string[] array) { Array.Sort(array, StringComparer.OrdinalIgnoreCase); } public static void StringSort(this List<string> list) { list.Sort(StringComparer.OrdinalIgnoreCase); } public static string Join<T>(this IEnumerable<T> source, string separator) { return string.Join(separator, source); } public static IEnumerable<TItem> Distinct<TItem, TKey>(this IEnumerable<TItem> source, Func<TItem, TKey> keySelector) { if (source == null) throw new ArgumentNullException(nameof(source)); if (keySelector == null) throw new ArgumentNullException(nameof(keySelector)); var set = new HashSet<TKey>(); foreach (var item in source) if (set.Add(keySelector(item))) yield return item; } } }
[["+", 0, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 16, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["-", 0, 16, 12, 74, 51, 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], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 12, 74, 51, 213, 3, 4, 0, 28, 0, 203]]
8
1,998
12
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = l[0], B = l[1], C = l[2]; var K = int.Parse(Console.ReadLine()); var max = Math.Max(A, Math.Max(B, C)); var afVal = max * 2 * K; var total = A + B + C; if (A == max) total -= A; else if (B == max) total -= B; else if (C == max) total -= C; total += afVal; Console.WriteLine(total); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var l = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = l[0], B = l[1], C = l[2]; var K = int.Parse(Console.ReadLine()); var max = Math.Max(A, Math.Max(B, C)); var afVal = max; for (var i = 0; i < K; i++) { afVal *= 2; } var total = A + B + C; if (A == max) total -= A; else if (B == max) total -= B; else if (C == max) total -= C; total += afVal; Console.WriteLine(total); } } }
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 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], ["+", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["+", 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], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 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, 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, 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, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
174
22
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; static class Extensions { public static int ToInt(this string s) => int.Parse(s); public static long ToLong(this string s) => long.Parse(s); public static char ToChar(this string s) => char.Parse(s); public static double ToDouble(this string s) => double.Parse(s); public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray(); public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray(); public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray(); } class Program { static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray(); static void Main() { int[] abc = Console.ReadLine().ToIntArray(); int A = abc[0]; int B = abc[1]; int C = abc[2]; int K = Console.ReadLine().ToInt(); var arr = new[] { A, B, C }; Array.Sort(arr); Console.WriteLine(arr[0] + arr[1] + (int)Math.Pow(arr[2], K)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Collections; static class Extensions { public static int ToInt(this string s) => int.Parse(s); public static long ToLong(this string s) => long.Parse(s); public static char ToChar(this string s) => char.Parse(s); public static double ToDouble(this string s) => double.Parse(s); public static int[] ToIntArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToInt()).ToArray(); public static long[] ToLongArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToLong()).ToArray(); public static double[] ToDoubleArray(this string s) => s.Replace(',', ' ').Split(' ').Select(x => x.ToDouble()).ToArray(); } class Program { static string[] ReadLines(int n) => Enumerable.Range(0, n).Select(s => Console.ReadLine()).ToArray(); static void Main() { int[] abc = Console.ReadLine().ToIntArray(); int A = abc[0]; int B = abc[1]; int C = abc[2]; int K = Console.ReadLine().ToInt(); var arr = new[] { A, B, C }; Array.Sort(arr); Console.WriteLine(arr[0] + arr[1] + arr[2] * (int)Math.Pow(2, K)); } }
[["+", 0, 28, 0, 16, 12, 16, 31, 204, 205, 22], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 17, 48], ["-", 51, 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
401
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } static void Main(string[] args) { SolveA(args); // SolveB(args); // SolveC(args); // SolveD(args); } static void SolveA(string[] args) { int[] abc = ReadAndParseIntArr(); int k = ReadAndParseInt(); int target = abc.Max(); int ans = target * 2 * k - target + abc.Sum(); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Practice { class Program { private static int ReadAndParseInt() { return int.Parse(Console.ReadLine()); } private static int[] ReadAndParseIntArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } private static long ReadAndParseLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadAndParseLongArr() { return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } static void Main(string[] args) { SolveA(args); // SolveB(args); // SolveC(args); // SolveD(args); } static void SolveA(string[] args) { int[] abc = ReadAndParseIntArr(); int k = ReadAndParseInt(); int target = abc.Max(); int ans = -target + abc.Sum(); for (int i = 0; i < k; ++i) { target *= 2; } ans += target; Console.WriteLine(ans); } } }
[["-", 0, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 16, 31, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 17, 48], ["-", 0, 212, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 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], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 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, 22], ["+", 0, 195, 8, 196, 0, 7, 26, 241, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 26, 241, 0, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 25], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 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], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 22]]
8
213
29
using System; namespace _96_2 { class Program { static void Main(string[] args) { string[] acs = Console.ReadLine().Split(' '); int A = int.Parse(acs[0]); int B = int.Parse(acs[1]); int C = int.Parse(acs[2]); int K = int.Parse(Console.ReadLine()); if (B < A && C < A) { Console.WriteLine(Math.Pow(A, K)); } else if (A < B && C < B) { Console.WriteLine(Math.Pow(B, K)); } else { Console.WriteLine(Math.Pow(C, K)); } } } }
using System; namespace _96_2 { class Program { static void Main(string[] args) { string[] acs = Console.ReadLine().Split(' '); int A = int.Parse(acs[0]); int B = int.Parse(acs[1]); int C = int.Parse(acs[2]); int K = int.Parse(Console.ReadLine()); if (B < A && C < A) { Console.WriteLine(Math.Pow(2, K) * A + B + C); } else if (A < B && C < B) { Console.WriteLine(Math.Pow(2, K) * B + A + C); } else { Console.WriteLine(Math.Pow(2, K) * C + A + B); } } } }
[["-", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 31, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 28, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
163
24
using System; using System.Text.RegularExpressions; using System.Numerics; using System.Linq; using System.Collections.Generic; namespace ConsoleApp2 { class Program { class ReverseComparer : IComparer<int> { public int Compare(int x, int y) { // 既定のComparerとは反対の結果を返す return Comparer<int>.Default.Compare(y, x); } } static void Main(string[] args) { List<int> values = new List<int>(); string str = Console.ReadLine(); //標準入力 // string str = "3 3 4"; string[] str2 = str.Split(' '); int a = int.Parse(str2[0]); int b = int.Parse(str2[1]); int c = int.Parse(str2[2]); str = Console.ReadLine(); //標準入力 // str = "2"; str2 = str.Split(' '); int d = int.Parse(str2[0]); values.Add(a); values.Add(b); values.Add(c); IComparer<int> reverseComparer = new ReverseComparer(); values.Sort(reverseComparer); values[0] = (int)Math.Pow(values[0], d); int count = values.Sum(); Console.WriteLine(count); } } }
using System; using System.Text.RegularExpressions; using System.Numerics; using System.Linq; using System.Collections.Generic; namespace ConsoleApp2 { class Program { class ReverseComparer : IComparer<int> { public int Compare(int x, int y) { // 既定のComparerとは反対の結果を返す return Comparer<int>.Default.Compare(y, x); } } static void Main(string[] args) { List<int> values = new List<int>(); string str = Console.ReadLine(); //標準入力 // string str = "3 3 4"; string[] str2 = str.Split(' '); int a = int.Parse(str2[0]); int b = int.Parse(str2[1]); int c = int.Parse(str2[2]); str = Console.ReadLine(); //標準入力 // str = "2"; str2 = str.Split(' '); int d = int.Parse(str2[0]); values.Add(a); values.Add(b); values.Add(c); IComparer<int> reverseComparer = new ReverseComparer(); values.Sort(reverseComparer); for (int i = 0; i < d; i++) { values[0] = values[0] * 2; } int count = values.Sum(); Console.WriteLine(count); } } }
[["+", 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], ["+", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["+", 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, 22], ["+", 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], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 205, 22], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 0, 131], ["-", 0, 11, 12, 74, 51, 213, 63, 214, 141, 22], ["-", 0, 11, 12, 74, 51, 213, 3, 4, 0, 24], ["-", 0, 11, 12, 74, 51, 213, 3, 4, 0, 21], ["-", 12, 74, 51, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 11, 12, 74, 51, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
270
28
using System; class Program { static void Main(string[] args) { string N = Console.ReadLine(); string[] t = N.Split(' '); int[] T = new int[t.Length]; for (int i = 0; i < T.Length; i++) { T[i] = int.Parse(t[i]); } int K = int.Parse(Console.ReadLine()); for (int i = 0; i < T.Length - 1; i++) { if (T[i] > T[i + 1]) { int n = T[i]; T[i] = T[i + 1]; T[i + 1] = n; } } int s = T[0] + T[1] + T[2] * K * 2; Console.WriteLine(s); } }
using System; class Program { static void Main(string[] args) { string N = Console.ReadLine(); string[] t = N.Split(' '); int[] T = new int[t.Length]; for (int i = 0; i < T.Length; i++) { T[i] = int.Parse(t[i]); } int K = int.Parse(Console.ReadLine()); for (int i = 0; i < T.Length - 1; i++) { if (T[i] > T[i + 1]) { int n = T[i]; T[i] = T[i + 1]; T[i + 1] = n; } } int s = T[0] + T[1] + T[2] * (int)Math.Pow(2, K); Console.WriteLine(s); } }
[["-", 0, 212, 0, 16, 12, 16, 31, 16, 12, 22], ["-", 0, 200, 0, 212, 0, 16, 12, 16, 17, 48], ["+", 0, 212, 0, 16, 12, 16, 12, 74, 0, 24], ["+", 0, 212, 0, 16, 12, 16, 12, 74, 39, 199], ["+", 0, 212, 0, 16, 12, 16, 12, 74, 0, 25], ["+", 12, 16, 12, 74, 51, 213, 63, 214, 205, 22], ["+", 12, 16, 12, 74, 51, 213, 63, 214, 0, 131], ["+", 12, 16, 12, 74, 51, 213, 63, 214, 141, 22], ["+", 12, 16, 12, 74, 51, 213, 3, 4, 0, 24], ["+", 12, 16, 12, 74, 51, 213, 3, 4, 0, 21], ["+", 12, 74, 51, 213, 3, 4, 0, 28, 0, 22], ["+", 12, 16, 12, 74, 51, 213, 3, 4, 0, 25]]
8
195
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ACprac { class Program { static void Main(string[] args) { string[] itmp = Console.ReadLine().Split(' '); int[] abc = new int[3]; abc[0] = int.Parse(itmp[0]); abc[1] = int.Parse(itmp[1]); abc[2] = int.Parse(itmp[2]); int k = int.Parse(Console.ReadLine()); for (int count = 0; count < k; count++) { int mNum = 0; int max = 0; for (int i = 0; i < 3; i++) { if (abc[i] >= max && abc[i] <= 25) { max = abc[i]; mNum = i; } } abc[mNum] = abc[mNum] * 2; } k = abc[0] + abc[1] + abc[2]; Console.WriteLine(k); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ACprac { class Program { static void Main(string[] args) { string[] itmp = Console.ReadLine().Split(' '); int[] abc = new int[3]; abc[0] = int.Parse(itmp[0]); abc[1] = int.Parse(itmp[1]); abc[2] = int.Parse(itmp[2]); int k = int.Parse(Console.ReadLine()); for (int count = 0; count < k; count++) { int mNum = 0; int max = 0; for (int i = 0; i < 3; i++) { if (abc[i] >= max) { max = abc[i]; mNum = i; } } abc[mNum] = abc[mNum] * 2; } k = abc[0] + abc[1] + abc[2]; Console.WriteLine(k); } } }
[["-", 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, 73], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
241
7
using System; class Test { static void Main() { string[] str = Console.ReadLine().Split(); int[] x = new int[3]; for (int i = 0; i < 3; i++) { x[i] = int.Parse(str[i]); } Array.Sort(x); int k = int.Parse(Console.ReadLine()); Console.WriteLine("ok"); for (int i = 0; i < k; i++) { x[2] *= 2; } Console.WriteLine(x[0] + x[1] + x[2]); } }
using System; class Test { static void Main() { string[] str = Console.ReadLine().Split(); int[] x = new int[3]; for (int i = 0; i < 3; i++) { x[i] = int.Parse(str[i]); } Array.Sort(x); int k = int.Parse(Console.ReadLine()); for (int i = 0; i < k; i++) { x[2] *= 2; } Console.WriteLine(x[0] + x[1] + x[2]); } }
[["-", 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
144
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { Solve(); } static void Solve() { Scan sc = new Scan(); write wr = new write(); var t = sc.intarr; int h = t[0]; int w = t[1]; bool ans = true; char[,] s = new char[h + 2, w + 2]; for (int i = 0; i < h + 1; ++i) { string ss = ""; if (i != h) ss = sc.str; for (int j = 0; j < w + 1; ++j) { if (i == 0 || i == h || j == 0 || j == w) { s[i, j] = '.'; } else s[i, j] = ss[j - 1]; } } for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (s[i, j] == '#' && s[i - 1, j] == '.' && s[i + 1, j] == '.' && s[i, j - 1] == '.' && s[i, j + 1] == '.') { ans = false; } } } if (ans) wr.wri("Yes"); else wr.wri("No"); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { Solve(); } static void Solve() { Scan sc = new Scan(); write wr = new write(); var t = sc.intarr; int h = t[0]; int w = t[1]; bool ans = true; char[,] s = new char[h + 2, w + 2]; for (int i = 0; i < h + 2; ++i) { string ss = ""; if (i != h + 1 && i != 0) ss = sc.str; for (int j = 0; j < w + 2; ++j) { if (i == 0 || i == h + 1 || j == 0 || j == w + 1) { s[i, j] = '.'; } else s[i, j] = ss[j - 1]; } } for (int i = 1; i < h + 1; ++i) { for (int j = 1; j < w + 1; ++j) { if (s[i, j] == '#' && s[i - 1, j] == '.' && s[i + 1, j] == '.' && s[i, j - 1] == '.' && s[i, j + 1] == '.') { ans = false; } } } if (ans) wr.wri("Yes"); else wr.wri("No"); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 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, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 31, 16, 31, 16, 12, 16, 12, 16, 17, 72], ["+", 31, 16, 31, 16, 12, 16, 12, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 16, 12, 16, 12, 16, 12, 203], ["-", 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, 16, 17, 72]]
8
443
22
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } const char B = '#'; const char W = '.'; static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var h = int.Parse(spl[0]); var w = int.Parse(spl[1]); var tbl = new char [h][]; for (int i = 0; i < h; i++) { tbl[i] = input.ReadLine().ToCharArray(); } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { var ok = false; ok |= i - 1 >= 0 && tbl[i - 1][j] == B; ok |= i + 1 < h && tbl[i + 1][j] == B; ok |= j - 1 >= 0 && tbl[i][j - 1] == B; ok |= j + 1 < w && tbl[i][j + 1] == B; if (!ok) return No; } } return Yes; } static int[] ToIntArray(string strs, int n) { var ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } static long Pow(long x, long n) { long ans = 1; while (n > 0) { if (n % 2 == 1) { ans = ans * x; } x = x * x; n /= 2; } return ans; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } const char B = '#'; const char W = '.'; static object process(TextReader input) { var spl = input.ReadLine().Split(' '); var h = int.Parse(spl[0]); var w = int.Parse(spl[1]); var tbl = new char [h][]; for (int i = 0; i < h; i++) { tbl[i] = input.ReadLine().ToCharArray(); } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (tbl[i][j] == W) continue; var ok = false; ok |= i - 1 >= 0 && tbl[i - 1][j] == B; ok |= i + 1 < h && tbl[i + 1][j] == B; ok |= j - 1 >= 0 && tbl[i][j - 1] == B; ok |= j + 1 < w && tbl[i][j + 1] == B; if (!ok) return No; } } return Yes; } static int[] ToIntArray(string strs, int n) { var ret = new int[n]; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } static long Pow(long x, long n) { long ans = 1; while (n > 0) { if (n % 2 == 1) { ans = ans * x; } x = x * x; n /= 2; } return ans; } }
[["+", 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, 204, 205, 204, 205, 22], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 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], ["+", 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
473
14
using System.Linq; using System; using System.IO; using System.Collections.Generic; using static System.Console; class Program { int[] dx = new int[] { 0, 1, 0, -1 }; int[] dy = new int[] { -1, 0, 1, 0 }; static void Main(string[] args) => new Program().solve(); void solve() { var param = ReadLine().Split(' ').Select(int.Parse).ToArray(); var h = param[0]; var w = param[1]; var tar = Enumerable.Range(0, h).Select(_ => ReadLine().ToCharArray()).ToArray(); var grid = new bool[h, w]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (!grid[y, x] && tar[y][x] == '#') { grid[y, x] = Enumerable.Range(0, 4) .Where(i => (x + dx[i]) >= 0 && (x + dx[i]) < h && (y + dy[i]) >= 0 && (y + dy[i]) < w) .Select(i => tar[y + dy[i]][x + dx[i]]) .Any(ch => ch == '#'); if (!grid[y, x]) { WriteLine("No"); return; } } } } WriteLine("Yes"); } }
using System.Linq; using System; using System.IO; using System.Collections.Generic; using static System.Console; class Program { int[] dx = new int[] { 0, 1, 0, -1 }; int[] dy = new int[] { -1, 0, 1, 0 }; static void Main(string[] args) => new Program().solve(); void solve() { var param = ReadLine().Split(' ').Select(int.Parse).ToArray(); var h = param[0]; var w = param[1]; var tar = Enumerable.Range(0, h).Select(_ => ReadLine().ToCharArray()).ToArray(); var grid = new bool[h, w]; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (tar[y][x] == '#') { grid[y, x] = Enumerable.Range(0, 4) .Where(i => (x + dx[i]) >= 0 && (x + dx[i]) < w && (y + dy[i]) >= 0 && (y + dy[i]) < h) .Select(i => tar[y + dy[i]][x + dx[i]]) .Any(ch => ch == '#'); if (!grid[y, x]) { WriteLine("No"); return; } } } } WriteLine("Yes"); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 241, 0, 111], ["-", 0, 57, 15, 16, 31, 241, 0, 204, 205, 22], ["-", 15, 16, 31, 241, 0, 204, 206, 207, 0, 70], ["-", 31, 241, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 31, 241, 0, 204, 206, 207, 0, 21], ["-", 15, 16, 31, 241, 0, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 8, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["-", 0, 28, 0, 218, 8, 16, 12, 16, 12, 22], ["+", 0, 28, 0, 218, 8, 16, 12, 16, 12, 22]]
8
359
12
using System; namespace ABC096 { class C { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int H = int.Parse(input[0]); int W = int.Parse(input[1]); char[,] c = new char[H, W]; string s = ""; for (int i = 0; i < H; i++) { s = Console.ReadLine(); for (int j = 0; j < W; j++) { c[i, j] = s[j]; } } bool isOK = false; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (c[i, j] == '#') { if (i + 1 < H && c[i + 1, j] == '#') { isOK = true; } if (0 <= i - 1 && c[i - 1, j] == '#') { isOK = true; } if (j + 1 < W && c[i, j + 1] == '#') { isOK = true; } if (0 <= j - 1 && c[i, j - 1] == '#') { isOK = true; } } } } if (isOK) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; namespace ABC096 { class C { static void Main(string[] args) { string[] input = Console.ReadLine().Split(); int H = int.Parse(input[0]); int W = int.Parse(input[1]); char[,] c = new char[H, W]; string s; for (int i = 0; i < H; i++) { s = Console.ReadLine(); for (int j = 0; j < W; j++) { c[i, j] = s[j]; } } bool isOneOK = true; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (c[i, j] == '#') { if ((i + 1 < H && c[i + 1, j] != '#') && (0 <= i - 1 && c[i - 1, j] != '#') && (j + 1 < W && c[i, j + 1] != '#') && (0 <= j - 1 && c[i, j - 1] != '#')) { isOneOK = false; } } } } if (isOneOK) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 211, 0, 147], ["+", 0, 198, 0, 200, 0, 212, 0, 211, 0, 146], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 31, 16, 31, 23, 0, 16, 12, 16, 17, 79], ["-", 0, 57, 64, 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, 32], ["-", 64, 196, 0, 1, 0, 11, 12, 211, 0, 146], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 98], ["+", 31, 16, 12, 23, 0, 16, 12, 16, 17, 79], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 211, 0, 147], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 15, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
318
51
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int h = int.Parse(input[0]); int w = int.Parse(input[1]); string[] masu = new string[h]; //入力マスを受け取る int result = 1; for (int i = 0; i < h; i++) { masu[i] = Console.ReadLine(); } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (masu[i][j] == '#') { result = 0; if (i - 1 >= 0) { if (masu[i - 1][j] == '#') result = 1; } if (i + 1 < h) { if (masu[i + 1][j] == '#') result = 1; } if (j - 1 >= 0) { if (masu[i][j - 1] == '#') result = 1; } if (j - 1 < w) { if (masu[i][j + 1] == '#') result = 1; } } } } Console.WriteLine((result == 1) ? "Yes" : "No"); } }
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int h = int.Parse(input[0]); int w = int.Parse(input[1]); string[] masu = new string[h]; //入力マスを受け取る int result = 1; for (int i = 0; i < h; i++) { masu[i] = Console.ReadLine(); } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (masu[i][j] == '#') { result = 0; if (i - 1 >= 0) { if (masu[i - 1][j] == '#') result = 1; } if (i + 1 < h) { if (masu[i + 1][j] == '#') result = 1; } if (j - 1 >= 0) { if (masu[i][j - 1] == '#') result = 1; } if (j + 1 < w) { if (masu[i][j + 1] == '#') result = 1; } } if (result == 0) break; } if (result == 0) break; } Console.WriteLine((result == 1) ? "Yes" : "No"); } }
[["-", 64, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 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, 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, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 93, 0, 35]]
8
293
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Painting_problem { class Program { static int height = 0; static int width = 0; static int[,] datas = new int[height + 1, width + 1]; static void Main(string[] args) { String input = Console.ReadLine(); try { height = Int32.Parse(input.Split(' ')[0]); width = Int32.Parse(input.Split(' ')[1]); for (int i = 0; i < height; i++) { input = Console.ReadLine(); for (int j = 0; j < width; j++) { if (input[j].Equals('#')) { datas[i, j] = 1; } } } } catch (Exception) { Console.WriteLine("形式エラー"); Console.ReadLine(); return; } // Paint for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (!PaintOut(i, j)) { Console.WriteLine("No"); return; } } } Console.WriteLine("Yes"); } static Boolean PaintOut(int x, int y) { if (datas[x, y] == 1) { bool isSuccess = false; if (x > 0) { isSuccess = isSuccess || datas[x - 1, y] != 0; } if (y > 0) { isSuccess = isSuccess || datas[x, y - 1] != 0; } isSuccess = isSuccess || datas[x + 1, y] != 0; isSuccess = isSuccess || datas[x, y + 1] != 0; return isSuccess; } return true; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Painting_problem { class Program { static int height = 0; static int width = 0; static int[,] datas; static void Main(string[] args) { String input = Console.ReadLine(); try { height = Int32.Parse(input.Split(' ')[0]); width = Int32.Parse(input.Split(' ')[1]); datas = new int[height + 1, width + 1]; for (int i = 0; i < height; i++) { input = Console.ReadLine(); for (int j = 0; j < width; j++) { if (input[j].Equals('#')) { datas[i, j] = 1; } } } } catch (Exception) { Console.WriteLine("形式エラー"); Console.ReadLine(); return; } // Paint for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (!PaintOut(i, j)) { Console.WriteLine("No"); return; } } } Console.WriteLine("Yes"); } static Boolean PaintOut(int x, int y) { if (datas[x, y] == 1) { bool isSuccess = false; if (x > 0) { isSuccess = isSuccess || datas[x - 1, y] != 0; } if (y > 0) { isSuccess = isSuccess || datas[x, y - 1] != 0; } isSuccess = isSuccess || datas[x + 1, y] != 0; isSuccess = isSuccess || datas[x, y + 1] != 0; return isSuccess; } return true; } } }
[["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 227, 0, 228], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["-", 0, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 21], ["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["+", 8, 196, 0, 246, 8, 196, 0, 1, 0, 35], ["+", 0, 246, 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, 227, 0, 228], ["+", 0, 1, 0, 11, 12, 227, 39, 224, 39, 199], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 70], ["+", 12, 227, 39, 224, 225, 226, 0, 16, 31, 22], ["+", 12, 227, 39, 224, 225, 226, 0, 16, 17, 72], ["+", 12, 227, 39, 224, 225, 226, 0, 16, 12, 203], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 21], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 73]]
8
392
26
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 A = Console.ReadLine().Split(' ').Select(x => // long.Parse(x)).ToArray(); var N = long.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var dic = new SortedDictionary<long, long>(); long sum = 0; long ans = 0; for (int i = 0; i < N; i++) { if (A[i] == 0) { ans++; } sum += A[i]; if (sum == 0) { ans++; } if (dic.ContainsKey(sum)) { ans += dic[sum]; dic[sum]++; } else { dic.Add(sum, 1); } } Console.WriteLine(ans); } } }
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 A = Console.ReadLine().Split(' ').Select(x => // long.Parse(x)).ToArray(); var N = long.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); var dic = new SortedDictionary<long, long>(); long sum = 0; long ans = 0; bool zero = false; dic.Add(0, 1); for (int i = 0; i < N; i++) { // if (A[i] == 0) //{ // ans++; //} sum += A[i]; // if (sum == 0 && A[i] != 0) //{ // ans++; //} if (dic.ContainsKey(sum)) { ans += dic[sum]; dic[sum]++; } else { dic.Add(sum, 1); } } Console.WriteLine(ans); } } }
[["+", 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], ["+", 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, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 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], ["-", 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], ["-", 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], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 31, 22]]
8
222
39
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { private const int INF = 1000000007; private const long INFINITY = 9223372036854775807; public static void Main() { // input int N = NextInt(); long[] A = LineLong(); for (int i = 1; i < N; i++) A[i] += A[i - 1]; Dictionary<long, long> dic = new Dictionary<long, long>(); dic[0] = 1; for (int i = 0; i < N; i++) { if (!dic.ContainsKey(A[i])) dic[A[i]] = 0; dic[A[i]]++; } long ans = 0; foreach (var d in dic) { if (d.Value < 2) continue; ans += d.Value / 2 * (d.Value - 1); } Console.WriteLine(ans); } } 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 const long INFINITY = 9223372036854775807; public static void Main() { // input int N = NextInt(); long[] A = LineLong(); for (int i = 1; i < N; i++) A[i] += A[i - 1]; Dictionary<long, long> dic = new Dictionary<long, long>(); for (int i = 0; i < N; i++) { if (!dic.ContainsKey(A[i])) dic[A[i]] = 0; dic[A[i]]++; } if (dic.ContainsKey(0)) dic[0]++; long ans = 0; foreach (var d in dic) { if (d.Value < 2) continue; ans += d.Value * (d.Value - 1) / 2; } Console.WriteLine(ans); } } 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, 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], ["+", 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, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 223, 0, 204, 205, 22], ["+", 64, 1, 0, 223, 0, 204, 206, 207, 0, 70], ["+", 0, 223, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 64, 1, 0, 223, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
519
26
using System; using System.Linq; using System.Collections.Generic; public class Test { public static void Main() { long foo = 0; Console.WriteLine( new long[] { 0 } .Concat(Console.ReadLine().Split().Select(s => long.Parse(s))) .Select(i => { foo += i; return foo; }) .GroupBy(v => v) .Select(g => g.LongCount()) .Where(i => i > 1) .Select(i => i * (i - 1) / 2) .Sum()); } }
using System; using System.Linq; using System.Collections.Generic; public class Test { public static void Main() { long foo = 0; Console.WriteLine( "{1}", Console.ReadLine(), new long[] { 0 } .Concat(Console.ReadLine().Split().Select(s => long.Parse(s))) .Select(i => { foo += i; return foo; }) .GroupBy(v => v) .Select(g => g.LongCount()) .Where(i => i > 1) .Select(i => i * (i - 1) / 2) .Sum()); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 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, 25]]
8
132
10
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); int N = int.Parse(Console.ReadLine()); long ans = 0; var map = new string[N]; for (var i = 0; i < N; i++) { map[i] = Console.ReadLine(); } for (var d = 0; d < N; d++) { var ok = true; for (var i = 0; i < N - 1; i++) { for (var j = i + 1; j < N; j++) { var y = i; var x = (j + d) % N; ok &= (map[y][x] == map[x][y]); } } if (ok) { ans += N; } } Console.WriteLine(ans); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Scanner { public int[] ReadSplitInt() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitLong() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplit_Double() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) { return (long)Pow(a, b); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Math; using static System.Array; using static AtCoder.Tool; namespace AtCoder { class AC { const int MOD = 1000000007; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dx = { 0, 1, 0, -1 }; static readonly int[] dy = { 1, 0, -1, 0 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>>G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { // var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = // false }; Console.SetOut(sw); var cin = new Scanner(); int N = int.Parse(Console.ReadLine()); long ans = 0; var map = new string[N]; for (var i = 0; i < N; i++) { map[i] = Console.ReadLine(); } for (var d = 0; d < N; d++) { var ok = true; for (var i = 0; i < N - 1; i++) { for (var j = i + 1; j < N; j++) { var y = i; var x = (j - d + N) % N; var cy = (x + d) % N; var cx = (y - d + N) % N; ok &= (map[y][x] == map[cy][cx]); } } if (ok) { ans += N; } } Console.WriteLine(ans); // Console.Out.Flush(); } struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Scanner { public int[] ReadSplitInt() { return ConvertAll(Console.ReadLine().Split(), int.Parse); } public long[] ReadSplitLong() { return ConvertAll(Console.ReadLine().Split(), long.Parse); } public double[] ReadSplit_Double() { return ConvertAll(Console.ReadLine().Split(), double.Parse); } } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { for (var i = 0; i < array.Length; i++) { array[i] = initialvalue; } } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long LPow(int a, int b) { return (long)Pow(a, b); } } }
[["+", 0, 16, 31, 23, 0, 16, 31, 16, 17, 33], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 109], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 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, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["-", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
8
643
30
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Runtime.Remoting.Contexts; using System.Security.Cryptography.X509Certificates; using System.Security.Policy; using System.Threading; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { var array = Array(); var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } } class Program { private int N; private string[] S; private void Scan() { var sc = new Scanner(); N = sc.NextInt(); S = new string[N]; for (int i = 0; i < N; i++) { S[i] = sc.Next(); } } public void Solve() { Scan(); long ans = 0; for (int i = 0; i < N; i++) { if (Q(i)) { ans += N; } } Console.WriteLine(ans); } private bool Q(int n) { for (int i = 0; i < N; i++) { for (int j = 0; j < i; j++) { if (S[i][(j + n) % N] != S[(j + n) % N][i]) return false; } } return true; } static void Main(string[] args) { new Program().Solve(); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Runtime.Remoting.Contexts; using System.Security.Cryptography.X509Certificates; using System.Security.Policy; using System.Threading; namespace Contest { class Scanner { private string[] line = new string[0]; private int index = 0; public string Next() { if (line.Length <= index) { line = Console.ReadLine().Split(' '); index = 0; } var res = line[index]; index++; return res; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public string[] Array() { line = Console.ReadLine().Split(' '); index = line.Length; return line; } public int[] IntArray() { var array = Array(); var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } public long[] LongArray() { var array = Array(); var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } } class Program { private int N; private string[] S; private void Scan() { var sc = new Scanner(); N = sc.NextInt(); S = new string[N]; for (int i = 0; i < N; i++) { S[i] = sc.Next(); } } public void Solve() { Scan(); long ans = 0; for (int i = 0; i < N; i++) { if (Q(i)) { ans += N; } } Console.WriteLine(ans); } private bool Q(int n) { for (int i = 0; i < N; i++) { for (int j = 0; j < i; j++) { if (S[i][(j + n) % N] != S[j][(i + n) % N]) return false; } } return true; } static void Main(string[] args) { new Program().Solve(); } } }
[["-", 206, 207, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 15, 16, 12, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 15, 16, 12, 204, 205, 204, 206, 207, 0, 73], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
8
557
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC023B { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[,] map = new string[N, N]; for (int i = 0; i < N; i++) { string str = Console.ReadLine(); for (int j = 0; j < N; j++) { map[i, j] = str.Substring(j, 1); } } int ans = 0; for (int i = 0; i < N; i++) { bool flag = true; for (int j = 0; j < N; j++) { int num = i + j; if (i + j >= N) { num -= N; } for (int k = 0; k < N; k++) { if (k > j) { if (map[k, num] != map[num, k]) { flag = false; } } } } if (flag) { ans += N; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC023B { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[,] map = new string[N, N]; for (int i = 0; i < N; i++) { string str = Console.ReadLine(); for (int j = 0; j < N; j++) { map[i, j] = str.Substring(j, 1); } } int ans = 0; for (int i = 0; i < N; i++) { bool flag = true; for (int j = 0; j < N; j++) { int num = i + j; if (i + j >= N) { num -= N; } for (int k = 0; k < N; k++) { if (k > j) { if (map[num, k] != map[(k + i) % N, j]) { flag = false; } } } } if (flag) { ans += N; } } Console.WriteLine(ans); } } }
[["-", 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, 21], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 57, 15, 16, 12, 204, 206, 207, 0, 21], ["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 109], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 21], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
8
257
14
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { long ans = 0; for (int jj = 0; jj < N; jj++) { bool chk = true; int r0 = 0; int c0 = jj; for (int i = 0; i < N; i++) { for (int j = 0; j < i; j++) { int r = (r0 + i) % N; int c = (c0 + j) % N; int tc = (r0 + i) % N; int tr = (c0 + j) % N; chk &= S[r][c] == S[tr][tc]; } } if (chk) ans += N; } Console.WriteLine(ans); } int N; String[] S; public Sol() { N = ri(); S = new String[N]; for (int i = 0; i < N; i++) { S[i] = rs(); } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; class TEST { static void Main() { Sol mySol = new Sol(); mySol.Solve(); } } class Sol { public void Solve() { long ans = 0; for (int jj = 0; jj < N; jj++) { bool chk = true; int r0 = 0; int c0 = jj; for (int i = 0; i < N; i++) { for (int j = 0; j < i; j++) { int r = (r0 + i) % N; int c = (c0 + j) % N; int tr = (r0 + j) % N; int tc = (c0 + i) % N; chk &= S[r][c] == S[tr][tc]; } } if (chk) ans += N; } Console.WriteLine(ans); } int N; String[] S; public Sol() { N = ri(); S = new String[N]; for (int i = 0; i < N; i++) { S[i] = rs(); } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa(char sep = ' ') { return Console.ReadLine().Split(sep); } static int[] ria(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); } static long[] rla(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); } static double[] rda(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 12, 22]]
8
480
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC023C { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] fact = new long[N]; long[] invfact = new long[N]; fact[0] = 1; invfact[0] = 1; for (int i = 1; i < N; i++) { fact[i] = multiply(fact[i - 1], i); invfact[i] = divide(1, fact[i]); } long[] nums = new long[N]; for (int i = 1; i <= N - 1; i++) { long conbi = 0; if (i - 1 >= N - 1 - i) { conbi = multiply(fact[i - 1], multiply(invfact[N - 1 - i], invfact[(i - 1) - (N - 1 - i)])); } nums[i] = multiply(multiply(fact[i], fact[N - 1 - i]), conbi); } long ans = 0; for (int i = 1; i < N; i++) { ans = (ans + multiply(nums[i] - nums[i - 1], i)) % mod; } Console.WriteLine(ans); } //定数です const long mod = 1000000007; // mod下でのx×yです private static long multiply(long x, long y) { return (x % mod) * (y % mod) % mod; } // mod下でのxのy乗です private static long power(long x, long y) { if (y == 0) { return 1; } else if (y == 1) { return x % mod; } else if (y % 2 == 0) { long p = power(x, y / 2); return p * p % mod; } else { long p = power(x, y / 2); return (p * p) % mod * (x % mod) % mod; } } private static long divide(long x, long y) { return multiply(x, power(y, mod - 2)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AGC023C { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] fact = new long[N]; long[] invfact = new long[N]; fact[0] = 1; invfact[0] = 1; for (int i = 1; i < N; i++) { fact[i] = multiply(fact[i - 1], i); invfact[i] = divide(1, fact[i]); } long[] nums = new long[N]; for (int i = 1; i < N; i++) { long conbi = 0; if (i - 1 >= N - 1 - i) { conbi = multiply(fact[i - 1], multiply(invfact[N - 1 - i], invfact[(i - 1) - (N - 1 - i)])); } nums[i] = multiply(multiply(fact[i], fact[N - 1 - i]), conbi); } long ans = 0; for (int i = 1; i < N; i++) { ans = (ans + multiply((nums[i] - nums[i - 1] + mod), i)) % mod; } Console.WriteLine(ans); } //定数です const long mod = 1000000007; // mod下でのx×yです private static long multiply(long x, long y) { return (x % mod) * (y % mod) % mod; } // mod下でのxのy乗です private static long power(long x, long y) { if (y == 0) { return 1; } else if (y == 1) { return x % mod; } else if (y % 2 == 0) { long p = power(x, y / 2); return p * p % mod; } else { long p = power(x, y / 2); return (p * p) % mod * (x % mod) % mod; } } private static long divide(long x, long y) { return multiply(x, power(y, mod - 2)); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 31, 23, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 23, 0, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 23, 0, 16, 12, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 23, 0, 25]]
8
478
8
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { Console.WriteLine(700 + Console.ReadLine().Count() * 100); } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { Console.WriteLine(700 + Console.ReadLine().Count(x => x == 'o') * 100); } }
[["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 31, 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, 28, 0, 218, 8, 16, 12, 252, 0, 104], ["+", 0, 28, 0, 218, 8, 16, 12, 252, 0, 253]]
8
92
7
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 cost = Console.ReadLine().Count(s => s.ToString() == "o") * 100; Console.WriteLine(cost); Console.WriteLine(cost + 700); } } }
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 cost = Console.ReadLine().Count(s => s.ToString() == "o") * 100; Console.WriteLine(cost + 700); } } }
[["-", 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, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
8
88
7
using System; namespace AtCoder { class Program { public static int CountChar(string s, char c) { return s.Length - s.Replace(c.ToString(), "").Length; } static void Main(string[] args) { int ramen; Console.WriteLine("oかxを3文字入力してください。"); String str = Console.ReadLine(); int count = CountChar(str, 'o'); switch (count) { case 0: ramen = 700; Console.WriteLine(ramen); break; case 1: ramen = 800; Console.WriteLine(ramen); break; case 2: ramen = 900; Console.WriteLine(ramen); break; case 3: ramen = 1000; Console.WriteLine(ramen); break; } } } }
using System; namespace AtCoder { class Program { public static int CountChar(string s, char c) { return s.Length - s.Replace(c.ToString(), "").Length; } static void Main(string[] args) { int ramen; String str = Console.ReadLine(); int count = CountChar(str, 'o'); switch (count) { case 0: ramen = 700; Console.WriteLine(ramen); break; case 1: ramen = 800; Console.WriteLine(ramen); break; case 2: ramen = 900; Console.WriteLine(ramen); break; case 3: ramen = 1000; Console.WriteLine(ramen); break; } } } }
[["-", 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
159
9
using System; namespace ABC095_b { class Program { static void Main(string[] args) { string[] array1 = Console.ReadLine().Split(' '); int n = int.Parse(array1[0]); int x = int.Parse(array1[1]); int[] ms = new int[n]; int sum = 0; int min = 0; int ans = 0; for (int i = 0; i < n; i++) { ms[i] = int.Parse(Console.ReadLine()); sum += ms[i]; min = ms[0]; if (ms[i] < min) { min = ms[i]; } ans = n + (x - sum) / min; } Console.WriteLine(ans); } } }
using System; namespace ABC095_b { class Program { static void Main(string[] args) { string[] array1 = Console.ReadLine().Split(' '); int n = int.Parse(array1[0]); int x = int.Parse(array1[1]); int[] ms = new int[n]; int sum = 0; int min = 1000000; int ans = 0; for (int i = 0; i < n; i++) { ms[i] = int.Parse(Console.ReadLine()); sum += ms[i]; if (ms[i] < min) { min = ms[i]; } ans = n + (x - sum) / min; } Console.WriteLine(ans); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 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, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 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, 203]]
8
175
9
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く var values = cin.ReadIntArray(2); var N = values[0]; var X = values[1]; int[] mlist = new int[N]; var ans = 0; for (int i = 0; i < N; i++) { mlist[i] = cin.ReadInt; } ans = ans + N; X = X - mlist.Sum(); var min = mlist.Min(); // WriteLine(X); while (min < X) { ans++; X = X - min; } WriteLine(ans); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く var values = cin.ReadIntArray(2); var N = values[0]; var X = values[1]; int[] mlist = new int[N]; var ans = 0; for (int i = 0; i < N; i++) { mlist[i] = cin.ReadInt; } ans = ans + N; X = X - mlist.Sum(); var min = mlist.Min(); // WriteLine(X); ans = N + (X / min); WriteLine(ans); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 31, 22], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 12, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 25], ["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 85], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46]]
8
540
17
using System; using System.Collections.Generic; using System.Linq; using System.IO; // using System.Text; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; // using System.Numerics; // using static System.Math; // using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; } void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; } void solve() { int N = cin.nextint; int K = cin.nextint; int Q = cin.nextint; var A = cin.scanint; var ans = long.MaxValue; for (int i = 0; i < N; i++) { var Z = A[i]; var W = new List<int>(); var P = new List<int>(); for (int r = 0; r <= N; r++) { if (r == N || A[r] < Z) // Zより小さいものは使わない { if (P.Count < K) continue; P.Sort(); for (int j = 0; j < P.Count - K + 1; j++) { W.Add(P[j]); } P = new List<int>(); } else { P.Add(A[r]); } } if (W.Count < Q) continue; W.Sort(); chmin(ref ans, W[Q - 1] - W[0]); } WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; // using System.Text; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; // using System.Numerics; // using static System.Math; // using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; } void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; } void solve() { int N = cin.nextint; int K = cin.nextint; int Q = cin.nextint; var A = cin.scanint; var ans = long.MaxValue; for (int i = 0; i < N; i++) { var Y = A[i]; var W = new List<int>(); var P = new List<int>(); for (int r = 0; r <= N; r++) { if (r == N || A[r] < Y) // Zより小さいものは使えない,部分列の区切りになる { P.Sort(); for (int j = 0; j < P.Count - K + 1; j++) { W.Add(P[j]); } P = new List<int>(); } else { P.Add(A[r]); } } if (W.Count < Q) continue; W.Sort(); chmin(ref ans, W[Q - 1] - W[0]); } WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 64, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["-", 64, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["-", 64, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 116, 0, 117], ["-", 0, 57, 64, 196, 0, 57, 64, 116, 0, 35]]
8
638
14
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; public class Hello { public static void Main() { string[] input = ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); long d = int.Parse(input[3]); // string temp = ReadLine(); // int a = int.Parse(ReadLine()); // int b = int.Parse(ReadLine()); // int c = int.Parse(ReadLine()); // int d = int.Parse(ReadLine()); // string a = ReadLine(); // string b = ReadLine(); // string c = ReadLine(); // string ko = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if (d % 2 == 0) { WriteLine(a - b); } else { WriteLine(b - a); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math; public class Hello { public static void Main() { string[] input = ReadLine().Split(' '); long a = long.Parse(input[0]); long b = long.Parse(input[1]); long c = long.Parse(input[2]); long d = long.Parse(input[3]); // string temp = ReadLine(); // int a = int.Parse(ReadLine()); // int b = int.Parse(ReadLine()); // int c = int.Parse(ReadLine()); // int d = int.Parse(ReadLine()); // string a = ReadLine(); // string b = ReadLine(); // string c = ReadLine(); // string ko = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; if (d % 2 == 0) { WriteLine(a - b); } else { WriteLine(b - a); } } }
[["-", 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
144
14
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var array = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long A = array[0]; long B = array[1]; long C = array[2]; long K = array[3]; if (Math.Abs(A - B) > Math.Pow(10, 18)) Console.WriteLine("Unfair"); var res = K % 2 == 0 ? B - A : A - B; Console.WriteLine(res); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var array = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); long A = array[0]; long B = array[1]; long C = array[2]; long K = array[3]; if (Math.Abs(A - B) > Math.Pow(10, 18)) Console.WriteLine("Unfair"); var res = K % 2 == 0 ? A - B : B - A; Console.WriteLine(res); } }
[["-", 0, 200, 0, 212, 0, 41, 64, 16, 31, 22], ["-", 0, 200, 0, 212, 0, 41, 64, 16, 17, 33], ["-", 0, 200, 0, 212, 0, 41, 64, 16, 12, 22], ["-", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 200, 0, 212, 0, 41, 64, 16, 12, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 41, 0, 102], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 41, 75, 16, 12, 22]]
8
147
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Template { class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int k = int.Parse(input[3]); k = k % 2 == 0 ? 1 : -1; //出力 Console.WriteLine((a - b) * k); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Template { class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); long a = long.Parse(input[0]); long b = long.Parse(input[1]); long c = long.Parse(input[2]); long k = long.Parse(input[3]); k = k % 2 == 0 ? 1 : -1; //出力 Console.WriteLine((a - b) * k); } } }
[["-", 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
144
16
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; using System.Numerics; class MainClass { static void Main() { int N = int.Parse(ReadLine()); var P = new int[N]; for (int i = 0; i < N; i++) { P[i] = int.Parse(ReadLine()); } var K = new int[N]; for (int i = 0; i < N; i++) //増加部分列を調べてみる { K[P[i] - 1] = i; } int zouka = 0; int num = 0; for (int i = 0; i < N - 1; i++) { if (K[i] < K[i + 1]) num++; else { zouka = Max(zouka, num); num = 0; } } WriteLine(N - zouka - 1); // WriteLine( P[K[P[K[P[K[P[K[0]]]]]]]] ); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; using System.Numerics; class MainClass { static void Main() { int N = int.Parse(ReadLine()); var P = new int[N]; for (int i = 0; i < N; i++) { P[i] = int.Parse(ReadLine()); } var K = new int[N]; for (int i = 0; i < N; i++) // K no増加部分列を調べてみる { K[P[i] - 1] = i; } int zouka = 0; int num = 0; for (int i = 0; i < N - 1; i++) { if (K[i] < K[i + 1]) num++; else { zouka = Max(zouka, num); num = 0; } } zouka = Max(zouka, num); WriteLine(N - zouka - 1); // } }
[["+", 0, 195, 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, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
203
9
using System; using System.Collections; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Threading.Tasks; class Program { // Main static void Main(string[] args) { //読み込む string S = Console.ReadLine(); int N = int.Parse(S); int[] Pn = new int[N]; for (int i = 0; i < N; i++) { //インデックスがややこしくならないように、最初から-1しておく int p = int.Parse(Console.ReadLine()) - 1; Pn[i] = p; } //数列Qnを作成 /* 各インデックスiについて、Pnでiが何番目に位置していたかを示す数列 e.g. Qn[3] = 6のとき、 Pnでは、3という数字は6番目に位置していた (即ち、Pn[6] = 3だった) */ int[] Qn = new int[N]; for (int i = 0; i < N; i++) { Qn[Pn[i]] = i; } // Qnの中で、連続して単調増加しているうち最長の部分を求めれば良い /* cf. LSIとは違い、増加部分が連続(数列内で隣接)している必要あり */ int max = 1; int cnt = 1; for (int i = 1; i < N; i++) { //連続部分が単調増加の場合 if (Qn[i] > Qn[i - 1]) { cnt++; } //そうではない場合 else { if (cnt > max) { max = cnt; } //初期化 cnt = 1; } } int ans = N - max; Console.WriteLine(ans); } }
using System; using System.Collections; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Threading.Tasks; class Program { // Main static void Main(string[] args) { //読み込む string S = Console.ReadLine(); int N = int.Parse(S); int[] Pn = new int[N]; for (int i = 0; i < N; i++) { //インデックスがややこしくならないように、最初から-1しておく int p = int.Parse(Console.ReadLine()) - 1; Pn[i] = p; } //数列Qnを作成 /* 各インデックスiについて、Pnでiが何番目に位置していたかを示す数列 e.g. Qn[3] = 6のとき、 Pnでは、3という数字は6番目に位置していた (即ち、Pn[6] = 3だった) */ int[] Qn = new int[N]; for (int i = 0; i < N; i++) { Qn[Pn[i]] = i; } // Qnの中で、連続して単調増加しているうち最長の部分を求めれば良い /* cf. LSIとは違い、増加部分が連続(数列内で隣接)している必要あり */ int max = 1; int cnt = 1; for (int i = 1; i < N; i++) { //連続部分が単調増加の場合 if (Qn[i] > Qn[i - 1]) { cnt++; } //そうではない場合 else { if (cnt > max) { max = cnt; } //初期化 cnt = 1; } } //最後まで増加した場合、改めてmaxの更新を確認する必要あり if (cnt > max) { max = cnt; } int ans = N - max; 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, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 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, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
253
12
using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.Contracts; using System.IO; using System.Linq; using System.Numerics; using System.Xml.Schema; using System.Threading; using System.Diagnostics.CodeAnalysis; using System.Security.Cryptography; using System.IO.Pipes; using Microsoft.Win32; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); } public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); } public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); } public static int BuildBitCount(this int bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } 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>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); 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 = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } class Comparable : IComparable<Comparable> { public Comparable(int value) { this.value = value; } public int value; public int CompareTo(Comparable c) { return this.value < c.value ? 1 : this.value == c.value ? 0 : -1; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { int N = GetInt(); var P = new int [N] .Select((_, index) => new { value = GetInt(), index }) .ToDictionary(d => d.value, d => d.index + 1); var max = 0; int cnt = 1; for (int i = 2; i <= N; i++) { if (P[i] > P[i - 1]) cnt++; else { max = Math.Max(cnt, max); cnt = 1; } } Console.WriteLine(N - max); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics.Contracts; using System.IO; using System.Linq; using System.Numerics; using System.Xml.Schema; using System.Threading; using System.Diagnostics.CodeAnalysis; using System.Security.Cryptography; using System.IO.Pipes; using Microsoft.Win32; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); } public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); } public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); } public static int BuildBitCount(this int bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } 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>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); 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 = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } class Comparable : IComparable<Comparable> { public Comparable(int value) { this.value = value; } public int value; public int CompareTo(Comparable c) { return this.value < c.value ? 1 : this.value == c.value ? 0 : -1; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { int N = GetInt(); var P = new int [N] .Select((_, index) => new { value = GetInt(), index }) .ToDictionary(d => d.value, d => d.index + 1); var max = 0; int cnt = 1; for (int i = 2; i <= N; i++) { if (P[i] > P[i - 1]) cnt++; else { max = Math.Max(cnt, max); cnt = 1; } } max = Math.Max(cnt, max); Console.WriteLine(N - max); } } }
[["+", 0, 195, 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], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
2,048
11
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; static public string al = "abcdefghijklmnopqrstuvwxyz"; public static void Main() { // 方針 // var n = rint(); var list = new int[n]; var num = new int[n]; for (int i = 0; i < n; i++) { list[i] = rint(); num[i] = i; } Array.Sort(list, num); // WriteLine(string.Join(" ",list)); // WriteLine(string.Join(" ",num)); var now = num[0]; var count = 1; var max = 0; for (int i = 1; i < n; i++) { if (num[i] > now) { count++; } else { max = Max(max, count); count = 1; } now = num[i]; if (i == n - 1) max = Max(max, count); } WriteLine(n - max); } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { if (n < r) return 0; r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = 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; static public string al = "abcdefghijklmnopqrstuvwxyz"; public static void Main() { // 方針 // var n = rint(); var list = new int[n]; var num = new int[n]; for (int i = 0; i < n; i++) { list[i] = rint(); num[i] = i; } Array.Sort(list, num); // WriteLine(string.Join(" ",list)); // WriteLine(string.Join(" ",num)); var now = num[0]; var count = 1; var max = 0; for (int i = 1; i < n; i++) { if (num[i] > now) { count++; } else { max = Max(max, count); count = 1; } now = num[i]; if (i == n - 1) max = Max(max, count); } if (n == 1) max = 1; WriteLine(n - max); } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { if (n < r) return 0; r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = 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(); } } }
[["+", 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], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
1,268
10
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.D { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Scanner cin = new Scanner(); int n = cin.NextInt(); var a = new List<Pair<int, int>>(); for (int i = 0; i < n; i++) { int x = cin.NextInt(); a.Add(new Pair<int, int>(x, i)); } a.Sort(); int maxascend = 1; int now = 1; int prev = a[0].second; for (int i = 1; i < n; i++) { if (a[i].second > prev) now++; else { maxascend = Math.Max(now, maxascend); now = 1; } prev = a[i].second; } Console.WriteLine(n - maxascend); Console.Out.Flush(); } } public class Pair<T, U> : IComparable, IEquatable<Pair<T, U>> where T : IComparable<T>, IEquatable<T> where U : IComparable<U>, IEquatable<U> { public T first; public U second; public Pair(T first, U second) { this.first = first; this.second = second; } public int CompareTo(object obj) { Pair<T, U> castedObj = (Pair<T, U>)obj; int x = first.CompareTo(castedObj.first); if (x != 0) return x; else return second.CompareTo(castedObj.second); } public static bool operator ==(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) == 0; public static bool operator !=(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) != 0; public static bool operator<(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) == 1; public static bool operator>(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) == -1; public static bool operator <=(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) > 0; public static bool operator >=(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) < 0; public bool Equals(Pair<T, U> x) => first.Equals(x.first) && second.Equals(x.second); /*public override bool Equals(object obj) { return obj is Pair<T, U> pair && EqualityComparer<T>.Default.Equals(first, pair.first) && EqualityComparer<U>.Default.Equals(second, pair.second); } public override int GetHashCode() { unchecked { var hashCode = 405212230; hashCode = hashCode * -1521134295 + EqualityComparer<T>.Default.GetHashCode(first); hashCode = hashCode * -1521134295 + EqualityComparer<U>.Default.GetHashCode(second); return hashCode; } }*/ } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
using System; using System.IO; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Contest.D { static class Program { public static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Scanner cin = new Scanner(); int n = cin.NextInt(); var a = new List<Pair<int, int>>(); for (int i = 0; i < n; i++) { int x = cin.NextInt(); a.Add(new Pair<int, int>(x, i)); } a.Sort(); int maxascend = 1; int now = 1; int prev = a[0].second; for (int i = 1; i < n; i++) { if (a[i].second > prev) now++; else { maxascend = Math.Max(now, maxascend); now = 1; } prev = a[i].second; } maxascend = Math.Max(now, maxascend); Console.WriteLine(n - maxascend); Console.Out.Flush(); } } public class Pair<T, U> : IComparable, IEquatable<Pair<T, U>> where T : IComparable<T>, IEquatable<T> where U : IComparable<U>, IEquatable<U> { public T first; public U second; public Pair(T first, U second) { this.first = first; this.second = second; } public int CompareTo(object obj) { Pair<T, U> castedObj = (Pair<T, U>)obj; int x = first.CompareTo(castedObj.first); if (x != 0) return x; else return second.CompareTo(castedObj.second); } public static bool operator ==(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) == 0; public static bool operator !=(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) != 0; public static bool operator<(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) == 1; public static bool operator>(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) == -1; public static bool operator <=(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) > 0; public static bool operator >=(Pair<T, U> x, Pair<T, U> y) => x.CompareTo(y) < 0; public bool Equals(Pair<T, U> x) => first.Equals(x.first) && second.Equals(x.second); /*public override bool Equals(object obj) { return obj is Pair<T, U> pair && EqualityComparer<T>.Default.Equals(first, pair.first) && EqualityComparer<U>.Default.Equals(second, pair.second); } public override int GetHashCode() { unchecked { var hashCode = 405212230; hashCode = hashCode * -1521134295 + EqualityComparer<T>.Default.GetHashCode(first); hashCode = hashCode * -1521134295 + EqualityComparer<U>.Default.GetHashCode(second); return hashCode; } }*/ } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string Next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return Next(); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = NextInt() + add; } return Array; } public long NextLong() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = NextLong() + add; } return Array; } public double NextDouble() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = NextDouble() + add; } return Array; } } }
[["+", 0, 195, 8, 196, 0, 1, 0, 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], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
969
11
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var N = Int1; var P = VerticalRead(N); var q = new int[N]; for (int i = 0; i < N; ++i) { if (P[i] == 0) q[P[i]] = 1; else q[P[i] - 1] = q[P[i] - 2] + 1; } Write(N - q.Max()); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = n; i >= n - r + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Numerics; using System.IO; using System.Runtime.InteropServices; using static System.Math; using static Math2; using static io; using static Utils; public class CompetitiveProgramming { public void Solve() { var N = Int1; var P = VerticalRead(N).Select(x => x - 1).ToArray(); var q = new int[N]; for (int i = 0; i < N; ++i) { if (P[i] == 0) q[P[i]] = 1; else q[P[i]] = q[P[i] - 1] + 1; } Write(N - q.Max()); } } public static class Math2 { public const int INF = 1 << 29; public const long INFL = 1L << 60; public const long MOD = 1000000007; public const int MOD2 = 998244353; public static long Power(long a, long b, long MOD = 1000000007) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } public static long Power2(long a, long b) // i^N { long res = 1; while (b > 0) { if ((b & 1) != 0) res = res * a; a = a * a; b >>= 1; } return res; } public static long GCD(long a, long b) { while (b > 0) { var r = a % b; a = b; b = r; } return a; } public static long LCM(long a, long b) => (b / GCD(a, b)) * a; public static long Comb(long n, long r, int MOD = 1000000007) { long ret = 1; long x = 1; for (long i = n; i >= n - r + 1; --i) { ret = ret / x * i; ret %= MOD; x++; } return ret; } public static long Comb2(long n, long r) { long Nume = 1; long Deno = 1; if (r > n - r) r = n - r; for (long i = 1; i <= r; ++i) { Deno *= i; Nume *= n - i + 1; } return Nume / Deno; } } public static class Utils { public static void Swap<T>(ref T A, ref T B) { T x = A; A = B; B = x; } public static int DigitSum(int N) { string s = N.ToString(); int ret = 0; for (int i = 0; i < s.Length; ++i) ret += s[i] - '0'; return ret; } } class Program { static void Main(string[] args) { var CompetitiveProgramming = new CompetitiveProgramming(); CompetitiveProgramming.Solve(); } } public static class io { public static string Str => Console.ReadLine(); public static string[] Strs => Str.Split(' '); public static long[] Longs => Strs.Select(long.Parse).ToArray(); public static int[] Ints => Strs.Select(int.Parse).ToArray(); public static char[] Chars => Str.ToArray(); public static double[] Doubles => Strs.Select(double.Parse).ToArray(); public static long Long1 => Longs[0]; public static int Int1 => Ints[0]; public static char Char1 => Chars[0]; public static double Double1 => Doubles[0]; public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; } public static void Write(string a) => Console.WriteLine(a); public static void Write(params object[] i) => Write(string.Join(" ", i)); public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a)); public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); } public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); } }
[["+", 0, 213, 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, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 205, 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, 33], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 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, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
982
17
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; // const int M = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n = sc.Int; var a = new int[n]; var dp = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.Int - 1; if (a[i] > 0) dp[a[i]] = dp[a[i] - 1] + 1;; } Prt(n - dp.Max()); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2); public override string ToString() => v1 + " " + v2; } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2); public static T sqr<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long[n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double[n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double a, double[] x) { int n = x.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i]; return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static double[][] mul(double a, double[][] A) { int n = A.Length; var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static long[][] mul(long a, long[][] A) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long[n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; // const int M = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n = sc.Int; var a = new int[n]; var dp = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.Int - 1; if (a[i] > 0) dp[a[i]] = dp[a[i] - 1] + 1; else dp[0] = 1; } Prt(n - dp.Max()); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2); public override string ToString() => v1 + " " + v2; } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2); public static T sqr<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long[n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double[n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double a, double[] x) { int n = x.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i]; return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static double[][] mul(double a, double[][] A) { int n = A.Length; var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static long[][] mul(long a, long[][] A) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long[n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
[["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 57, 75, 1, 0, 11, 31, 204, 205, 22], ["+", 75, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 75, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 12, 203]]
8
4,296
7
using System; using System.Linq; using System.Diagnostics; using System.Collections.Generic; using static System.Math; class P { static void Main() { int n = int.Parse(Console.ReadLine()); int[] p = Enumerable.Repeat(0, n) .Select(_ => int.Parse(Console.ReadLine())) .ToArray(); int[] index = new int[p.Length]; for (int i = 0; i < p.Length; i++) { index[p[i] - 1] = i; } //ある中心から順々に下ってる場合は嬉しい //中心の数字を決めます //中心の数字から上が全て順、または下が全て順であれば、逆側をもう一度やり直すだけ //それより上が順だったら?一番上を中心にすればいいだけ //昇順の最大まで求める //前より後ろよりを組み合わせると効率的にできる? //真ん中の方の連続列でもOK 連続列ならね // LIS(only +1) int count = 1; int max = 0; for (int i = 1; i < index.Length; i++) { if (index[i - 1] > index[i]) { max = Max(max, count); count = 0; } count++; } Console.WriteLine(n - max); } }
using System; using System.Linq; using System.Diagnostics; using System.Collections.Generic; using static System.Math; class P { static void Main() { int n = int.Parse(Console.ReadLine()); int[] p = Enumerable.Repeat(0, n) .Select(_ => int.Parse(Console.ReadLine())) .ToArray(); int[] index = new int[p.Length]; for (int i = 0; i < p.Length; i++) { index[p[i] - 1] = i; } //ある中心から順々に下ってる場合は嬉しい //中心の数字を決めます //中心の数字から上が全て順、または下が全て順であれば、逆側をもう一度やり直すだけ //それより上が順だったら?一番上を中心にすればいいだけ //昇順の最大まで求める //前より後ろよりを組み合わせると効率的にできる? //真ん中の方の連続列でもOK 連続列ならね // LIS(only +1) int count = 1; int max = 0; for (int i = 1; i < index.Length; i++) { if (index[i - 1] > index[i]) { max = Max(max, count); count = 0; } count++; } max = Max(max, count); Console.WriteLine(n - max); } }
[["+", 0, 195, 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, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
205
9
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { int N = re.i(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[re.i() - 1] = i; } int max = 0; int p = 1; for (int i = 1; i < N; i++) { if (A[i] > A[i - 1]) { p++; } else { max = Math.Max(max, p); p = 1; } } int count = N - max; sb.Append(count + "\n"); } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; class Solve { public Solve() {} StringBuilder sb; ReadData re; public static int Main() { new Solve().Run(); return 0; } void Run() { sb = new StringBuilder(); re = new ReadData(); Calc(); Console.Write(sb.ToString()); } void Calc() { int N = re.i(); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[re.i() - 1] = i; } int max = 1; int p = 1; for (int i = 1; i < N; i++) { if (A[i] > A[i - 1]) { p++; } else { max = Math.Max(max, p); p = 1; } } max = Math.Max(max, p); int count = N - max; sb.Append(count + "\n"); } } class ReadData { string[] str; int counter; public ReadData() { counter = 0; } public string s() { if (counter == 0) { str = Console.ReadLine().Split(' '); counter = str.Length; } counter--; return str[str.Length - counter - 1]; } public int i() { return int.Parse(s()); } public long l() { return long.Parse(s()); } public double d() { return double.Parse(s()); } public int[] ia(int N) { int[] ans = new int[N]; for (int j = 0; j < N; j++) { ans[j] = i(); } return ans; } public int[] ia() { str = Console.ReadLine().Split(' '); counter = 0; int[] ans = new int[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = int.Parse(str[j]); } return ans; } public long[] la(int N) { long[] ans = new long[N]; for (int j = 0; j < N; j++) { ans[j] = l(); } return ans; } public long[] la() { str = Console.ReadLine().Split(' '); counter = 0; long[] ans = new long[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = long.Parse(str[j]); } return ans; } public double[] da(int N) { double[] ans = new double[N]; for (int j = 0; j < N; j++) { ans[j] = d(); } return ans; } public double[] da() { str = Console.ReadLine().Split(' '); counter = 0; double[] ans = new double[str.Length]; for (int j = 0; j < str.Length; j++) { ans[j] = double.Parse(str[j]); } return ans; } public List<int>[] g(int N, int[] f, int[] t) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < f.Length; j++) { ans[f[j]].Add(t[j]); ans[t[j]].Add(f[j]); } return ans; } public List<int>[] g(int N, int M) { List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } public List<int>[] g() { int N = i(); int M = i(); List<int>[] ans = new List<int>[N]; for (int j = 0; j < N; j++) { ans[j] = new List<int>(); } for (int j = 0; j < M; j++) { int f = i() - 1; int t = i() - 1; ans[f].Add(t); ans[t].Add(f); } return ans; } } public static class Define { public const long mod = 1000000007; } public static class Debug { public static void Print(double[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(double[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(double[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(long[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(long[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(long[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } public static void Print(int[,,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { for (int l = 0; l < k.GetLength(2); l++) { Console.Write(k[i, j, l] + " "); } Console.WriteLine(); } Console.WriteLine(); } } public static void Print(int[,] k) { for (int i = 0; i < k.GetLength(0); i++) { for (int j = 0; j < k.GetLength(1); j++) { Console.Write(k[i, j] + " "); } Console.WriteLine(); } } public static void Print(int[] k) { for (int i = 0; i < k.Length; i++) { Console.WriteLine(k[i]); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 195, 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], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
1,795
13
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace AGC024C { class Program { static void Main(string[] args) { var N = RInt; var A = RIntsC(N); if (A[0] != 0) { Console.WriteLine(-1); return; } long count = 0; for (int i = 0; i < N - 1; i++) { if (A[i] < A[i + 1]) count += A[i + 1] - A[i]; else count += A[i + 1]; } Console.WriteLine(count); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } public struct Mlong { long _v; const long mod = 1000000007; public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; } public static implicit operator Mlong(long _x) => new Mlong(_x); public static implicit operator long(Mlong _x) => _x._v; public static Mlong operator +(Mlong m1, Mlong m2) { long m = m1._v + m2._v; return m >= mod ? m - mod : m; } public static Mlong operator -(Mlong m1, Mlong m2) { long m = m1._v - m2._v; return m >= 0 ? m : m + mod; } public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod; public static Mlong operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod; public static long ModPow(long a, long n) { if (n == 0) return 1; else if (n % 2 == 1) return a * ModPow(a, n - 1) % mod; else return ModPow(a * a, n / 2); } static Mlong[] fac, finv, inv; public static void nCkInit(int max) { fac = new Mlong[max]; finv = new Mlong[max]; inv = new Mlong[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i; inv[i] = mod - inv[mod % i] * (mod / i); finv[i] = finv[i - 1] * inv[i]; } } public static Mlong nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } } static class Debug { static public void Draw2D<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D<T>(T[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace AGC024C { class Program { static void Main(string[] args) { var N = RInt; var A = RIntsC(N); if (A[0] > 0) { Console.WriteLine(-1); return; } long count = 0; for (int i = 0; i < N - 1; i++) { if (A[i] < A[i + 1]) { count += A[i + 1] - A[i]; if (A[i + 1] - A[i] > 1) { Console.WriteLine(-1); return; } } else { count += A[i + 1]; } } Console.WriteLine(count); } } } namespace Assistant { static class Input { static List<string> line = new List<string>(); static int index = 0; static String RNext() { if (line.Count <= index) line.AddRange(Console.ReadLine().Split()); return line[index++]; } public static int RInt => int.Parse(RNext()); public static long RLong => long.Parse(RNext()); public static int[] RInts => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static long[] RLongs => Console.ReadLine().Split().Select(long.Parse).ToArray(); public static string RString => RNext(); //以下未テスト public static int[] RIntsC(int c) => Enumerable.Repeat(0, c).Select(x => int.Parse(RNext())).ToArray(); public static long[] RLongsC(int c) => Enumerable.Repeat(0, c).Select(x => long.Parse(RNext())).ToArray(); public static char[][] RMap(int h) => Enumerable.Repeat(0, h) .Select(x => Console.ReadLine().ToCharArray()) .ToArray(); } public struct Mlong { long _v; const long mod = 1000000007; public Mlong(long n = 0) : this() { _v = n >= mod ? n % mod : n; } public static implicit operator Mlong(long _x) => new Mlong(_x); public static implicit operator long(Mlong _x) => _x._v; public static Mlong operator +(Mlong m1, Mlong m2) { long m = m1._v + m2._v; return m >= mod ? m - mod : m; } public static Mlong operator -(Mlong m1, Mlong m2) { long m = m1._v - m2._v; return m >= 0 ? m : m + mod; } public static Mlong operator *(Mlong m1, Mlong m2) => m1._v * m2._v % mod; public static Mlong operator /(Mlong m1, Mlong m2) => m1._v * ModPow(m2._v, mod - 2) % mod; public static long ModPow(long a, long n) { if (n == 0) return 1; else if (n % 2 == 1) return a * ModPow(a, n - 1) % mod; else return ModPow(a * a, n / 2); } static Mlong[] fac, finv, inv; public static void nCkInit(int max) { fac = new Mlong[max]; finv = new Mlong[max]; inv = new Mlong[max]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < max; i++) { fac[i] = fac[i - 1] * i; inv[i] = mod - inv[mod % i] * (mod / i); finv[i] = finv[i - 1] * inv[i]; } } public static Mlong nCk(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } } static class Debug { static public void Draw2D<T>(T[,] map, int mode = 1) { #if DEBUG int W = map.GetLength(0); int H = map.GetLength(1); string[,] map2 = new string[W + 1, H + 1]; for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (i == 0 && j == 0) map2[i, j] = 0.ToString(); else if (i == 0) map2[i, j] = (j - 1).ToString(); else if (j == 0) map2[i, j] = (i - 1).ToString(); else map2[i, j] = map[i - 1, j - 1].ToString(); } } for (int i = 0; i < W + 1; i++) { for (int j = 0; j < H + 1; j++) { if (mode == 0) Console.Write(map2[i, j].Last()); if (mode == 1) Console.Write(map2[i, j] + " "); } Console.WriteLine(); } Console.WriteLine(); #endif } public static void Draw1D<T>(T[] array, int mode = 0) { #if DEBUG Console.WriteLine(string.Join(" ", array)); #endif } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 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, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 204, 205, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 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, 241, 0, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 64, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,209
34
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200227.Cin; using static _20200227.Util; using Pair = _20200227.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200227 { public class Program { public static void Main(string[] args) { // Abc089_B(); 4m // Arc090_A(); 10m // Abc133_C(); 24m // Abc075_C(); 42m Agc024_C(); } public static void Agc024_C() { long N = rl; long[] A = new long[N]; for (int i = 0; i < N; i++) { A[i] = rl; } if (A[0] != 0) { Console.WriteLine(-1); return; } long ans = 0; for (int i = 1; i < N; i++) { if (A[i - 1] - A[i] > 1) { Console.WriteLine(-1); return; } if (A[i] == A[i - 1] + 1) { ans += 1; } else { ans += A[i]; } } Console.WriteLine(ans); } public static void Abc075_C() { long N = rl; long M = rl; Pair[] edges = new Pair[M]; List<long>[] edgeIndexes = new List<long>[N]; for (int i = 0; i < N; i++) { edgeIndexes[i] = new List<long>(); } for (int i = 0; i < M; i++) { long a = rl - 1; long b = rl - 1; edges[i] = new Pair(a, b); edgeIndexes[a].Add(i); edgeIndexes[b].Add(i); } long ans = 0; for (int skipEdge = 0; skipEdge < M; skipEdge++) { bool[] vis = new bool[N]; Queue<long> q = new Queue<long>(); q.Enqueue(0); while (q.Any()) { var v = q.Dequeue(); vis[v] = true; foreach (var ei in edgeIndexes[v]) { if (ei == skipEdge) continue; var e = edges[ei]; var nv = e.First + e.Second - v; if (!vis[nv]) q.Enqueue(nv); } } if (vis.Any(b => !b)) ans++; } Console.WriteLine(ans); } public static void Abc133_C() { long L = rl; long R = rl; if (R - L + 1 >= 2019) { Console.WriteLine(0); } else { long min = INF; for (int l = (int)L; l < R; l++) { for (int r = l + 1; r <= R; r++) { ChMin(ref min, ((l % 2019) * (r % 2019)) % 2019); } } Console.WriteLine(min); } } public static void Arc090_A() { long N = rl; long[] A = rla; long[] B = rla; A = Accumulate(A); B = Accumulate(B); long max = 0; for (int i = 1; i <= N; i++) { ChMax(ref max, A[i] + B[N] - B[i - 1]); } Console.WriteLine(max); } public static void Abc089_B() { long N = rl; HashSet<string> hs = new HashSet<string>(); for (int i = 0; i < N; i++) { hs.Add(rs); } if (hs.Count == 3) { Console.WriteLine("Three"); } else { Console.WriteLine("Four"); } } } public struct VTuple<T1, T2> : IComparable<VTuple<T1, T2>>, IEquatable<VTuple<T1, T2>> { public T1 First; public T2 Second; public VTuple(T1 a, T2 b) { First = a; Second = b; } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(First, a.First); if (b != 0) return b; return Comparer<T2>.Default.Compare(Second, a.Second); } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(First, a.First) && EqualityComparer<T2>.Default.Equals(Second, a.Second); } public override int GetHashCode() { int a = First != null ? First.GetHashCode() : 0; int b = Second != null ? Second.GetHashCode() : 0; uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } } public class HashMap<K, V> : Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static int ReadInt() { return int.Parse(k()); } public static long ReadLong() { return long.Parse(k()); } public static double ReadDouble() { return double.Parse(k()); } public static string ReadString() { return k(); } public static int[] ReadIntArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[][] ReadIntTable(int a) { i = null; int[][] b = new int [a][]; for (int c = 0; c < a; c++) b[c] = ReadIntArray(); return b; } public static long[][] ReadLongTable(long a) { i = null; long[][] b = new long [a][]; for (long c = 0; c < a; c++) b[c] = ReadLongArray(); return b; } static string[] i { get; set; } static int j { get; set; } static string k() { if (i == null || i.Length <= j) { i = Console.ReadLine().Split(' '); j = 0; } return i[j++]; } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Math; using static _20200227.Cin; using static _20200227.Util; using Pair = _20200227.VTuple<long, long>; using Graph = System.Collections.Generic.List<System.Collections.Generic.List<long>>; using System.Text; namespace _20200227 { public class Program { public static void Main(string[] args) { // Abc089_B(); 4m // Arc090_A(); 10m // Abc133_C(); 24m // Abc075_C(); 42m Agc024_C(); } public static void Agc024_C() { long N = rl; long[] A = new long[N]; for (int i = 0; i < N; i++) { A[i] = rl; } if (A[0] != 0) { Console.WriteLine(-1); return; } long ans = 0; for (int i = 1; i < N; i++) { if (A[i] - A[i - 1] > 1) { Console.WriteLine(-1); return; } if (A[i] == A[i - 1] + 1) { ans += 1; } else { ans += A[i]; } } Console.WriteLine(ans); } public static void Abc075_C() { long N = rl; long M = rl; Pair[] edges = new Pair[M]; List<long>[] edgeIndexes = new List<long>[N]; for (int i = 0; i < N; i++) { edgeIndexes[i] = new List<long>(); } for (int i = 0; i < M; i++) { long a = rl - 1; long b = rl - 1; edges[i] = new Pair(a, b); edgeIndexes[a].Add(i); edgeIndexes[b].Add(i); } long ans = 0; for (int skipEdge = 0; skipEdge < M; skipEdge++) { bool[] vis = new bool[N]; Queue<long> q = new Queue<long>(); q.Enqueue(0); while (q.Any()) { var v = q.Dequeue(); vis[v] = true; foreach (var ei in edgeIndexes[v]) { if (ei == skipEdge) continue; var e = edges[ei]; var nv = e.First + e.Second - v; if (!vis[nv]) q.Enqueue(nv); } } if (vis.Any(b => !b)) ans++; } Console.WriteLine(ans); } public static void Abc133_C() { long L = rl; long R = rl; if (R - L + 1 >= 2019) { Console.WriteLine(0); } else { long min = INF; for (int l = (int)L; l < R; l++) { for (int r = l + 1; r <= R; r++) { ChMin(ref min, ((l % 2019) * (r % 2019)) % 2019); } } Console.WriteLine(min); } } public static void Arc090_A() { long N = rl; long[] A = rla; long[] B = rla; A = Accumulate(A); B = Accumulate(B); long max = 0; for (int i = 1; i <= N; i++) { ChMax(ref max, A[i] + B[N] - B[i - 1]); } Console.WriteLine(max); } public static void Abc089_B() { long N = rl; HashSet<string> hs = new HashSet<string>(); for (int i = 0; i < N; i++) { hs.Add(rs); } if (hs.Count == 3) { Console.WriteLine("Three"); } else { Console.WriteLine("Four"); } } } public struct VTuple<T1, T2> : IComparable<VTuple<T1, T2>>, IEquatable<VTuple<T1, T2>> { public T1 First; public T2 Second; public VTuple(T1 a, T2 b) { First = a; Second = b; } public int CompareTo(VTuple<T1, T2> a) { int b = Comparer<T1>.Default.Compare(First, a.First); if (b != 0) return b; return Comparer<T2>.Default.Compare(Second, a.Second); } public override bool Equals(object a) { return a is VTuple<T1, T2> && Equals((VTuple<T1, T2>)a); } public bool Equals(VTuple<T1, T2> a) { return EqualityComparer<T1>.Default.Equals(First, a.First) && EqualityComparer<T2>.Default.Equals(Second, a.Second); } public override int GetHashCode() { int a = First != null ? First.GetHashCode() : 0; int b = Second != null ? Second.GetHashCode() : 0; uint c = ((uint)a << 5) | ((uint)a >> 27); return ((int)c + a) ^ b; } } public class HashMap<K, V> : Dictionary<K, V> { V i; static Func<V> j = System.Linq.Expressions.Expression .Lambda<Func<V>>(System.Linq.Expressions.Expression.New(typeof(V))) .Compile(); public HashMap() {} public HashMap(V a) { i = a; } new public V this[K a] { get { V b; if (TryGetValue(a, out b)) return b; else return base[a] = i != null ? i : j(); } set { base[a] = value; } } } public static class Util { public static readonly long INF = (long)1e17; public readonly static long MOD = (long)1e9 + 7; public readonly static int[] DXY4 = { 0, 1, 0, -1, 0 }; public readonly static int[] DXY8 = { 1, 1, 0, 1, -1, 0, -1, -1, 1 }; public static void DontAutoFlush() { var a = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(a); } public static void Flush() { Console.Out.Flush(); } public static T[] Sort<T>(T[] a) { Array.Sort<T>(a); return a; } public static T[] SortDecend<T>(T[] a) { Array.Sort<T>(a); Array.Reverse(a); return a; } public static void Swap<T>(ref T a, ref T b) { T c = a; a = b; b = c; } public static int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); } public static void ChMax(ref long a, long b) { if (a < b) a = b; } public static void ChMin(ref long a, long b) { if (a > b) a = b; } public static long ModAdd(long a, long b) { long c = a + b; if (c >= MOD) return c % MOD; return c; } public static long ModMul(long a, long b) { long c = a * b; if (c >= MOD) return c % MOD; return c; } public static void ChModAdd(ref long a, long b) { a += b; if (a >= MOD) a %= MOD; } public static void ChModMul(ref long a, long b) { a *= b; if (a >= MOD) a %= MOD; } public static void FillArray<T>(T[] a, T b) { int c = a.Length; for (int d = 0; d < c; d++) a[d] = b; } public static void FillArray<T>(T[,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); for (int e = 0; e < c; e++) for (int f = 0; f < d; f++) { a[e, f] = b; } } public static void FillArray<T>(T[,,] a, T b) { int c = a.GetLength(0); int d = a.GetLength(1); int e = a.GetLength(2); for (int f = 0; f < c; f++) for (int g = 0; g < d; g++) { for (int h = 0; h < e; h++) { a[f, g, h] = b; } } } public static long[] Accumulate(long[] a) { long[] b = new long[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } public static double[] Accumulate(double[] a) { double[] b = new double[a.Length + 1]; for (int c = 0; c < a.Length; c++) b[c + 1] = b[c] + a[c]; return b; } } public static class Cin { public static long rl { get { return ReadLong(); } } public static long[] rla { get { return ReadLongArray(); } } public static double rd { get { return ReadDouble(); } } public static double[] rda { get { return ReadDoubleArray(); } } public static string rs { get { return ReadString(); } } public static int ReadInt() { return int.Parse(k()); } public static long ReadLong() { return long.Parse(k()); } public static double ReadDouble() { return double.Parse(k()); } public static string ReadString() { return k(); } public static int[] ReadIntArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); } public static long[] ReadLongArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); } public static double[] ReadDoubleArray() { i = null; return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse); } public static void ReadCols(out long[] a, out long[] b, long c) { a = new long[c]; b = new long[c]; for (int d = 0; d < c; d++) { a[d] = ReadLong(); b[d] = ReadLong(); } } public static void ReadCols(out long[] a, out long[] b, out long[] c, long d) { a = new long[d]; b = new long[d]; c = new long[d]; for (int e = 0; e < d; e++) { a[e] = ReadLong(); b[e] = ReadLong(); c[e] = ReadLong(); } } public static int[][] ReadIntTable(int a) { i = null; int[][] b = new int [a][]; for (int c = 0; c < a; c++) b[c] = ReadIntArray(); return b; } public static long[][] ReadLongTable(long a) { i = null; long[][] b = new long [a][]; for (long c = 0; c < a; c++) b[c] = ReadLongArray(); return b; } static string[] i { get; set; } static int j { get; set; } static string k() { if (i == null || i.Length <= j) { i = Console.ReadLine().Split(' '); j = 0; } return i[j++]; } } }
[["-", 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, 17, 33], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
2,649
4
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); long N = long.Parse(s); long[] P = new long[N]; long count = 0; string b = Console.ReadLine(); P[0] = long.Parse(b); if (P[0] > 0) { count = -1; } else { for (var i = 1; i < N; i++) { string t = Console.ReadLine(); P[i] = long.Parse(t); if (P[i] - P[i - 1] == 1) { count += 1; } else if (P[i] - P[i - 1] >= 2) { count += P[i] / (P[i - 1] + 1) + P[i] % (P[i - 1] + 1); } else { count += P[i]; } } } Console.WriteLine(count); } }
using System; class Program { static void Main(string[] args) { string s = Console.ReadLine(); long N = long.Parse(s); long[] P = new long[N]; long count = 0; string b = Console.ReadLine(); P[0] = long.Parse(b); if (P[0] > 0) { count = -1; } else { for (var i = 1; i < N; i++) { string t = Console.ReadLine(); P[i] = long.Parse(t); if (P[i] - P[i - 1] == 1) { count += 1; } else if (P[i] - P[i - 1] >= 2) { count = -1; break; } else { count += P[i]; } } } Console.WriteLine(count); } }
[["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 0, 11, 12, 16, 31, 16, 31, 204, 205, 22], ["-", 12, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 85], ["-", 0, 11, 12, 16, 31, 16, 12, 23, 0, 24], ["-", 31, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["-", 12, 23, 0, 16, 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, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["-", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 11, 12, 16, 31, 16, 12, 23, 0, 25], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 0, 11, 12, 16, 12, 16, 31, 204, 205, 22], ["-", 12, 16, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 16, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 17, 109], ["-", 0, 11, 12, 16, 12, 16, 12, 23, 0, 24], ["-", 12, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 12, 16, 12, 16, 12, 23, 0, 16, 17, 72], ["-", 12, 16, 12, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 11, 12, 16, 12, 16, 12, 23, 0, 25], ["+", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 57, 64, 196, 0, 93, 0, 94]]
8
222
33
using System; using System.Collections.Generic; using System.Linq; class Solution { static void Main() { var n = int.Parse(Console.ReadLine()); var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(Console.ReadLine()); } long ope = 0; var right = -1; for (int i = n - 1; i >= 0; i--) { if (a[i] > i) { ope = -1; break; } if (a[i] + 1 != right) { ope += a[i]; } right = a[i]; } Console.WriteLine(ope); } }
using System; using System.Collections.Generic; using System.Linq; class Solution { static void Main() { var n = int.Parse(Console.ReadLine()); var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(Console.ReadLine()); } long ope = 0; var right = -1; for (int i = n - 1; i >= 0; i--) { if (a[i] > i) { ope = -1; break; } if (a[i] + 1 < right) { ope = -1; break; } if (a[i] + 1 != right) { ope += a[i]; } right = a[i]; } Console.WriteLine(ope); } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 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, 196, 0, 45], ["+", 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, 241, 0, 33], ["+", 64, 196, 0, 1, 0, 11, 12, 241, 0, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 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, 204, 205, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
162
20
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; namespace ReadWriteTemplate { public static class Solver { private static void SolveCase() { int n = ReadInt(); long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } if (a[0] != 0) { Writer.WriteLine(-1); return; } long max = 0; long ans = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] < max) { Writer.WriteLine(-1); return; } ans += (a[i] - max); max = a[i] - 1; } Writer.WriteLine(ans); } public static void Solve() { SolveCase(); /*var sw = Stopwatch.StartNew();*/ /*int T = ReadInt(); for (int i = 0; i < T; i++) { Writer.Write("Case #{0}: ", i + 1); SolveCase(); }*/ /*sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds);*/ } public static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; #if DEBUG // Reader = Console.In; Writer = Console.Out; Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt"); #else Reader = Console.In; Writer = Console.Out; #endif Solve(); /*Thread thread = new Thread(Solve, 64 * 1024 * 1024); thread.CurrentCulture = CultureInfo.InvariantCulture; thread.Start(); thread.Join();*/ Reader.Close(); Writer.Close(); } public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { return source.Shuffle().OrderBy(keySelector); } public static T[] Shuffle<T>(this IEnumerable<T> source) { T[] result = source.ToArray(); Random rnd = new Random(); for (int i = result.Length - 1; i >= 1; i--) { int k = rnd.Next(i + 1); T tmp = result[k]; result[k] = result[i]; result[i] = tmp; } return result; } #region Read / Write private static TextReader Reader; private static TextWriter Writer; private static Queue<string> CurrentLineTokens = new Queue<string>(); private static string[] ReadAndSplitLine() { return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); } public static string ReadToken() { while (CurrentLineTokens.Count == 0) CurrentLineTokens = new Queue<string>(ReadAndSplitLine()); return CurrentLineTokens.Dequeue(); } public static string ReadLine() { return Reader.ReadLine(); } public static int ReadInt() { return int.Parse(ReadToken()); } public static long ReadLong() { return long.Parse(ReadToken()); } public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); } public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { return ReadAndSplitLine() .Select(s => double.Parse(s, CultureInfo.InvariantCulture)) .ToArray(); } public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int [numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; } public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = Reader.ReadLine().Trim(); return lines; } public static void WriteArray<T>(IEnumerable<T> array) { Writer.WriteLine(string.Join(" ", array)); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; namespace ReadWriteTemplate { public static class Solver { private static void SolveCase() { int n = ReadInt(); long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = ReadLong(); } if (a[0] != 0) { Writer.WriteLine(-1); return; } long max = 0; long ans = 0; for (int i = n - 1; i >= 0; i--) { if (a[i] < max) { Writer.WriteLine(-1); return; } if (a[i] > max) { ans += a[i]; } max = a[i] - 1; } Writer.WriteLine(ans); } public static void Solve() { SolveCase(); /*var sw = Stopwatch.StartNew();*/ /*int T = ReadInt(); for (int i = 0; i < T; i++) { Writer.Write("Case #{0}: ", i + 1); SolveCase(); }*/ /*sw.Stop(); Console.WriteLine(sw.ElapsedMilliseconds);*/ } public static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; #if DEBUG // Reader = Console.In; Writer = Console.Out; Reader = File.OpenText("input.txt"); Writer = File.CreateText("output.txt"); #else Reader = Console.In; Writer = Console.Out; #endif Solve(); /*Thread thread = new Thread(Solve, 64 * 1024 * 1024); thread.CurrentCulture = CultureInfo.InvariantCulture; thread.Start(); thread.Join();*/ Reader.Close(); Writer.Close(); } public static IOrderedEnumerable<TSource> OrderByWithShuffle<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) { return source.Shuffle().OrderBy(keySelector); } public static T[] Shuffle<T>(this IEnumerable<T> source) { T[] result = source.ToArray(); Random rnd = new Random(); for (int i = result.Length - 1; i >= 1; i--) { int k = rnd.Next(i + 1); T tmp = result[k]; result[k] = result[i]; result[i] = tmp; } return result; } #region Read / Write private static TextReader Reader; private static TextWriter Writer; private static Queue<string> CurrentLineTokens = new Queue<string>(); private static string[] ReadAndSplitLine() { return Reader.ReadLine().Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); } public static string ReadToken() { while (CurrentLineTokens.Count == 0) CurrentLineTokens = new Queue<string>(ReadAndSplitLine()); return CurrentLineTokens.Dequeue(); } public static string ReadLine() { return Reader.ReadLine(); } public static int ReadInt() { return int.Parse(ReadToken()); } public static long ReadLong() { return long.Parse(ReadToken()); } public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); } public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); } public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); } public static double[] ReadDoubleArray() { return ReadAndSplitLine() .Select(s => double.Parse(s, CultureInfo.InvariantCulture)) .ToArray(); } public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int [numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; } public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = Reader.ReadLine().Trim(); return lines; } public static void WriteArray<T>(IEnumerable<T> array) { Writer.WriteLine(string.Join(" ", array)); } #endregion } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["-", 0, 1, 0, 11, 12, 23, 0, 16, 17, 33], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 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], ["+", 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, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
836
13
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; // const int M = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n = sc.Int; var edge = new List<int>[n]; for (int i = 0; i < n; i++) { edge[i] = new List<int>(); } var edges = new P[n - 1]; for (int i = 0; i < n - 1; i++) { int a, b; sc.Multi(out a, out b); --a; --b; edge[a].Add(b); edge[b].Add(a); edges[i] = new P(a, b); } int mincol = n; long minleaf = LM; for (int i = 0; i < n; i++) { var q = new Queue<int>(); var dist = new int[n]; var maxdeg = new int[n]; for (int j = 0; j < n; j++) { dist[j] = M; } maxdeg[0] = edge[i].Count; int maxdis = 0; dist[i] = 0; q.Enqueue(i); while (q.Any()) { int p = q.Dequeue(); foreach (var item in edge[p]) { if (dist[item] > dist[p] + 1) { dist[item] = dist[p] + 1; maxdeg[dist[item]] = Math.Max(maxdeg[dist[item]], edge[item].Count - 1); maxdis = Math.Max(maxdis, dist[item] + 1); q.Enqueue(item); } } } long leaf = 1; for (int j = 0; j < n; j++) { if (maxdeg[j] > 0) { if (leaf * (double)maxdeg[j] > LM) { leaf = LM; } else leaf *= maxdeg[j]; } } if (mincol > maxdis) { mincol = maxdis; minleaf = leaf; } else if (mincol == maxdis && minleaf > leaf) { minleaf = leaf; } } foreach (var es in edges) { var q = new Queue<int>(); var dist = new int[n]; var maxdeg = new int[n]; for (int j = 0; j < n; j++) { dist[j] = M; } int i1 = es.v1, i2 = es.v2; maxdeg[0] = Math.Max(edge[i1].Count, edge[i2].Count) - 1; int maxdis = 0; dist[i1] = 0; dist[i2] = 0; q.Enqueue(i1); q.Enqueue(i2); while (q.Any()) { int p = q.Dequeue(); foreach (var item in edge[p]) { if (dist[item] > dist[p] + 1) { dist[item] = dist[p] + 1; maxdeg[dist[item]] = Math.Max(maxdeg[dist[item]], edge[item].Count - 1); maxdis = Math.Max(maxdis, dist[item] + 1); q.Enqueue(item); } } } long leaf = 2; for (int j = 0; j < n; j++) { if (maxdeg[j] > 0) { if (leaf * (double)maxdeg[j] > LM) { leaf = LM; } else leaf *= maxdeg[j]; } } if (mincol > maxdis) { mincol = maxdis; minleaf = leaf; } else if (mincol == maxdis && minleaf > leaf) { minleaf = leaf; } } Prt(mincol, minleaf); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2); public override string ToString() => v1 + " " + v2; } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2); public static T sqr<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long[n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double[n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double a, double[] x) { int n = x.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i]; return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static double[][] mul(double a, double[][] A) { int n = A.Length; var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static long[][] mul(long a, long[][] A) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long[n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using static util; using P = pair<int, int>; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; // const int M = 998244353; const long LM = (long)1e18; const double eps = 1e-11; static readonly int[] dd = { 0, 1, 0, -1, 0 }; const string dstring = "RDLU"; static void Main() { int n = sc.Int; var edge = new List<int>[n]; for (int i = 0; i < n; i++) { edge[i] = new List<int>(); } var edges = new P[n - 1]; for (int i = 0; i < n - 1; i++) { int a, b; sc.Multi(out a, out b); --a; --b; edge[a].Add(b); edge[b].Add(a); edges[i] = new P(a, b); } int mincol = n; long minleaf = long.MaxValue; for (int i = 0; i < n; i++) { var q = new Queue<int>(); var dist = new int[n]; var maxdeg = new int[n]; for (int j = 0; j < n; j++) { dist[j] = M; } maxdeg[0] = edge[i].Count; int maxdis = 1; dist[i] = 0; q.Enqueue(i); while (q.Any()) { int p = q.Dequeue(); foreach (var item in edge[p]) { if (dist[item] > dist[p] + 1) { dist[item] = dist[p] + 1; maxdeg[dist[item]] = Math.Max(maxdeg[dist[item]], edge[item].Count - 1); maxdis = Math.Max(maxdis, dist[item] + 1); q.Enqueue(item); } } } long leaf = 1; for (int j = 0; j < n; j++) { if (maxdeg[j] > 0) { if (leaf * (double)maxdeg[j] > long.MaxValue) { leaf = long.MaxValue; } else leaf *= maxdeg[j]; } } if (mincol > maxdis) { mincol = maxdis; minleaf = leaf; } else if (mincol == maxdis && minleaf > leaf) { minleaf = leaf; } } foreach (var es in edges) { var q = new Queue<int>(); var dist = new int[n]; var maxdeg = new int[n]; for (int j = 0; j < n; j++) { dist[j] = M; } int i1 = es.v1, i2 = es.v2; maxdeg[0] = Math.Max(edge[i1].Count, edge[i2].Count) - 1; int maxdis = 1; dist[i1] = 0; dist[i2] = 0; q.Enqueue(i1); q.Enqueue(i2); while (q.Any()) { int p = q.Dequeue(); foreach (var item in edge[p]) { if (dist[item] > dist[p] + 1) { dist[item] = dist[p] + 1; maxdeg[dist[item]] = Math.Max(maxdeg[dist[item]], edge[item].Count - 1); maxdis = Math.Max(maxdis, dist[item] + 1); q.Enqueue(item); } } } long leaf = 2; for (int j = 0; j < n; j++) { if (maxdeg[j] > 0) { if (leaf * (double)maxdeg[j] > long.MaxValue) { leaf = long.MaxValue; } else leaf *= maxdeg[j]; } } if (mincol > maxdis) { mincol = maxdis; minleaf = leaf; } else if (mincol == maxdis && minleaf > leaf) { minleaf = leaf; } } Prt(mincol, minleaf); sw.Flush(); } static void DBG(string a) => Console.WriteLine(a); static void DBG<T>(IEnumerable<T> a) => DBG(string.Join(" ", a)); static void DBG(params object[] a) => DBG(string.Join(" ", a)); static void Prt(string a) => sw.WriteLine(a); static void Prt<T>(IEnumerable<T> a) => Prt(string.Join(" ", a)); static void Prt(params object[] a) => Prt(string.Join(" ", a)); } class pair<T, U> : IComparable<pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T v1; public U v2; public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) => v1.CompareTo(a.v1) != 0 ? v1.CompareTo(a.v1) : v2.CompareTo(a.v2); public override string ToString() => v1 + " " + v2; } static class util { public static pair<T, T> make_pair<T>(this IList<T> l) where T : IComparable<T> => make_pair(l[0], l[1]); public static pair<T, U> make_pair<T, U>(T v1, U v2) where T : IComparable<T> where U : IComparable<U> => new pair<T, U>(v1, v2); public static T sqr<T>(T a) => Operator<T>.Multiply(a, a); public static T Max<T>(params T[] a) => a.Max(); public static T Min<T>(params T[] a) => a.Min(); public static bool inside(int i, int j, int h, int w) => i >= 0 && i < h && j >= 0 && j < w; public static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) => Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); public static Func<T, T> Lambda(Unary op) => Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } class Scan { public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => Console.ReadLine().Trim(); public pair<T, U> Pair<T, U>() where T : IComparable<T> where U : IComparable<U> { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public string[] StrArr => Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries); bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public void Multi<T>(out T a) => a = cv<T>(Str); public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long[n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double[n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double a, double[] x) { int n = x.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i]; return ret; } public static long[] mul(long a, long[] x) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = a * x[i] % Mod; return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static double[][] mul(double a, double[][] A) { int n = A.Length; var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static long[][] mul(long a, long[][] A) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(a, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long[n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) => pow(a, Mod - 2); public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) => a / gcd(a, b) * b; static long[] facts; public static long[] setfacts(int n) { facts = new long[n + 1]; facts[0] = 1; for (int i = 0; i < n; i++) facts[i + 1] = facts[i] * (i + 1) % Mod; return facts; } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts != null && facts.Length > n) return facts[n] * inv(facts[r]) % Mod * inv(facts[n - r]) % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long[n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 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], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 214, 205, 199], ["+", 64, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 64, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 205, 199], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 141, 22]]
8
4,994
24
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; namespace cswork { class Program { class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } public Program() {} static void Main(string[] args) { new Program().Omame(); } Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } public static List<long> GeneratePrime(long max) { long prime; double sqrtMax = Math.Sqrt(max); var primeList = new List<long>(); List<long> searchList = new List<long>(); for (long i = 2; i <= max - 1; i++) { searchList.Add(i); } do { prime = searchList.First(); primeList.Add(prime); searchList.RemoveAll(n => n % prime == 0); } while (prime < sqrtMax); primeList.AddRange(searchList); return primeList; } void Omame() { cin = new Scanner(); long a = cin.nextLong(); long b = cin.nextLong(); long c = cin.nextLong(); long d = cin.nextLong(); if (a - c <= d || (a - b <= d && b - c <= d)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Text; namespace cswork { class Program { class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next(); } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } public double nextDouble() { return double.Parse(next()); } } public Program() {} static void Main(string[] args) { new Program().Omame(); } Scanner cin; const int MAXIN = 1024; bool[] used = new bool[MAXIN]; int[] perm = new int[MAXIN]; List<int[]> permList = new List<int[]>(); public void Permutation(int pos, int n, int length) { if (pos == n) { permList.Add((int[])perm.Clone()); } for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; used[i] = true; Permutation(pos + 1, n, length); used[i] = false; } } } public static List<long> GeneratePrime(long max) { long prime; double sqrtMax = Math.Sqrt(max); var primeList = new List<long>(); List<long> searchList = new List<long>(); for (long i = 2; i <= max - 1; i++) { searchList.Add(i); } do { prime = searchList.First(); primeList.Add(prime); searchList.RemoveAll(n => n % prime == 0); } while (prime < sqrtMax); primeList.AddRange(searchList); return primeList; } void Omame() { cin = new Scanner(); long a = cin.nextLong(); long b = cin.nextLong(); long c = cin.nextLong(); long d = cin.nextLong(); if (Math.Abs(a - c) <= d || (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d)) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 15, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["+", 15, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 15, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 15, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 16, 12, 16, 31, 213, 3, 4, 0, 25]]
8
589
15
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var a = cin.nextInt(); var b = cin.nextInt(); var c = cin.nextInt(); var d = cin.nextInt(); Console.WriteLine((b - a <= d && c - b <= d) ? "Yes" : "No"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { public class Solver { public void Solve() { var cin = new Scanner(); var a = cin.nextInt(); var b = cin.nextInt(); var c = cin.nextInt(); var d = cin.nextInt(); Console.WriteLine( (Math.Abs(a - c) <= d || (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d)) ? "Yes" : "No"); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public int[] DPArrayInt(int N, int ex) { int[] Array = new int[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextInt(); } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public long[] DPArrayLong(int N, int ex) { long[] Array = new long[N + ex]; for (int i = 0; i < N; i++) { Array[i] = nextLong(); } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Program { static void Main(string[] s) => new Solver().Solve(); } }
[["-", 15, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 16, 31, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 17, 19], ["+", 0, 41, 15, 23, 0, 16, 31, 16, 12, 22], ["+", 0, 28, 0, 41, 15, 23, 0, 16, 17, 106], ["+", 0, 41, 15, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 15, 23, 0, 16, 12, 16, 31, 16, 31, 22], ["-", 15, 23, 0, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 0, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 0, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 0, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 16, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 41, 15, 23, 0, 16, 12, 23, 0, 25]]
8
602
29
using System; using static System.Console; using System.Linq; namespace Main { class Program { static void Main(string[] args) { int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray(); WriteLine((tmp[1] - tmp[0] <= tmp[3] && tmp[2] - tmp[1] <= tmp[3]) || tmp[2] - tmp[0] <= tmp[3] ? "Yes" : "No"); } } }
using System; using static System.Console; using System.Linq; using static System.Math; namespace Main { class Program { static void Main(string[] args) { decimal[] tmp = ReadLine().Split(' ').Select(decimal.Parse).ToArray(); WriteLine( (Abs(tmp[1] - tmp[0]) <= tmp[3] && Abs(tmp[2] - tmp[1]) <= tmp[3]) || Abs(tmp[2] - tmp[0]) <= tmp[3] ? "Yes" : "No"); } } }
[["+", 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], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 31, 23, 0, 16, 31, 16, 31, 213, 63, 22], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 31, 213, 3, 4, 0, 25], ["+", 31, 23, 0, 16, 12, 16, 31, 213, 63, 22], ["+", 0, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 16, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 41, 15, 16, 12, 16, 31, 213, 63, 22], ["+", 15, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 15, 16, 12, 16, 31, 213, 3, 4, 0, 25]]
8
118
19
using System; namespace abc097A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int C = int.Parse(str[2]); int D = int.Parse(str[3]); int[] src = { A, B, C }; Array.Sort(src); int E = src[2] - src[1]; int F = src[1] - src[0]; int G = C - A; if ((E <= D && F <= D) || G <= D) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; namespace abc097A { class MainClass { public static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int C = int.Parse(str[2]); int D = int.Parse(str[3]); int[] src = { A, B, C }; Array.Sort(src); int E = src[2] - src[1]; int F = src[1] - src[0]; int G = C - A; if (G < 0) G = -G; if ((E <= D && F <= D) || G <= D) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 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, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 241, 0, 22], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24]]
8
178
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp34 { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int A = s[0]; int B = s[1]; int C = s[2]; int D = s[3]; if (Math.Abs(A - B) <= D || Math.Abs(C - B) <= D) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp34 { class Program { static void Main(string[] args) { var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int A = s[0]; int B = s[1]; int C = s[2]; int D = s[3]; if ((Math.Abs(A - B) <= D && Math.Abs(C - B) <= D) || Math.Abs(A - C) <= D) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 31, 23, 0, 16, 17, 98], ["+", 0, 16, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 17, 19], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 15, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
152
15
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var f = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (Math.Abs(f[1] - f[0]) <= f[3] && Math.Abs(f[2] - f[1]) <= f[3]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var f = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if ((Math.Abs(f[1] - f[0]) <= f[3] && Math.Abs(f[2] - f[1]) <= f[3]) || Math.Abs(f[2] - f[0]) <= f[3]) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 16, 12, 16, 31, 213, 3, 4, 0, 25], ["+", 15, 16, 31, 23, 0, 16, 12, 16, 17, 19], ["+", 31, 23, 0, 16, 12, 16, 12, 204, 205, 22], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 205, 22], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 0, 131], ["+", 15, 16, 12, 16, 31, 213, 63, 214, 141, 22], ["+", 15, 16, 12, 16, 31, 213, 3, 4, 0, 24], ["+", 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], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["+", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
145
22
using System; class p { static void Main() { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int d = int.Parse(input[3]); Console.WriteLine((Math.Abs(a - b) <= d) && (Math.Abs(b - c) <= d) ? "Yes" : "No"); } }
using System; class p { static void Main() { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int d = int.Parse(input[3]); Console.WriteLine(((Math.Abs(a - b) <= d) && (Math.Abs(b - c) <= d)) || (Math.Abs(a - c) <= d) ? "Yes" : "No"); } }
[["+", 15, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 12, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 19], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 15, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 28, 0, 41, 15, 16, 31, 23, 0, 25], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 106], ["+", 0, 28, 0, 41, 15, 16, 12, 23, 0, 24], ["+", 12, 23, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 12, 23, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 12, 23, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 12, 23, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22]]
8
123
15
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int[] array = sc.intarr; int a = array[0]; int b = array[1]; int c = array[2]; int d = array[3]; int dif_ab = Math.Abs(a - b); int dif_bc = Math.Abs(b - c); int dif_ca = Math.Abs(c - a); if ((dif_ab <= d && dif_bc <= d) || (dif_bc <= d && dif_ca <= d) || (dif_ca <= d && dif_ab <= d)) { wr.wri("Yes"); } else { wr.wri("No"); } } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { MainStream(); } static void MainStream() { Scan sc = new Scan(); write wr = new write(); int[] array = sc.intarr; int a = array[0]; int b = array[1]; int c = array[2]; int d = array[3]; int dif_ab = Math.Abs(a - b); int dif_bc = Math.Abs(b - c); int dif_ca = Math.Abs(c - a); if (dif_ca <= d || (dif_ab <= d && dif_bc <= d)) { wr.wri("Yes"); } else { wr.wri("No"); } } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } } class Method { static public int max(params int[] nums) { int maxx = nums[0]; for (int i = 1; i < nums.Length; i++) { maxx = Math.Max(maxx, nums[i]); } return maxx; } } }
[["-", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24], ["-", 31, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["-", 31, 16, 31, 23, 0, 16, 31, 16, 17, 19], ["-", 31, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["-", 15, 16, 31, 16, 31, 23, 0, 16, 17, 98], ["-", 31, 16, 31, 23, 0, 16, 12, 16, 31, 22], ["-", 31, 16, 31, 23, 0, 16, 12, 16, 17, 19], ["-", 31, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["-", 0, 57, 15, 16, 31, 16, 31, 23, 0, 25], ["-", 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, 22], ["-", 31, 16, 12, 23, 0, 16, 31, 16, 17, 19], ["-", 31, 16, 12, 23, 0, 16, 31, 16, 12, 22], ["-", 15, 16, 31, 16, 12, 23, 0, 16, 17, 98], ["-", 0, 57, 15, 16, 31, 16, 12, 23, 0, 25], ["-", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["-", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 15, 16, 12, 23, 0, 16, 12, 16, 31, 22]]
8
355
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace atcoder097_A { class Program { static void Main(string[] args) { //入力を受け取る int[] t_input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); int a = t_input[0]; int b = t_input[1]; int c = t_input[2]; int d = t_input[3]; string result = "No"; if ((Math.Abs(a - b) <= d) && (Math.Abs(b - c) <= d)) result = "Yes"; Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace atcoder097_A { class Program { static void Main(string[] args) { //入力を受け取る int[] t_input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); int a = t_input[0]; int b = t_input[1]; int c = t_input[2]; int d = t_input[3]; string result = "No"; if ((Math.Abs(a - b) <= d) && (Math.Abs(b - c) <= d)) result = "Yes"; if (Math.Abs(a - c) <= d) result = "Yes"; Console.WriteLine(result); } } }
[["+", 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], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 62], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["+", 0, 195, 8, 196, 0, 57, 64, 1, 0, 35]]
8
151
19
using System; namespace ABC097_A_Colorful_Transceivers { internal class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int d = int.Parse(input[3]); if (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; namespace ABC097_A_Colorful_Transceivers { internal class Program { public static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int c = int.Parse(input[2]); int d = int.Parse(input[3]); if (Math.Abs(a - b) <= d && Math.Abs(b - c) <= d) { Console.WriteLine("Yes"); } else if (Math.Abs(a - c) <= d) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 205, 22], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 0, 131], ["+", 75, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 75, 57, 15, 16, 31, 213, 3, 4, 0, 24], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 31, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 75, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 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], ["+", 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, 196, 0, 57, 75, 57, 75, 196, 0, 45]]
8
141
25
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { // 入力 string[] sS = Console.ReadLine().Trim().Split(' '); int iA = int.Parse(sS[0]); int iB = int.Parse(sS[1]); int iC = int.Parse(sS[2]); int iD = int.Parse(sS[3]); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); // 解析 string sOut = "No"; if (Math.Abs(iA - iC) <= iD) { sOut = "Yes"; } else { int iOk = 0; if (Math.Abs(iA - iB) <= iD) { iOk += 1; } if (Math.Abs(iB - iC) <= iD) { iOk += 1; } if (iOk >= 2) { sOut = "Yes"; } } sw.Stop(); #if DEBUG Console.WriteLine(); Console.WriteLine("{0}", sw.Elapsed.ToString()); Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { // 入力 string[] sS = Console.ReadLine().Trim().Split(' '); int iA = int.Parse(sS[0]); int iB = int.Parse(sS[1]); int iC = int.Parse(sS[2]); int iD = int.Parse(sS[3]); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); // 解析 string sOut = "No"; if (Math.Abs(iA - iC) <= iD) { sOut = "Yes"; } else { int iOk = 0; if (Math.Abs(iA - iB) <= iD) { iOk += 1; } if (Math.Abs(iB - iC) <= iD) { iOk += 1; } if (iOk >= 2) { sOut = "Yes"; } } // 出力 Console.WriteLine("{0}", sOut.ToString().Trim()); sw.Stop(); #if DEBUG Console.WriteLine(); Console.WriteLine("{0}", sw.Elapsed.ToString()); Console.WriteLine("続行するには何かキーを押してください..."); Console.ReadKey(); #endif } }
[["+", 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 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], ["+", 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, 25], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
270
19
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace atPra97a { class Class1 { static void Main() { int diff1, diff2, diff3; string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int c = int.Parse(str[2]); int d = int.Parse(str[3]); diff1 = Math.Abs(a - b); diff2 = Math.Abs(b - c); diff3 = Math.Abs(c - a); if (diff1 <= d && diff2 <= d && diff3 <= d) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace atPra97a { class Class1 { static void Main() { int diff1, diff2, diff3; string[] str = Console.ReadLine().Split(' '); int a = int.Parse(str[0]); int b = int.Parse(str[1]); int c = int.Parse(str[2]); int d = int.Parse(str[3]); diff1 = Math.Abs(a - b); diff2 = Math.Abs(b - c); diff3 = Math.Abs(c - a); if (diff1 <= d && diff2 <= d) Console.WriteLine("Yes"); else if (diff3 <= d) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 0, 131], ["+", 0, 57, 64, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 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], ["+", 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], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24]]
8
195
14
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); // Out.Flush(); Read(); } static void Solve() { var X = Sarray()[0]; var max = 1L; for (var i = 2; i * i <= X; ++i) max = Max(max, i * i); WriteLine(max); } static long Mod = 998244353; static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static public (T1 a, T2 b) Slice<T1, T2>() { var t = ReadLine().Split(); return ((T1)Convert.ChangeType(t[0], typeof(T1)), (T2)Convert.ChangeType(t[1], typeof(T2))); } static public (T a, T b) Slice2<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T))); } static public (T a, T b, T c) Slice3<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T)), (T)Convert.ChangeType(t[2], typeof(T))); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; using System.Numerics; namespace AtCoder { public class Program { public static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); // Out.Flush(); Read(); } static void Solve() { var X = Sarray()[0]; var max = 1L; for (var i = 2; i * i <= X; ++i) { var t = i * i; while (t * i <= X) t *= i; max = Max(max, t); } WriteLine(max); } static long Mod = 998244353; static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static public (T1 a, T2 b) Slice<T1, T2>() { var t = ReadLine().Split(); return ((T1)Convert.ChangeType(t[0], typeof(T1)), (T2)Convert.ChangeType(t[1], typeof(T2))); } static public (T a, T b) Slice2<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T))); } static public (T a, T b, T c) Slice3<T>() { var t = ReadLine().Split(); return ((T)Convert.ChangeType(t[0], typeof(T)), (T)Convert.ChangeType(t[1], typeof(T)), (T)Convert.ChangeType(t[2], typeof(T))); } } }
[["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 45], ["+", 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, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 48], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 52, 0, 89], ["+", 8, 196, 0, 7, 8, 196, 0, 52, 0, 24], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 48], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 52, 0, 25], ["+", 8, 196, 0, 52, 8, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 1, 0, 11, 0, 202, 0, 108], ["+", 8, 196, 0, 52, 8, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 52, 8, 1, 0, 35], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
418
25
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { Solve(); } static void Solve() { Scan sc = new Scan(); write wr = new write(); var x = sc.intarr[0]; int ma = 1; for (int i = 1; i <= 35; ++i) { for (int j = 2; j <= 10; ++j) { if ((int)Math.Pow(i, j) <= x && (int)Math.Pow(i, j) >= 1) { int l = (int)Math.Pow(i, j); wr.wri(l); ma = Math.Max(ma, l); } } } wr.wri(ma); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { Solve(); } static void Solve() { Scan sc = new Scan(); write wr = new write(); var x = sc.intarr[0]; int ma = 1; for (int i = 1; i <= 35; ++i) { for (int j = 2; j <= 10; ++j) { if ((int)Math.Pow(i, j) <= x && (int)Math.Pow(i, j) >= 1) { int l = (int)Math.Pow(i, j); // wr.wri(l); ma = Math.Max(ma, l); } } } wr.wri(ma); } } class Scan { public string str => Console.ReadLine(); public string[] strarr => str.Split(' '); public long[] longarr => strarr.Select(long.Parse).ToArray(); public int[] intarr => strarr.Select(int.Parse).ToArray(); public char[] chararr => str.ToArray(); } class write { public void wri<Type>(Type x) { Console.WriteLine(x); } }
[["-", 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, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
290
7
using System; namespace B___Exponential { class Program { static void Main(string[] args) { var x = int.Parse(Console.ReadLine()); var ans = 1.0; for (var i = 1; i <= x; i++) { for (var j = 2; j <= x; j++) { if (Math.Pow(i, j) <= x) { ans = Math.Pow(i, j); } else break; } } Console.WriteLine(ans); } } }
using System; namespace B___Exponential { class Program { static void Main(string[] args) { var x = int.Parse(Console.ReadLine()); var ans = 1.0; for (var i = 1; i <= x; i++) { for (var j = 2; j <= x; j++) { if (Math.Pow(i, j) <= x) { ans = Math.Max(ans, Math.Pow(i, j)); } else break; } } Console.WriteLine(ans); } } }
[["+", 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], ["+", 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, 3, 4, 0, 25]]
8
109
7
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var X = int.Parse(Console.ReadLine()); if (X == 1) { Console.WriteLine(1); } double ret = 0; for (int i = 2; i < X; i++) { for (int j = 2; j < 1000; j++) { var cal = Math.Pow(i, j); if (cal > X) { break; } if (ret < cal) { ret = cal; } } } Console.WriteLine(ret); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Text.RegularExpressions; using Console = System.Console; namespace Atcoder { class Program { static void Main(string[] args) { var X = int.Parse(Console.ReadLine()); double ret = 1; for (int i = 1; i < X; i++) { for (int j = 2; j < 1000; j++) { var cal = Math.Pow(i, j); if (cal > X) { break; } if (ret < cal) { ret = cal; } } } Console.WriteLine(ret); } } }
[["-", 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], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
160
19
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 ABC097B { static public void Solve() { var X = NN; var max = 0L; for (var i = 1; i <= X; i++) { var tmp = i; max = Max(tmp, max); for (var j = 2; j <= X; j++) { tmp *= i; if (tmp > X) break; max = Max(tmp, max); } } Console.WriteLine(max); } //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // TEST _/ //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ class BT<T> where T : IComparable { private class Node { public Node left; public Node right; public T val; public bool isBlack; } private Comparison<T> c; private Node root; private bool change; public BT(Comparison<T> _c) { c = _c; } public BT() : this((x, y) => x.CompareTo(y)) {} private bool Red(Node n) => n != null && !n.isBlack; private bool Black(Node n) => n != null && n.isBlack; private Node RotateL(Node n) { Node m = n.right, t = m.left; m.left = n; n.right = t; return m; } private Node RotateR(Node n) { Node m = n.left, t = m.right; m.right = n; n.left = t; return m; } private Node RotateLR(Node n) { n.left = RotateL(n.left); return RotateR(n); } private Node RotateRL(Node n) { n.right = RotateR(n.right); return RotateL(n); } public void Add(T x) { root = Add(root, x); root.isBlack = true; } private Node Add(Node n, T x) { if (n == null) { change = true; return new Node() { val = x }; } var r = c(x, n.val); if (r < 0) { n.left = Add(n.left, x); return Balance(n); } if (r > 0) { n.right = Add(n.right, x); return Balance(n); } change = false; return n; } private Node Balance(Node n) { if (!change) return n; if (!Black(n)) return n; if (Red(n.left) && Red(n.left.left)) { n = RotateR(n); n.left.isBlack = true; } else if (Red(n.left) && Red(n.left.right)) { n = RotateLR(n); n.left.isBlack = true; } else if (Red(n.right) && Red(n.right.left)) { n = RotateRL(n); n.right.isBlack = true; } else if (Red(n.right) && Red(n.right.right)) { n = RotateL(n); n.right.isBlack = true; } else { change = false; } return n; } public void Remove(T x) { root = Remove(root, x); if (root != null) root.isBlack = true; } private Node Remove(Node n, T x) { if (n == null) { change = false; return n; } var r = c(x, n.val); if (r < 0) { n.left = Remove(n.left, x); return BalanceL(n); } if (r > 0) { n.right = Remove(n.right, x); return BalanceR(n); } if (n.left == null) { change = n.isBlack; return n.right; } n.left = RemoveMax(n.left); n.val = lmax; return BalanceL(n); } private T lmax; private Node RemoveMax(Node n) { if (n.right != null) { n.right = RemoveMax(n.right); return BalanceR(n); } lmax = n.val; change = n.isBlack; return n.left; } private Node BalanceL(Node n) { if (!change) return n; if (Black(n.right) && Red(n.right.left)) { var b = n.isBlack; n = RotateRL(n); n.isBlack = b; n.left.isBlack = true; change = false; } else if (Black(n.right) && Red(n.right.right)) { var b = n.isBlack; n = RotateL(n); n.isBlack = b; n.right.isBlack = true; n.left.isBlack = true; change = false; } else if (Black(n.right)) { change = n.isBlack; n.isBlack = true; n.right.isBlack = false; } else { n = RotateL(n); n.isBlack = true; n.left.isBlack = false; n.left = BalanceL(n.left); change = false; } return n; } private Node BalanceR(Node n) { if (!change) return n; if (Black(n.left) && Red(n.left.right)) { var b = n.isBlack; n = RotateLR(n); n.isBlack = b; n.right.isBlack = true; change = false; } else if (Black(n.left) && Red(n.left.left)) { var b = n.isBlack; n = RotateR(n); n.isBlack = b; n.left.isBlack = true; n.right.isBlack = true; change = false; } else if (Black(n.left)) { change = n.isBlack; n.isBlack = true; n.left.isBlack = false; } else { n = RotateR(n); n.isBlack = true; n.right.isBlack = false; n.right = BalanceR(n.right); change = false; } return n; } public Tuple<bool, T> FindUpper(T x) { var v = FindUpper(root, x); if (v == null) return Tuple.Create(false, default(T)); return v; } private Tuple<bool, T> FindUpper(Node n, T x) { if (n == null) return null; var r = c(x, n.val); if (r < 0) { var v = FindUpper(n.left, x); if (v == null) return Tuple.Create(true, n.val); return v; } else if (r > 0) return FindUpper(n.right, x); else return Tuple.Create(true, x); } public Tuple<bool, T> FindLower(T x) { var v = FindLower(root, x); if (v == null) return Tuple.Create(false, default(T)); return v; } private Tuple<bool, T> FindLower(Node n, T x) { if (n == null) return null; var r = c(x, n.val); if (r < 0) return FindLower(n.left, x); else if (r > 0) { var v = FindLower(n.right, x); if (v == null) return Tuple.Create(true, n.val); return v; } else return Tuple.Create(true, x); } public T Min() { Node n = root, p = null; while (n != null) { p = n; n = n.left; } return p == null ? default(T) : p.val; } public T Max() { Node n = root, p = null; while (n != null) { p = n; n = n.right; } return p == null ? default(T) : p.val; } public bool Any() => root != null; public int CountSlow() => List(root).Count(); public IEnumerable<T> List() => List(root); private IEnumerable<T> List(Node n) { if (n == null) yield break; foreach (var i in List(n.left)) yield return i; yield return n.val; foreach (var i in List(n.right)) yield return i; } } //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // TEST END _/ //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ 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 long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); [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 IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l, Comparison<T> comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); } [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; } static long LCM(long a, long b) => a * b / GCD(a, b); 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 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(long 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(long n, long k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)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 T Pow<T>(T x, long y) { T a = (dynamic)1; while (y != 0) { if ((y & 1) == 1) a *= (dynamic)x; x *= (dynamic)x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _Build(long 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(long n, long k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)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 ABC097B { static public void Solve() { var X = NN; var max = 0L; for (var i = 1; i <= X; i++) { var tmp = i; for (var j = 1; j <= X; j++) { tmp *= i; if (tmp > X) break; max = Max(tmp, max); } } Console.WriteLine(max); } //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // TEST _/ //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ class BT<T> where T : IComparable { private class Node { public Node left; public Node right; public T val; public bool isBlack; } private Comparison<T> c; private Node root; private bool change; public BT(Comparison<T> _c) { c = _c; } public BT() : this((x, y) => x.CompareTo(y)) {} private bool Red(Node n) => n != null && !n.isBlack; private bool Black(Node n) => n != null && n.isBlack; private Node RotateL(Node n) { Node m = n.right, t = m.left; m.left = n; n.right = t; return m; } private Node RotateR(Node n) { Node m = n.left, t = m.right; m.right = n; n.left = t; return m; } private Node RotateLR(Node n) { n.left = RotateL(n.left); return RotateR(n); } private Node RotateRL(Node n) { n.right = RotateR(n.right); return RotateL(n); } public void Add(T x) { root = Add(root, x); root.isBlack = true; } private Node Add(Node n, T x) { if (n == null) { change = true; return new Node() { val = x }; } var r = c(x, n.val); if (r < 0) { n.left = Add(n.left, x); return Balance(n); } if (r > 0) { n.right = Add(n.right, x); return Balance(n); } change = false; return n; } private Node Balance(Node n) { if (!change) return n; if (!Black(n)) return n; if (Red(n.left) && Red(n.left.left)) { n = RotateR(n); n.left.isBlack = true; } else if (Red(n.left) && Red(n.left.right)) { n = RotateLR(n); n.left.isBlack = true; } else if (Red(n.right) && Red(n.right.left)) { n = RotateRL(n); n.right.isBlack = true; } else if (Red(n.right) && Red(n.right.right)) { n = RotateL(n); n.right.isBlack = true; } else { change = false; } return n; } public void Remove(T x) { root = Remove(root, x); if (root != null) root.isBlack = true; } private Node Remove(Node n, T x) { if (n == null) { change = false; return n; } var r = c(x, n.val); if (r < 0) { n.left = Remove(n.left, x); return BalanceL(n); } if (r > 0) { n.right = Remove(n.right, x); return BalanceR(n); } if (n.left == null) { change = n.isBlack; return n.right; } n.left = RemoveMax(n.left); n.val = lmax; return BalanceL(n); } private T lmax; private Node RemoveMax(Node n) { if (n.right != null) { n.right = RemoveMax(n.right); return BalanceR(n); } lmax = n.val; change = n.isBlack; return n.left; } private Node BalanceL(Node n) { if (!change) return n; if (Black(n.right) && Red(n.right.left)) { var b = n.isBlack; n = RotateRL(n); n.isBlack = b; n.left.isBlack = true; change = false; } else if (Black(n.right) && Red(n.right.right)) { var b = n.isBlack; n = RotateL(n); n.isBlack = b; n.right.isBlack = true; n.left.isBlack = true; change = false; } else if (Black(n.right)) { change = n.isBlack; n.isBlack = true; n.right.isBlack = false; } else { n = RotateL(n); n.isBlack = true; n.left.isBlack = false; n.left = BalanceL(n.left); change = false; } return n; } private Node BalanceR(Node n) { if (!change) return n; if (Black(n.left) && Red(n.left.right)) { var b = n.isBlack; n = RotateLR(n); n.isBlack = b; n.right.isBlack = true; change = false; } else if (Black(n.left) && Red(n.left.left)) { var b = n.isBlack; n = RotateR(n); n.isBlack = b; n.left.isBlack = true; n.right.isBlack = true; change = false; } else if (Black(n.left)) { change = n.isBlack; n.isBlack = true; n.left.isBlack = false; } else { n = RotateR(n); n.isBlack = true; n.right.isBlack = false; n.right = BalanceR(n.right); change = false; } return n; } public Tuple<bool, T> FindUpper(T x) { var v = FindUpper(root, x); if (v == null) return Tuple.Create(false, default(T)); return v; } private Tuple<bool, T> FindUpper(Node n, T x) { if (n == null) return null; var r = c(x, n.val); if (r < 0) { var v = FindUpper(n.left, x); if (v == null) return Tuple.Create(true, n.val); return v; } else if (r > 0) return FindUpper(n.right, x); else return Tuple.Create(true, x); } public Tuple<bool, T> FindLower(T x) { var v = FindLower(root, x); if (v == null) return Tuple.Create(false, default(T)); return v; } private Tuple<bool, T> FindLower(Node n, T x) { if (n == null) return null; var r = c(x, n.val); if (r < 0) return FindLower(n.left, x); else if (r > 0) { var v = FindLower(n.right, x); if (v == null) return Tuple.Create(true, n.val); return v; } else return Tuple.Create(true, x); } public T Min() { Node n = root, p = null; while (n != null) { p = n; n = n.left; } return p == null ? default(T) : p.val; } public T Max() { Node n = root, p = null; while (n != null) { p = n; n = n.right; } return p == null ? default(T) : p.val; } public bool Any() => root != null; public int CountSlow() => List(root).Count(); public IEnumerable<T> List() => List(root); private IEnumerable<T> List(Node n) { if (n == null) yield break; foreach (var i in List(n.left)) yield return i; yield return n.val; foreach (var i in List(n.right)) yield return i; } } //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ // TEST END _/ //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ 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 long NN => long.Parse(Console_.NextString()); static double ND => double.Parse(Console_.NextString()); static string NS => Console_.NextString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); [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 IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l) where T : IComparable { Array.Sort(l, (x, y) => y.CompareTo(x)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static void RevSort<T>(T[] l, Comparison<T> comp) where T : IComparable { Array.Sort(l, (x, y) => comp(y, x)); } [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; } static long LCM(long a, long b) => a * b / GCD(a, b); 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 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(long 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(long n, long k) { Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)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 T Pow<T>(T x, long y) { T a = (dynamic)1; while (y != 0) { if ((y & 1) == 1) a *= (dynamic)x; x *= (dynamic)x; y >>= 1; } return a; } static List<long> _fact = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void _Build(long 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(long n, long k) { _Build(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)] / _fact[(int)k]; } } }
[["-", 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, 21], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
5,424
11
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC097B { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var Number = new List<int>(); var max = 0; for (var i = 1; i <= N; i++) { Number.Add((int)(Math.Pow(i, 2))); } for (var i = 0; i < Number.Count; i++) { if (Number[i] <= N) { max = Math.Max(Number[i], max); } } Console.WriteLine(max); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC097B { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var Number = new List<int>(); var max = 0; for (var i = 1; i <= N; i++) for (var j = 2; j <= 10; j++) { Number.Add((int)(Math.Pow(i, j))); } for (var i = 0; i < Number.Count; i++) { if (Number[i] <= N && Number[i] > 0) { max = Math.Max(Number[i], max); } } Console.WriteLine(max); } } }
[["+", 0, 195, 8, 196, 0, 7, 8, 7, 0, 88], ["+", 0, 195, 8, 196, 0, 7, 8, 7, 0, 24], ["+", 0, 7, 8, 7, 10, 198, 39, 216, 0, 217], ["+", 0, 7, 8, 7, 10, 198, 0, 200, 141, 22], ["+", 8, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["+", 8, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 195, 8, 196, 0, 7, 8, 7, 0, 35], ["+", 8, 196, 0, 7, 8, 7, 15, 16, 31, 22], ["+", 8, 196, 0, 7, 8, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 7, 8, 7, 15, 16, 12, 203], ["+", 8, 196, 0, 7, 8, 7, 26, 223, 0, 22], ["+", 8, 196, 0, 7, 8, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 7, 8, 7, 0, 25], ["-", 51, 23, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 51, 23, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 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, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
161
23
using System; using System.Web; using System.IO; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { int n = int.Parse(Console.ReadLine()); int max = 1; for (int i = 2; i <= n; i++) { int a = 1; while (true) { if (a * i > n) break; a *= i; } max = Max(max, a); } Console.WriteLine(max); } }
using System; using System.Web; using System.IO; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; using System.Diagnostics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Runtime.CompilerServices; using static System.Math; class P { static void Main() { int n = int.Parse(Console.ReadLine()); var upper = Floor(Sqrt(n)); int max = 1; for (int i = 2; i <= upper; i++) { int a = i; while (true) { if (a * i > n) break; a *= i; } max = Max(max, a); } Console.WriteLine(max); } }
[["+", 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, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 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, 25], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22]]
8
161
15
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace practice1 { class Program { static void Main(string[] args) { int number = int.Parse(Console.ReadLine()); int i; int max = 1; i = 1; while (true) { if (i * i > number) break; max = i * i; i++; } MYCP.PrintNumber(max); } public static bool CheckBekizyousuu(int number) { if (number == 1) return true; int i, copy; for (i = 2; i < number; i++) { copy = number; while (copy % i == 0) { copy /= i; } if (copy == 1) return true; } return false; } } class MYCP { //標準出力の後改行する public static void Println(string str) { Console.WriteLine(str); } //標準出力の後改行しない public static void Print(string str) { Console.Write(str); } // int変数を標準出力する public static void PrintNumber(long number) { Console.WriteLine("" + number); } //あまり意味はない private static string MyScanf() { return Console.ReadLine(); } //文字列を配列化して返す public static string[] MyScanfSplit() { return MyScanf().Split(); } // double変数をソートする public static void MyDoubleSort(double[] boo) { if (boo.Length < 2) return; long i, count; double a; while (true) { count = 0; for (i = 0; i < boo.Length - 1; i++) { if (boo[i] > boo[i + 1]) { a = boo[i]; boo[i] = boo[i + 1]; boo[i + 1] = a; count++; } } if (count == 0) break; } } // int変数をソートする public static void MyLongSort(int[] boo) { if (boo.Length < 2) return; long i, count; int a; while (true) { count = 0; for (i = 0; i < boo.Length - 1; i++) { if (boo[i] > boo[i + 1]) { a = boo[i]; boo[i] = boo[i + 1]; boo[i + 1] = a; count++; } } if (count == 0) break; } } //指定された個数分数字を読み取る public static int[] ReadNumbers(long number) { int[] a = new int[number]; string[] buff = MyScanfSplit(); for (long i = 0; i < number; i++) { a[i] = int.Parse(buff[i]); } return a; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace practice1 { class Program { static void Main(string[] args) { int number = int.Parse(Console.ReadLine()); int max = 0; for (int i = number; i > 0; i--) { if (Bekizyousuu_Check(i)) { max = i; break; } } MYCP.PrintNumber(max); } public static bool Bekizyousuu_Check(int number) { if (number == 1) return true; int i, copy; for (i = 2; i < number; i++) { copy = number; while (copy % i == 0) { copy /= i; } if (copy == 1) return true; } return false; } } class MYCP { //標準出力の後改行する public static void Println(string str) { Console.WriteLine(str); } //標準出力の後改行しない public static void Print(string str) { Console.Write(str); } // int変数を標準出力する public static void PrintNumber(long number) { Console.WriteLine("" + number); } //あまり意味はない private static string MyScanf() { return Console.ReadLine(); } //文字列を配列化して返す public static string[] MyScanfSplit() { return MyScanf().Split(); } // double変数をソートする public static void MyDoubleSort(double[] boo) { if (boo.Length < 2) return; long i, count; double a; while (true) { count = 0; for (i = 0; i < boo.Length - 1; i++) { if (boo[i] > boo[i + 1]) { a = boo[i]; boo[i] = boo[i + 1]; boo[i + 1] = a; count++; } } if (count == 0) break; } } // int変数をソートする public static void MyLongSort(int[] boo) { if (boo.Length < 2) return; long i, count; int a; while (true) { count = 0; for (i = 0; i < boo.Length - 1; i++) { if (boo[i] > boo[i + 1]) { a = boo[i]; boo[i] = boo[i + 1]; boo[i + 1] = a; count++; } } if (count == 0) break; } } //指定された個数分数字を読み取る public static int[] ReadNumbers(long number) { int[] a = new int[number]; string[] buff = MyScanfSplit(); for (long i = 0; i < number; i++) { a[i] = int.Parse(buff[i]); } return a; } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 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], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["-", 8, 201, 0, 195, 8, 196, 0, 52, 0, 24], ["-", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 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, 68], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["+", 0, 7, 8, 196, 0, 57, 15, 213, 63, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 24], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 0, 52, 8, 196, 0, 57, 64, 93, 0, 94], ["-", 0, 52, 8, 196, 0, 57, 64, 93, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["-", 0, 52, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22]]
8
567
37
using System; namespace ABC97_B { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var M = 0; for (int i = 1; i < N; i++) { for (int j = 2; j <= 10; j++) { if (Math.Pow(i, j) <= N) M = (int)Math.Pow(i, j); } } Console.WriteLine(M); } } }
using System; namespace ABC97_B { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var M = 1; for (int i = 1; i < N; i++) { for (int j = 2; j <= 10; j++) { if (M <= Math.Pow(i, j) && Math.Pow(i, j) <= N) M = (int)Math.Pow(i, j); } } Console.WriteLine(M); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 15, 16, 31, 16, 12, 213, 63, 214, 205, 22], ["+", 15, 16, 31, 16, 12, 213, 63, 214, 0, 131], ["+", 15, 16, 31, 16, 12, 213, 63, 214, 141, 22], ["+", 15, 16, 31, 16, 12, 213, 3, 4, 0, 24], ["+", 31, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 12, 213, 3, 4, 0, 21], ["+", 15, 16, 31, 16, 12, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
107
13
using System; namespace AtCoder { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int ans = 0; for (int i = 1; i <= 40; i++) for (int j = 2; j <= 10; j++) if (Math.Pow(i, j) <= n) ans = (int)Math.Pow(i, j); Console.WriteLine(ans); } } }
using System; namespace AtCoder { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int ans = 0; for (int i = 1; i <= 40; i++) for (int j = 2; j <= 10; j++) if (Math.Pow(i, j) <= n) ans = Math.Max(ans, (int)Math.Pow(i, j)); Console.WriteLine(ans); } } }
[["+", 64, 1, 0, 11, 12, 213, 63, 214, 205, 22], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["+", 64, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["+", 0, 28, 0, 74, 51, 213, 3, 4, 0, 25]]
8
99
7
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace AtCoder_Project_CSharp { class Program { static void Main(string[] args) { var x = int.Parse(Console.ReadLine()); int max = 1; for (int i = 1; i <= x; i++) { for (int j = 2; j <= x; j++) { int pow = (int)Math.Pow(i, j); if (pow <= x) { max = pow; } else { break; } } } Console.WriteLine(max); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace AtCoder_Project_CSharp { class Program { static void Main(string[] args) { var x = int.Parse(Console.ReadLine()); int max = 1; for (int i = 1; i <= x; i++) { for (int j = 2; j <= x; j++) { int pow = (int)Math.Pow(i, j); if (pow <= x) { if (max <= pow) { max = pow; } } else { break; } } } Console.WriteLine(max); } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
131
8
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int inpt = int.Parse(Reader.ReadLine()); int ans = 1; for (int i = 2; i <= 1000; i++) { for (int j = 2; j <= 1000; j++) { long tmp = (long)Math.Pow(i, j); if (tmp > inpt) { break; } ans = (int)tmp; } } Console.WriteLine(ans); } public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 999 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public void Proc() { int inpt = int.Parse(Reader.ReadLine()); long ans = 1; for (int i = 2; i <= 1000; i++) { long tmp = i; for (int j = 2; j <= 1000; j++) { tmp = tmp * i; if (tmp > inpt) { break; } ans = Math.Max(ans, tmp); } } Console.WriteLine(ans); } public class Reader { static StringReader sr; public static bool IsDebug = false; public static string ReadLine() { if (IsDebug) { if (sr == null) { sr = new StringReader(InputText.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } private static string InputText = @" 10 "; } public static void Main(string[] args) { #if DEBUG Reader.IsDebug = true; #endif Program prg = new Program(); prg.Proc(); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 0, 212, 0, 74, 51, 213, 63, 214, 205, 22], ["-", 0, 212, 0, 74, 51, 213, 63, 214, 0, 131], ["-", 0, 212, 0, 74, 51, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 74, 51, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 212, 0, 74, 51, 213, 3, 4, 0, 21], ["-", 0, 74, 51, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 212, 0, 74, 51, 213, 3, 4, 0, 25], ["+", 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], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258], ["+", 0, 124, 0, 198, 0, 200, 0, 212, 0, 258]]
8
238
30
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { var s = Console.ReadLine(); int k = int.Parse(Console.ReadLine()); var subsList = new List<string>(); var charList = new List<char>(); for (int i = 0; i < s.Length; i++) charList.Add(s[i]); charList = charList.Distinct().OrderBy(c => c).ToList(); for (int x = 0; x < charList.Count(); x++) { subsList.Add(charList[x].ToString()); subsList = subsList.Distinct().ToList(); if (subsList.Count > k) break; for (int i = 1; i <= 4; i++) for (int j = 0; j < s.Length - i; j++) if (s[j] == charList[x]) subsList.Add(s.Substring(j, i + 1)); } Console.WriteLine( subsList.OrderBy(x => x).Where((x, y) => y == k - 1).First()); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { var s = Console.ReadLine(); int k = int.Parse(Console.ReadLine()); var subsList = new List<string>(); var charList = new List<char>(); for (int i = 0; i < s.Length; i++) charList.Add(s[i]); charList = charList.Distinct().OrderBy(c => c).ToList(); for (int x = 0; x < charList.Count(); x++) { subsList.Add(charList[x].ToString()); if (subsList.Count > k) break; for (int i = 1; i <= 4; i++) for (int j = 0; j < s.Length - i; j++) if (s[j] == charList[x]) subsList.Add(s.Substring(j, i + 1)); subsList = subsList.Distinct().ToList(); } Console.WriteLine( subsList.OrderBy(x => x).Where((x, y) => y == k - 1).First()); } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 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, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 7, 8, 7, 8, 57, 64, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["+", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 12, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 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]]
8
265
24
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Numerics; #if DEBUG using Microsoft.VisualStudio.TestTools.UnitTesting; #endif namespace competitive_programming { public class Program { static void Main(string[] args) { #if DEBUG var scanner = new IO.StreamScanner(File.Open("input.txt", FileMode.Open)); #else var scanner = new IO.StreamScanner(Console.OpenStandardInput()); #endif var s = scanner.ScanLine(); var k = scanner.Integer(); s = new string(Enumerable.Range(0, 5000) .Select(i => (char)('a' + (i % 26))) .ToArray()); var subStrs = new List<string>(); for (int i = 0; i < s.Length; i++) { for (int j = 1; i + j <= s.Length && j <= 5; j++) { subStrs.Add(s.Substring(i, j)); } } subStrs = subStrs.Distinct().ToList(); subStrs.Sort(); IO.Printer.Out.WriteLine(subStrs[k - 1]); IO.Printer.Out.Flush(); } } } #if DEBUG #endif #region INOUT namespace IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } 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; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; 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 = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Numerics; #if DEBUG using Microsoft.VisualStudio.TestTools.UnitTesting; #endif namespace competitive_programming { public class Program { static void Main(string[] args) { #if DEBUG var scanner = new IO.StreamScanner(File.Open("input.txt", FileMode.Open)); #else var scanner = new IO.StreamScanner(Console.OpenStandardInput()); #endif var s = scanner.ScanLine(); var k = scanner.Integer(); var subStrs = new List<string>(); for (int i = 0; i < s.Length; i++) { for (int j = 1; i + j <= s.Length && j <= 5; j++) { subStrs.Add(s.Substring(i, j)); } } subStrs = subStrs.Distinct().ToList(); subStrs.Sort(); IO.Printer.Out.WriteLine(subStrs[k - 1]); IO.Printer.Out.Flush(); } } } #if DEBUG #endif #region INOUT namespace IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { static Printer() { Out = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; } public static Printer Out { get; set; } public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(Stream stream, Encoding encoding) : base(stream, encoding) {} public void Write<T>(string format, T[] source) { base.Write(format, source.OfType<object>().ToArray()); } public void WriteLine<T>(string format, T[] source) { base.WriteLine(format, source.OfType<object>().ToArray()); } } 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; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr < len) return buf[ptr++]; ptr = 0; if ((len = str.Read(buf, 0, 1024)) > 0) return buf[ptr++]; isEof = true; return 0; } public char Char() { byte b; 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 = (char)read()) if (b == 0) break; else if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { if (isEof) return long.MinValue; long ret = 0; byte b; var ng = false; do b = read(); while (b != 0 && b != '-' && (b < '0' || '9' < b)); if (b == 0) return long.MinValue; if (b == '-') { ng = true; b = read(); } for (;; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; ret = ret * 10 + b - '0'; } } public int Integer() { return (isEof) ? int.MinValue : (int)Long(); } public double Double() { var s = Scan(); return s != "" ? double.Parse(s, CultureInfo.InvariantCulture) : double.NaN; } static T[] enumerate<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; ++i) a[i] = f(); return a; } public char[] Char(int n) { return enumerate(n, Char); } public string[] Scan(int n) { return enumerate(n, Scan); } public double[] Double(int n) { return enumerate(n, Double); } public int[] Integer(int n) { return enumerate(n, Integer); } public long[] Long(int n) { return enumerate(n, Long); } } } #endregion
[["-", 0, 195, 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, 230, 0, 228], ["-", 8, 196, 0, 1, 0, 11, 12, 230, 39, 199], ["-", 0, 1, 0, 11, 12, 230, 3, 4, 0, 24], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 21], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 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, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 3, 4, 0, 28, 0, 218, 8, 74, 0, 24], ["-", 3, 4, 0, 28, 0, 218, 8, 74, 39, 199], ["-", 3, 4, 0, 28, 0, 218, 8, 74, 0, 25], ["-", 0, 28, 0, 218, 8, 74, 51, 23, 0, 24], ["-", 8, 74, 51, 23, 0, 16, 31, 252, 0, 104], ["-", 8, 74, 51, 23, 0, 16, 31, 252, 0, 253], ["-", 0, 218, 8, 74, 51, 23, 0, 16, 17, 72], ["-", 8, 74, 51, 23, 0, 16, 12, 23, 0, 24], ["-", 51, 23, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 51, 23, 0, 16, 12, 23, 0, 16, 17, 109], ["-", 51, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 8, 74, 51, 23, 0, 16, 12, 23, 0, 25], ["-", 0, 28, 0, 218, 8, 74, 51, 23, 0, 25], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 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, 25], ["-", 0, 1, 0, 11, 12, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
1,111
39
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var S = Console.ReadLine(); var K = int.Parse(Console.ReadLine()); var subd = new List<string>(); for (var i = 1; i <= K; i++) { for (var j = 0; j < S.Length - i; j++) { subd.Add(S.Substring(j, i)); } } var sub = subd.OrderBy(s => s).Distinct().ToList(); Console.WriteLine(sub[K - 1]); } }
using System; using System.Linq; using System.Collections.Generic; public class Hello { public static void Main() { var S = Console.ReadLine(); var K = int.Parse(Console.ReadLine()); var list = new List<string>(); for (var i = 0; i < K; i++) { //文字列の長さを1つづつ増やす for (var j = 0; j < S.Length - i; j++) { // list.Add(S.Substring(j, i + 1)); } } var sub = list.OrderBy(s => s).Distinct().ToList(); Console.WriteLine(sub[K - 1]); } }
[["-", 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, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 0, 208, 0, 231, 141, 232, 234, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 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, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 205, 22]]
8
144
20
using System; using System.Collections.Generic; using System.Linq; using System.IO; // using System.Text; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; // using System.Numerics; // using static System.Math; // using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; } void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; } void solve() { var S = ReadLine(); int K = cin.nextint; var P = new List<string>(); for (int i = 0; i < S.Length; i++) { var L = ""; for (int j = 0; j < K; j++) { if (i + j == S.Length) { break; } L += S[i + j]; P.Add(L); } } P.Sort(); WriteLine(P[K]); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; // using System.Text; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; // using System.Numerics; // using static System.Math; // using pair = Pair<int, int>; class Program { static void Main() { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); new Program().solve(); Out.Flush(); } Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; } void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; } void solve() { var S = ReadLine(); int K = cin.nextint; var P = new SortedSet<string>(); for (int i = 0; i < S.Length; i++) { var L = ""; for (int j = 0; j < K; j++) { if (i + j == S.Length) { break; } L += S[i + j]; P.Add(L); } } WriteLine(P.ElementAt(K - 1)); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan { get { return ReadLine().Split(); } } public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } } public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } } public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } } public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint { get { return int.Parse(next); } } public long nextlong { get { return long.Parse(next); } } public double nextdouble { get { return double.Parse(next); } } }
[["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 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, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
524
16
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) { string[] input = Console.ReadLine().Split(); int N = int.Parse(input[0]); //種類 int X = int.Parse(input[1]); //お菓子のもと(グラム) List<int> m = new List<int>(); for (int i = 0; i < N; i++) { m.Add(int.Parse(Console.ReadLine().ToString())); } int count = 0; for (int i = 0; i < N; i++) { X -= m[i]; count++; } int min = m.Min(); while (X > min) { count++; X -= min; } Console.WriteLine(count); } } }
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) { string[] input = Console.ReadLine().Split(); int N = int.Parse(input[0]); //種類 int X = int.Parse(input[1]); //お菓子のもと(グラム) int[] m = new int[N]; for (int i = 0; i < N; i++) { m[i] = int.Parse(Console.ReadLine().ToString()); } int count = 0; for (int i = 0; i < N; i++) { X -= m[i]; count++; } int min = m.Min(); while (X >= min) { count++; X -= min; } Console.WriteLine(count); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 236, 141, 22], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 18], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 47], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 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, 47], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 70], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 73], ["-", 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, 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], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20]]
8
201
23
using System; namespace atcoder_BegginerContest95_Question2 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int donutTypes = Int32.Parse(input[0]); int amountMoto = Int32.Parse(input[1]); int[] donut = new int[donutTypes]; int minDonut = amountMoto; int sumMoto = 0; int numDonut = donutTypes; for (var i = 0; i < donutTypes; i++) { donut[i] = Int32.Parse(Console.ReadLine()); if (minDonut > amountMoto) minDonut = amountMoto; sumMoto += donut[i]; } amountMoto -= sumMoto; while (true) { if (amountMoto >= minDonut) { amountMoto -= minDonut; numDonut++; } else { break; } } Console.WriteLine(numDonut); } } }
using System; namespace atcoder_BegginerContest95_Question2 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int donutTypes = Int32.Parse(input[0]); int amountMoto = Int32.Parse(input[1]); int[] donut = new int[donutTypes]; int minDonut = amountMoto; int sumMoto = 0; int numDonut = donutTypes; for (var i = 0; i < donutTypes; i++) { donut[i] = Int32.Parse(Console.ReadLine()); if (minDonut > donut[i]) minDonut = donut[i]; sumMoto += donut[i]; } amountMoto -= sumMoto; while (true) { if (amountMoto >= minDonut) { amountMoto -= minDonut; numDonut++; } else { break; } } Console.WriteLine(numDonut); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 1, 0, 11, 12, 204, 205, 22], ["+", 64, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 64, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
8
178
10
using static System.Math; using static System.Console; using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var s = ReadLine().Split().Select(int.Parse).ToArray(); var count = s[0]; var a = new List<int>(); for (int i = 0; i < s[0]; i++) { a.Add(int.Parse(ReadLine())); count -= a[i]; } WriteLine(s[0] + count / a.Min()); } }
using static System.Console; using System; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { var s = ReadLine().Split().Select(int.Parse).ToArray(); var count = s[1]; var a = new List<int>(); for (int i = 0; i < s[0]; i++) { a.Add(int.Parse(ReadLine())); count -= a[i]; } WriteLine(s[0] + count / a.Min()); } }
[["-", 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, 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], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203]]
8
139
8
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int X = int.Parse(input[1]); int[] a = new int[N]; int max = 0; int min = 1000000; for (int i = 0; i < N; i++) { a[i] = int.Parse(Console.ReadLine()); max += a[i]; if (min > a[i]) min = a[i]; } int count = N; for (int i = 0; i < 100; i++) { if (max + min <= X) { max += min; count++; } else { break; } } Console.WriteLine(count); } }
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int X = int.Parse(input[1]); int[] a = new int[N]; int max = 0; int min = 1000000; for (int i = 0; i < N; i++) { a[i] = int.Parse(Console.ReadLine()); max += a[i]; if (min > a[i]) min = a[i]; //最小値 } int count = N; while (true) { if (max + min <= X) { max += min; count++; } else { break; } } Console.WriteLine(count); } }
[["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 88], ["+", 8, 201, 0, 195, 8, 196, 0, 52, 0, 89], ["-", 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], ["-", 8, 201, 0, 195, 8, 196, 0, 7, 0, 35], ["-", 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], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29], ["+", 0, 195, 8, 196, 0, 52, 15, 211, 0, 146]]
8
189
14
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 inputs = Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); var A = inputs[0]; var B = inputs[1]; var C = inputs[2]; var X = inputs[3]; var Y = inputs[4]; var ab = (double)(A + B) / 2; long ans = 0; if (ab > C) { var min = Math.Min(X, Y); X -= min; Y -= min; ans += C * min * 2; } ans += X * A; ans += Y * B; ans = Math.Min(ans, C * Math.Max(X, Y) * 2); Console.WriteLine(ans); } } }
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 inputs = Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); var A = inputs[0]; var B = inputs[1]; var C = inputs[2]; var X = inputs[3]; var Y = inputs[4]; long ans = 0; var ab = (double)(A + B) / 2; long min = 0; if (ab > C) { min = Math.Min(X, Y); ans += C * min * 2; } ans += (X - min) * A; ans += (Y - min) * B; ans = Math.Min(ans, C * Math.Max(X, Y) * 2); Console.WriteLine(ans); } } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 57, 64, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
8
214
24