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 static Input; public class Prog { public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void Solve() { string s = NextString(); string t = NextString(); if (s == t) { Console.WriteLine(1); return; } Dictionary<char, List<int>> d = new Dictionary<char, List<int>>(); for (char c = 'a'; c <= 'z'; c++) d[c] = new List<int>(); for (int i = 0; i < s.Length; i++) { d[s[i]].Add(i); } int now_ind = -1; long ans = 0; for (int i = 0; i < t.Length; i++) { // t[i]があるか探す if (d[t[i]].Count() == 0) { ans = -1; break; } else { if (1 <= i && t[i - 1] == t[i] && d[t[i]].Count() == 1) { ans++; // Console.WriteLine("=" + now_ind.ToString()); } else if (now_ind < d[t[i]].First()) { //周期変更なし now_ind = d[t[i]].First(); // Console.WriteLine("<" + now_ind.ToString()); } else if (d[t[i]].Last() < now_ind) { //必ず周期変更する ans++; now_ind = d[t[i]].First(); // Console.WriteLine(">" + now_ind.ToString()); } else { //二部探索で超える場所を探す now_ind = UpperBound(d[t[i]], now_ind + 1); // Console.WriteLine("0" + now_ind.ToString()); } } } if (ans == -1) Console.WriteLine(-1); else Console.WriteLine(ans * (long)(s.Length) + now_ind + 1); } private static int UpperBound(List<int> list, int n) { int a = 0, b = list.Count(); while (b - a != 1) { int x = (a + b) / 2; if (list[x] > n) b = x; else a = x; } return b; } private static int LowerBound(List<int> list, int n) { int a = 0, b = list.Count(); if (list[b - 1] <= n) return b - 1; else if (list[a] > n) return -1; while (b - a != 1) { int x = (a + b) / 2; if (list[x] <= n) a = x; else b = x; } return a; } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; 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 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 { public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void Solve() { string s = NextString(); string t = NextString(); if (s == t) { Console.WriteLine(s.Length); return; } Dictionary<char, List<int>> d = new Dictionary<char, List<int>>(); for (char c = 'a'; c <= 'z'; c++) d[c] = new List<int>(); for (int i = 0; i < s.Length; i++) { d[s[i]].Add(i); } int now_ind = -1; long ans = 0; for (int i = 0; i < t.Length; i++) { // t[i]があるか探す if (d[t[i]].Count() == 0) { ans = -1; break; } else { if (1 <= i && t[i - 1] == t[i] && d[t[i]].Count() == 1) { ans++; // Console.WriteLine("=" + now_ind.ToString()); } else if (now_ind < d[t[i]].First()) { //周期変更なし now_ind = d[t[i]].First(); // Console.WriteLine("<" + now_ind.ToString()); } else if (d[t[i]].Last() < now_ind + 1) { //必ず周期変更する ans++; now_ind = d[t[i]].First(); // Console.WriteLine(">" + now_ind.ToString()); } else { //二部探索で超える場所を探す now_ind = d[t[i]][UpperBound(d[t[i]], now_ind)]; // Console.WriteLine("0" + now_ind.ToString()); } } } if (ans == -1) Console.WriteLine(-1); else Console.WriteLine(ans * (long)(s.Length) + now_ind + 1); } private static int UpperBound(List<int> list, int n) { int a = 0, b = list.Count(); while (b - a != 1) { int x = (a + b) / 2; if (list[x] > n) b = x; else a = x; } return b; } private static int LowerBound(List<int> list, int n) { int a = 0, b = list.Count(); if (list[b - 1] <= n) return b - 1; else if (list[a] > n) return -1; while (b - a != 1) { int x = (a + b) / 2; if (list[x] <= n) a = x; else b = x; } return a; } public static void Main() { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; 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 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(); } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 141, 22], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 17, 72], ["+", 75, 57, 75, 57, 15, 16, 12, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 204, 205, 204, 205, 22], ["+", 0, 11, 12, 204, 205, 204, 206, 207, 0, 70], ["+", 205, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 11, 12, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73]]
8
931
17
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; //using static System.Globalization.CultureInfo; using System.Text; class Program { private static void chmin<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == 1 ? val : num; private static void chmax<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == -1 ? val : num; static void Main(string[] args) { var pr = new Program(); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); pr.Solve(); Console.Out.Flush(); } void Solve() { var s = ReadLine(); var t = ReadLine(); /*var b = new bool[30]; for (var i = 0; i < s.Length; i++) b[s[i] - 'a'] = true; for(var i=0;i<t.Length;i++) if(!b[t[i]-'a']) { WriteLine(-1);return; }*/ var res = 0L; var dp = new int[2*s.Length+1, 30]; for (var j = 0; j < 30; j++) dp[2 * s.Length, j] = -1; for(var i = 2 * s.Length - 1; i >= 0; i--) { for (var j = 0; j <= 'z' - 'a'; j++) if (s[i%s.Length] - 'a' == j) dp[i, j] = i % s.Length; else dp[i , j] = dp[i+1, j]; } for(var i=0;i<t.Length;i++) { var index = res % s.Length; var m = dp[index, t[i] - 'a']; if (m == -1) { WriteLine(-1);return; } res += (m - index + s.Length+1) % s.Length; } WriteLine(res); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] grid(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object)int.Parse(g); if (t == typeof(long)) return (T)(object)long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object)char.Parse(g); if (t == typeof(double)) return (T)(object)double.Parse(g); if (t == typeof(bool)) return (T)(object)bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>(){ sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item);return GetValue<T>(sc.Dequeue()); } public static void Next<T>(ref T val) => val = Next<T>(); public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1 { get; set; } public T2 v2 { get; set; } public Pair() { v1 = Input.Next<T1>(); v2 = Input.Next<T2>(); } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public override bool Equals(object obj) => this == (Pair<T1, T2>)obj; public override int GetHashCode() => v1.GetHashCode() ^ v2.GetHashCode(); public static bool operator ==(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 0; public static bool operator !=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 0; public static bool operator >(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 1; public static bool operator >=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != -1; public static bool operator <(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == -1; public static bool operator <=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 1; } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3 { get; set; } public Pair() : base() { v3 = Input.Next<T3>(); } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; //using static System.Globalization.CultureInfo; using System.Text; class Program { private static void chmin<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == 1 ? val : num; private static void chmax<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == -1 ? val : num; static void Main(string[] args) { var pr = new Program(); var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); pr.Solve(); Console.Out.Flush(); } void Solve() { var s = ReadLine(); var t = ReadLine(); /*var b = new bool[30]; for (var i = 0; i < s.Length; i++) b[s[i] - 'a'] = true; for(var i=0;i<t.Length;i++) if(!b[t[i]-'a']) { WriteLine(-1);return; }*/ var res = 0L; var dp = new int[2*s.Length+1, 30]; for (var j = 0; j < 30; j++) dp[2 * s.Length, j] = -1; for(var i = 2 * s.Length - 1; i >= 0; i--) { for (var j = 0; j <= 'z' - 'a'; j++) if (s[i%s.Length] - 'a' == j) dp[i, j] = i % s.Length; else dp[i , j] = dp[i+1, j]; } for(var i=0;i<t.Length;i++) { var index = res % s.Length; var m = dp[index, t[i] - 'a']; if (m == -1) { WriteLine(-1);return; } if (m < index) res += s.Length - index + m + 1; else res += m - index + 1; } WriteLine(res); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] grid(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object)int.Parse(g); if (t == typeof(long)) return (T)(object)long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object)char.Parse(g); if (t == typeof(double)) return (T)(object)double.Parse(g); if (t == typeof(bool)) return (T)(object)bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>(){ sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item);return GetValue<T>(sc.Dequeue()); } public static void Next<T>(ref T val) => val = Next<T>(); public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1 { get; set; } public T2 v2 { get; set; } public Pair() { v1 = Input.Next<T1>(); v2 = Input.Next<T2>(); } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public override bool Equals(object obj) => this == (Pair<T1, T2>)obj; public override int GetHashCode() => v1.GetHashCode() ^ v2.GetHashCode(); public static bool operator ==(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 0; public static bool operator !=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 0; public static bool operator >(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == 1; public static bool operator >=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != -1; public static bool operator <(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) == -1; public static bool operator <=(Pair<T1, T2> p1, Pair<T1, T2> p2) => p1.CompareTo(p2) != 1; } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3 { get; set; } public Pair() : base() { v3 = Input.Next<T3>(); } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; }
[["-", 0, 7, 8, 196, 0, 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], ["-", 31, 23, 0, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 12, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["+", 8, 196, 0, 7, 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, 107], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 16, 31, 16, 12, 22], ["+", 64, 1, 0, 11, 12, 16, 31, 16, 17, 72], ["+", 64, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["-", 0, 1, 0, 11, 12, 16, 12, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 16, 12, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 16, 12, 214, 141, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 1, 0, 35], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["+", 0, 57, 75, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["+", 75, 1, 0, 11, 12, 16, 31, 16, 17, 33], ["+", 75, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 17, 72], ["+", 0, 57, 75, 1, 0, 11, 12, 16, 12, 203]]
8
1,851
27
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemA { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var S = NS; var ans = 0; for (var i = 0; i < S.Length; i++) { if (i > 0 && S[i - 1] == S[i]) ++i; ++ans; } Console.WriteLine(ans); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Math; using System.Text; using System.Threading; using System.Globalization; using System.Runtime.CompilerServices; using Library; namespace Program { public static class ProblemA { static bool SAIKI = false; static public int numberOfRandomCases = 0; static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker) {} static public void Solve() { var S = NS; var ans = 0; for (var i = 0; i < S.Length; i++) { if (i > 0 && S[i - 1] == S[i]) { if (i == S.Length - 1) ans -= 2; if (i == S.Length - 2) ans -= 1; i += 2; ans++; } ++ans; } Console.WriteLine(ans); } class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; } public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; } } static LIB_FastIO fastio = new LIB_FastIODebug(); static public void Main(string[] args) { if (args.Length == 0) { fastio = new LIB_FastIO(); Console.SetOut(new Printer(Console.OpenStandardOutput())); } if (SAIKI) { var t = new Thread(Solve, 134217728); t.Start(); t.Join(); } else Solve(); Console.Out.Flush(); } static long NN => fastio.Long(); static double ND => fastio.Double(); static string NS => fastio.Scan(); static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray(); static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray(); static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray(); static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred); static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n); static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c); static IOrderedEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x, _ => xorshift); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x) => Enumerable.OrderBy(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderBy<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderBy(x.OrderByRand(), selector); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x) => Enumerable.OrderByDescending(x.OrderByRand(), e => e); static IOrderedEnumerable<T1> OrderByDescending<T1, T2>(this IEnumerable<T1> x, Func<T1, T2> selector) => Enumerable.OrderByDescending(x.OrderByRand(), selector); static IOrderedEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderByRand().OrderBy(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderBy(selector, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByRand().OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase); static IOrderedEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByRand().OrderByDescending(selector, StringComparer.OrdinalIgnoreCase); static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } } } namespace Library { class LIB_FastIO { public LIB_FastIO() { str = Console.OpenStandardInput(); } readonly Stream str; readonly byte[] buf = new byte[1024]; int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } virtual public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } virtual public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } virtual public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); } } class LIB_FastIODebug : LIB_FastIO { Queue<string> param = new Queue<string>(); string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); } public LIB_FastIODebug() {} public override string Scan() => NextString(); public override long Long() => long.Parse(NextString()); public override double Double() => double.Parse(NextString()); } }
[["-", 8, 196, 0, 57, 64, 1, 0, 241, 0, 29], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 57, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 1, 0, 11, 0, 202, 0, 110], ["+", 64, 196, 0, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,462
36
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderA { static void Main() { var sc = new Scanner(); string s = sc.Next(); List<string> strs = new List<string>(); string tmp = ""; for (int i = 0; i < s.Length; i++) { tmp += s[i].ToString(); if (strs.Contains(tmp)) { continue; } strs.Add(tmp); tmp = ""; } int answer = strs.Count(); 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(); string s = sc.Next(); List<string> strs = new List<string>(); int answer = 0; string tmp = ""; string before = ""; for (int i = 0; i < s.Length; i++) { tmp += s[i].ToString(); if (before != tmp) { answer++; before = tmp; tmp = ""; } } 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, 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, 198, 0, 200, 0, 212, 0, 5, 0, 62], ["-", 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, 7, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 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, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
433
39
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // // var n = inta(); var s = rstr(); char a = s[0]; int count = 1; for (int i = 1; i < s.Length; i++) { if (a == s[i]) { a = '2'; i++; } else { a = s[i]; } count++; } WriteLine(count); } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // // var n = inta(); var s = rstr(); char a = s[0]; int count = 1; for (int i = 1; i < s.Length; i++) { if (i == s.Length - 1 && a == s[i]) break; if (a == s[i]) { a = '2'; i++; } else { a = s[i]; } count++; } WriteLine(count); } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
[["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 205, 22], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 0, 131], ["+", 15, 16, 31, 16, 12, 16, 31, 214, 141, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 33], ["+", 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, 17, 60], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 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, 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]]
8
1,254
19
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 M2 = 998244353; const long LM = 1L << 60; const double eps = 1e-11; static void Main(string[] args) { var s = sc.Str; int n = s.Length; var dp = new int [n][]; for (int i = 0; i < n; i++) { dp[i] = new int[2]; dp[i][0] = dp[i][1] = -M; } dp[0][0] = 1; for (int i = 1; i < n; i++) { dp[i][0] = dp[i - 1][1] + 1; if (i >= 2) dp[i][1] = dp[i - 2][0] + 1; if (s[i - 1] != s[i]) { dp[i][0] = Math.Max(dp[i][0], dp[i - 1][0] + 1); } if (i >= 3 && s[i - 2] != s[i] && s[i - 3] != s[i - 1]) { dp[i][1] = Math.Max(dp[i][1], dp[i - 2][1] + 1); } } Prt(dp[n - 1].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>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } public static bool operator>(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator<(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator >=(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) >= 0; public static bool operator <=(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) <= 0; } static class util { public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static T sq<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; static readonly int[] dd = { 0, 1, 0, -1 }; static readonly string dstring = "RDLU"; public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static pair<P, char>[] adjacents_with_str(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new pair<P, char>(new P(i + dd[k], j + dd[k ^ 1]), dstring[k])) .ToArray(); public static pair<P, char>[] adjacents_with_str(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new pair<P, char>(new P(i + dd[k], j + dd[k ^ 1]), dstring[k])) .Where(p => inside(p.v1.v1, p.v1.v2, h, w)) .ToArray(); public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static void Assert(bool cond) { if (!cond) throw new Exception(); } public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { 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 { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); 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[] { ' ' }, 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]); } }
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 M2 = 998244353; const long LM = 1L << 60; const double eps = 1e-11; static void Main(string[] args) { var s = sc.Str; int n = s.Length; if (n == 1) { DBG(1); return; } var dp = new int [n][]; for (int i = 0; i < n; i++) { dp[i] = new int[2]; dp[i][0] = dp[i][1] = -M; } dp[0][0] = 1; dp[1][1] = 1; for (int i = 1; i < n; i++) { dp[i][0] = dp[i - 1][1] + 1; if (i >= 2) dp[i][1] = dp[i - 2][0] + 1; if (s[i - 1] != s[i]) { dp[i][0] = Math.Max(dp[i][0], dp[i - 1][0] + 1); } if (i >= 3 && s[i - 2] != s[i] && s[i - 3] != s[i - 1]) { dp[i][1] = Math.Max(dp[i][1], dp[i - 2][1] + 1); } } Prt(dp[n - 1].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>> { public T v1; public U v2; public pair() : this(default(T), default(U)) {} public pair(T v1, U v2) { this.v1 = v1; this.v2 = v2; } public int CompareTo(pair<T, U> a) { int c = Comparer<T>.Default.Compare(v1, a.v1); return c != 0 ? c : Comparer<U>.Default.Compare(v2, a.v2); } public override string ToString() => v1 + " " + v2; public void Deconstruct(out T a, out U b) { a = v1; b = v2; } public static bool operator>(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) > 0; public static bool operator<(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) < 0; public static bool operator >=(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) >= 0; public static bool operator <=(pair<T, U> a, pair<T, U> b) => a.CompareTo(b) <= 0; } static class util { public static pair<T, U> make_pair<T, U>(T v1, U v2) => new pair<T, U>(v1, v2); public static T sq<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; static readonly int[] dd = { 0, 1, 0, -1 }; static readonly string dstring = "RDLU"; public static P[] adjacents(this P p) => adjacents(p.v1, p.v2); public static P[] adjacents(this P p, int h, int w) => adjacents(p.v1, p.v2, h, w); public static pair<P, char>[] adjacents_with_str(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new pair<P, char>(new P(i + dd[k], j + dd[k ^ 1]), dstring[k])) .ToArray(); public static pair<P, char>[] adjacents_with_str(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new pair<P, char>(new P(i + dd[k], j + dd[k ^ 1]), dstring[k])) .Where(p => inside(p.v1.v1, p.v1.v2, h, w)) .ToArray(); public static P[] adjacents(int i, int j) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .ToArray(); public static P[] adjacents(int i, int j, int h, int w) => Enumerable.Range(0, dd.Length) .Select(k => new P(i + dd[k], j + dd[k ^ 1])) .Where(p => inside(p.v1, p.v2, h, w)) .ToArray(); public static void Assert(bool cond) { if (!cond) throw new Exception(); } public static Dictionary<T, int> compress<T>(this IEnumerable<T> a) => a.Distinct() .OrderBy(v => v) .Select((v, i) => new { v, i }) .ToDictionary(p => p.v, p => p.i); public static Dictionary<T, int> compress<T>(params IEnumerable<T>[] a) => compress(a.Aggregate(Enumerable.Union)); public static void swap<T>(ref T a, ref T b) where T : struct { var t = a; a = b; b = t; } public static void swap<T>(this IList<T> a, int i, int j) where T : struct { 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 { StreamReader sr; public Scan() { sr = new StreamReader(Console.OpenStandardInput()); } public Scan(string path) { sr = new StreamReader(path); } public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public string Str => sr.ReadLine().Trim(); public pair<T, U> Pair<T, U>() { T a; U b; Multi(out a, out b); return new pair<T, U>(a, b); } public P P => Pair<int, int>(); 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[] { ' ' }, 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]); } }
[["+", 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], ["+", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["+", 0, 1, 0, 11, 31, 204, 205, 204, 205, 22], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 203]]
8
2,655
25
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.Numerics; class AtCoder { const int MOD = 1000000007; public void Slove() { var str = Console.ReadLine(); char[] bef = new char[2]; bef[0] = str.First(); var dp = Enumerable.Range(0, str.Length).Select(x => new int[2]).ToArray(); foreach (int i in str.Select((x, index) => index).Skip(1)) { char c = str[i]; if (bef[0] != c) { dp[i][0] = dp[i - 1][0] + 1; } if (i > 1) { dp[i][0] = Math.Max(dp[i][0], dp[i - 1][1] + 1); } if (i > 2) { dp[i][1] = dp[i - 2][0] + 1; if (bef[0] != bef[1] || bef[0] != c) { dp[i][1] = Math.Max(dp[i][1], dp[i - 2][1] + 1); } } // Console.WriteLine(c + string.Join("", bef)); bef[1] = bef[0]; bef[0] = c; // Console.WriteLine(string.Join(" ", dp[i])); } Console.WriteLine(dp[str.Length - 1].Max() + 1); } static void Main() { var ac = new AtCoder(); ac.Slove(); } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.Numerics; class AtCoder { const int MOD = 1000000007; public void Slove() { var str = Console.ReadLine(); char[] bef = new char[2]; bef[0] = str.First(); var dp = Enumerable.Range(0, str.Length).Select(x => new int[2]).ToArray(); foreach (int i in str.Select((x, index) => index).Skip(1)) { char c = str[i]; if (bef[0] != c) { dp[i][0] = dp[i - 1][0] + 1; } if (i > 1) { dp[i][0] = Math.Max(dp[i][0], dp[i - 1][1] + 1); dp[i][1] = dp[i - 2][0] + 1; if (bef[0] != bef[1] || bef[0] != c) { dp[i][1] = Math.Max(dp[i][1], dp[i - 2][1] + 1); } } // Console.WriteLine(c + string.Join("", bef)); bef[1] = bef[0]; bef[0] = c; // Console.WriteLine(string.Join(" ", dp[i])); } Console.WriteLine(dp[str.Length - 1].Max() + 1); } static void Main() { var ac = new AtCoder(); ac.Slove(); } }
[["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 24], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 210, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 196, 0, 210, 8, 196, 0, 57, 0, 25], ["-", 0, 210, 8, 196, 0, 57, 64, 196, 0, 45]]
8
349
8
using System; class pg { static void Main(string[] args) { string a = Console.ReadLine(); int count = 0; string ppreStr = string.Empty; string preStr = string.Empty; string nowStr = string.Empty; foreach (char i in a) { nowStr = nowStr + i; if (preStr == nowStr) { } else { ppreStr = preStr; preStr = nowStr; nowStr = string.Empty; count++; } } if (!String.IsNullOrEmpty(nowStr)) { if (ppreStr == preStr + nowStr) { count--; } } Console.WriteLine(count); } }
using System; class pg { static void Main(string[] args) { string a = Console.ReadLine(); int count = 0; string ppreStr = string.Empty; string preStr = string.Empty; string nowStr = string.Empty; foreach (char i in a) { nowStr = nowStr + i; if (preStr == nowStr) { } else { ppreStr = preStr; preStr = nowStr; nowStr = string.Empty; count++; } } Console.WriteLine(count); } }
[["-", 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, 241, 0, 111], ["-", 0, 57, 15, 241, 0, 213, 63, 214, 205, 22], ["-", 0, 57, 15, 241, 0, 213, 63, 214, 0, 131], ["-", 0, 57, 15, 241, 0, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 241, 0, 213, 3, 4, 0, 24], ["-", 15, 241, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 15, 241, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 31, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 60], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 64, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["-", 64, 196, 0, 57, 15, 16, 12, 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, 1, 0, 223, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["-", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["-", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46]]
8
128
25
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string s = Console.ReadLine(); char c = '0'; int count = 0; int ans = 0; for (int i = 0; i < s.Length; i++) { if (c != s[i]) { if (count % 3 == 2) { ans += 2 * (count + 1) / 3; i++; c = s[i]; count = 1; } else { ans += 2 * count / 3 + count % 3; c = s[i]; count = 1; } } else count++; } if (count % 3 == 2) ans += 2 * (count + 1) / 3 - 1; else ans += 2 * count / 3 + count % 3; Console.WriteLine(ans); } } // mcs Main.cs // mono Main.exe
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string s = Console.ReadLine(); char c = '0'; int count = 0; int ans = 0; for (int i = 0; i < s.Length; i++) { if (c != s[i]) { if (count % 3 == 2) { ans += 2 * (count + 1) / 3; i++; if (i == s.Length) { Console.WriteLine(ans); return; } c = s[i]; count = 1; } else { ans += 2 * count / 3 + count % 3; c = s[i]; count = 1; } } else count++; } if (count % 3 == 2) ans += 2 * (count + 1) / 3 - 1; else ans += 2 * count / 3 + count % 3; Console.WriteLine(ans); } } // mcs Main.cs // mono Main.exe
[["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 64, 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, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 214, 0, 131], ["+", 64, 196, 0, 57, 15, 16, 12, 214, 141, 22], ["+", 64, 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, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 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]]
8
190
19
using System; class Program { static void Main(string[] args) { string S = Console.ReadLine(); int length = S.Length; int[] ct = new int[length]; int sw = 0; int r = 0; int ls = 0; for (var i = 0; i < length; i++) { if (sw == 0) { if (S[i] == 'R') { r++; } else { r++; ct[i - 1] += (r + 0) / 2; ct[i] += (r + 1) / 2; sw = 1; r = 0; ls = i; } } else { if (S[i] == 'L') { r++; } else { ct[ls - 1] += (r + 1) / 2; ct[ls] += (r + 0) / 2; sw = 0; r = 1; } } } if (sw == 1) { ct[ls - 1] += (r + 1) / 2; ct[ls] += (r + 0) / 2; } Console.Write("0"); for (var i = 1; i < length; i++) { Console.Write(" " + ct[i].ToString()); } } }
using System; class Program { static void Main(string[] args) { string S = Console.ReadLine(); int length = S.Length; int[] ct = new int[length]; int sw = 0; int r = 0; int ls = 0; for (var i = 0; i < length; i++) { if (sw == 0) { if (S[i] == 'R') { r++; } else { r++; ct[i - 1] += (r + 0) / 2; ct[i] += (r + 1) / 2; sw = 1; r = 0; ls = i; } } else { if (S[i] == 'L') { r++; } else { ct[ls - 1] += (r + 1) / 2; ct[ls] += (r + 0) / 2; sw = 0; r = 1; } } } if (sw == 1) { ct[ls - 1] += (r + 1) / 2; ct[ls] += (r + 0) / 2; } Console.Write(ct[0].ToString()); for (var i = 1; i < length; i++) { Console.Write(" " + ct[i].ToString()); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 28, 0, 213, 63, 214, 205, 204, 205, 22], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 0, 213, 63, 214, 205, 204, 206, 207, 0, 73], ["+", 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
283
9
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; //using static System.Globalization.CultureInfo; using System.Text; class Program { private static void chmin<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == 1 ? val : num; private static void chmax<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == -1 ? val : num; static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); //WriteLine(Solve()); } static void Solve() { int num, k; Input.Make(out num, out k); var ar = Input.ar; var sum = ar.Sum(); var list = new List<int>(); for(var i=1;i*i<=sum;i++) if (sum % i == 0) { list.Add(i); if (i * i != sum) list.Add(sum / i); } var max = -1; foreach (var v in list) { var or = ar.Select(a => a % v).OrderBy(a => a).ToArray(); var mi = new int[num + 1]; var pl = new int[num + 1]; for (var i = 1; i <= num; i++) mi[i] += mi[i - 1] + or[i - 1]; for (var i = num - 1; i >= 0; i--) pl[i] += pl[i + 1] + (v - or[i]); for (var i = 0; i <= num; i++) if (pl[i]<=k&& mi[i] <= k && (pl[i]-mi[i]) % v == 0) { max = Max(max, v); break; } } WriteLine(max); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] gred(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object)int.Parse(g); if (t == typeof(long)) return (T)(object)long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object)char.Parse(g); if (t == typeof(double)) return (T)(object)double.Parse(g); if (t == typeof(bool)) return (T)(object)bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>(){ sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item);return GetValue<T>(sc.Dequeue()); } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Convert; using static System.Math; //using static System.Globalization.CultureInfo; using System.Text; class Program { private static void chmin<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == 1 ? val : num; private static void chmax<T>(ref T num, T val) where T : IComparable<T> => num = num.CompareTo(val) == -1 ? val : num; static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); //WriteLine(Solve()); } static void Solve() { int num, k; Input.Make(out num, out k); var ar = Input.ar; var sum = ar.Sum(); var list = new List<int>(); for(var i=1;i*i<=sum;i++) if (sum % i == 0) { list.Add(i); if (i * i != sum) list.Add(sum / i); } var max = -1; foreach (var v in list) { var or = ar.Select(a => a % v).OrderBy(a => a).ToArray(); var mi = new int[num + 1]; var pl = new int[num + 1]; for (var i = 1; i <= num; i++) mi[i] += mi[i - 1] + or[i - 1]; for (var i = num - 1; i >= 0; i--) pl[i] += pl[i + 1] + (v - or[i]); for (var i = 0; i <= num; i++) if (pl[i]<=k&& mi[i] <= k && pl[i]==mi[i]) { max = Max(max, v); break; } } WriteLine(max); } } public class Input { public static string read => ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => ToInt64(read); public static T[] create<T>(int n, Func<int, T> f) => Enumerable.Repeat(0, n).Select(f).ToArray(); public static char[][] gred(int h) => create(h, _ => read.ToCharArray()); public static int[] ar1D(int n) => create(n, _ => num); public static long[] arL1D(int n) => create(n, _ => numL); public static string[] strs(int n) => create(n, _ => read); public static int[][] ar2D(int n) => create(n, _ => ar); public static long[][] arL2D(int n) => create(n, _ => arL); public static List<T>[] edge<T>(int n) => create(n, _ => new List<T>()); public static T GetValue<T>(string g) { var t = typeof(T); if (t == typeof(int)) return (T)(object)int.Parse(g); if (t == typeof(long)) return (T)(object)long.Parse(g); if (t == typeof(string)) return (T)(object)g; if (t == typeof(char)) return (T)(object)char.Parse(g); if (t == typeof(double)) return (T)(object)double.Parse(g); if (t == typeof(bool)) return (T)(object)bool.Parse(g); return default(T); } public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } private static Queue<string> sc; public static T Next<T>(){ sc = sc ?? new Queue<string>(); if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item);return GetValue<T>(sc.Dequeue()); } public const long Inf = (long)1e18; public const double eps = 1e-6; public const string Alfa = "abcdefghijklmnopqrstuvwxyz"; public const int MOD = 1000000007; }
[["-", 15, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["-", 12, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 7, 8, 57, 15, 16, 12, 16, 17, 60], ["-", 15, 16, 12, 16, 31, 16, 31, 23, 0, 25], ["-", 8, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["-", 8, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["-", 0, 7, 8, 57, 15, 16, 12, 16, 17, 60], ["-", 0, 7, 8, 57, 15, 16, 12, 16, 12, 203]]
8
1,298
8
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC136E { class Program { public static void Solve(Input input) { var n = input.NextInt(); var k = input.NextInt(); var a = input.NextInt(n); var divs = Divisor.Divisors(a.Sum()); Array.Sort(divs); for (int i = divs.Length - 1; i >= 0; i--) { if (Can(a, k, (int)divs[i])) { Console.WriteLine(divs[i]); return; } } Console.WriteLine(1); } static bool Can(int[] a, int k, int g) { var mods = a.Select(x => x % g).Where(x => x != 0).OrderBy(x => x).ToArray(); var sums = new int[mods.Length + 1]; for (int i = 1; i < sums.Length; i++) { sums[i] = sums[i - 1] + mods[i - 1]; } var min = int.MaxValue; for (int i = 0; i < mods.Length; i++) { // i以下を0方向に動かす var minus = sums[i]; var plus = g * (mods.Length - i) - (sums.Last() - minus); if (minus != plus) continue; min = Math.Min(min, minus); } return min <= k; } /// <summary> /// 約数列挙 /// </summary> static class Divisor { /// <summary> /// 約数列挙 順番はバラバラなので注意! /// </summary> static IEnumerable<long> Divisors(long n) { if (n < 1) yield break; var rn = (int)(Math.Sqrt(n) + 1); for (long i = 1; i < rn; i++) { if ((n % i) == 0) { yield return i; if (i != (n / i)) yield return n / i; } } } /// <summary> /// 約数列挙 /// </summary> /// <param name="n"></param> /// <param name="needsSort">昇順ソートするか</param> /// <returns></returns> public static long[] Divisors(long n, bool needsSort = false) { var divs = Divisors(n).ToArray(); if (needsSort) Array.Sort(divs); return divs; } } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // そのときにTLEするのはアルゴリズムが悪いせいだし、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする input.SetText("5 0 1 2 3 4 5"); Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) SetText(item); } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (string.IsNullOrEmpty(s)) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) queue.Enqueue(elem); return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => queue.Any() || Read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!queue.Any() && !Read()) return ""; return queue.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool Accumulate(int n) { while (queue.Count() < n) if (!Read()) return false; return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; namespace ABC136E { class Program { public static void Solve(Input input) { var n = input.NextInt(); var k = input.NextInt(); var a = input.NextInt(n); var divs = Divisor.Divisors(a.Sum()); Array.Sort(divs); for (int i = divs.Length - 1; i >= 0; i--) { if (Can(a, k, (int)divs[i])) { Console.WriteLine(divs[i]); return; } } Console.WriteLine(1); } static bool Can(int[] a, int k, int g) { var mods = a.Select(x => x % g).Where(x => x != 0).OrderBy(x => x).ToArray(); var sums = new int[mods.Length + 1]; for (int i = 1; i < sums.Length; i++) { sums[i] = sums[i - 1] + mods[i - 1]; } var min = int.MaxValue; for (int i = 0; i < mods.Length; i++) { // i以下を0方向に動かす var minus = sums[i]; var plus = g * (mods.Length - i) - (sums.Last() - minus); if (minus != plus) continue; min = Math.Min(min, minus); } return min <= k; } /// <summary> /// 約数列挙 /// </summary> static class Divisor { /// <summary> /// 約数列挙 順番はバラバラなので注意! /// </summary> static IEnumerable<long> Divisors(long n) { if (n < 1) yield break; var rn = (int)(Math.Sqrt(n) + 1); for (long i = 1; i < rn; i++) { if ((n % i) == 0) { yield return i; if (i != (n / i)) yield return n / i; } } } /// <summary> /// 約数列挙 /// </summary> /// <param name="n"></param> /// <param name="needsSort">昇順ソートするか</param> /// <returns></returns> public static long[] Divisors(long n, bool needsSort = false) { var divs = Divisors(n).ToArray(); if (needsSort) Array.Sort(divs); return divs; } } #region Main public static void Main(string[] args) { // 出力が少ないときはこれをセットする方が時間かかるけれど // そのときにTLEするのはアルゴリズムが悪いせいだし、まあ良しとする var needsFlushOutput = true; if (needsFlushOutput) { // 細かく出力しないようにする var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } // 通常は引数無しで、ファイルから読み出したい場合はpath指定する var input = new Input(); // 仮想的に標準入力をセットする // input.SetText("5 0 1 2 3 4 5"); Solve(input); Console.Out.Flush(); } #endregion #region Competitive Template #pragma warning disable CS0414 static readonly int MOD = (int)1e9 + 7; static readonly int[] dx = { 1, 0, -1, 0 }; static readonly int[] dy = { 0, 1, 0, -1 }; /// <summary> 左上が原点 </summary> static readonly char[] dir = { 'R', 'U', 'L', 'D' }; #pragma warning restore CS0414 public class Input { // 変な改行コードがたまに混じっているので、一応セパレート指定する // スペース単独指定の方がもちろん早い static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; /// <summary> /// 特定のファイルから読み出したい場合はpath指定する /// </summary> public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } /// <summary> /// 入力予約 /// </summary> public void SetText(IEnumerable<string> items) { foreach (var item in items) SetText(item); } /// <summary> /// 入力予約 /// </summary> public bool SetText(string s) { if (string.IsNullOrEmpty(s)) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) queue.Enqueue(elem); return true; } /// <summary> /// 要素が存在するか /// </summary> public bool Any() => queue.Any() || Read(); /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } /// <summary> /// 次のstringを一つ読み込む /// </summary> public string Next() { if (!queue.Any() && !Read()) return ""; return queue.Dequeue(); } /// <summary> /// 指定個数queueにたまるまでenqueueし続ける /// </summary> bool Accumulate(int n) { while (queue.Count() < n) if (!Read()) return false; return true; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); /// <summary> /// n個の要素をparseして、それぞれにoffsetをaddした配列を返す /// </summary> T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) => NextT(n, "", x => x, (x, y) => x); public int[] NextInt(int n, int offset = 0) => NextT(n, offset, int.Parse, (x, y) => x + y); public long[] NextLong(int n, long offset = 0) => NextT(n, offset, long.Parse, (x, y) => x + y); public double[] NextDouble(int n, double offset = 0.0) => NextT(n, offset, double.Parse, (x, y) => x + y); } static class Utils { public static T Max<T>(params T[] objs) => objs.Max(); public static T Min<T>(params T[] objs) => objs.Min(); /// <summary> /// vでfillされたT[d1][d2]配列を作成する /// </summary> public static T[][] Create2DArray<T>(int d1, int d2, T v) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(v, d2).ToArray()) .ToArray(); } /// <summary> /// vでfillされたT[d1][d2][d3]配列を作成する /// </summary> public static T[][][] Create3DArray<T>(int d1, int d2, int d3, T v) { return Enumerable.Repeat(0, d1) .Select(_ => Enumerable.Repeat(0, d2) .Select(__ => Enumerable.Repeat(v, d3).ToArray()) .ToArray()) .ToArray(); } } #endregion } }
[["-", 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
1,438
9
using System; using System.Collections.Generic; using System.Linq; public class S { public static void Main() { /* var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = input[0]; var M = input[1]; var bridge = new int[M,2]; for(int i = 0; i < M; i++){ input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); bridge[i,0] = input[0]; bridge[i,1] = input[1]; } solver(N,M,bridge); */ var input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var N = int.Parse(input[0].ToString()); var M = input[1]; solver(N, M, Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse)); // solver(2, 10, new int[]{3,5}); } public static void solver(int N, int K, int[] input) { var sum = input.Sum(); var divisors = getDivisorList(sum); Array.Sort(divisors); var amari = new int[input.Length]; // amari list int max = input.Max(); int amariTot = 0; int moveCount = 0; for (int i = divisors.Length - 1; i >= 0; i--) { amariTot = 0; moveCount = 0; for (int k = 0; k < input.Length; k++) { // Console.WriteLine(k); amari[k] = input[k] % divisors[i]; amariTot += input[k] % divisors[i]; } Array.Sort(amari); amari.Reverse(); amariTot /= divisors[i]; for (int k = 0; k < amariTot; k++) { moveCount += Math.Abs(divisors[i] - amari[k]); } if (moveCount <= K) { Console.WriteLine(divisors[i]); return; } } } public static int[] getDivisorList(int num) { int x = 1; int cap = Convert.ToInt32(Math.Sqrt(num)); var result = new List<int>(); while (x <= cap) { if (num % x == 0) { if (x == num / x) { result.Add(x); } else { result.Add(x); result.Add(num / x); } } x++; } return result.ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; public class S { public static void Main() { /* var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var N = input[0]; var M = input[1]; var bridge = new long[M,2]; for(long i = 0; i < M; i++){ input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); bridge[i,0] = input[0]; bridge[i,1] = input[1]; } solver(N,M,bridge); */ var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var N = long.Parse(input[0].ToString()); var M = input[1]; solver(N, M, Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse)); // solver(2, 10, new long[]{3,5}); } public static void solver(long N, long K, long[] input) { var sum = input.Sum(); var divisors = getDivisorList(sum); Array.Sort(divisors); var amari = new long[input.Length]; // amari list long max = input.Max(); long amariTot = 0; long moveCount = 0; for (int i = divisors.Length - 1; i >= 0; i--) { amariTot = 0; moveCount = 0; for (int k = 0; k < input.Length; k++) { // Console.WriteLine(k); amari[k] = input[k] % divisors[i]; amariTot += input[k] % divisors[i]; } Array.Sort(amari); Array.Reverse(amari); amariTot /= divisors[i]; for (int k = 0; k < amariTot; k++) { // Console.WriteLine(amari[k]); moveCount += Math.Abs(divisors[i] - amari[k]); } if (moveCount <= K) { Console.WriteLine(divisors[i]); return; } } } public static long[] getDivisorList(long num) { long x = 1; long cap = Convert.ToInt64(Math.Sqrt(num)); var result = new List<long>(); while (x <= cap) { if (num % x == 0) { if (x == num / x) { result.Add(x); } else { result.Add(x); result.Add(num / x); } } x++; } return result.ToArray(); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["+", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["+", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
436
35
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder_Beginner_Contest_13 { class Program { //配列にする static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } // Listにする static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } static void Solve() { var NK = Sarray(); var N = NK[0]; var K = NK[1]; var Ai = Slist(); var sum = Ai.Sum(); var max = Ai.Max(); if (0 == max) { WriteLine(0); return; } var dc = yaku(sum).OrderByDescending(e => e.Key); foreach (var pk in dc) { Ai.Sort((l, r) => (int)(r % pk.Key - l % pk.Key)); var pls = new long[N + 1]; var mns = new long[N + 1]; for (var i = 1; i < N + 1; ++i) { pls[i] = pls[i - 1] + (pk.Key - Ai[i - 1] % pk.Key); } for (var i = N - 1; 0 <= i; --i) { mns[i] = mns[i + 1] + Ai[(int)i] % pk.Key; } for (var i = 1; i < N; ++i) { if (pls[i] == mns[i] && pls[i] <= K) { WriteLine(pk.Key); return; } } } } static Dictionary<long, long> yaku(long n) { var ret = new Dictionary<long, long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret[i] = 1; ret[n / i] = 1; } } return ret; } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder_Beginner_Contest_13 { class Program { //配列にする static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } // Listにする static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } static void Solve() { var NK = Sarray(); var N = NK[0]; var K = NK[1]; var Ai = Slist(); var sum = Ai.Sum(); var max = Ai.Max(); if (0 == max) { WriteLine(0); return; } var dc = yaku(sum).OrderByDescending(e => e.Key); var ans = 0L; foreach (var pk in dc) { Ai.Sort((l, r) => (int)(r % pk.Key - l % pk.Key)); var pls = new long[N + 1]; var mns = new long[N + 1]; for (var i = 1; i < N + 1; ++i) { pls[i] = pls[i - 1] + (pk.Key - Ai[i - 1] % pk.Key); } for (var i = N - 1; 0 <= i; --i) { mns[i] = mns[i + 1] + Ai[(int)i] % pk.Key; } for (var i = 1; i < N; ++i) { if (pls[i] == mns[i] && pls[i] <= K) { WriteLine(pk.Key); return; } } } WriteLine(1); } static Dictionary<long, long> yaku(long n) { var ret = new Dictionary<long, long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret[i] = 1; ret[n / i] = 1; } } return ret; } } }
[["+", 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, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
494
10
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder_Beginner_Contest_13 { class Program { //配列にする static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } // Listにする static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } static void Solve() { var NK = Sarray(); var N = NK[0]; var K = NK[1]; var Ai = Slist(); var sum = Ai.Sum(); var max = Ai.Max(); var dc = prime_factor(sum).OrderByDescending(e => e.Key); var ans = 0L; foreach (var pk in dc) { Ai.Sort((l, r) => (int)(r % pk.Key - l % pk.Key)); var pls = new long[N + 1]; var mns = new long[N + 1]; for (var i = 1; i < N + 1; ++i) { pls[i] = pls[i - 1] + (pk.Key - Ai[i - 1] % pk.Key); } for (var i = N - 1; 0 <= i; --i) { mns[i] = mns[i + 1] + Ai[(int)i] % pk.Key; } for (var i = 1; i < N; ++i) { if (pls[i] == mns[i] && pls[i] <= K) { ans = Math.Max(ans, pk.Key); continue; } } } if (max > 0) ans = Math.Max(1, ans); WriteLine(ans); } static Dictionary<long, long> prime_factor(long n) { var ret = new Dictionary<long, long>(); ret[n] = 1; for (long i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i] = 1; ret[n] = 1; n /= i; } } if (n != 1) ret[n] = 1; return ret; } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; namespace AtCoder_Beginner_Contest_13 { class Program { //配列にする static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } // Listにする static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static void Main(string[] args) { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); Solve(); Out.Flush(); } static void Solve() { var NK = Sarray(); var N = NK[0]; var K = NK[1]; var Ai = Slist(); var sum = Ai.Sum(); var max = Ai.Max(); var dc = yaku(sum).OrderByDescending(e => e.Key); var ans = 0L; foreach (var pk in dc) { Ai.Sort((l, r) => (int)(r % pk.Key - l % pk.Key)); var pls = new long[N + 1]; var mns = new long[N + 1]; for (var i = 1; i < N + 1; ++i) { pls[i] = pls[i - 1] + (pk.Key - Ai[i - 1] % pk.Key); } for (var i = N - 1; 0 <= i; --i) { mns[i] = mns[i + 1] + Ai[(int)i] % pk.Key; } for (var i = 1; i < N; ++i) { if (pls[i] == mns[i] && pls[i] <= K) { ans = Math.Max(ans, pk.Key); break; } } } if (max > 0) ans = Math.Max(1, ans); WriteLine(ans); } static Dictionary<long, long> yaku(long n) { var ret = new Dictionary<long, long>(); for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret[i] = 1; ret[n / i] = 1; } } return ret; } } }
[["-", 0, 212, 0, 213, 63, 214, 205, 213, 63, 22], ["+", 0, 212, 0, 213, 63, 214, 205, 213, 63, 22], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 8, 196, 0, 52, 0, 89], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 85], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 22], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 90], ["-", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["-", 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, 79], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 1, 0, 11, 31, 204, 205, 22], ["-", 64, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["-", 64, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["-", 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
534
36
using System; //外 using System.Linq; // Linq public class ABC { public static void Main() { var line = Console.ReadLine(); var l = line.Split(' ').Select(s => int.Parse(s)).ToArray(); // Select,λ型 int a = l[0]; int b = l[1]; if ((a - b) % 2 == 1) { Console.WriteLine("IMPOSSIBLE"); } else { Console.WriteLine((a + b) / 2); } } }
using System; //外 using System.Linq; // Linq public class ABC { public static void Main() { var line = Console.ReadLine(); var l = line.Split(' ').Select(s => int.Parse(s)).ToArray(); // Select,λ型 int a = l[0]; int b = l[1]; if (b > a) { var t = a; a = b; b = t; } if ((a - b) % 2 == 1) { //%の定義がa-(a/b)*b Console.WriteLine("IMPOSSIBLE"); } else { Console.WriteLine((a + b) / 2); } } }
[["+", 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], ["+", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 64, 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, 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, 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, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 0, 57, 15, 16, 31, 16, 31, 23, 0, 24]]
8
116
21
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int n = Math.Abs(a - b); Console.WriteLine(n % 2 == 0 ? (n / 2).ToString() : "IMPOSSIBLE"); } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int a = int.Parse(input[0]); int b = int.Parse(input[1]); int n = Math.Abs(a - b); Console.WriteLine(n % 2 == 1 ? "IMPOSSIBLE" : (Math.Min(a, b) + n / 2).ToString()); } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 205, 23, 0, 16, 31, 213, 63, 214, 205, 22], ["+", 205, 23, 0, 16, 31, 213, 63, 214, 0, 131], ["+", 205, 23, 0, 16, 31, 213, 63, 214, 141, 22], ["+", 205, 23, 0, 16, 31, 213, 3, 4, 0, 24], ["+", 0, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 205, 23, 0, 16, 31, 213, 3, 4, 0, 21], ["+", 205, 23, 0, 16, 31, 213, 3, 4, 0, 25], ["+", 75, 213, 63, 214, 205, 23, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 62], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
99
19
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp21 { class Program { static void Main(string[] args) { string s = Console.ReadLine(); int A = int.Parse(s.Split(' ')[0]); int B = int.Parse(s.Split(' ')[1]); if ((int)((A + B) / 2.0f) == (A + B) / 2.0f) { Console.WriteLine((int)((A + B) / 2.0f)); } else { Console.WriteLine("IMPOSSIBLE"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp21 { class Program { static void Main(string[] args) { string s = Console.ReadLine(); int A = int.Parse(s.Split(' ')[0]); int B = int.Parse(s.Split(' ')[1]); if ((A + B) % 2 == 0) { Console.WriteLine((A + B) / 2); } else { Console.WriteLine("IMPOSSIBLE"); } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 74, 39, 199], ["-", 8, 196, 0, 57, 15, 16, 31, 74, 0, 25], ["-", 0, 57, 15, 16, 31, 74, 51, 23, 0, 24], ["-", 31, 74, 51, 23, 0, 16, 31, 23, 0, 24], ["-", 31, 74, 51, 23, 0, 16, 31, 23, 0, 25], ["-", 15, 16, 31, 74, 51, 23, 0, 16, 17, 85], ["-", 15, 16, 31, 74, 51, 23, 0, 16, 12, 250], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 16, 31, 23, 0, 24], ["-", 15, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["-", 15, 16, 12, 16, 31, 23, 0, 16, 17, 72], ["-", 15, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["-", 0, 57, 15, 16, 12, 16, 31, 23, 0, 25], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 85], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 250], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["-", 3, 4, 0, 28, 0, 74, 51, 23, 0, 24], ["-", 0, 74, 51, 23, 0, 16, 31, 23, 0, 24], ["-", 0, 28, 0, 74, 51, 23, 0, 16, 12, 250], ["-", 3, 4, 0, 28, 0, 74, 51, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
150
24
using System; using System.Collections.Generic; using System.Linq; using System.IO; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { // string A = Console.ReadLine();//Aから読み込む string[] s = Console.ReadLine().Split(' '); // 文字たちを読み込む int A = int.Parse(s[0]); // int B = int.Parse(s[1]); // int K = 0; // string s = Console.ReadLine();//こいつだけは文字列 //ここまでが入力部分でーす💛 if (System.Math.Abs(A - K) == System.Math.Abs(B - K)) { Console.WriteLine(K); } else { Console.WriteLine("IMPOSSIBLE"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { // string A = Console.ReadLine();//Aから読み込む string[] s = Console.ReadLine().Split(' '); // 文字たちを読み込む int A = int.Parse(s[0]); // int B = int.Parse(s[1]); // int K = (A + B) / 2; // string s = Console.ReadLine();//こいつだけは文字列 //ここまでが入力部分でーす💛 if (Math.Abs(A - K) == Math.Abs(B - K)) { Console.WriteLine(K); } else { Console.WriteLine("IMPOSSIBLE"); } } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 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, 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, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 15, 16, 31, 213, 63, 214, 205, 214, 205, 22], ["-", 15, 16, 31, 213, 63, 214, 205, 214, 0, 131], ["-", 15, 16, 12, 213, 63, 214, 205, 214, 205, 22], ["-", 15, 16, 12, 213, 63, 214, 205, 214, 0, 131]]
8
139
12
using System; class Program { static void Main(string[] args) { string[] line = Console.ReadLine().Split(); int a = int.Parse(line[0]); int b = int.Parse(line[1]); double answer = (a + b) / 2; if (answer == (int)answer) { Console.WriteLine(answer); } else { Console.WriteLine("IMPOSSIBLE"); } } }
using System; class Program { static void Main(string[] args) { string[] line = Console.ReadLine().Split(); double a = double.Parse(line[0]); double b = double.Parse(line[1]); double answer = (a + b) / 2; if (answer == (int)answer) { Console.WriteLine((int)answer); } else { Console.WriteLine("IMPOSSIBLE"); } } }
[["-", 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], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 24], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25]]
8
100
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 Hello { static public int mod = 1000000007; public static void Main() { // 方針 // int n = rint(); int[] a = inta(); int count = 0; for (int i = 0; i < n; i++) { if (a[i] != i + 1) count++; // WriteLine(count); } string ans = "YES"; if (count != 2) ans = "NO"; WriteLine(ans); } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(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); } } class UnionFind { private int[] unionfind; private int[] unionfind_size; public UnionFind(int a) { unionfind = new int[a]; unionfind_size = new int[a]; for (int i = 0; i < a; i++) { unionfind[i] = i; unionfind_size[i] = 1; } } public int root(int x) { if (unionfind[x] == x) return x; return unionfind[x] = root(unionfind[x]); } public void unite(int a, int b) { a = root(a); b = root(b); if (a == b) return; if (unionfind_size[a] < unionfind_size[b]) { int temp = a; a = b; b = temp; } unionfind[b] = a; unionfind_size[a] += unionfind_size[b]; } public bool same(int a, int b) { return root(a) == root(b); } public int size(int x) { return unionfind_size[root(x)]; } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue() // スタック -> 深さ優先 ??? // var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek() // stack.Count // if (list?.Count > 0) リストが空でもnullでもない // ソート // list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート // StringComparer.Ordinal とは // Array.Sort(list1,list2); // 出力 // foreach(var a int list){ WriteLine(a); } より // WriteLine(string.Join("\n", list)); が速い // var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false}; // Console.SetOut(sw); // 出力部分 // Console.Out.Flush(); // 未知 // 最小費用流 // 二分探索の理解が浅い
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Hello { static public int mod = 1000000007; public static void Main() { // 方針 // int n = rint(); int[] a = inta(); int count = 0; for (int i = 0; i < n; i++) { if (a[i] != i + 1) count++; // WriteLine(count); } string ans = "NO"; if (count == 2 || count == 0) ans = "YES"; WriteLine(ans); } static int binarysearchd(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] >= b) { return 0; } else if (a[leng - 1] < b) { return leng; } else { if (a[max] < b) { return max + 1; } return min + 1; } } static int binarysearchu(int[] a, int b) { int leng = a.Length; int min = 0; int max = leng - 1; while (max - min > 1) { int mid = (min + max) / 2; if (a[mid] < b) { min = mid; } else { max = mid; } } if (a[0] > b) { return leng; } else if (a[leng - 1] <= b) { return 0; } else { if (a[max] <= b) { return leng - (max + 1); } return leng - (min + 1); } } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(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); } } class UnionFind { private int[] unionfind; private int[] unionfind_size; public UnionFind(int a) { unionfind = new int[a]; unionfind_size = new int[a]; for (int i = 0; i < a; i++) { unionfind[i] = i; unionfind_size[i] = 1; } } public int root(int x) { if (unionfind[x] == x) return x; return unionfind[x] = root(unionfind[x]); } public void unite(int a, int b) { a = root(a); b = root(b); if (a == b) return; if (unionfind_size[a] < unionfind_size[b]) { int temp = a; a = b; b = temp; } unionfind[b] = a; unionfind_size[a] += unionfind_size[b]; } public bool same(int a, int b) { return root(a) == root(b); } public int size(int x) { return unionfind_size[root(x)]; } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // var queue = new Queue<int>(); queue.Enqueue() queue.Dequeue() // スタック -> 深さ優先 ??? // var stack = new Stack<int>(); stack.Push(hoge) stack.Pop() stackPeek() // stack.Count // if (list?.Count > 0) リストが空でもnullでもない // ソート // list.Sort(StringComparer.Ordinal); listの(辞書順?)ソート // StringComparer.Ordinal とは // Array.Sort(list1,list2); // 出力 // foreach(var a int list){ WriteLine(a); } より // WriteLine(string.Join("\n", list)); が速い // var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false}; // Console.SetOut(sw); // 出力部分 // Console.Out.Flush(); // 未知 // 最小費用流 // 二分探索の理解が浅い
[["-", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 222]]
8
1,779
10
using System; using System.Linq; public class ABC135_B { public static void Main() { int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int warn = 0; for (int i = 0; i < ints.Length; i++) { if (ints[0] != i + 1) warn++; if (warn > 2) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); } }
using System; using System.Linq; public class ABC135_B { public static void Main() { int count = int.Parse(Console.ReadLine()); int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int warn = 0; for (int i = 0; i < count; i++) { if (ints[i] != i + 1) warn++; if (warn > 2) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); } }
[["+", 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, 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], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 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], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22]]
8
115
20
// ABC 135 B - 0 or 1 Swap // 201909012 using System; using System.Linq; using static System.Math; using System.Collections.Generic; namespace B { class Program { static void Main(string[] args) { // Console.WriteLine("Hello World!"); int N = int.Parse(Console.ReadLine()); int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray(); int count = 0; for (int i = 0; i < N; i++) { count += i == P[i] ? 0 : 1; } if (count > 2) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
// ABC 135 B - 0 or 1 Swap // 201909012 using System; using System.Linq; using static System.Math; using System.Collections.Generic; namespace B { class Program { static void Main(string[] args) { // Console.WriteLine("Hello World!"); int N = int.Parse(Console.ReadLine()); int[] P = Console.ReadLine().Split().Select(int.Parse).ToArray(); int count = 0; for (int i = 0; i < N; i++) { count += (i + 1 == P[i] ? 0 : 1); } if (count > 2) Console.WriteLine("NO"); else Console.WriteLine("YES"); } } }
[["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 17, 72], ["+", 12, 23, 0, 41, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 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
146
12
using System; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); int[] b = new int[n]; int[] c = new int[n]; int i = 0; foreach (string s in input) { b[i] = int.Parse(s); c[i] = b[i]; i++; } for (int ii = 0; ii < n - 1; ii++) { for (int jj = ii; jj < n; jj++) { if (b[ii] > b[jj]) { int buf = b[ii]; b[ii] = b[jj]; b[jj] = buf; } } } int counter = 0; for (int ii = 0; ii < n; ii++) { if (b[ii] != c[ii]) { counter++; } if (counter > 2) { Console.WriteLine("NO"); return; } } if (counter == 2) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
using System; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string[] input = Console.ReadLine().Split(' '); int[] b = new int[n]; int[] c = new int[n]; int i = 0; foreach (string s in input) { b[i] = int.Parse(s); c[i] = b[i]; i++; } for (int ii = 0; ii < n - 1; ii++) { for (int jj = ii + 1; jj < n; jj++) { if (b[ii] > b[jj]) { int buf = b[ii]; b[ii] = b[jj]; b[jj] = buf; } } } int counter = 0; for (int ii = 0; ii < n; ii++) { if (b[ii] != c[ii]) { counter++; } if (counter > 2) { Console.WriteLine("NO"); return; } } if (counter == 2) { Console.WriteLine("YES"); } else if (counter == 0) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } }
[["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 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, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 12, 203]]
8
270
20
using System; namespace question2 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); int[] a = new int[N]; for (int i = 0; i < N; i++) { a[i] = int.Parse(str[i]); } int count = 0; for (int i = 1; i < N; i++) { if (a[i] != 1 + a[i - 1]) count++; } if (count == 0) Console.WriteLine("YES"); else if (count == 2) Console.WriteLine("YES"); else Console.WriteLine("NO"); Console.ReadLine(); } } }
using System; namespace question2 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); int[] a = new int[N]; for (int i = 0; i < N; i++) { a[i] = int.Parse(str[i]); } int count = 0; for (int i = 0; i < N; i++) { if (a[i] != (i + 1)) count++; } if (count == 0) Console.WriteLine("YES"); else if (count == 2) Console.WriteLine("YES"); else Console.WriteLine("NO"); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 203], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 72], ["-", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 24], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 23, 0, 16, 17, 72], ["-", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 15, 16, 12, 23, 0, 25], ["-", 75, 57, 75, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 75, 57, 75, 1, 0, 35], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24]]
8
183
17
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string s = Console.ReadLine(); string[] number = s.Split(' '); int[] numberList = number.Select(x => int.Parse(x)).ToArray(); int[] sortList = numberList.OrderBy(x => x).ToArray(); int flg = 0; for (int i = 0; i < number.Length; i++) { if (numberList[i] != sortList[i]) { flg++; } } if (flg == 0 || flg == 2) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string n = Console.ReadLine(); string s = Console.ReadLine(); string[] number = s.Split(' '); int[] numberList = number.Select(x => int.Parse(x)).ToArray(); int[] sortList = numberList.OrderBy(x => x).ToArray(); int flg = 0; for (int i = 0; i < number.Length; i++) { if (numberList[i] != sortList[i]) { flg++; } } if (flg == 0 || flg == 2) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } }
[["+", 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, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
164
9
using System; using System.Collections.Generic; using System.Linq; public class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var array = Console.ReadLine() .Split(' ') .Select(int.Parse) .OrderBy(x => x) .ToArray(); var count = 0; for (int i = 1; i < N; i++) { if (array[i - 1] < array[i]) { count++; if (count > 1) { break; } } } if (count > 1) { Console.WriteLine("NO"); } else { Console.WriteLine("YES"); } } }
using System; using System.Collections.Generic; using System.Linq; public class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); var trueArray = array.OrderBy(x => x).ToArray(); var count = 0; for (int i = 0; i < N; i++) { if (array[i] != trueArray[i]) { count++; if (count > 2) { break; } } } if (count > 2) { Console.WriteLine("NO"); } else { Console.WriteLine("YES"); } } }
[["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 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, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["+", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 204, 205, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203]]
8
158
21
using System; namespace ABC135 { class Program { static int Main(string[] args) { problemB(); return 0; } static void problemB() { string Nstr = Console.ReadLine(); string[] input = Console.ReadLine().Split(' '); int N = int.Parse(Nstr); int[] pArray = new int[N]; for (int i = 0; i < N; i++) { pArray[i] = int.Parse(input[i]); } int ans = 0; for (int i = 0; i < N - 1; i++) { if (pArray[i + 1] - pArray[i] != 1) { ans += 1; } } if (ans > 2) { Console.WriteLine("NO"); } else { Console.WriteLine("YES"); } } } }
using System; namespace ABC135 { class Program { static int Main(string[] args) { problemB(); return 0; } static void problemB() { string Nstr = Console.ReadLine(); string[] input = Console.ReadLine().Split(' '); int N = int.Parse(Nstr); int[] pArray = new int[N]; for (int i = 0; i < N; i++) { pArray[i] = int.Parse(input[i]); } int ans = 0; for (int i = 0; i < N; i++) { if (i + 1 != pArray[i]) { ans += 1; } } if (ans > 2) { Console.WriteLine("NO"); } else { Console.WriteLine("YES"); } } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 57, 15, 16, 31, 16, 31, 204, 205, 22], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["-", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 33], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 203]]
8
189
9
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { var exStdIn = new System.IO.StreamReader("stdin.txt"); System.Console.SetIn(exStdIn); string[] input = Console.ReadLine().Split(' '); int r = int.Parse(input[0]); int m = 3 * (r * r); Console.WriteLine(m.ToString()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int r = int.Parse(input[0]); int m = 3 * (r * r); Console.WriteLine(m.ToString()); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 234, 22], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 0, 131], ["-", 0, 212, 0, 230, 39, 232, 234, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 0, 131], ["-", 0, 200, 0, 212, 0, 230, 39, 232, 141, 22], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 1, 0, 213, 63, 214, 205, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
128
24
using System; namespace Dodecagon { public class Dominigon { static void Main(string[] args) { string decagon = Console.ReadLine(); int minigon = System.Int32.Parse(decagon); Console.WriteLine(3 * (minigon ^ 2)); } } }
using System; namespace Dodecagon { public class Dominigon { static void Main(string[] args) { string decagon = Console.ReadLine(); int minigon = int.Parse(decagon); Console.WriteLine(3 * minigon * minigon); } } }
[["-", 0, 212, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 212, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 212, 0, 213, 63, 214, 205, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 17, 140], ["-", 0, 28, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 3, 4, 0, 28, 0, 16, 12, 23, 0, 25]]
8
57
10
using System; using static System.Console; namespace AC_Field { class AtCoder { static void Main() { int r; r = int.Parse(ReadLine()); WriteLine(3 * r ^ 2); } } }
using static System.Math; using static System.Console; namespace AC_Field { class AtCoder { static void Main() { int r; r = int.Parse(ReadLine()); WriteLine(3 * Pow(r, 2)); } } }
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 115], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 3, 4, 0, 28, 0, 16, 12, 213, 63, 22], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 140], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25]]
8
47
4
using System; using System.Collections.Generic; using System.Linq; using System.Security.AccessControl; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var n = ReadLineIntSpilit(); var w = (2 * n[1]) + 1; Console.WriteLine(Math.Floor((double)(n[0] / w))); ReadLine(); } //メモ //アルゴリズム //・全探索解 /* * 例 [A, B, C] * * A - B, A - C * B - C * for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { array[i], array[j] } } */ //配列 //降順 // var sort = array.OrderBy(x => -x).ToArray(); //合計値 // array.Sum(); //切り捨て // double d = Math.Floor(n); //切り上げ // double d = Math.Celling(n); // kのn乗 //(int) Math.Pow(k, n); // for文の逆 // for(int i = array.Length - 1; i >= 0; i--) { } /// <summary> /// 最大公約数 /// </summary> static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } /// <summary> /// 数字配列の重複をカウント /// </summary> public static int DistinctInt(IEnumerable<int> array) { var q = array.Distinct().Count(); return array.Count() - q; } /// <summary> /// 文字配列の重複をカウント /// </summary> /// <param name="array"></param> /// <returns></returns> public static int DistinctString(IEnumerable<string> array) { var q = array.Distinct().Count(); return array.Count() - q; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAlphaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAlphaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
using System; using System.Collections.Generic; using System.Linq; using System.Security.AccessControl; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var n = ReadLineIntSpilit(); var w = (2 * n[1]) + 1; var r = n[0] * 1.0 / w; Console.WriteLine(Math.Ceiling(r)); ReadLine(); } //メモ //アルゴリズム //・全探索解 /* * 例 [A, B, C] * * A - B, A - C * B - C * for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { array[i], array[j] } } */ //配列 //降順 // var sort = array.OrderBy(x => -x).ToArray(); //合計値 // array.Sum(); //切り捨て // double d = Math.Floor(n); //切り上げ // double d = Math.Celling(n); // kのn乗 //(int) Math.Pow(k, n); // for文の逆 // for(int i = array.Length - 1; i >= 0; i--) { } /// <summary> /// 最大公約数 /// </summary> static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } /// <summary> /// 数字配列の重複をカウント /// </summary> public static int DistinctInt(IEnumerable<int> array) { var q = array.Distinct().Count(); return array.Count() - q; } /// <summary> /// 文字配列の重複をカウント /// </summary> /// <param name="array"></param> /// <returns></returns> public static int DistinctString(IEnumerable<string> array) { var q = array.Distinct().Count(); return array.Count() - q; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAlphaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAlphaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
[["+", 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, 212, 0, 16, 31, 16, 31, 204, 205, 22], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 70], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 48], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 250], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 85], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 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, 74, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 74, 0, 25], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 141, 22], ["-", 0, 74, 51, 23, 0, 16, 31, 204, 205, 22], ["-", 51, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 51, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 28, 0, 74, 51, 23, 0, 16, 17, 85], ["-", 0, 28, 0, 74, 51, 23, 0, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 74, 51, 23, 0, 25], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 22]]
8
724
26
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static int D; static List<int> monitors; static void Main(string[] args) { //[summary]B - Golden Apple var line = ReadLine(); int N = line[0]; D = line[1]; monitors = new List<int>(); //両端の木をカバーする監視員を配置する monitors.Add(1 + D); if (!IsMonitorning(N)) { monitors.Add(N - D); } for (int i = 2; i < N; i++) { if (!IsMonitorning(i)) { monitors.Add(i); } } Console.WriteLine(monitors.Count); } static bool IsMonitorning(int i) { foreach (var m in monitors) { int left = m - D; int right = m + D; if (left <= i && i <= right) { return true; } } return false; } static List<int> ReadLine() { var line = Console.ReadLine(); var arr = line.Split(' '); return arr.Select(x => int.Parse(x)).ToList(); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static int D; static List<int> monitors; static void Main(string[] args) { //[summary]B - Golden Apple var line = ReadLine(); int N = line[0]; D = line[1]; monitors = new List<int>(); for (int i = 1; i <= N; i++) { if (!IsMonitorning(i)) { monitors.Add(i + D); } } Console.WriteLine(monitors.Count); } static bool IsMonitorning(int i) { foreach (var m in monitors) { int left = m - D; int right = m + D; if (left <= i && i <= right) { return true; } } return false; } static List<int> ReadLine() { var line = Console.ReadLine(); var arr = line.Split(' '); return arr.Select(x => int.Parse(x)).ToList(); } } }
[["-", 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, 203], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 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], ["-", 0, 195, 8, 196, 0, 57, 15, 241, 0, 111], ["-", 8, 196, 0, 57, 15, 241, 0, 213, 63, 22], ["-", 0, 57, 15, 241, 0, 213, 3, 4, 0, 24], ["-", 15, 241, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 57, 15, 241, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 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, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
249
34
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int D = int.Parse(input[1]); int ans = N / (2 * D + 1) + 1; Console.WriteLine(ans); } }
using System; class Program { static void Main() { string[] input = Console.ReadLine().Split(' '); int N = int.Parse(input[0]); int D = int.Parse(input[1]); int ans = (N + 2 * D) / (2 * D + 1); Console.WriteLine(ans); } }
[["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["+", 0, 212, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 16, 31, 23, 0, 16, 12, 16, 31, 203], ["+", 0, 16, 31, 23, 0, 16, 12, 16, 17, 48], ["+", 0, 16, 31, 23, 0, 16, 12, 16, 12, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
80
8
using System; namespace GoldenApple { public class SilverApple { static void Main(string[] args) { string BronzeApple = Console.ReadLine(); string[] NomalApple = BronzeApple.Split(); int N = int.Parse(NomalApple[0]); int D = int.Parse(NomalApple[1]); if (N % D == 0) { Console.WriteLine(N / D); } else { Console.WriteLine(N / D + 1); } } } }
using System; namespace GoldenApple { public class SilverApple { static void Main(string[] args) { string BronzeApple = Console.ReadLine(); string[] NomalApple = BronzeApple.Split(); int N = int.Parse(NomalApple[0]); int D = int.Parse(NomalApple[1]); int Q = D * 2 + 1; if (N % Q == 0) { Console.WriteLine(N / Q); } else { Console.WriteLine(N / Q + 1); } } } }
[["+", 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, 200, 0, 212, 0, 16, 31, 16, 31, 22], ["+", 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, 72], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22]]
8
102
15
using System; using System.Linq; class P { static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToList(); var N = input[0]; var D = input[1]; if (N < D * 2 + 1) Console.WriteLine(1); else { Console.WriteLine(N / (D * 2 + 1)); } } }
using System; using System.Linq; class P { static void Main() { var input = Console.ReadLine().Split().Select(int.Parse).ToList(); var N = input[0]; var D = input[1]; if (N % (D * 2 + 1) > 0) Console.WriteLine(N / (D * 2 + 1) + 1); else { Console.WriteLine(N / (D * 2 + 1)); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 57, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 57, 64, 1, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 31, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 85], ["+", 31, 16, 12, 23, 0, 16, 31, 16, 31, 22], ["+", 31, 16, 12, 23, 0, 16, 31, 16, 17, 48], ["+", 31, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
94
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); int[] ND = cin.ArrayInt(2, 0); int D = ND[1] * 2 + 1; int N = ND[0]; if (N % D != 0) N /= D + 1; else N /= D; Console.WriteLine(N); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Diagnostics; class Myon { public Myon() {} public static int Main() { new Myon().calc(); return 0; } Scanner cin; Func cin2; void calc() { cin = new Scanner(); cin2 = new Func(); int[] ND = cin.ArrayInt(2, 0); int D = ND[1] * 2 + 1; int N = ND[0]; if (N % D != 0) { N /= D; N++; } else N /= D; Console.WriteLine(N); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
[["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 17, 72], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203], ["+", 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
746
7
using System; using System.Linq; using System.Collections.Generic; namespace Sample { class Sample { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] values1 = new int[N]; for (int i = 0; i < N; i++) { values1[i] = int.Parse(Console.ReadLine()); } int max = values1.Max(); int[] dis = values1; Array.Sort(dis); Array.Reverse(dis); int sec = dis[1]; // Console.WriteLine(max); // Console.WriteLine(sec); for (int i = 0; i < N; i++) { // Console.WriteLine(sec); if (values1[i] == max) { Console.WriteLine(sec); } else { Console.WriteLine(max); } } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Sample { class Sample { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] values1 = new int[N]; for (int i = 0; i < N; i++) { values1[i] = int.Parse(Console.ReadLine()); } int max = values1.Max(); int[] dis = new int[N]; values1.CopyTo(dis, 0); Array.Sort(dis); Array.Reverse(dis); int sec = dis[1]; for (int i = 0; i < N; i++) { if (values1[i] == max) { Console.WriteLine(sec); } else { Console.WriteLine(max); } } } } }
[["+", 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], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
176
13
using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = new List<int>(); for (int i = 0; i < N; i++) { A.Add(int.Parse(Console.ReadLine())); } // 降順ソートする var maxList = new List<int>(A); maxList.Sort((a, b) => (b - a)); // 先頭二つを保存 var max = maxList[0]; var subMax = maxList[1]; for (int i = 0; i < N - 1; i++) { if (A[i] == max) Console.WriteLine(subMax); Console.WriteLine(max); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var A = new List<int>(); for (int i = 0; i < N; i++) { A.Add(int.Parse(Console.ReadLine())); } // 降順ソートする var maxList = new List<int>(A); maxList.Sort((a, b) => (b - a)); var maxIndex = A.IndexOf(maxList[0]); for (int i = 0; i < N; i++) { if (i == maxIndex) Console.WriteLine(maxList[1]); else Console.WriteLine(maxList[0]); } } }
[["-", 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], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 204, 205, 22], ["-", 0, 200, 0, 212, 0, 204, 206, 207, 0, 70], ["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 12, 22], ["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
180
3
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; class Program { const long MOD = 1000000007; static void Main(string[] args) { // ここにかく int n = ScanOneInt(); int[] ar = new int[n]; for (int i = 0; i < n; i++) { ar[i] = ScanOneInt(); } int[] ars = ar; Array.Sort(ars); for (int i = 0; i < n; i++) { if (ar[i - 1] == ars[n - 1]) { Console.WriteLine(ars[n - 2]); } else { Console.WriteLine(ars[n - 1]); } } } static int[] ruiseki(int[] array) { int[] res = new int[array.Length]; for (int i = 0; i < array.Length; i++) { if (i == 0) { res[i] = array[i]; } else { res[i] = res[i - 1] + array[i]; } } return res; } static int Nibutan(long[] array, long k) { int low = 0; int high = array.Length - 1; int mid = high; while (low < high) { mid = (low + high) / 2; if (array[mid] >= k) // k以上の最小index.ココを変えるだけ { high = mid; } else { low = mid + 1; } mid = (low + high) / 2; } return mid; } static int ScanOneInt() { return int.Parse(Console.ReadLine()); } static long ScanOneLong() { return long.Parse(Console.ReadLine()); } static string[] ScanStringArray(int lines) { string[] str = new string[lines]; for (int i = 0; i < lines; i++) { str[i] = Console.ReadLine(); } return str; } static int[] ScanIntArray(int t) { string[] str = Console.ReadLine().Split(' '); int[] ar = new int[t]; for (int i = 0; i < t; i++) { ar[i] = int.Parse(str[i]); } return ar; } static Tuple<int, int> ScanTuple() { int[] tmp = ScanIntArray(2); return new Tuple<int, int>(tmp[0], tmp[1]); } static long[] ScanLongArray(int t) { string[] str = Console.ReadLine().Split(' '); long[] ar = new long[t]; for (int i = 0; i < t; i++) { ar[i] = long.Parse(str[i]); } return ar; } static string[] ScanStringArray() { return Console.ReadLine().Split(' '); } static double[] ScanDoubleArray(int t) { string[] str = Console.ReadLine().Split(' '); double[] ar = new double[t]; for (int i = 0; i < t; i++) { ar[i] = double.Parse(str[i]); } return ar; } static int[,] ScanIntSquareArray(int h, int w) { int[,] resAr = new int[h, w]; for (int i = 0; i < h; i++) { int[] ar = ScanIntArray(w); for (int j = 0; j < w; j++) { resAr[i, j] = ar[j]; } } return resAr; } static int[,] CombModMake() { int[,] res = new int[2005, 2005]; for (int i = 0; i < 2005; i++) { for (int j = 0; j < 2005; j++) { if (i == 0 || i < j) { res[i, j] = 0; } else if (j == 0 || i == j) { res[i, j] = 1; } else { res[i, j] = (res[i - 1, j] + res[i - 1, j - 1]) % (int)MOD; } } } return res; } // int, long両方で出来るGCDを作った static T GCD<T>(T a, T b) { if ((dynamic)a % (dynamic)b == 0) { return b; } else { return GCD((dynamic)b, (dynamic)a % (dynamic)b); } } } public class Dijkstra // 書きかけ { private int maxIndex = -1; private const long INF = Int64.MaxValue; } public class Pair<T, U> : IComparable where T : IComparable<T> where U : IComparable<U> { public T Item1; public U Item2; public int CompareTo(object obj) { Pair<T, U> pair = (Pair<T, U>)obj; return Item1.CompareTo(pair.Item1); } public Pair(T t, U u) { Item1 = t; Item2 = u; } } // 計算量: Push -> O(logN), Peek -> O(1)。Clear() -> O(logN) // ToArray()で配列化 public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /* -> Item: _heap(ヒープを持つ.sizeはmaxSize) -> Item: _type -> 0:asc(昇順), 1:desc(降順) */ public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); // typeが0なら昇順, 1なら降順にソートするCompare } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() // O(1) { return _count; } public T Peek() // O(1) { return _heap[0]; } public bool Contains(T x) // O(N)なので注意 { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (Count() > 0) Pop(); } public IEnumerator<T> GetEnumerator() // なにこれ { var ret = new List<T>(); while (Count() > 0) { ret.Add(Pop()); } foreach (var r in ret) { Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } public class GenericOperation<T> { public GenericOperation() { var availableT = new Type[] { typeof(int), typeof(uint), typeof(short), typeof(ushort), typeof(long), typeof(ulong), typeof(byte), typeof(decimal), typeof(double) }; if (!availableT.Contains(typeof(T))) { throw new NotSupportedException(); } var p1 = Expression.Parameter(typeof(T)); var p2 = Expression.Parameter(typeof(T)); Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2) .Compile(); Subtract = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2) .Compile(); Multiply = Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2) .Compile(); Divide = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2) .Compile(); Modulo = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2) .Compile(); Equal = Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2) .Compile(); GreaterThan = Expression .Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2) .Compile(); GreaterThanOrEqual = Expression .Lambda<Func<T, T, bool>>( Expression.GreaterThanOrEqual(p1, p2), p1, p2) .Compile(); LessThan = Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2) .Compile(); LessThanOrEqual = Expression .Lambda<Func<T, T, bool>>( Expression.LessThanOrEqual(p1, p2), p1, p2) .Compile(); } public Func<T, T, T> Add { get; private set; } public Func<T, T, T> Subtract { get; private set; } public Func<T, T, T> Multiply { get; private set; } public Func<T, T, T> Divide { get; private set; } public Func<T, T, T> Modulo { get; private set; } public Func<T, T, bool> Equal { get; private set; } public Func<T, T, bool> GreaterThan { get; private set; } public Func<T, T, bool> GreaterThanOrEqual { get; private set; } public Func<T, T, bool> LessThan { get; private set; } public Func<T, T, bool> LessThanOrEqual { get; private set; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; exnum = ex; n = 1; while (n < m) n <<= 1; // resize calc tree = new T[(n << 1) - 1]; // resize for (int i = 0; i < tree.Length; i++) tree[i] = ex; // init } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; All_update(); } public void Assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void Update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void All_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T Look(int i) { return tree[i + n - 1]; } // [s, t) public T Run(int s, int t) { return Query(s, t, 0, 0, n); } T Query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(Query(s, t, (k << 1) + 1, l, (l + r) >> 1), Query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; class Program { const long MOD = 1000000007; static void Main(string[] args) { // ここにかく int n = ScanOneInt(); int[] ar = new int[n]; int[] ars = new int[n]; for (int i = 0; i < n; i++) { ar[i] = ScanOneInt(); ars[i] = ar[i]; } Array.Sort(ars); for (int i = 0; i < n; i++) { if (ar[i] == ars[n - 1]) { Console.WriteLine(ars[n - 2]); } else { Console.WriteLine(ars[n - 1]); } } } static int[] ruiseki(int[] array) { int[] res = new int[array.Length]; for (int i = 0; i < array.Length; i++) { if (i == 0) { res[i] = array[i]; } else { res[i] = res[i - 1] + array[i]; } } return res; } static int Nibutan(long[] array, long k) { int low = 0; int high = array.Length - 1; int mid = high; while (low < high) { mid = (low + high) / 2; if (array[mid] >= k) // k以上の最小index.ココを変えるだけ { high = mid; } else { low = mid + 1; } mid = (low + high) / 2; } return mid; } static int ScanOneInt() { return int.Parse(Console.ReadLine()); } static long ScanOneLong() { return long.Parse(Console.ReadLine()); } static string[] ScanStringArray(int lines) { string[] str = new string[lines]; for (int i = 0; i < lines; i++) { str[i] = Console.ReadLine(); } return str; } static int[] ScanIntArray(int t) { string[] str = Console.ReadLine().Split(' '); int[] ar = new int[t]; for (int i = 0; i < t; i++) { ar[i] = int.Parse(str[i]); } return ar; } static Tuple<int, int> ScanTuple() { int[] tmp = ScanIntArray(2); return new Tuple<int, int>(tmp[0], tmp[1]); } static long[] ScanLongArray(int t) { string[] str = Console.ReadLine().Split(' '); long[] ar = new long[t]; for (int i = 0; i < t; i++) { ar[i] = long.Parse(str[i]); } return ar; } static string[] ScanStringArray() { return Console.ReadLine().Split(' '); } static double[] ScanDoubleArray(int t) { string[] str = Console.ReadLine().Split(' '); double[] ar = new double[t]; for (int i = 0; i < t; i++) { ar[i] = double.Parse(str[i]); } return ar; } static int[,] ScanIntSquareArray(int h, int w) { int[,] resAr = new int[h, w]; for (int i = 0; i < h; i++) { int[] ar = ScanIntArray(w); for (int j = 0; j < w; j++) { resAr[i, j] = ar[j]; } } return resAr; } static int[,] CombModMake() { int[,] res = new int[2005, 2005]; for (int i = 0; i < 2005; i++) { for (int j = 0; j < 2005; j++) { if (i == 0 || i < j) { res[i, j] = 0; } else if (j == 0 || i == j) { res[i, j] = 1; } else { res[i, j] = (res[i - 1, j] + res[i - 1, j - 1]) % (int)MOD; } } } return res; } // int, long両方で出来るGCDを作った static T GCD<T>(T a, T b) { if ((dynamic)a % (dynamic)b == 0) { return b; } else { return GCD((dynamic)b, (dynamic)a % (dynamic)b); } } } public class Dijkstra // 書きかけ { private int maxIndex = -1; private const long INF = Int64.MaxValue; } public class Pair<T, U> : IComparable where T : IComparable<T> where U : IComparable<U> { public T Item1; public U Item2; public int CompareTo(object obj) { Pair<T, U> pair = (Pair<T, U>)obj; return Item1.CompareTo(pair.Item1); } public Pair(T t, U u) { Item1 = t; Item2 = u; } } // 計算量: Push -> O(logN), Peek -> O(1)。Clear() -> O(logN) // ToArray()で配列化 public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } /* -> Item: _heap(ヒープを持つ.sizeはmaxSize) -> Item: _type -> 0:asc(昇順), 1:desc(降順) */ public PriorityQueue(int maxSize, int type = 0) { _heap = new T[maxSize]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); // typeが0なら昇順, 1なら降順にソートするCompare } public void Push(T x) { _count++; // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() // O(1) { return _count; } public T Peek() // O(1) { return _heap[0]; } public bool Contains(T x) // O(N)なので注意 { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (Count() > 0) Pop(); } public IEnumerator<T> GetEnumerator() // なにこれ { var ret = new List<T>(); while (Count() > 0) { ret.Add(Pop()); } foreach (var r in ret) { Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } public class GenericOperation<T> { public GenericOperation() { var availableT = new Type[] { typeof(int), typeof(uint), typeof(short), typeof(ushort), typeof(long), typeof(ulong), typeof(byte), typeof(decimal), typeof(double) }; if (!availableT.Contains(typeof(T))) { throw new NotSupportedException(); } var p1 = Expression.Parameter(typeof(T)); var p2 = Expression.Parameter(typeof(T)); Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(p1, p2), p1, p2) .Compile(); Subtract = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(p1, p2), p1, p2) .Compile(); Multiply = Expression.Lambda<Func<T, T, T>>(Expression.Multiply(p1, p2), p1, p2) .Compile(); Divide = Expression.Lambda<Func<T, T, T>>(Expression.Divide(p1, p2), p1, p2) .Compile(); Modulo = Expression.Lambda<Func<T, T, T>>(Expression.Modulo(p1, p2), p1, p2) .Compile(); Equal = Expression.Lambda<Func<T, T, bool>>(Expression.Equal(p1, p2), p1, p2) .Compile(); GreaterThan = Expression .Lambda<Func<T, T, bool>>(Expression.GreaterThan(p1, p2), p1, p2) .Compile(); GreaterThanOrEqual = Expression .Lambda<Func<T, T, bool>>( Expression.GreaterThanOrEqual(p1, p2), p1, p2) .Compile(); LessThan = Expression.Lambda<Func<T, T, bool>>(Expression.LessThan(p1, p2), p1, p2) .Compile(); LessThanOrEqual = Expression .Lambda<Func<T, T, bool>>( Expression.LessThanOrEqual(p1, p2), p1, p2) .Compile(); } public Func<T, T, T> Add { get; private set; } public Func<T, T, T> Subtract { get; private set; } public Func<T, T, T> Multiply { get; private set; } public Func<T, T, T> Divide { get; private set; } public Func<T, T, T> Modulo { get; private set; } public Func<T, T, bool> Equal { get; private set; } public Func<T, T, bool> GreaterThan { get; private set; } public Func<T, T, bool> GreaterThanOrEqual { get; private set; } public Func<T, T, bool> LessThan { get; private set; } public Func<T, T, bool> LessThanOrEqual { get; private set; } } class Segtree<T> { int n; T[] tree; Func<T, T, T> f; T exnum; public Segtree(int m, Func<T, T, T> f, T ex) { this.f = f; exnum = ex; n = 1; while (n < m) n <<= 1; // resize calc tree = new T[(n << 1) - 1]; // resize for (int i = 0; i < tree.Length; i++) tree[i] = ex; // init } public Segtree(int m, T ini, Func<T, T, T> f, T ex) : this(m, f, ex) { for (int i = 0; i < m; ++i) tree[i + n - 1] = ini; All_update(); } public void Assign_without_update(int j, T x) { tree[j + n - 1] = x; } public void Update(int j, T x) { int i = j + n - 1; tree[i] = x; while (i > 0) { i = (i - 1) >> 1; tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } } public void All_update() { for (int i = n - 2; i >= 0; i--) tree[i] = f(tree[(i << 1) + 1], tree[(i << 1) + 2]); } public T Look(int i) { return tree[i + n - 1]; } // [s, t) public T Run(int s, int t) { return Query(s, t, 0, 0, n); } T Query(int s, int t, int k, int l, int r) { if (r <= s || t <= l) return exnum; if (s <= l && r <= t) return tree[k]; return f(Query(s, t, (k << 1) + 1, l, (l + r) >> 1), Query(s, t, (k + 1) << 1, (l + r) >> 1, r)); } }
[["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["+", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 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, 7, 8, 196, 0, 46], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
2,752
22
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder { public static class Program { static void Main() { var N = int.Parse(Console.ReadLine()); var forSort = new List<int>(N); var array = new int[N]; foreach (var i in Enumerable.Range(0, N)) { var v = int.Parse(Console.ReadLine()); array[i] = v; forSort.Add(int.Parse(Console.ReadLine())); } forSort.Sort(); var top = forSort[forSort.Count - 1]; var second = forSort[forSort.Count - 2]; for (int i = 0; i < array.Length; i++) { if (array[i] == top) { Console.WriteLine(second); continue; } Console.WriteLine(top); } } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder { public static class Program { static void Main() { var N = int.Parse(Console.ReadLine()); var forSort = new List<int>(N); var array = new int[N]; foreach (var i in Enumerable.Range(0, N)) { var v = int.Parse(Console.ReadLine()); array[i] = v; forSort.Add(v); } forSort.Sort(); var top = forSort[forSort.Count - 1]; var second = forSort[forSort.Count - 2]; for (int i = 0; i < array.Length; i++) { if (array[i] == top) { Console.WriteLine(second); continue; } Console.WriteLine(top); } } } }
[["-", 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], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 22], ["-", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
200
11
using System; using System.Linq; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(Console.ReadLine()); } int MaxA = A.Max(); int count = 0; int secondMax = 0; for (int i = 0; i < N; i++) { if (A[i] == MaxA) { count += 1; } if (A[i] < MaxA) { secondMax = A[i]; } } for (int i = 0; i < N; i++) { if (A[i] == MaxA && count > 1) { Console.WriteLine(MaxA); } else if (A[i] == MaxA && count <= 1) { Console.WriteLine(secondMax); } else { Console.WriteLine(MaxA); } } } }
using System; using System.Linq; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(Console.ReadLine()); } int MaxA = A.Max(); int count = 0; int secondMax = 0; for (int i = 0; i < N; i++) { if (A[i] == MaxA) { count += 1; } if (A[i] < MaxA && secondMax < A[i]) { secondMax = A[i]; } } for (int i = 0; i < N; i++) { if (A[i] == MaxA && count > 1) { Console.WriteLine(MaxA); } else if (A[i] == MaxA && count <= 1) { Console.WriteLine(secondMax); } else { Console.WriteLine(MaxA); } } } }
[["+", 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, 18], ["+", 0, 57, 15, 16, 12, 16, 12, 204, 205, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 70], ["+", 12, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 16, 12, 204, 206, 207, 0, 73]]
8
219
7
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(); int N = int.Parse(input); int[] ary = new int[N]; ary[0] = int.Parse(Console.ReadLine()); ary[1] = int.Parse(Console.ReadLine()); int max1 = ary[0] < ary[1] ? ary[1] : ary[0]; int max2 = ary[0] < ary[1] ? ary[0] : ary[1]; for (int i = 2; i < N; i++) { input = Console.ReadLine(); ary[i] = int.Parse(input); if (max1 <= ary[i]) { max2 = max1; max1 = ary[i]; } } for (int i = 0; i < N; i++) { if (max1 == max2) { Console.WriteLine(max1); } else { if (ary[i] != max1) { Console.WriteLine(max1); } else { Console.WriteLine(max2); } } } return; } } }
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(); int N = int.Parse(input); int[] ary = new int[N]; ary[0] = int.Parse(Console.ReadLine()); ary[1] = int.Parse(Console.ReadLine()); int max1 = ary[0] < ary[1] ? ary[1] : ary[0]; int max2 = ary[0] < ary[1] ? ary[0] : ary[1]; for (int i = 2; i < N; i++) { input = Console.ReadLine(); ary[i] = int.Parse(input); if (max1 < ary[i]) { max2 = max1; max1 = ary[i]; } else if (max2 < ary[i]) { max2 = ary[i]; } } for (int i = 0; i < N; i++) { if (max1 == max2) { Console.WriteLine(max1); } else { if (ary[i] != max1) { Console.WriteLine(max1); } else { Console.WriteLine(max2); } } } return; } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 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], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 24], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18], ["+", 0, 57, 75, 57, 15, 16, 12, 204, 205, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 70], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 75, 57, 15, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 196, 0, 57, 75, 57, 0, 25], ["+", 8, 196, 0, 57, 75, 57, 64, 196, 0, 45], ["+", 75, 57, 64, 196, 0, 1, 0, 11, 31, 22]]
8
276
21
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var org = new int[N]; var array = new int[N]; for (var i = 0; i < N; i++) { array[i] = int.Parse(Console.ReadLine()); org[i] = array[i]; } Array.Sort(array); for (var i = 0; i < N; i++) { if (array[i] == org[N - 1]) Console.WriteLine(array[N - 2]); else Console.WriteLine(array[N - 1]); } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var org = new int[N]; var array = new int[N]; for (var i = 0; i < N; i++) { array[i] = int.Parse(Console.ReadLine()); org[i] = array[i]; } Array.Sort(array); for (var i = 0; i < N; i++) { if (array[N - 1] == org[i]) Console.WriteLine(array[N - 2]); else Console.WriteLine(array[N - 1]); } } } }
[["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22]]
8
170
8
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Main { public static class Program { static void Main(string[] arg) { int n = int.Parse(Console.ReadLine()); var array = GetIntList(Console.ReadLine()); int answer = 0; var list = new List<int>(); int max = 0; int semimax = 0; bool maxes = false; for (int i = 0; i < n; i++) { int num = int.Parse(Console.ReadLine()); list.Add(num); if (num > max) { semimax = max; max = num; } else if (num > semimax) { semimax = num; } } if (list.Where(x => x == max).Count() > 1) maxes = true; for (int i = 0; i < n; i++) { if (list[i] < max) { Console.WriteLine(max); } else { if (maxes) { Console.WriteLine(max); } else { Console.WriteLine(semimax); } } // Console.WriteLine(answer); Console.ReadLine(); } } #region libraries private static int[] GetIntList(string line) { return line.Split(' ').Select(x => int.Parse(x)).ToArray(); } private static double[] GetDoubleList(string line) { return line.Split(' ').Select(x => double.Parse(x)).ToArray(); } private static ulong[] GetUlongList(string line) { return line.Split(' ').Select(x => ulong.Parse(x)).ToArray(); } private static long[] GetLongList(string line) { return line.Split(' ').Select(x => long.Parse(x)).ToArray(); } private static int SearchNearest(this IEnumerable<int> list, int target) { var min = list.Min(c => Math.Abs(c - target)); return list.First(c => Math.Abs(c - target) == min); } public static bool IsOdd(int i) { return i % 2 == 1 ? true : false; } public static int Gcd(int a, int b) { if (a < b) { Gcd(b, a); } while (b != 0) { var rm = a % b; a = b; b = rm; } return a; } #endregion } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Main { public static class Program { static void Main(string[] arg) { int n = int.Parse(Console.ReadLine()); // var array = GetIntList(Console.ReadLine()); int answer = 0; var list = new List<int>(); int max = 0; int semimax = 0; bool maxes = false; for (int i = 0; i < n; i++) { int num = int.Parse(Console.ReadLine()); list.Add(num); if (num > max) { semimax = max; max = num; } else if (num > semimax) { semimax = num; } } if (list.Where(x => x == max).Count() > 1) maxes = true; for (int i = 0; i < n; i++) { if (list[i] < max) { Console.WriteLine(max); } else { if (maxes) { Console.WriteLine(max); } else { Console.WriteLine(semimax); } } // Console.WriteLine(answer); Console.ReadLine(); } } #region libraries private static int[] GetIntList(string line) { return line.Split(' ').Select(x => int.Parse(x)).ToArray(); } private static double[] GetDoubleList(string line) { return line.Split(' ').Select(x => double.Parse(x)).ToArray(); } private static ulong[] GetUlongList(string line) { return line.Split(' ').Select(x => ulong.Parse(x)).ToArray(); } private static long[] GetLongList(string line) { return line.Split(' ').Select(x => long.Parse(x)).ToArray(); } private static int SearchNearest(this IEnumerable<int> list, int target) { var min = list.Min(c => Math.Abs(c - target)); return list.First(c => Math.Abs(c - target) == min); } public static bool IsOdd(int i) { return i % 2 == 1 ? true : false; } public static int Gcd(int a, int b) { if (a < b) { Gcd(b, a); } while (b != 0) { var rm = a % b; a = b; b = rm; } return a; } #endregion } }
[["-", 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], ["-", 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], ["-", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35]]
8
553
12
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { class Program { static void Main(string[] args) { var cin = new Scanner(); var N = cin.nextInt(); int[] a = new int[N]; for (int i = 0; i < N; i++) { a[i] = cin.nextInt(); } var list = a.ToList(); var clist = new List<int>(list); list.Sort(); for (int i = 0; i < N; i++) { var now = a[i]; if (now != list[N - 1]) { Console.WriteLine(clist[N - 2]); } else { Console.WriteLine(clist[N - 1]); } } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { class Program { static void Main(string[] args) { var cin = new Scanner(); var N = cin.nextInt(); int[] a = new int[N]; for (int i = 0; i < N; i++) { a[i] = cin.nextInt(); } var list = a.ToList(); list.Sort(); for (int i = 0; i < N; i++) { var now = a[i]; if (now == list[N - 1]) { Console.WriteLine(list[N - 2]); } else { Console.WriteLine(list[N - 1]); } } } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["-", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["-", 0, 212, 0, 230, 3, 4, 0, 28, 0, 22], ["-", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 60], ["-", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22]]
8
547
18
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0030 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int[] B = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); int result = 0; for (int i = 0; i < B.Length; i++) { if (B[i] <= A[i]) { A[i] = A[i] - B[i]; result += B[i]; B[i] = B[i] - B[i]; } else { B[i] = B[i] - A[i]; result += A[i]; } if (B[i] == 0) { continue; } if (B[i] <= A[i + 1]) { A[i + 1] = A[i + 1] - B[i]; result += B[i]; } else { result += A[i + 1]; A[i + 1] = 0; } } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atc_0030 { class Program { static void Main(string[] args) { Int64 N = Int64.Parse(Console.ReadLine()); Int64[] A = Console.ReadLine().Split(' ').Select(Int64.Parse).ToArray(); Int64[] B = Console.ReadLine().Split(' ').Select(Int64.Parse).ToArray(); Int64 result = 0; for (int i = 0; i < B.Length; i++) { if (B[i] <= A[i]) { A[i] = A[i] - B[i]; result += B[i]; B[i] = 0; } else { B[i] = B[i] - A[i]; result += A[i]; } if (B[i] == 0) { continue; } if (B[i] <= A[i + 1]) { A[i + 1] = A[i + 1] - B[i]; result += B[i]; } else { result += A[i + 1]; A[i + 1] = 0; } } Console.WriteLine(result); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["-", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 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], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
300
24
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC135C { class Program { static void Main(string[] args) { var N = RInt; var A = RLongs; var B = RLongs; long ans = 0; for (int i = 0; i < N; i++) { if (A[i] <= B[i]) { long atk = Math.Min(B[i], A[i]); ans += atk; A[i] -= atk; B[i] -= atk; atk = Math.Min(B[i], A[i + 1]); ans += atk; A[i + 1] -= atk; } } Console.WriteLine(ans); } } } 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(); } 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 ABC135C { class Program { static void Main(string[] args) { var N = RInt; var A = RLongs; var B = RLongs; long ans = 0; for (int i = 0; i < N; i++) { long atk = Math.Min(B[i], A[i]); ans += atk; A[i] -= atk; B[i] -= atk; atk = Math.Min(B[i], A[i + 1]); ans += atk; A[i + 1] -= atk; } Console.WriteLine(ans); } } } 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(); } 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 } } }
[["-", 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, 19], ["-", 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, 7, 8, 196, 0, 57, 0, 25], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
784
14
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { { int N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(int.Parse).ToArray(); var B = Console.ReadLine().Split().Select(int.Parse).ToArray(); int a, b, cnt; int ans = 0; for (int i = 0; i < N; i++) { a = A[i]; b = B[i]; ans += cnt = Math.Min(a, b); ans += cnt = Math.Min(b - cnt, A[i + 1]); A[i + 1] -= cnt; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { { long N = long.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(long.Parse).ToArray(); var B = Console.ReadLine().Split().Select(long.Parse).ToArray(); long a, b, cnt; long ans = 0; for (long i = 0; i < N; i++) { a = A[i]; b = B[i]; ans += cnt = Math.Min(a, b); ans += cnt = Math.Min(b - cnt, A[i + 1]); A[i + 1] -= cnt; } Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 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], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 8, 196, 0, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 196, 0, 7, 10, 198, 39, 199]]
8
182
14
using System; class ProgramC { static void Main(string[] args) { string input = Console.ReadLine(); int n = int.Parse(input); string[] input_a = Console.ReadLine().Split(' '); int[] a = new int[n + 1]; for (int i = 0; i < n + 1; i++) a[i] = int.Parse(input_a[i]); string[] input_b = Console.ReadLine().Split(' '); int[] b = new int[n]; for (int i = 0; i < n; i++) b[i] = int.Parse(input_b[i]); int count = 0; if (a[0] >= b[0]) { count += b[0]; b[0] = 0; } else { count += a[0]; b[0] -= a[0]; } for (int i = 1; i < n; i++) { if (a[i] >= b[i - 1]) { count += b[i - 1]; a[i] -= b[i - 1]; b[i - 1] = 0; } else { count += a[i]; b[i - 1] -= a[i]; a[i] = 0; } if (a[i] >= b[i]) { count += b[i]; a[i] -= b[i - 1]; b[i] = 0; } else { count += a[i]; b[i] -= a[i]; a[i] = 0; } } if (a[n] >= b[n - 1]) { count += b[n - 1]; a[n] -= b[n - 1]; b[n - 1] = 0; } else { count += a[n]; b[n - 1] -= a[n]; a[n] = 0; } Console.WriteLine(count); } }
using System; class ProgramC { static void Main(string[] args) { string input = Console.ReadLine(); int n = int.Parse(input); string[] input_a = Console.ReadLine().Split(' '); long[] a = new long[n + 1]; for (int i = 0; i < n + 1; i++) a[i] = long.Parse(input_a[i]); string[] input_b = Console.ReadLine().Split(' '); long[] b = new long[n]; for (int i = 0; i < n; i++) b[i] = long.Parse(input_b[i]); long count = 0; if (a[0] >= b[0]) { count += b[0]; b[0] = 0; } else { count += a[0]; b[0] -= a[0]; } for (int i = 1; i < n; i++) { if (a[i] >= b[i - 1]) { count += b[i - 1]; a[i] -= b[i - 1]; b[i - 1] = 0; } else { count += a[i]; b[i - 1] -= a[i]; a[i] = 0; } if (a[i] >= b[i]) { count += b[i]; a[i] -= b[i]; b[i] = 0; } else { count += a[i]; b[i] -= a[i]; a[i] = 0; } } if (a[n] >= b[n - 1]) { count += b[n - 1]; a[n] -= b[n - 1]; b[n - 1] = 0; } else { count += a[n]; b[n - 1] -= a[n]; a[n] = 0; } Console.WriteLine(count); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 8, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 8, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["-", 12, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
450
16
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { // Console.WriteLine($"enter number."); // var num = int.Parse(Console.ReadLine()); // Console.WriteLine($"fibonacci num: {SolveFibonacci(num)}"); // Console.ReadLine(); // for (int i = 0; i < 50; i++) //{ // Console.WriteLine($"Solve({i}): {SolveFibonacci(i)}"); // //Console.WriteLine($"Solve({i}): {SolveFibonacciAsync(i).Result}"); //} int n = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(int.Parse).ToArray(); var B = Console.ReadLine().Split().Select(int.Parse).ToArray(); // 下から順番に倒せるだけ倒す int remainPower = 0; long killCnt = 0; for (int i = 0; i < n; i++) { // killCnt += Math.Min(A[i], B[i]); if (A[i] < B[i] + remainPower) { killCnt += A[i]; remainPower = B[i] - Math.Max(A[i] - remainPower, 0); } else { // A[i] >= B[i] + remainPower remainPower = 0; killCnt += B[i] + remainPower; } if (i + 1 == n && remainPower > 0) killCnt += Math.Min(remainPower, A[i + 1]); // 1. B[i] + remainPower ( A[i] >= ( B[i] + remainPower)) // 2. A[i] ( A[i] < (B[i] + remainPower) ) // 2.の場合remainPowerにB[i] - (A[i] - // remainPower)を代入し、次回に持ち越す 1.の場合はremainPowerを0にする } Console.WriteLine(killCnt); // Console.ReadLine(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FibonacciSample { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split().Select(int.Parse).ToArray(); var B = Console.ReadLine().Split().Select(int.Parse).ToArray(); // 下から順番に倒せるだけ倒す int remainPower = 0; long killCnt = 0; for (int i = 0; i < n; i++) { // killCnt += Math.Min(A[i], B[i]); if (A[i] < B[i] + remainPower) { killCnt += A[i]; remainPower = B[i] - Math.Max(A[i] - remainPower, 0); } else { // A[i] >= B[i] + remainPower killCnt += B[i] + remainPower; remainPower = 0; } if (i + 1 == n && remainPower > 0) killCnt += Math.Min(remainPower, A[i + 1]); // 1. B[i] + remainPower ( A[i] >= ( B[i] + remainPower)) // 2. A[i] ( A[i] < (B[i] + remainPower) ) // 2.の場合remainPowerにB[i] - (A[i] - // remainPower)を代入し、次回に持ち越す 1.の場合はremainPowerを0にする } Console.WriteLine(killCnt); } } }
[["+", 36, 36, 36, 36, 0, 208, 0, 209, 0, 256], ["+", 36, 36, 36, 36, 0, 208, 0, 209, 141, 22], ["+", 36, 36, 0, 208, 0, 209, 8, 201, 0, 45], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46]]
8
242
12
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp2 { public class Program { static long D = (long)Math.Pow(10, 9) + 7; public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] monsterNumbers = Console.ReadLine().Split(' '); string[] limits = Console.ReadLine().Split(' '); int killNumber = 0; int nextMonsterNumber = int.Parse(monsterNumbers[0]); for (int i = 0; i < N; i++) { int mNumber = nextMonsterNumber; nextMonsterNumber = int.Parse(monsterNumbers[i + 1]); int limit = int.Parse(limits[i]); if (mNumber >= limit) killNumber += limit; else { int surplus = limit - mNumber; killNumber += mNumber; if (nextMonsterNumber >= surplus) { nextMonsterNumber -= surplus; killNumber += surplus; } else { killNumber += nextMonsterNumber; nextMonsterNumber = 0; } } } Console.WriteLine(killNumber); Console.ReadLine(); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp2 { public class Program { public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] monsterNumbers = Console.ReadLine().Split(' '); string[] limits = Console.ReadLine().Split(' '); long killNumber = 0; int nextMonsterNumber = int.Parse(monsterNumbers[0]); for (int i = 0; i < N; i++) { int mNumber = nextMonsterNumber; nextMonsterNumber = int.Parse(monsterNumbers[i + 1]); int limit = int.Parse(limits[i]); if (mNumber >= limit) killNumber += limit; else { int surplus = limit - mNumber; killNumber += mNumber; if (nextMonsterNumber >= surplus) { nextMonsterNumber -= surplus; killNumber += surplus; } else { killNumber += nextMonsterNumber; nextMonsterNumber = 0; } } } Console.WriteLine(killNumber); Console.ReadLine(); } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 251, 0, 115], ["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 8, 201, 0, 124, 0, 198, 0, 200, 141, 22], ["-", 0, 124, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 0, 24], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 39, 199], ["-", 0, 200, 0, 212, 0, 16, 31, 74, 0, 25], ["-", 0, 16, 31, 74, 51, 213, 63, 214, 205, 22], ["-", 0, 16, 31, 74, 51, 213, 63, 214, 0, 131], ["-", 0, 16, 31, 74, 51, 213, 63, 214, 141, 22], ["-", 0, 16, 31, 74, 51, 213, 3, 4, 0, 24], ["-", 31, 74, 51, 213, 3, 4, 0, 28, 0, 203], ["-", 0, 16, 31, 74, 51, 213, 3, 4, 0, 21], ["-", 0, 16, 31, 74, 51, 213, 3, 4, 0, 25], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 8, 201, 0, 235, 8, 201, 0, 124, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
234
20
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { int N = cin.ReadInt; int[] A = cin.ReadIntArray(N + 1); int[] B = cin.ReadIntArray(N); int ans = 0; for (int i = 0; i < N; i++) { if (B[i] <= A[i]) { ans += B[i]; } else { ans += A[i]; B[i] -= A[i]; if (B[i] <= A[i + 1]) { ans += B[i]; A[i + 1] -= B[i]; } else { ans += A[i + 1]; A[i + 1] = 0; } } } Console.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; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { long N = cin.ReadLong; long[] A = cin.ReadLongArray(N + 1); long[] B = cin.ReadLongArray(N); long ans = 0; for (long i = 0; i < N; i++) { if (B[i] <= A[i]) { ans += B[i]; } else { ans += A[i]; B[i] -= A[i]; if (B[i] <= A[i + 1]) { ans += B[i]; A[i + 1] -= B[i]; } else { ans += A[i + 1]; A[i + 1] = 0; } } } Console.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; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
8
626
16
namespace AtCoder { using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Util; class AtCoder { /*------------------------------------------------------------------*/ private int N; private long[] A, B; void Solve() { io.i(out N); io.ini(out A, N + 1); B = new long[N + 1]; REP(N, i => B[i] = io.Int); ZIP(A, B) .Aggregate(new Tuple<long, long>(0, 0), (acc, x) => { var sum = acc.Item1; var pre = acc.Item2; var a = x.Item1; var b = x.Item2 + pre; var use = Min(a, b); return new Tuple<long, long>(sum + use, b - use); }) .Item1.Prt(); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] _) => new AtCoder().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class Util { public static T Id<T>(T x) => x; public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static IEnumerable<TResult> ZIP<T1, T2, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, Func<T1, T2, TResult> f = null) { using (var e1 = xs.GetEnumerator()) using ( var e2 = ys.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext()) yield return f(e1.Current, e2.Current); } public static IEnumerable<Tuple<T1, T2>> ZIP<T1, T2>(IEnumerable<T1> xs, IEnumerable<T2> ys) => ZIP(xs, ys, (x, y) => new Tuple<T1, T2>(x, y)); public static IEnumerable<TResult> ZIP<T1, T2, T3, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs, Func<T1, T2, T3, TResult> f) { using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) using ( var e3 = zs.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) yield return f(e1.Current, e2.Current, e3.Current); } public static IEnumerable<Tuple<T1, T2, T3>> ZIP<T1, T2, T3>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs) => ZIP(xs, ys, zs, (x, y, z) => new Tuple<T1, T2, T3>(x, y, z)); public static bool ODD(int x) => x % 2 != 0; public static bool ODD(long x) => x % 2L != 0L; public static bool EVE(int x) => !ODD(x); public static bool EVE(long x) => !ODD(x); public static T MAX<T>(params T[] xs) => xs.Max(); public static T MIN<T>(params T[] xs) => xs.Min(); public static int SUM(params int[] xs) => xs.Sum(); public static long SUM(params long[] xs) => xs.Sum(); public static IEnumerable<int> RANGE(int start, int step = 1) { var v = start; while (true) { yield return v; v += step; } } public struct IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public class Counts<T> : Dictionary<T, int> { public Counts() {} public Counts(params T[] xs) : this() { Add(xs); } public Counts(IEnumerable<T> xs) : this() { foreach (var x in xs) Add(x); } public new int this[T key] { get { int v; return this.TryGetValue(key, out v) ? v : 0; } } public void Add(T key) { if (!base.ContainsKey(key)) base.Add(key, 0); base[key]++; } public void Add(params T[] xs) => xs.Iter(Add); public IEnumerable<KeyValuePair<T, int>> SortByCount(bool isAsc) => (isAsc ? (this.OrderBy(kp => kp.Value)) : (this.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key); } public class PriorityQueue<T> where T : IComparable<T> { private List<T> heap; private readonly bool isAsc; private int size; public T Peek => heap[0]; public int Count => size; public bool Any => size > 0; public bool Empty => !Any; public IEnumerable<T> Values => heap; public PriorityQueue(bool isAsc = true) { this.isAsc = isAsc; size = 0; heap = new List<T>(); } public void Enqueue(T item) { heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) / 2; if (Compare(heap[p], item) <= 0) break; heap[i] = heap[p]; i = p; } heap[i] = item; } public T Dequeue() { var ret = heap[0]; var x = heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } private int Compare(T x, T y) => isAsc ? x.CompareTo(y) : y.CompareTo(x); } } static class Ex { public static Tuple<IEnumerable<T>, IEnumerable<T>> Split<T>(this IEnumerable<T> xs, Func<T, bool> f) { var ys = xs.Where(f); var zs = xs.Where(x => !f(x)); return Tuple.Create(ys, zs); } public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x)); public static void Log<T>(this T x) { #if DEBUG WriteLine($"LOG [{nameof(x)}] : {x}"); #endif } public static IEnumerable<IndexedItem<T>> Indexed<T>(this IEnumerable<T> xs) => xs.Select((x, idx) => new IndexedItem<T>(idx, x)); public static IEnumerable<T> UnIndexed<T>(this IEnumerable<IndexedItem<T>> xs) => xs.Select(x => x.Val); public static IEnumerable<Tuple<T, T>> Pairwise<T>(this IEnumerable<T> xs) => ZIP(xs, xs.Skip(1)); public static IEnumerable<int> ToZeroIndexed(this IEnumerable<int> xs) => xs.Select(x => x - 1); public static string Join<T>(this IEnumerable<T> xs, string str = " ") => String.Join(str, xs); public static string Sort(this string s) { var arr = s.ToCharArray(); Array.Sort(arr); return new string(arr); } public static string Yn(this bool f, string y = "Yes", string n = "No") => f ? y : n; public static bool Is<T>(this T x, Func<T, bool> f) => f(x); public static TU Fun<T, TU>(this T x, Func<T, TU> f) => f(x); } }
namespace AtCoder { using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using static System.Console; using static System.Math; using static Util; class AtCoder { /*------------------------------------------------------------------*/ private int N; private long[] A, B; void Solve() { io.i(out N); io.ini(out A, N + 1); B = new long[N + 1]; REP(N, i => B[i] = io.Int); ZIP(A, B) .Aggregate(new Tuple<long, long>(0, 0), (acc, x) => { var sum = acc.Item1; var pre = acc.Item2; var a = x.Item1; var b = x.Item2; var usePre = Min(a, pre); var useOrig = Min(a - usePre, b); return new Tuple<long, long>(sum + useOrig + usePre, b - useOrig); }) .Item1.Prt(); } /*------------------------------------------------------------------*/ void Test() { //--- TEST ---// } public static void Main(string[] _) => new AtCoder().Stream(); IO io = new IO(); private void Stream() { /* var exStdIn = new System.IO.StreamReader("stdin.txt"); SetIn(exStdIn); Test(); */ Solve(); io.Flush(); } } class IO { #region INPUT #region FastRead private const int Size = 1 << 12; private readonly Stream _stream = OpenStandardInput(); private readonly byte[] _buffer = new byte[Size]; private int _ptr = 0, _buffLen = 0; private bool HasNextByte() { if (_ptr < _buffLen) return true; _ptr = 0; _buffLen = _stream.Read(_buffer, 0, Size); return _buffLen > 0; } private byte ReadByte() { if (HasNextByte()) return _buffer[_ptr++]; else // inputの末尾の改行がないとerror throw new EndOfStreamException(); } private bool IsAscii(int c) => '!' <= c && c <= '~'; private char NextChar() { var b = ReadByte(); while (!IsAscii(b)) b = ReadByte(); return (char)b; } private string Next() { var sb = new StringBuilder(); for (var b = NextChar(); IsAscii(b); b = (char)ReadByte()) sb.Append(b); return sb.ToString(); } public string String => Next(); public char Char => NextChar(); public int Int => int.Parse(Next()); public long Long => long.Parse(Next()); public double Double => double.Parse(Next()); #endregion #region LazyRead private void scan<T>(ref T x) { if (x is int) __refvalue(__makeref(x), int) = int.Parse(Next()); else if (x is long) __refvalue(__makeref(x), long) = long.Parse(Next()); else if (x is double) __refvalue(__makeref(x), double) = double.Parse(Next()); else if (x is char) __refvalue(__makeref(x), char) = NextChar(); else __refvalue(__makeref(x), string) = Next(); } public void i<T>(out T t) { t = default(T); scan(ref t); } public void i<T, TU>(out T t, out TU u) { i(out t); i(out u); } public void i<T, TU, TV>(out T t, out TU u, out TV v) { i(out t, out u); i(out v); } public void i<T, TU, TV, TW>(out T t, out TU u, out TV v, out TW w) { i(out t, out u); i(out v, out w); } public void i<T, TU, TV, TW, TX>(out T t, out TU u, out TV v, out TW w, out TX x) { i(out t, out u, out v); i(out w, out x); } public void i<T, TU, TV, TW, TX, TY>(out T t, out TU u, out TV v, out TW w, out TX x, out TY y) { i(out t, out u, out v); i(out w, out x, out y); } public void ini<T>(out T[] a, int n) { a = new T[n]; for (int i = 0; i < n; ++i) i<T>(out a[i]); } public void ini<T, TU>(out T[] a, out TU[] b, int n) { a = new T[n]; b = new TU[n]; for (int i = 0; i < n; ++i) i<T, TU>(out a[i], out b[i]); } public void ini<T, TU, TV>(out T[] a, out TU[] b, out TV[] c, int n) { a = new T[n]; b = new TU[n]; c = new TV[n]; for (var i = 0; i < n; ++i) i<T, TU, TV>(out a[i], out b[i], out c[i]); } public void ini<T>(out T[,] a, int h, int w) { a = new T[h, w]; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) i<T>(out a[i, j]); } #endregion #endregion #region OUTPUT private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput()) { #if DEBUG AutoFlush = true #else AutoFlush = false #endif }; public void Flush() => Out.Flush(); public void YN(bool f) => yn(f, "YES", "NO"); public void Yn(bool f) => yn(f, "Yes", "No"); public void yn(bool f, string y = "yes", string n = "no") => WriteLine(f ? y : n); #endregion public IO() { SetOut(_sw); } } static class Util { public static T Id<T>(T x) => x; public static void FOR(int a, int b, Action<int> f) => FOR(a, b, 1, f); public static void FOR(int a, int b, int n, Action<int> f) { for (int i = a; i < b; i += n) f(i); } public static void FOREQ(int a, int b, int n, Action<int> f) => FOR(a, b + 1, n, f); public static void FOREQ(int a, int b, Action<int> f) => FOR(a, b + 1, f); public static void REP(int a, Action<int> f) => FOR(0, a, f); public static void REPEQ(int a, Action<int> f) => FOR(0, a + 1, f); public static IEnumerable<TResult> ZIP<T1, T2, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, Func<T1, T2, TResult> f = null) { using (var e1 = xs.GetEnumerator()) using ( var e2 = ys.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext()) yield return f(e1.Current, e2.Current); } public static IEnumerable<Tuple<T1, T2>> ZIP<T1, T2>(IEnumerable<T1> xs, IEnumerable<T2> ys) => ZIP(xs, ys, (x, y) => new Tuple<T1, T2>(x, y)); public static IEnumerable<TResult> ZIP<T1, T2, T3, TResult>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs, Func<T1, T2, T3, TResult> f) { using (var e1 = xs.GetEnumerator()) using (var e2 = ys.GetEnumerator()) using ( var e3 = zs.GetEnumerator()) while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) yield return f(e1.Current, e2.Current, e3.Current); } public static IEnumerable<Tuple<T1, T2, T3>> ZIP<T1, T2, T3>(IEnumerable<T1> xs, IEnumerable<T2> ys, IEnumerable<T3> zs) => ZIP(xs, ys, zs, (x, y, z) => new Tuple<T1, T2, T3>(x, y, z)); public static bool ODD(int x) => x % 2 != 0; public static bool ODD(long x) => x % 2L != 0L; public static bool EVE(int x) => !ODD(x); public static bool EVE(long x) => !ODD(x); public static T MAX<T>(params T[] xs) => xs.Max(); public static T MIN<T>(params T[] xs) => xs.Min(); public static int SUM(params int[] xs) => xs.Sum(); public static long SUM(params long[] xs) => xs.Sum(); public static IEnumerable<int> RANGE(int start, int step = 1) { var v = start; while (true) { yield return v; v += step; } } public struct IndexedItem<T> { public int Idx; public T Val; public IndexedItem(int idx, T val) { Idx = idx; Val = val; } } public class Counts<T> : Dictionary<T, int> { public Counts() {} public Counts(params T[] xs) : this() { Add(xs); } public Counts(IEnumerable<T> xs) : this() { foreach (var x in xs) Add(x); } public new int this[T key] { get { int v; return this.TryGetValue(key, out v) ? v : 0; } } public void Add(T key) { if (!base.ContainsKey(key)) base.Add(key, 0); base[key]++; } public void Add(params T[] xs) => xs.Iter(Add); public IEnumerable<KeyValuePair<T, int>> SortByCount(bool isAsc) => (isAsc ? (this.OrderBy(kp => kp.Value)) : (this.OrderByDescending(kp => kp.Value))) .ThenBy(kp => kp.Key); } public class PriorityQueue<T> where T : IComparable<T> { private List<T> heap; private readonly bool isAsc; private int size; public T Peek => heap[0]; public int Count => size; public bool Any => size > 0; public bool Empty => !Any; public IEnumerable<T> Values => heap; public PriorityQueue(bool isAsc = true) { this.isAsc = isAsc; size = 0; heap = new List<T>(); } public void Enqueue(T item) { heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) / 2; if (Compare(heap[p], item) <= 0) break; heap[i] = heap[p]; i = p; } heap[i] = item; } public T Dequeue() { var ret = heap[0]; var x = heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && Compare(heap[b], heap[a]) < 0) a = b; if (Compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } private int Compare(T x, T y) => isAsc ? x.CompareTo(y) : y.CompareTo(x); } } static class Ex { public static Tuple<IEnumerable<T>, IEnumerable<T>> Split<T>(this IEnumerable<T> xs, Func<T, bool> f) { var ys = xs.Where(f); var zs = xs.Where(x => !f(x)); return Tuple.Create(ys, zs); } public static void Iter<T>(this IEnumerable<T> xs, Action<T> f) { foreach (var x in xs) f(x); } public static void Prt<T>(this T x) => WriteLine(x); public static void Prt<T>(this IEnumerable<T> xs) => xs.Iter(x => WriteLine(x)); public static void Log<T>(this T x) { #if DEBUG WriteLine($"LOG [{nameof(x)}] : {x}"); #endif } public static IEnumerable<IndexedItem<T>> Indexed<T>(this IEnumerable<T> xs) => xs.Select((x, idx) => new IndexedItem<T>(idx, x)); public static IEnumerable<T> UnIndexed<T>(this IEnumerable<IndexedItem<T>> xs) => xs.Select(x => x.Val); public static IEnumerable<Tuple<T, T>> Pairwise<T>(this IEnumerable<T> xs) => ZIP(xs, xs.Skip(1)); public static IEnumerable<int> ToZeroIndexed(this IEnumerable<int> xs) => xs.Select(x => x - 1); public static string Join<T>(this IEnumerable<T> xs, string str = " ") => String.Join(str, xs); public static string Sort(this string s) { var arr = s.ToCharArray(); Array.Sort(arr); return new string(arr); } public static string Yn(this bool f, string y = "Yes", string n = "No") => f ? y : n; public static bool Is<T>(this T x, Func<T, bool> f) => f(x); public static TU Fun<T, TU>(this T x, Func<T, TU> f) => f(x); } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 0, 28, 0, 218, 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, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 212, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["-", 0, 230, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 12, 22], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 230, 3, 4, 0, 28, 0, 16, 12, 22]]
8
3,165
20
using System; using System.Text.RegularExpressions; namespace CitySavers { class Program { static void Main(string[] args) { int Savernum = Convert.ToInt32(Console.ReadLine()); int[] CityMonster = new int[Savernum + 1]; int[] Saver = new int[Savernum]; int tmpnum = 0; foreach (string x in Regex.Split(Console.ReadLine(), @"\s+")) { CityMonster[tmpnum] = Convert.ToInt32(x); tmpnum += 1; } tmpnum = 0; foreach (string x in Regex.Split(Console.ReadLine(), @"\s+")) { Saver[tmpnum] = Convert.ToInt32(x); tmpnum += 1; } int destroy = 0; for (int i = 0; i < Savernum; i++) { destroyMons(ref destroy, ref CityMonster, Saver, i); } Console.WriteLine(destroy); } public static void destroyMons(ref int destroy, ref int[] CityMonster, int[] Saver, int num) { int saver = Saver[num]; int sum = CityMonster[num] + CityMonster[num + 1]; if (saver >= sum) { destroy += sum; CityMonster[num] = 0; CityMonster[num + 1] = 0; } else { destroy += saver; int tmpnum = CityMonster[num] - saver; if (tmpnum < 0) { CityMonster[num] = 0; CityMonster[num + 1] += tmpnum; } else { CityMonster[num] = tmpnum; } } } } }
using System; using System.Text.RegularExpressions; namespace CitySavers { class Program { static void Main(string[] args) { int Savernum = Convert.ToInt32(Console.ReadLine()); Double[] CityMonster = new Double[Savernum + 1]; Double[] Saver = new Double[Savernum]; int tmpnum = 0; foreach (string x in Regex.Split(Console.ReadLine(), @"\s+")) { CityMonster[tmpnum] = Convert.ToDouble(x); tmpnum += 1; } tmpnum = 0; foreach (string x in Regex.Split(Console.ReadLine(), @"\s+")) { Saver[tmpnum] = Convert.ToDouble(x); tmpnum += 1; } Double destroy = 0; for (int i = 0; i < Savernum; i++) { destroyMons(ref destroy, ref CityMonster, Saver, i); } Console.WriteLine(destroy); } public static void destroyMons(ref Double destroy, ref Double[] CityMonster, Double[] Saver, int num) { Double saver = Saver[num]; Double sum = CityMonster[num] + CityMonster[num + 1]; if (saver >= sum) { destroy += sum; CityMonster[num] = 0; CityMonster[num + 1] = 0; } else { destroy += saver; Double tmpnum = CityMonster[num] - saver; if (tmpnum < 0) { CityMonster[num] = 0; CityMonster[num + 1] += tmpnum; } else { CityMonster[num] = tmpnum; } } } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 22], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 22], ["-", 0, 195, 54, 55, 0, 220, 39, 224, 39, 199], ["+", 0, 195, 54, 55, 0, 220, 39, 224, 39, 22], ["-", 0, 57, 75, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 57, 75, 196, 0, 197, 0, 198, 39, 22]]
8
316
26
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp5 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] A = new long[N + 1]; long[] B = new long[N]; String S = Console.ReadLine(); String[] L = S.Split(' '); for (int i = 0; i < N + 1; i++) { A[i] = long.Parse(L[i]); } S = Console.ReadLine(); L = S.Split(' '); long ans = 0; for (int i = 0; i < N; i++) { B[i] = long.Parse(L[i]); } for (int i = 0; i < N; i++) { if (A[i] <= B[i]) { ans = ans + A[i]; B[i] = B[i] - A[i]; A[i] = 0; if (A[i + 1] <= B[i]) { ans = ans + A[i + 1]; B[i] = B[i] - A[i + 1]; A[i + 1] = 0; } else { ans = ans + B[i]; B[i] = 0; A[i + 1] = A[i + 1] - B[i]; } } else { ans = ans + B[i]; B[i] = 0; A[i] = A[i] - B[i]; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp5 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] A = new long[N + 1]; long[] B = new long[N]; String S = Console.ReadLine(); String[] L = S.Split(' '); for (int i = 0; i < N + 1; i++) { A[i] = long.Parse(L[i]); } S = Console.ReadLine(); L = S.Split(' '); long ans = 0; for (int i = 0; i < N; i++) { B[i] = long.Parse(L[i]); } for (int i = 0; i < N; i++) { if (A[i] <= B[i]) { ans = ans + A[i]; B[i] = B[i] - A[i]; A[i] = 0; if (A[i + 1] <= B[i]) { ans = ans + A[i + 1]; B[i] = B[i] - A[i + 1]; A[i + 1] = 0; } else { ans = ans + B[i]; A[i + 1] = A[i + 1] - B[i]; B[i] = 0; } } else { ans = ans + B[i]; B[i] = 0; A[i] = A[i] - B[i]; } } Console.WriteLine(ans); } } }
[["-", 75, 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], ["-", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["-", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 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], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203]]
8
388
14
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 int n = int.Parse(Console.ReadLine()); int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), i => int.Parse(i)); int[] b = Array.ConvertAll(Console.ReadLine().Split(' '), i => int.Parse(i)); long sum = 0; for (int i = 0; i < n; i++) { if (a[i] >= b[i]) { sum += b[i]; } else { sum += a[i]; b[i] -= a[i]; if (a[i + 1] >= b[i]) { sum += b[i]; } else { sum += a[i + 1]; a[i + 1] = 0; } } } Console.WriteLine(sum); } }
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 int n = int.Parse(Console.ReadLine()); int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), i => int.Parse(i)); int[] b = Array.ConvertAll(Console.ReadLine().Split(' '), i => int.Parse(i)); long sum = 0; for (int i = 0; i < n; i++) { if (a[i] >= b[i]) { sum += b[i]; } else { sum += a[i]; b[i] -= a[i]; if (a[i + 1] >= b[i]) { sum += b[i]; a[i + 1] -= b[i]; } else { sum += a[i + 1]; a[i + 1] = 0; } } } Console.WriteLine(sum); } }
[["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 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], ["+", 75, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
210
12
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using static System.Math; namespace NewCompetitionProgramming { public class Program { public static void Main(string[] args) { using (var sc = new SetConsole()) { Solve(); } } public static void Solve() { int n = GetString().ToInt(); var a = GetArray<int>(); var b = GetArray<int>(); int count = 0; for (int i = 0; i < n; i++) { var diff = b[i] - a[i]; if (-1 * diff >= 0) { count += b[i]; continue; } if (a[i + 1] - diff >= 0) { count += a[i] + diff; a[i + 1] -= diff; } else { count += a[i] + a[i + 1]; a[i + 1] = 0; } } CWrite(count); } static void CWrite<T>(T str) => Console.WriteLine(str); static string GetString() => Console.ReadLine(); static T[] GetArray<T>() { var t = typeof(T); var str = Console.ReadLine(); if (t == typeof(string)) { return (T[])(object)str.Split(); } if (t == typeof(int)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(long)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(double)) { return (T[])(object)str.ToNumArray<T>(); } throw new NotSupportedException($"{t} is not supported."); } } class SetConsole : IDisposable { readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); public SetConsole() { sw.AutoFlush = false; Console.SetOut(sw); } public void Dispose() { Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } } static class ExtentionsLibrary { public static T[] CopyArray<T>(this T[] array) { var newArray = new T[array.Length]; Array.Copy(array, newArray, array.Length); return newArray; } public static T[,] CopyTwoDimensionalArray<T>(this T[,] dArray) { var firstDimentionLength = dArray.GetLength(0); var secondDimentionLength = dArray.GetLength(1); var newDArray = new T[firstDimentionLength, secondDimentionLength]; Array.Copy(dArray, newDArray, firstDimentionLength * secondDimentionLength); return newDArray; } public static T[] ToNumArray<T>(this string str) { var t = typeof(T); if (t == typeof(int)) { return (T[])(object)str.Split().Select(int.Parse).ToArray(); } if (t == typeof(long)) { return (T[])(object)str.Split().Select(long.Parse).ToArray(); } if (t == typeof(double)) { return (T[])(object)str.Split().Select(double.Parse).ToArray(); } throw new NotSupportedException(); } public static int ToInt(this string str) => int.Parse(str); public static int ToInt(this char chr) => int.Parse(chr.ToString()); public static long ToLong(this string str) => long.Parse(str); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using static System.Math; namespace NewCompetitionProgramming { public class Program { public static void Main(string[] args) { using (var sc = new SetConsole()) { Solve(); } } public static void Solve() { int n = GetString().ToInt(); var a = GetArray<int>(); var b = GetArray<int>(); var count = 0L; for (int i = 0; i < n; i++) { var diff = b[i] - a[i]; if (a[i] - b[i] >= 0) { count += b[i]; continue; } if (a[i + 1] - diff > 0) { count += b[i]; a[i + 1] -= diff; } else { count += a[i] + a[i + 1]; a[i + 1] = 0; } } CWrite(count); } static void CWrite<T>(T str) => Console.WriteLine(str); static string GetString() => Console.ReadLine(); static T[] GetArray<T>() { var t = typeof(T); var str = Console.ReadLine(); if (t == typeof(string)) { return (T[])(object)str.Split(); } if (t == typeof(int)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(long)) { return (T[])(object)str.ToNumArray<T>(); } if (t == typeof(double)) { return (T[])(object)str.ToNumArray<T>(); } throw new NotSupportedException($"{t} is not supported."); } } class SetConsole : IDisposable { readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); public SetConsole() { sw.AutoFlush = false; Console.SetOut(sw); } public void Dispose() { Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } } static class ExtentionsLibrary { public static T[] CopyArray<T>(this T[] array) { var newArray = new T[array.Length]; Array.Copy(array, newArray, array.Length); return newArray; } public static T[,] CopyTwoDimensionalArray<T>(this T[,] dArray) { var firstDimentionLength = dArray.GetLength(0); var secondDimentionLength = dArray.GetLength(1); var newDArray = new T[firstDimentionLength, secondDimentionLength]; Array.Copy(dArray, newDArray, firstDimentionLength * secondDimentionLength); return newDArray; } public static T[] ToNumArray<T>(this string str) { var t = typeof(T); if (t == typeof(int)) { return (T[])(object)str.Split().Select(int.Parse).ToArray(); } if (t == typeof(long)) { return (T[])(object)str.Split().Select(long.Parse).ToArray(); } if (t == typeof(double)) { return (T[])(object)str.Split().Select(double.Parse).ToArray(); } throw new NotSupportedException(); } public static int ToInt(this string str) => int.Parse(str); public static int ToInt(this char chr) => int.Parse(chr.ToString()); public static long ToLong(this string str) => long.Parse(str); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 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], ["-", 0, 57, 15, 16, 31, 16, 31, 241, 0, 203], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 48], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 204, 205, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 70], ["+", 31, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 16, 12, 204, 206, 207, 0, 73], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47], ["-", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 22]]
8
789
21
using System; using System.Collections.Generic; using System.Linq; namespace debug { public static partial class Program { public static void Main() { var n = Console.ReadLine().ToLong(); var ais = Console.ReadLine().ToLongArray(); var bis = Console.ReadLine().ToLongArray(); long cnt = 0; for (int i = 0; i < n; i++) { cnt += Math.Min(ais[i], bis[i]); cnt += Math.Min(ais[i + 1], bis[i] - Math.Min(ais[i], bis[i])); } Console.WriteLine(cnt); } } public static partial class Program { //テンプレここから private static long GCD(long aaa, long bbb) => bbb == 0 ? aaa : GCD(bbb, aaa % bbb); private static long LCM(long aaa, long bbb) => aaa * bbb / GCD(aaa, bbb); private static long ToLong(this double ddd) => (long)ddd; private static long ToLong(this string str) => long.Parse(str); private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray(); private static long[] ToLongArray(this string str, char opr = ' ') => str.Split(opr).ToLong(); private static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb)); private static long Sign(this long iii) => Math.Sign(iii); private static bool IsEven(this long iii) => iii % 2 == 0; private static readonly int[] Dx = { 0, -1, 0, 1 }; private static readonly int[] Dy = { -1, 0, 1, 0 }; public const int MOD = 1000000007; public const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const string alphabet = "abcdefghijklmnopqrstuvwxyz"; public static long ToLong(this char ccc) => ccc.ToString().ToLong(); public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array); public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array); public static string JoinToStr(this IEnumerable<long> array, string sep = "") => array.Select(xxx => xxx.ToString()).Join(sep); public static string JoinToStr(this IEnumerable<int> array, string sep = "") => array.Select(xxx => xxx.ToString()).Join(sep); //テンプレここまで } }
using System; using System.Collections.Generic; using System.Linq; namespace debug { public static partial class Program { public static void Main() { var n = Console.ReadLine().ToLong(); var ais = Console.ReadLine().ToLongArray(); var bis = Console.ReadLine().ToLongArray(); long cnt = 0; for (int i = 0; i < n; i++) { var m = Math.Min(ais[i], bis[i]); cnt += m; bis[i] -= m; var na = Math.Min(ais[i + 1], bis[i]); cnt += na; ais[i + 1] -= na; } Console.WriteLine(cnt); } } public static partial class Program { //テンプレここから private static long GCD(long aaa, long bbb) => bbb == 0 ? aaa : GCD(bbb, aaa % bbb); private static long LCM(long aaa, long bbb) => aaa * bbb / GCD(aaa, bbb); private static long ToLong(this double ddd) => (long)ddd; private static long ToLong(this string str) => long.Parse(str); private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray(); private static long[] ToLongArray(this string str, char opr = ' ') => str.Split(opr).ToLong(); private static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb)); private static long Sign(this long iii) => Math.Sign(iii); private static bool IsEven(this long iii) => iii % 2 == 0; private static readonly int[] Dx = { 0, -1, 0, 1 }; private static readonly int[] Dy = { -1, 0, 1, 0 }; public const int MOD = 1000000007; public const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const string alphabet = "abcdefghijklmnopqrstuvwxyz"; public static long ToLong(this char ccc) => ccc.ToString().ToLong(); public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array); public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array); public static string JoinToStr(this IEnumerable<long> array, string sep = "") => array.Select(xxx => xxx.ToString()).Join(sep); public static string JoinToStr(this IEnumerable<int> array, string sep = "") => array.Select(xxx => xxx.ToString()).Join(sep); //テンプレここまで } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 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, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 205, 22], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 0, 131], ["-", 0, 28, 0, 16, 12, 213, 63, 214, 141, 22], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 21], ["-", 12, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["-", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["-", 0, 28, 0, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 25]]
8
586
39
#if true //#if false #define UTAKA_DEBUG #endif using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using System.IO; using static System.Math; namespace UtakaApp { public class Program { public const string ContestName = "abc135"; public const string ProblemName = "C"; public static void Main(string[] args) { #if UTAKA_LOCAL new TestCaseChecker().TestProblems(); #else new Program().Solve(Console.In, new ConsoleWriter()); #endif } public void Solve(TextReader textReader, IConsoleWriter consoleWriter) { var cin = new ConsoleInput(textReader, ' '); int N = cin.ReadInt; int[] A = cin.ReadIntArray(N + 1); int[] B = cin.ReadIntArray(N); long ans = 0; for (int i = 0; i < N; i++) { int left = Min(A[i], B[i]); ans += left; A[i] -= left; B[i] -= left; // 残った戦力で右を倒す int right = Min(A[i + 1], B[i]); ans += right; B[i] -= right; } consoleWriter.WriteLine(ans.ToString()); // long total = 0; // // var killedByFormer = Min(b[0], a[0]); // // total += killedByFormer; // // var remainPowerOfFormer = b[0] - killedByFormer; // // Dbg.WriteLine($"{0} {0} {killedByFormer}"); // // for (int i = 1; i < n; i++) // { // killedByFormer = Min(remainPowerOfFormer, a[i]); // // total += killedByFormer; // // var rest = a[i] - killedByFormer; // // var killedByLatter = Min(rest, b[i]); // // total += killedByLatter; // // remainPowerOfFormer = b[i] - killedByLatter; // // Dbg.WriteLine($"{i} {killedByFormer} {killedByLatter}"); // } // // var lastKill = Min(remainPowerOfFormer, a[n]); // // Dbg.WriteLine($"{n} {lastKill} -"); // // total += lastKill; // // consoleWriter.WriteLine(total.ToString()); } } public class ConsoleInput { private readonly TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(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 => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } public interface IConsoleWriter { void Write(string str); void WriteLine(string str); } public class ConsoleWriter : IConsoleWriter { public void Write(string str) { Console.Write(str); } public void WriteLine(string str) { Console.WriteLine(str); } } #if UTAKA_LOCAL public class DebugConsoleWriter : IConsoleWriter { private StringBuilder mSb; public DebugConsoleWriter() { mSb = new StringBuilder(); } public void Write(string str) { mSb.Append(str); } public void WriteLine(string str) { mSb.AppendLine(str); } public string GetAllOutput() { return mSb.ToString(); } } public class TestCaseChecker { private string DirectoryPath => $"../../../../{Program.ContestName}/{Program.ProblemName}"; private string GetInputFilePath(int testCaseNumber) { return $"{DirectoryPath}/in_{testCaseNumber}.txt"; } private string GetOutputFilePath(int testCaseNumber) { return $"{DirectoryPath}/out_{testCaseNumber}.txt"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var debugConsoleWriter = new DebugConsoleWriter(); new Program().Solve(inputStream, debugConsoleWriter); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); #if UTAKA_DEBUG Console.Write(output); Console.Write(outputAnswer); #endif var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems() { var isSuccessAll = true; var testCaseNumber = 1; while (true) { var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine($"Success"); } else { isSuccessAll = false; Console.WriteLine($"Failure *****"); } testCaseNumber++; } if (isSuccessAll) { Console.WriteLine($"!!!!!!!!! All Success !!!!!!!!!"); } } } public static class Dbg { public static void WriteLine(string str) { Console.WriteLine(str); } public static void Write(string str) { Console.Write(str); } } #else public static class Dbg { public static void WriteLine(string str) {} public static void Write(string str) {} } #endif }
#if true //#if false #define UTAKA_DEBUG #endif using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using System.IO; using static System.Math; namespace UtakaApp { public class Program { public const string ContestName = "abc135"; public const string ProblemName = "C"; public static void Main(string[] args) { #if UTAKA_LOCAL new TestCaseChecker().TestProblems(); #else new Program().Solve(Console.In, new ConsoleWriter()); #endif } public void Solve(TextReader textReader, IConsoleWriter consoleWriter) { var cin = new ConsoleInput(textReader, ' '); int N = cin.ReadInt; int[] A = cin.ReadIntArray(N + 1); int[] B = cin.ReadIntArray(N); long ans = 0; for (int i = 0; i < N; i++) { int left = Min(A[i], B[i]); ans += left; A[i] -= left; B[i] -= left; // 残った戦力で右を倒す int right = Min(A[i + 1], B[i]); ans += right; A[i + 1] -= right; B[i] -= right; } consoleWriter.WriteLine(ans.ToString()); // long total = 0; // // var killedByFormer = Min(b[0], a[0]); // // total += killedByFormer; // // var remainPowerOfFormer = b[0] - killedByFormer; // // Dbg.WriteLine($"{0} {0} {killedByFormer}"); // // for (int i = 1; i < n; i++) // { // killedByFormer = Min(remainPowerOfFormer, a[i]); // // total += killedByFormer; // // var rest = a[i] - killedByFormer; // // var killedByLatter = Min(rest, b[i]); // // total += killedByLatter; // // remainPowerOfFormer = b[i] - killedByLatter; // // Dbg.WriteLine($"{i} {killedByFormer} {killedByLatter}"); // } // // var lastKill = Min(remainPowerOfFormer, a[n]); // // Dbg.WriteLine($"{n} {lastKill} -"); // // total += lastKill; // // consoleWriter.WriteLine(total.ToString()); } } public class ConsoleInput { private readonly TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(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 => _stream.ReadLine(); public int ReadInt => int.Parse(Read); public long ReadLong => long.Parse(Read); public double ReadDouble => double.Parse(Read); public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } public interface IConsoleWriter { void Write(string str); void WriteLine(string str); } public class ConsoleWriter : IConsoleWriter { public void Write(string str) { Console.Write(str); } public void WriteLine(string str) { Console.WriteLine(str); } } #if UTAKA_LOCAL public class DebugConsoleWriter : IConsoleWriter { private StringBuilder mSb; public DebugConsoleWriter() { mSb = new StringBuilder(); } public void Write(string str) { mSb.Append(str); } public void WriteLine(string str) { mSb.AppendLine(str); } public string GetAllOutput() { return mSb.ToString(); } } public class TestCaseChecker { private string DirectoryPath => $"../../../../{Program.ContestName}/{Program.ProblemName}"; private string GetInputFilePath(int testCaseNumber) { return $"{DirectoryPath}/in_{testCaseNumber}.txt"; } private string GetOutputFilePath(int testCaseNumber) { return $"{DirectoryPath}/out_{testCaseNumber}.txt"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var debugConsoleWriter = new DebugConsoleWriter(); new Program().Solve(inputStream, debugConsoleWriter); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); #if UTAKA_DEBUG Console.Write(output); Console.Write(outputAnswer); #endif var isCorrect = output == outputAnswer; return isCorrect; } public void TestProblems() { var isSuccessAll = true; var testCaseNumber = 1; while (true) { var inputFileName = GetInputFilePath(testCaseNumber); if (!File.Exists(inputFileName)) { break; } Console.WriteLine( $"TestCase {testCaseNumber} ====================================================="); var result = TestProblem(testCaseNumber); if (result) { Console.WriteLine($"Success"); } else { isSuccessAll = false; Console.WriteLine($"Failure *****"); } testCaseNumber++; } if (isSuccessAll) { Console.WriteLine($"!!!!!!!!! All Success !!!!!!!!!"); } } } public static class Dbg { public static void WriteLine(string str) { Console.WriteLine(str); } public static void Write(string str) { Console.Write(str); } } #else public static class Dbg { public static void WriteLine(string str) {} public static void Write(string str) {} } #endif }
[["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35]]
8
1,108
9
using System; using System.Collections.Generic; class Program { static int x; static List<int> s = new List<int>(); static List<int> t = new List<int>(); static int result; static int tmp2; static void Main() { result = 0; x = int.Parse(Console.ReadLine()); string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < x + 1; i++) { s.Add(int.Parse(tmp[i])); } string[] tmp3 = Console.ReadLine().Split(' '); // sが町tが勇者 for (int i = 0; i < x; i++) { t.Add(int.Parse(tmp3[i])); } for (int a = 0; a < x; a++) { if (t[a] <= s[a]) { result += t[a]; } else { tmp2 = s[a + 1] - t[a] + s[a]; if (tmp2 >= 0) { result += t[a]; s[a] = 0; s[a + 1] = tmp2; } else { result += s[a] + s[a + 1]; s[a] = 0; s[a + 1] = 0; } } } Console.WriteLine(result.ToString()); Console.Out.Flush(); } }
using System; using System.Collections.Generic; class Program { static int x; static List<long> s = new List<long>(); static List<long> t = new List<long>(); static long result; static long tmp2; static void Main() { result = 0; x = int.Parse(Console.ReadLine()); string[] tmp = Console.ReadLine().Split(' '); for (int i = 0; i < x + 1; i++) { s.Add(long.Parse(tmp[i])); } string[] tmp3 = Console.ReadLine().Split(' '); // sが町tが勇者 for (int i = 0; i < x; i++) { t.Add(long.Parse(tmp3[i])); } for (int a = 0; a < x; a++) { if (t[a] <= s[a]) { result += t[a]; s[a] = s[a] - t[a]; } else { tmp2 = s[a + 1] - t[a] + s[a]; if (tmp2 >= 0) { result += t[a]; s[a] = 0; s[a + 1] = tmp2; } else { result += s[a] + s[a + 1]; s[a] = 0; s[a + 1] = 0; } } } Console.WriteLine(result.ToString()); Console.Out.Flush(); } }
[["-", 0, 124, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 124, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 3, 4, 0, 28, 0, 213, 63, 214, 205, 199], ["+", 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], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 204, 205, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 12, 16, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 33]]
8
323
31
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 AAddtion { public static void Main(string[] args) { new AAddtion().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く var n = cin.ReadInt; var aList = cin.ReadLongArray(n + 1); var bList = cin.ReadLongArray(n); long ans = 0; for (int i = 0; i < bList.Length; i++) { if (aList[i] >= bList[i]) { ans += bList[i]; } else { ans += aList[i]; if (aList[i + 1] >= (bList[i] - aList[i])) { ans += bList[i] - aList[i]; } else { ans += aList[i + 1]; } aList[i + 1] = bList[i] - aList[i]; } } 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 AAddtion { public static void Main(string[] args) { new AAddtion().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { // 解答はココに書く var n = cin.ReadInt; var aList = cin.ReadLongArray(n + 1); var bList = cin.ReadLongArray(n); long ans = 0; for (int i = 0; i < bList.Length; i++) { if (aList[i] >= bList[i]) { ans += bList[i]; } else { ans += aList[i]; if (aList[i + 1] >= (bList[i] - aList[i])) { ans += bList[i] - aList[i]; } else { ans += aList[i + 1]; } aList[i + 1] = aList[i + 1] - (bList[i] - aList[i]) < 0 ? 0 : aList[i + 1] - (bList[i] - aList[i]); } } 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; } }
[["+", 12, 41, 15, 16, 31, 16, 31, 204, 205, 22], ["+", 15, 16, 31, 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], ["+", 15, 16, 31, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 11, 12, 41, 15, 16, 31, 16, 17, 33], ["+", 12, 41, 15, 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], ["+", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 31, 16, 12, 23, 0, 16, 12, 204, 205, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 70], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 23, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 12, 41, 15, 16, 31, 16, 12, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 18], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 12, 203], ["+", 75, 196, 0, 1, 0, 11, 12, 41, 0, 101], ["+", 75, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["+", 75, 196, 0, 1, 0, 11, 12, 41, 0, 102], ["+", 0, 11, 12, 41, 75, 16, 31, 204, 205, 22], ["+", 12, 41, 75, 16, 31, 204, 206, 207, 0, 70], ["+", 12, 41, 75, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 1, 0, 11, 12, 41, 75, 16, 17, 33], ["+", 0, 11, 12, 41, 75, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 41, 75, 16, 12, 23, 0, 25]]
8
577
32
using System; using System.Collections.Generic; namespace ABC135_C { class Program { static void Main(string[] args) { long n = long.Parse(Console.ReadLine()); string[] input1 = Console.ReadLine().Split(); string[] input2 = Console.ReadLine().Split(); List<long> alist = new List<long>(); List<long> blist = new List<long>(); for (long i = 0; i < n; i++) { alist.Add(long.Parse(input1[i])); blist.Add(long.Parse(input2[i])); } alist.Add(long.Parse(input1[n])); long ans = 0; for (int i = 0; i < n; i++) { if (alist[i] >= blist[i]) { ans += blist[i]; } else { blist[i] -= alist[i]; ans += alist[i]; if (alist[i + 1] >= blist[i]) { alist[i + 1] -= blist[i]; ans += blist[i]; } else { ans += alist[i + 1]; } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; namespace ABC135_C { class Program { static void Main(string[] args) { long n = long.Parse(Console.ReadLine()); string[] input1 = Console.ReadLine().Split(); string[] input2 = Console.ReadLine().Split(); List<long> alist = new List<long>(); List<long> blist = new List<long>(); for (long i = 0; i < n; i++) { alist.Add(long.Parse(input1[i])); blist.Add(long.Parse(input2[i])); } alist.Add(long.Parse(input1[n])); long ans = 0; for (int i = 0; i < n; i++) { if (alist[i] >= blist[i]) { ans += blist[i]; } else { blist[i] -= alist[i]; ans += alist[i]; if (alist[i + 1] >= blist[i]) { alist[i + 1] -= blist[i]; ans += blist[i]; } else { ans += alist[i + 1]; alist[i + 1] = 0; } } } Console.WriteLine(ans); } } }
[["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 75, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
8
278
9
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int[] m = new int[N + 1]; int[] b = new int[N]; string[] s = Console.ReadLine().Split(' '); for (int i = 0; i < N + 1; i++) { m[i] = int.Parse(s[i]); } s = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { b[i] = int.Parse(s[i]); } int ans = 0; int remain = 0; for (int i = 0; i < N; i++) { if (m[i] < remain) { ans += m[i]; remain = b[i]; } else { ans += remain; m[i] -= remain; if (b[i] > m[i]) { ans += m[i]; remain = b[i] - m[i]; } else { ans += b[i]; remain = 0; } } } if (m[N] > remain) { ans += remain; } else { ans += m[N]; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long[] m = new long[N + 1]; long[] b = new long[N]; string[] s = Console.ReadLine().Split(' '); for (int i = 0; i < N + 1; i++) { m[i] = long.Parse(s[i]); } s = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { b[i] = long.Parse(s[i]); } long ans = 0; long remain = 0; for (int i = 0; i < N; i++) { if (m[i] < remain) { ans += m[i]; remain = b[i]; } else { ans += remain; m[i] -= remain; if (b[i] > m[i]) { ans += m[i]; remain = b[i] - m[i]; } else { ans += b[i]; remain = 0; } } } if (m[N] > remain) { ans += remain; } else { ans += m[N]; } Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
323
16
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { int N = int.Parse(ReadLine()); int[] Aarray = ReadLine().Split(' ').Select(int.Parse).ToArray(); var ls = new List<int>(); ls.AddRange(Aarray); int[] Barray = ReadLine().Split(' ').Select(int.Parse).ToArray(); int ans = 0; for (int i = 0; i < N; i++) { int tmp = Barray[i]; //まだ一回転保証 if (tmp - ls[i] >= 0) //左全部殺せる { tmp -= ls[i]; ans += ls[i]; ls[i] = 0; if (tmp - ls[i + 1] >= 0) //右も全部殺せる { ans += ls[i + 1]; ls[i + 1] = 0; } else //殺しきれない { ls[i + 1] -= tmp; ans += tmp; } } else //左殺しきれない { ans += tmp; } } WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { long N = long.Parse(ReadLine()); long[] Aarray = ReadLine().Split(' ').Select(long.Parse).ToArray(); var ls = new List<long>(); ls.AddRange(Aarray); long[] Barray = ReadLine().Split(' ').Select(long.Parse).ToArray(); long ans = 0; for (int i = 0; i < N; i++) { long tmp = Barray[i]; //まだ一回転保証 if (tmp - ls[i] >= 0) //左全部殺せる { tmp -= ls[i]; ans += ls[i]; ls[i] = 0; if (tmp - ls[i + 1] >= 0) //右も全部殺せる { ans += ls[i + 1]; ls[i + 1] = 0; } else //殺しきれない { ls[i + 1] -= tmp; ans += tmp; } } else //左殺しきれない { ans += tmp; } } WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 205, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199]]
8
264
18
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { class Program { static void Main(string[] args) { var cin = new Scanner(); var N = cin.nextInt(); int[] A = new int[N + 1]; for (int i = 0; i < N + 1; i++) { A[i] = cin.nextInt(); } int[] B = new int[N]; for (int i = 0; i < N; i++) { B[i] = cin.nextInt(); } int count = 0; for (int i = N - 1; 0 <= i; i--) { var power = B[i]; if (A[i + 1] <= power) { // 次の街の敵をすべて倒せるとき count += A[i + 1]; var amariPower = power - A[i + 1]; if (A[i] <= amariPower) { // 残りの力で今の街をすべて倒せるとき count += A[i]; A[i] = 0; } else { // 残りの力で今の街をすべて倒せないとき count += amariPower; A[i] -= amariPower; } } else { // 次の街の一部分を倒せるとき count += power; } } Console.WriteLine(count); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Numerics; namespace AtCoderWorkspace { class Program { static void Main(string[] args) { var cin = new Scanner(); var N = cin.nextLong(); long[] A = new long[N + 1]; for (int i = 0; i < N + 1; i++) { A[i] = cin.nextLong(); } long[] B = new long[N]; for (int i = 0; i < N; i++) { B[i] = cin.nextLong(); } long count = 0; for (long i = N - 1; 0 <= i; i--) { var power = B[i]; if (A[i + 1] <= power) { // 次の街の敵をすべて倒せるとき count += A[i + 1]; var amariPower = power - A[i + 1]; if (A[i] <= amariPower) { // 残りの力で今の街をすべて倒せるとき count += A[i]; A[i] = 0; } else { // 残りの力で今の街をすべて倒せないとき count += amariPower; A[i] -= amariPower; } } else { // 次の街の一部分を倒せるとき count += power; } } Console.WriteLine(count); } } 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, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
8
620
18
using System; class C_Savers { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] sA = Console.ReadLine().Split(' '); string[] sB = Console.ReadLine().Split(' '); int[] A = new int[N + 1]; int[] B = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(sA[i]); B[i] = int.Parse(sB[i]); } A[N] = int.Parse(sA[N]); int Kill = 0; for (int i = 0; i < N; i++) { if (A[i] >= B[i]) { A[i] -= B[i]; Kill += B[i]; B[i] = 0; } else { B[i] -= A[i]; Kill += A[i]; A[i] = 0; if (A[i + 1] >= B[i]) { A[i + 1] -= B[i]; Kill += B[i]; B[i] = 0; } else { B[i] -= A[i + 1]; Kill += A[i + 1]; A[i + 1] = 0; } } } Console.WriteLine(Kill); } }
using System; class C_Savers { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] sA = Console.ReadLine().Split(' '); string[] sB = Console.ReadLine().Split(' '); long[] A = new long[N + 1]; long[] B = new long[N]; for (int i = 0; i < N; i++) { A[i] = long.Parse(sA[i]); B[i] = long.Parse(sB[i]); } A[N] = long.Parse(sA[N]); long Kill = 0; for (int i = 0; i < N; i++) { if (A[i] >= B[i]) { A[i] -= B[i]; Kill += B[i]; B[i] = 0; } else { B[i] -= A[i]; Kill += A[i]; A[i] = 0; if (A[i + 1] >= B[i]) { A[i + 1] -= B[i]; Kill += B[i]; B[i] = 0; } else { B[i] -= A[i + 1]; Kill += A[i + 1]; A[i + 1] = 0; } } } Console.WriteLine(Kill); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
321
16
using System; using System.Collections.Generic; using System.Linq; public class Solution { public static void Main() { int N = int.Parse(Console.ReadLine()); string str1 = Console.ReadLine(); string str2 = Console.ReadLine(); string[] strA = str1.Split(' '); string[] strB = str2.Split(' '); int[] A = new int[N + 1]; int[] B = new int[N]; for (int i = 0; i < N; i++) { A[i] = int.Parse(strA[i]); B[i] = int.Parse(strB[i]); } A[N] = int.Parse(strA[N]); // N+1番目の町はN番目の勇者しか倒せないので // N+1からやっていけばよさそう int total = 0; int amari = 0; for (int i = N; i > 0; i--) { // 一つ前の処理でN+1番目の勇者が残した倒せる数を処理する // モンスターの数が同じか残る場合、 // totalに勇者が残した倒せる数を足す、モンスターの数から倒した数をひく // モンスターの数より倒せる場合、totalにモンスターの数を足す、モンスターの数を0にする if (A[i] - amari >= 0) { total += amari; A[i] -= amari; } else { total += A[i]; A[i] = 0; } // N番目の勇者が倒せるモンスターの数を処理する // モンスターの数が同じか残る場合、 // totalに勇者が残した倒せる数を足す、勇者あまりを0にする // モンスターの数より倒せる場合、 // totalにモンスターの数を足す、勇者あまりを勇者からモンスターを引く if (A[i] - B[i - 1] >= 0) { total += B[i - 1]; amari = 0; } else { total += A[i]; amari = B[i - 1] - A[i]; } } // 1番目の町の処理 if (A[0] - amari >= 0) { total += amari; A[0] -= amari; } else { total += A[0]; A[0] = 0; } Console.WriteLine($"{total}"); // Console.WriteLine($"{p[0]} {p[1]} {p[2]} {p[3]} {p[4]}"); // Console.WriteLine($"{dst[0]} {dst[1]} {dst[2]} {dst[3]} {dst[4]}"); // Console.WriteLine($"{cnt}"); } }
using System; using System.Collections.Generic; using System.Linq; public class Solution { public static void Main() { long N = long.Parse(Console.ReadLine()); string str1 = Console.ReadLine(); string str2 = Console.ReadLine(); string[] strA = str1.Split(' '); string[] strB = str2.Split(' '); long[] A = new long[N + 1]; long[] B = new long[N]; for (int i = 0; i < N; i++) { A[i] = long.Parse(strA[i]); B[i] = long.Parse(strB[i]); } A[N] = long.Parse(strA[N]); // N+1番目の町はN番目の勇者しか倒せないので // N+1からやっていけばよさそう long total = 0; long amari = 0; for (long i = N; i > 0L; i--) { // 一つ前の処理でN+1番目の勇者が残した倒せる数を処理する // モンスターの数が同じか残る場合、 // totalに勇者が残した倒せる数を足す、モンスターの数から倒した数をひく // モンスターの数より倒せる場合、totalにモンスターの数を足す、モンスターの数を0にする if (A[i] - amari >= 0) { total += amari; A[i] -= amari; } else { total += A[i]; A[i] = 0; } // N番目の勇者が倒せるモンスターの数を処理する // モンスターの数が同じか残る場合、 // totalに勇者が残した倒せる数を足す、勇者あまりを0にする // モンスターの数より倒せる場合、 // totalにモンスターの数を足す、勇者あまりを勇者からモンスターを引く if (A[i] - B[i - 1] >= 0) { total += B[i - 1]; amari = 0; } else { total += A[i]; amari = B[i - 1] - A[i]; } } // 1番目の町の処理 if (A[0] - amari >= 0) { total += amari; A[0] -= amari; } else { total += A[0]; A[0] = 0; } Console.WriteLine($"{total}"); // Console.WriteLine($"{p[0]} {p[1]} {p[2]} {p[3]} {p[4]}"); // Console.WriteLine($"{dst[0]} {dst[1]} {dst[2]} {dst[3]} {dst[4]}"); // Console.WriteLine($"{cnt}"); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
8
362
26
using System; using System.Linq; namespace abc135_c { static class Program { static void Main(string[] args) { // 勇者の数 var n = Console.ReadLine().ToInteger(); // 街の数 var c = n + 1; // それぞれの街を襲っているモンスターの数 var a = Console.ReadLine().ToIntArray(); // それぞれの勇者が倒せるモンスターの数 var b = Console.ReadLine().ToIntArray(); // はじめの街のモンスターははじめの勇者でしか倒せない // →はじめの街のモンスターはすべてはじめの勇者が倒しておくべき // はじめの街から順に、討伐数を確定していく // 討伐数合計 var sum = 0; for (int i = 0; i < b.Length; i++) { // iでの討伐数 var mon1 = Math.Min(a[i], b[i]); // 残りの討伐数 var sub = b[i] - mon1; // i+1での討伐数 var mon2 = Math.Min(a[i + 1], sub); // i+1での討ち漏らし a[i + 1] -= mon2; // 合計数を加算 sum += mon1 + mon2; } Console.WriteLine($"{sum}"); } static int ToInteger(this string s) { return int.Parse(s); } static int[] ToIntArray(this string s, char separator = ' ') { return s.Split(separator).Select(m => m.ToInteger()).ToArray(); } } }
using System; using System.Linq; namespace abc135_c { static class Program { static void Main(string[] args) { // 勇者の数 var n = Console.ReadLine().ToLong(); // 街の数 var c = n + 1; // それぞれの街を襲っているモンスターの数 var a = Console.ReadLine().ToLongArray(); // それぞれの勇者が倒せるモンスターの数 var b = Console.ReadLine().ToLongArray(); // はじめの街のモンスターははじめの勇者でしか倒せない // →はじめの街のモンスターはすべてはじめの勇者が倒しておくべき // はじめの街から順に、討伐数を確定していく // 討伐数合計 var sum = 0L; for (int i = 0; i < b.Length; i++) { // iでの討伐数 var mon1 = Math.Min(a[i], b[i]); // 残りの討伐数 var sub = b[i] - mon1; // i+1での討伐数 var mon2 = Math.Min(a[i + 1], sub); // i+1での討ち漏らし a[i + 1] -= mon2; // 合計数を加算 sum += mon1 + mon2; } Console.WriteLine($"{sum}"); } static long ToLong(this string s) { return long.Parse(s); } static long[] ToLongArray(this string s, char separator = ' ') { return s.Split(separator).Select(m => m.ToLong()).ToArray(); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["-", 8, 196, 0, 37, 0, 213, 63, 214, 205, 199], ["+", 8, 196, 0, 37, 0, 213, 63, 214, 205, 199], ["-", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["+", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["-", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 141, 22]]
8
241
20
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace A { partial class Program { public IEnumerable<string> Solve() { var n = ScanInt; var a = ScanLongs(n + 1); var b = ScanLongs(n); long res = 0L; for (int i = n - 1; i >= 0; i--) { if (a[i + 1] <= b[i]) { res += a[i + 1]; b[i] -= a[i + 1]; } var d = Math.Min(a[i], b[i]); res += d; a[i] -= d; } yield return res.ToString(); } } class StartingPoint { static void Main(string[] args) { if (args?.Any() == true) { var assembly = Assembly.GetEntryAssembly(); var resourceName = "AtCoderCSharp.In.txt"; var stream = assembly.GetManifestResourceStream(resourceName); var streamReader = new StreamReader(stream, Encoding.UTF8); var str = streamReader.ReadToEnd(); var textReader = new StringReader(str); Console.SetIn(textReader); } try { foreach (var s in new Program().Solve()) { Console.WriteLine(s); } } catch (Exception e) { Console.WriteLine(e); if (args?.Any() != true) throw e; } if (args?.Any() == true) Console.ReadKey(); } } partial class Program { public List<int> ScanInts(int count) => Enumerable.Range(0, count).Select(_ => ScanInt).ToList(); public List<int> ScanInts(long count) => ScanInts((int)count); public List<long> ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList(); public List<long> ScanLongs(long count) => ScanLongs((int)count); public int ScanInt => int.Parse(Str); public long Scan => long.Parse(Str); public double ScanDouble => (double)Scan; StringBuilder sb = new StringBuilder(); public string Str => ScanStr(); public string ScanStr() { sb.Clear(); int r = 0; bool? b = null; do { r = Console.Read(); b = IsBreak(r); } while (b == true); if (b == null) throw new Exception("input error: unexpected end of stream"); do { sb.Append((char)r); r = Console.Read(); b = IsBreak(r); } while (b == false); return sb.ToString(); } bool? IsBreak(int c) { switch (c) { case -1: return null; case (int)' ': case (int)'\n': case (int)'\r': return true; default: return false; } } public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count); public IEnumerable<int> Loop(int from, int to) => Enumerable.Range(from, to - from + 1); public string YesNo(bool isYes) => isYes ? "YES" : "NO"; public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts); public int Gcm(int a, int b) { if (a < b) return GcmImpl(b, a); else return GcmImpl(a, b); } int GcmImpl(int a, int b) { var remainder = a % b; if (remainder == 0) return b; else return GcmImpl(b, remainder); } public int Lcm(int a, int b) { return a / Gcm(a, b) * b; } int GetFirstIndexGreater(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } int GetFirstIndexGreater(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } int GetLastIndexLess(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } int GetLastIndexLess(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } class Mod { readonly int _divider = 1000000007; public Mod(int divider = 1000000007) { _divider = divider; } public int Add(int a, int b) => (int)Add((long)a, (long)b); public int Sub(int a, int b) => (int)Sub((long)a, (long)b); public int Mul(int a, int b) => (int)Mul((long)a, (long)b); public int Div(int a, int b) => (int)Div((long)a, (long)b); public int Pow(int a, int p) => (int)Pow((long)a, (long)p); public long Add(long a, long b) => (a + b) % _divider; public long Sub(long a, long b) { var t = (a - b) % _divider; if (t < 0) t += _divider; return t; } public long Mul(long a, long b) => (a * b) % _divider; public long Div(long a, long b) => Mul(a, Inv(b)); public long Pow(long a, long p) { switch (p) { case 0: return 1; case 1: return a; default: var halfP = p / 2; var halfPowered = Pow(a, halfP); var powered = Mul(halfPowered, halfPowered); return p % 2 == 0 ? powered : Mul(powered, a); } } readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); long Inv(long a) { long cache = 0L; if (invCache.TryGetValue(a, out cache)) return cache; var result = Pow(a, _divider - 2); invCache.Add(a, result); return result; } readonly List<int> facCache = new List<int>() { 1 }; public int Fac(int a) { if (a < facCache.Count) return facCache[a]; var val = facCache.Last(); var start = facCache.Count; for (int i = start; i <= a; i++) { val = Mul(val, i); facCache.Add(val); } return val; } public int Perm(int n, int r) { if (n < r) return 0; if (r <= 0) return 1; int nn = Fac(n); int nr = Fac(n - r); return Div(nn, nr); } public int Comb(int n, int r) { if (n < r) return 0; if (n == r) return 1; int nn = Fac(n); int nr = Fac(n - r); int rr = Fac(r); return Div(Div(nn, nr), rr); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace A { partial class Program { public IEnumerable<string> Solve() { var n = ScanInt; var a = ScanLongs(n + 1); var b = ScanLongs(n); long res = 0L; for (int i = n - 1; i >= 0; i--) { if (a[i + 1] <= b[i]) { res += a[i + 1]; b[i] -= a[i + 1]; } else { res += b[i]; b[i] = 0; } var d = Math.Min(a[i], b[i]); res += d; a[i] -= d; } yield return res.ToString(); } } class StartingPoint { static void Main(string[] args) { if (args?.Any() == true) { var assembly = Assembly.GetEntryAssembly(); var resourceName = "AtCoderCSharp.In.txt"; var stream = assembly.GetManifestResourceStream(resourceName); var streamReader = new StreamReader(stream, Encoding.UTF8); var str = streamReader.ReadToEnd(); var textReader = new StringReader(str); Console.SetIn(textReader); } try { foreach (var s in new Program().Solve()) { Console.WriteLine(s); } } catch (Exception e) { Console.WriteLine(e); if (args?.Any() != true) throw e; } if (args?.Any() == true) Console.ReadKey(); } } partial class Program { public List<int> ScanInts(int count) => Enumerable.Range(0, count).Select(_ => ScanInt).ToList(); public List<int> ScanInts(long count) => ScanInts((int)count); public List<long> ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList(); public List<long> ScanLongs(long count) => ScanLongs((int)count); public int ScanInt => int.Parse(Str); public long Scan => long.Parse(Str); public double ScanDouble => (double)Scan; StringBuilder sb = new StringBuilder(); public string Str => ScanStr(); public string ScanStr() { sb.Clear(); int r = 0; bool? b = null; do { r = Console.Read(); b = IsBreak(r); } while (b == true); if (b == null) throw new Exception("input error: unexpected end of stream"); do { sb.Append((char)r); r = Console.Read(); b = IsBreak(r); } while (b == false); return sb.ToString(); } bool? IsBreak(int c) { switch (c) { case -1: return null; case (int)' ': case (int)'\n': case (int)'\r': return true; default: return false; } } public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count); public IEnumerable<int> Loop(int from, int to) => Enumerable.Range(from, to - from + 1); public string YesNo(bool isYes) => isYes ? "YES" : "NO"; public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts); public int Gcm(int a, int b) { if (a < b) return GcmImpl(b, a); else return GcmImpl(a, b); } int GcmImpl(int a, int b) { var remainder = a % b; if (remainder == 0) return b; else return GcmImpl(b, remainder); } public int Lcm(int a, int b) { return a / Gcm(a, b) * b; } int GetFirstIndexGreater(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } int GetFirstIndexGreater(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } int GetLastIndexLess(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } int GetLastIndexLess(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } class Mod { readonly int _divider = 1000000007; public Mod(int divider = 1000000007) { _divider = divider; } public int Add(int a, int b) => (int)Add((long)a, (long)b); public int Sub(int a, int b) => (int)Sub((long)a, (long)b); public int Mul(int a, int b) => (int)Mul((long)a, (long)b); public int Div(int a, int b) => (int)Div((long)a, (long)b); public int Pow(int a, int p) => (int)Pow((long)a, (long)p); public long Add(long a, long b) => (a + b) % _divider; public long Sub(long a, long b) { var t = (a - b) % _divider; if (t < 0) t += _divider; return t; } public long Mul(long a, long b) => (a * b) % _divider; public long Div(long a, long b) => Mul(a, Inv(b)); public long Pow(long a, long p) { switch (p) { case 0: return 1; case 1: return a; default: var halfP = p / 2; var halfPowered = Pow(a, halfP); var powered = Mul(halfPowered, halfPowered); return p % 2 == 0 ? powered : Mul(powered, a); } } readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); long Inv(long a) { long cache = 0L; if (invCache.TryGetValue(a, out cache)) return cache; var result = Pow(a, _divider - 2); invCache.Add(a, result); return result; } readonly List<int> facCache = new List<int>() { 1 }; public int Fac(int a) { if (a < facCache.Count) return facCache[a]; var val = facCache.Last(); var start = facCache.Count; for (int i = start; i <= a; i++) { val = Mul(val, i); facCache.Add(val); } return val; } public int Perm(int n, int r) { if (n < r) return 0; if (r <= 0) return 1; int nn = Fac(n); int nr = Fac(n - r); return Div(nn, nr); } public int Comb(int n, int r) { if (n < r) return 0; if (n == r) return 1; int nn = Fac(n); int nr = Fac(n - r); int rr = Fac(r); return Div(Div(nn, nr), rr); } } }
[["+", 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, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 75, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 70], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 12, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 75, 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], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,855
17
using System; using System.Collections.Generic; using System.Linq; class WithIndex<T> { public T Value; public int Index; public WithIndex(T value, int index) { this.Value = value; this.Index = index; } } static class Template { public static int LineToInt() { return int.Parse(Console.ReadLine()); } public static string[] LineToStrings() { return Console.ReadLine().Split(); } public static int[] LineToInts() { return LineToStrings().Select(s => int.Parse(s)).ToArray(); } public static int[,] LinesToIntTable(int lineCount, int columnCount) { var value = new int[lineCount, columnCount]; foreach (var y in Enumerable.Range(0, lineCount)) { var ints = LineToInts(); foreach (var x in Enumerable.Range(0, columnCount)) { value[y, x] = ints[x]; } } return value; } public static IEnumerable<WithIndex<T>> WithIndex<T>(this IEnumerable<T> sequence) { int index = 0; foreach (var item in sequence) { yield return new WithIndex<T>(item, index); index++; } } static void Main(string[] args) { var townCount = LineToInt() + 1; var braveCount = townCount - 1; var osou = LineToInts(); var beatable = LineToInts(); var beatCount = 0; foreach (var i in Enumerable.Range(0, braveCount)) { var tempBeat = Math.Min(osou[i], beatable[i]); osou[i] -= tempBeat; beatable[i] -= tempBeat; beatCount += tempBeat; var tempBeat2 = Math.Min(osou[i + 1], beatable[i]); osou[i + 1] -= tempBeat2; beatable[i] -= tempBeat; beatCount += tempBeat2; } Console.WriteLine(beatCount); } }
using System; using System.Collections.Generic; using System.Linq; class WithIndex<T> { public T Value; public int Index; public WithIndex(T value, int index) { this.Value = value; this.Index = index; } } static class Template { public static int LineToInt() { return int.Parse(Console.ReadLine()); } public static string[] LineToStrings() { return Console.ReadLine().Split(); } public static int[] LineToInts() { return LineToStrings().Select(s => int.Parse(s)).ToArray(); } public static int[,] LinesToIntTable(int lineCount, int columnCount) { var value = new int[lineCount, columnCount]; foreach (var y in Enumerable.Range(0, lineCount)) { var ints = LineToInts(); foreach (var x in Enumerable.Range(0, columnCount)) { value[y, x] = ints[x]; } } return value; } public static IEnumerable<WithIndex<T>> WithIndex<T>(this IEnumerable<T> sequence) { int index = 0; foreach (var item in sequence) { yield return new WithIndex<T>(item, index); index++; } } static void Main(string[] args) { var townCount = LineToInt() + 1; var braveCount = townCount - 1; var osou = LineToInts().Select(x => (long)x).ToArray(); var beatable = LineToInts().Select(x => (long)x).ToArray(); var beatCount = 0L; foreach (var i in Enumerable.Range(0, braveCount)) { var tempBeat = Math.Min(osou[i], beatable[i]); osou[i] -= tempBeat; beatable[i] -= tempBeat; beatCount += tempBeat; var tempBeat2 = Math.Min(osou[i + 1], beatable[i]); osou[i + 1] -= tempBeat2; beatable[i] -= tempBeat; beatCount += tempBeat2; } Console.WriteLine(beatCount); } }
[["+", 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], ["+", 3, 4, 0, 28, 0, 218, 8, 74, 51, 22], ["+", 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], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["+", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
409
30
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Threading.Tasks; // 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(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { int N = cin.nextint; var A = cin.scanlong; var B = cin.scanlong; long power = 0; long sum = 0; for (int i = 0; i < N; i++) { power += B[i]; var burst = Min(power, A[i]); sum += burst; power -= burst; } sum += Min(power, A[N]); WriteLine(sum); } } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => 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 => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Threading.Tasks; // 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(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { int N = cin.nextint; var A = cin.scanlong; var B = cin.scanlong; long power = 0; long sum = 0; for (int i = 0; i < N; i++) { var last = Min(power, A[i]); sum += last; A[i] -= last; power = B[i]; var burst = Min(power, A[i]); sum += burst; power -= burst; } sum += Min(power, A[N]); WriteLine(sum); } } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => 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 => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
[["+", 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, 200, 0, 212, 0, 213, 3, 4, 0, 21], ["+", 0, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 1, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32]]
8
925
24
using System; using System.Text; using System.Collections.Generic; using System.Linq; namespace DigitsParades { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var mod = 1000000007; var exi = false; //一桁目から扱えるようにするため、反転させる var charS = S.ToCharArray(); Array.Reverse(charS); var figsum = 0L; for (int i = 0; i < S.Length; i++) { if (charS[i] != '?') { var num = int.Parse(charS[i].ToString()); //繰り返し二乗法により10のi乗を13で割った数値を保存する var mnum = RepeatSquaring(10, i, 13); figsum += mnum * num; } else { exi = true; } } //初期に数字が入ってる数の13で割った余り figsum %= 13; //目的値(?の部分を足していってこの数字に合わせるようにする) long aim = 13 + 5; aim -= figsum; aim %= 13; // Console.WriteLine(aim); //それぞれのmodの組み合わせパターン var comb = new long[13]; // var ans = 0L; var once = true; for (int i = 0; i < charS.Length; i++) { if (charS[i] == '?') { //繰り返し二乗法により10のi乗を13で割った数値を保存する var mnum = RepeatSquaring(10, i, 13); var tmp = new long[13]; //?が0から9まで動くことを考慮する for (int j = 1; j <= 9; j++) { // jとの和がaimと13で合同な数を探す。 // var comp = (13 + aim - figmod) % 13; var figmod = (mnum * j) % 13; if (once) { tmp[figmod]++; } for (int k = 0; k < 13; k++) { var tai = (figmod + k) % 13; tmp[tai] += comb[k]; tmp[tai] %= mod; } } if (once) { once = false; comb[0]++; } //移す for (int j = 0; j < 13; j++) { comb[j] += tmp[j]; comb[j] %= mod; } } } if (exi) { Console.WriteLine(comb[aim]); } else if (figsum == 5) { Console.WriteLine(1); } } //繰り返し2乗法 static long RepeatSquaring(long N, long M = 1000000005, long mod = 1000000007) { if (M == 0) { return 1; } else if (M % 2 == 0) { long t = RepeatSquaring(N, (M / 2), mod) % mod; return (t * t) % mod; } else { return ((N % mod) * RepeatSquaring(N, M - 1, mod)) % mod; } } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; namespace DigitsParades { class Program { static void Main(string[] args) { var S = Console.ReadLine(); var mod = 1000000007; var exi = false; //一桁目から扱えるようにするため、反転させる var charS = S.ToCharArray(); Array.Reverse(charS); var figsum = 0L; for (int i = 0; i < S.Length; i++) { if (charS[i] != '?') { var num = int.Parse(charS[i].ToString()); //繰り返し二乗法により10のi乗を13で割った数値を保存する var mnum = RepeatSquaring(10, i, 13); figsum += mnum * num; } else { exi = true; } } //初期に数字が入ってる数の13で割った余り figsum %= 13; //目的値(?の部分を足していってこの数字に合わせるようにする) long aim = 13 + 5; aim -= figsum; aim %= 13; // Console.WriteLine(aim); //それぞれのmodの組み合わせパターン var comb = new long[13]; // var ans = 0L; var once = true; for (int i = 0; i < charS.Length; i++) { if (charS[i] == '?') { //繰り返し二乗法により10のi乗を13で割った数値を保存する var mnum = RepeatSquaring(10, i, 13); var tmp = new long[13]; //?が0から9まで動くことを考慮する for (int j = 1; j <= 9; j++) { // jとの和がaimと13で合同な数を探す。 // var comp = (13 + aim - figmod) % 13; var figmod = (mnum * j) % 13; if (once) { tmp[figmod]++; } for (int k = 0; k < 13; k++) { var tai = (figmod + k) % 13; tmp[tai] += comb[k]; tmp[tai] %= mod; } } if (once) { once = false; comb[0]++; } //移す for (int j = 0; j < 13; j++) { comb[j] += tmp[j]; comb[j] %= mod; } } } if (exi) { Console.WriteLine(comb[aim]); } else if (figsum == 5) { Console.WriteLine(1); } else { Console.WriteLine(0); } } //繰り返し2乗法 static long RepeatSquaring(long N, long M = 1000000005, long mod = 1000000007) { if (M == 0) { return 1; } else if (M % 2 == 0) { long t = RepeatSquaring(N, (M / 2), mod) % mod; return (t * t) % mod; } else { return ((N % mod) * RepeatSquaring(N, M - 1, mod)) % mod; } } } }
[["+", 0, 195, 8, 196, 0, 57, 75, 57, 0, 95], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 0, 57, 75, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46]]
8
507
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class Contest { public static void Main() { string s; MyIO.ReadMulti(out s); int[] digmod = { 1, 10, 9, 12, 3, 4 }; List<int> qmod = new List<int>(); int sum = 0; for (int i = 0; i < s.Length; i++) { string c = s[s.Length - i - 1].ToString(); if (c == "?") { qmod.Add(i % 6); } else { int k = int.Parse(c); sum += (k * digmod[i % 6]) % 13; } } sum %= 13; long[,] dp = new long[qmod.Count, 13]; for (int k = 0; k < 10; k++) { dp[0, (sum + k * digmod[qmod[0]]) % 13]++; } for (int i = 1; i < qmod.Count; i++) { for (int j = 0; j < 13; j++) { for (int k = 0; k < 10; k++) { dp[i, j] += dp[i - 1, ((j - k * digmod[qmod[i]]) % 13 + 13) % 13]; } dp[i, j] %= 1000000007; } } MyIO.WriteMulti(dp[qmod.Count - 1, 5]); } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(int n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(int n, out Tuple<T, U>[] a) { a = new Tuple<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new Tuple<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(int n, out Tuple<T, U, V>[] a) { a = new Tuple<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new Tuple<T, U, V>(o, p, q); } return arr; } public static string[][] ReadMatrix<T>(int n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } public static void WriteMulti(params object[] a) { wwp(() => { foreach (object x in a) Console.Write("{0} ", x); Console.WriteLine(); }); } public static void WriteArray<T>(T[] a) { wwp(() => { foreach (T x in a) Console.Write("{0} ", x); Console.WriteLine(); }); } public static void WriteLines<T>(T[] a) { wwp(() => { foreach (T x in a) Console.WriteLine(x); }); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class Contest { public static void Main() { string s; MyIO.ReadMulti(out s); int[] digmod = { 1, 10, 9, 12, 3, 4 }; List<int> qmod = new List<int>(); int sum = 0; for (int i = 0; i < s.Length; i++) { string c = s[s.Length - i - 1].ToString(); if (c == "?") { qmod.Add(i % 6); } else { int k = int.Parse(c); sum += (k * digmod[i % 6]) % 13; } } sum %= 13; if (qmod.Count == 0) { if (sum == 5) { MyIO.WriteMulti(1); } else { MyIO.WriteMulti(0); } } else { long[,] dp = new long[qmod.Count, 13]; for (int k = 0; k < 10; k++) { dp[0, (sum + k * digmod[qmod[0]]) % 13]++; } for (int i = 1; i < qmod.Count; i++) { for (int j = 0; j < 13; j++) { for (int k = 0; k < 10; k++) { dp[i, j] += dp[i - 1, ((j - k * digmod[qmod[i]]) % 13 + 13) % 13]; } dp[i, j] %= 1000000007; } } MyIO.WriteMulti(dp[qmod.Count - 1, 5]); } } } public class Printer : System.IO.StreamWriter { public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } } public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) {} public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) {} } public static class MyIO { private static char[] splitter = new char[] { ' ' }; private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse( s, System.Globalization.CultureInfo.InvariantCulture)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); a = ar.Select(cv<T>).ToArray(); return ar; } public static string[][] ReadLines<T>(int n, out T[] a) { a = new T[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadMulti(out a[i]); return arr; } public static string[][] ReadLines<T, U>(int n, out Tuple<T, U>[] a) { a = new Tuple<T, U>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; arr[i] = ReadMulti(out o, out p); a[i] = new Tuple<T, U>(o, p); } return arr; } public static string[][] ReadLines<T, U, V>(int n, out Tuple<T, U, V>[] a) { a = new Tuple<T, U, V>[n]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) { T o; U p; V q; arr[i] = ReadMulti(out o, out p, out q); a[i] = new Tuple<T, U, V>(o, p, q); } return arr; } public static string[][] ReadMatrix<T>(int n, out T[][] a) { a = new T[n][]; string[][] arr = new string[n][]; for (int i = 0; i < n; i++) arr[i] = ReadArray(out a[i]); return arr; } private static void wwp(Action act) { var sw = new Printer(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); act(); Console.Out.Flush(); sw.AutoFlush = true; Console.SetOut(sw); } public static void WriteMulti(params object[] a) { wwp(() => { foreach (object x in a) Console.Write("{0} ", x); Console.WriteLine(); }); } public static void WriteArray<T>(T[] a) { wwp(() => { foreach (T x in a) Console.Write("{0} ", x); Console.WriteLine(); }); } public static void WriteLines<T>(T[] a) { wwp(() => { foreach (T x in a) Console.WriteLine(x); }); } }
[["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 121], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 0, 131], ["+", 8, 196, 0, 57, 15, 16, 31, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 25], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 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, 60], ["+", 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, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 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, 95], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 75, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 75, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 201, 0, 195, 8, 196, 0, 57, 0, 95], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 75, 196, 0, 46]]
8
1,672
38
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace ABC135.D { using static Util; public class Solver : SolverBase { public void Run() { var S = ReadLine(); var ary = new int[13]; if (S[0] == '?') { for (int i = 0; i < 10; i++) { ary[i] = 1; } } else { int x = int.Parse(S[0].ToString()); ary[x] = 1; } //Dump(ary); var d = 1; for (int i = 1; i < S.Length; i++) { d = (d * 10) % 13; if (S[i] != '?') { int x = int.Parse(S[i].ToString()); var cd = (d * x) % 13; // cdぶんだけシフト var nary = new int[13]; for (int j = 0; j < 13; j++) { var n = ary[j]; nary[(j + cd) % 13] = n; } ary = nary; } else { // ?の場合、cdぶんだけシフト を10回加算 var nary = new int[13]; for (int j = 0; j < 10; j++) { var cd = (d * j) % 13; for (int k = 0; k < 13; k++) { var n = ary[k]; nary[(k + cd) % 13] = (nary[(k + cd) % 13] + n) % IMOD; } } ary = nary; } } Dump(ary); WriteLine(ary[6]); } #if !MYHOME static void Main(string[] args) { new Solver().Run(); } #endif } public static class Util { public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public readonly static int IMOD = 1000000007; public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } public 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]; } return max; } public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static bool ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) { r = v; return true; } else { return false; } } public static bool ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) { r = v; return true; } else { return false; } } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); //virtual protected void ReadInt2(out int x, out int y) { // var aryS = ReadLine().Split(' '); // x = int.Parse(aryS[0]); // y = int.Parse(aryS[1]); //} virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected int[] ReadIntArray() => ReadLine().Split(' ').Select<string, int>(s => int.Parse(s)).ToArray(); virtual protected long[] ReadLongArray() => ReadLine().Split(' ').Select<string, long>(s => long.Parse(s)).ToArray(); virtual protected double[] ReadDoubleArray() => ReadLine().Split(' ').Select<string, double>(s => double.Parse(s)).ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(int x) => Console.WriteLine(x); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; namespace ABC135.D { using static Util; public class Solver : SolverBase { public void Run() { var S = ReadLine(); S = new string(S.Reverse().ToArray()); var ary = new int[13]; if (S[0] == '?') { for (int i = 0; i < 10; i++) { ary[i] = 1; } } else { int x = int.Parse(S[0].ToString()); ary[x] = 1; } //Dump(ary); var d = 1; for (int i = 1; i < S.Length; i++) { d = (d * 10) % 13; if (S[i] != '?') { int x = int.Parse(S[i].ToString()); var cd = (d * x) % 13; // cdぶんだけシフト var nary = new int[13]; for (int j = 0; j < 13; j++) { var n = ary[j]; nary[(j + cd) % 13] = n; } ary = nary; } else { // ?の場合、cdぶんだけシフト を10回加算 var nary = new int[13]; for (int j = 0; j < 10; j++) { var cd = (d * j) % 13; for (int k = 0; k < 13; k++) { var n = ary[k]; nary[(k + cd) % 13] = (nary[(k + cd) % 13] + n) % IMOD; } } ary = nary; } } Dump(ary); WriteLine(ary[5]); } #if !MYHOME static void Main(string[] args) { new Solver().Run(); } #endif } public static class Util { public static int Gcd(int a, int b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public readonly static int IMOD = 1000000007; public readonly static long MOD = 1000000007; public static string DumpToString<T>(IEnumerable<T> array) where T : IFormattable { var sb = new StringBuilder(); foreach (var item in array) { sb.Append(item); sb.Append(", "); } return sb.ToString(); } public static void InitArray<T>(T[] ary, T value) { for (int i = 0; i < ary.Length; i++) { ary[i] = value; } } public static void InitDP2<T>(T[,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { dp[i, j] = value; } } } public static void InitDP3<T>(T[,,] dp, T value) { for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { for (int k = 0; k < dp.GetLength(2); k++) { dp[i, j, k] = value; } } } } public 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]; } return max; } public static T Min<T>(params T[] nums) where T : IComparable { if (nums.Length == 0) return default(T); T min = nums[0]; for (int i = 1; i < nums.Length; i++) { min = min.CompareTo(nums[i]) < 0 ? min : nums[i]; } return min; } /// <summary> /// ソート済み配列 ary に同じ値の要素が含まれている? /// ※ソート順は昇順/降順どちらでもよい /// </summary> public static bool HasDuplicateInSortedArray<T>(T[] ary) where T : IComparable, IComparable<T> { if (ary.Length <= 1) return false; var lastNum = ary[ary.Length - 1]; foreach (var n in ary) { if (lastNum.CompareTo(n) == 0) { return true; } else { lastNum = n; } } return false; } public static bool ReplaceIfBigger<T>(ref T r, T v) where T : IComparable { if (r.CompareTo(v) < 0) { r = v; return true; } else { return false; } } public static bool ReplaceIfSmaller<T>(ref T r, T v) where T : IComparable { if (0 < r.CompareTo(v)) { r = v; return true; } else { return false; } } /// <summary> /// 二分探索 /// ※条件を満たす最小のidxを返す /// ※満たすものがない場合は ary.Length を返す /// ※『aryの先頭側が条件を満たさない、末尾側が条件を満たす』という前提 /// ただし、IsOK(...)の戻り値を逆転させれば、逆でも同じことが可能。 /// </summary> /// <param name="ary">探索対象配列 ★ソート済みであること</param> /// <param name="key">探索値 ※これ以上の値を持つ(IsOKがtrueを返す)最小のindexを返す</param> public static int BinarySearch<T>(T[] ary, T key) where T : IComparable, IComparable<T> { int left = -1; int right = ary.Length; while (1 < right - left) { var mid = left + (right - left) / 2; if (IsOK(ary, mid, key)) { right = mid; } else { left = mid; } } // left は条件を満たさない最大の値、right は条件を満たす最小の値になっている return right; } public static bool IsOK<T>(T[] ary, int idx, T key) where T : IComparable, IComparable<T> { // key <= ary[idx] と同じ意味 return key.CompareTo(ary[idx]) <= 0; } } public class SolverBase { virtual protected string ReadLine() => Console.ReadLine(); virtual protected int ReadInt() => int.Parse(ReadLine()); //virtual protected void ReadInt2(out int x, out int y) { // var aryS = ReadLine().Split(' '); // x = int.Parse(aryS[0]); // y = int.Parse(aryS[1]); //} virtual protected long ReadLong() => long.Parse(ReadLine()); virtual protected string[] ReadStringArray() => ReadLine().Split(' '); virtual protected int[] ReadIntArray() => ReadLine().Split(' ').Select<string, int>(s => int.Parse(s)).ToArray(); virtual protected long[] ReadLongArray() => ReadLine().Split(' ').Select<string, long>(s => long.Parse(s)).ToArray(); virtual protected double[] ReadDoubleArray() => ReadLine().Split(' ').Select<string, double>(s => double.Parse(s)).ToArray(); virtual protected void WriteLine(string line) => Console.WriteLine(line); virtual protected void WriteLine(double d) => Console.WriteLine($"{d:F9}"); virtual protected void WriteLine<T>(T value) where T : IFormattable => Console.WriteLine(value); [Conditional("DEBUG")] protected void Dump(string s) => Console.WriteLine(s); [Conditional("DEBUG")] protected void Dump(char c) => Console.WriteLine(c); [Conditional("DEBUG")] protected void Dump(int x) => Console.WriteLine(x); [Conditional("DEBUG")] protected void Dump(double d) => Console.WriteLine($"{d:F9}"); [Conditional("DEBUG")] protected void Dump<T>(IEnumerable<T> array) where T : IFormattable { string s = Util.DumpToString(array); // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(s); //_writer.WriteLine(s); } [Conditional("DEBUG")] protected void DumpGrid<T>(IEnumerable<IEnumerable<T>> arrayOfArray) where T : IFormattable { var sb = new StringBuilder(); foreach (var a in arrayOfArray) { sb.AppendLine(Util.DumpToString(a)); } // Consoleに出力すると、UnitTestの邪魔をしないというメリットあり。 Console.WriteLine(sb.ToString()); //_writer.WriteLine(sb.ToString()); } [Conditional("DEBUG")] protected void DumpDP<T>(T[,] dp) where T : IFormattable { var sb = new StringBuilder(); for (int i = 0; i < dp.GetLength(0); i++) { for (int j = 0; j < dp.GetLength(1); j++) { sb.Append(dp[i, j]); sb.Append(", "); } sb.AppendLine(); } Console.WriteLine(sb.ToString()); } } }
[["+", 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], ["+", 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], ["+", 0, 1, 0, 11, 12, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
1,814
18
using System; class F { static void Main() { var s = Console.ReadLine(); var t = Console.ReadLine(); var t_sub = new int[t.Length]; t_sub[0] = -1; for (int i = 1; i < t.Length; i++) { var p = t_sub[i - 1]; t_sub[i] = p > -1 && t[i] == t[p + 1] ? p + 1 : t[i] == t[0] ? 0 : -1; } var st = new bool[s.Length]; for (int i = 0, j = 0; i < s.Length;) { for (;; j++) { if (s[(i + j) % s.Length] != t[j]) break; if (j == t.Length - 1) { st[i] = true; break; } } if (t_sub[j] == -1) { i += j + 1; j = 0; } else { i += j - t_sub[j]; j = t_sub[j] + 1; } } var M = 0; var u = new int[s.Length]; for (int i = 0; i < s.Length; i++) { if (!st[i] || u[i] > 0) continue; var j = i; while (st[MInt(j - t.Length, s.Length)]) { j = MInt(j - t.Length, s.Length); if (j == i) { Console.WriteLine(-1); return; } } var c = 0; while (st[j]) { u[j] = ++c; j = (j + t.Length) % s.Length; } M = Math.Max(M, c); } Console.WriteLine(M); } static int MInt(int x, int mod) => (x %= mod) < 0 ? x + mod : x; }
using System; class F { static void Main() { var s = Console.ReadLine(); var t = Console.ReadLine(); var t_sub = new int[t.Length]; t_sub[0] = -1; for (int i = 1; i < t.Length; i++) { var p = t_sub[i - 1]; t_sub[i] = p > -1 && t[i] == t[p + 1] ? p + 1 : t[i] == t[0] ? 0 : -1; } var st = new bool[s.Length]; for (int i = 0, j = 0; i < s.Length;) { for (;; j++) { if (s[(i + j) % s.Length] != t[j]) { j--; break; } if (j == t.Length - 1) { st[i] = true; break; } } if (j == -1) { i++; j = 0; } else if (t_sub[j] == -1) { i += j + 1; j = 0; } else { i += j - t_sub[j]; j = t_sub[j] + 1; } } var M = 0; var u = new int[s.Length]; for (int i = 0; i < s.Length; i++) { if (!st[i] || u[i] > 0) continue; var j = i; while (st[MInt(j - t.Length, s.Length)]) { j = MInt(j - t.Length, s.Length); if (j == i) { Console.WriteLine(-1); return; } } var c = 0; while (st[j]) { u[j] = ++c; j = (j + t.Length) % s.Length; } M = Math.Max(M, c); } Console.WriteLine(M); } static int MInt(int x, int mod) => (x %= mod) < 0 ? x + mod : x; }
[["+", 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, 68], ["+", 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, 7, 8, 196, 0, 46], ["+", 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], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 25], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95]]
8
434
22
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static bool inf = false; static string s; static string t; //実はループするから目も入らない TLEしたら消す static int[] memo; static bool[] calling; //頭から何文字 static ModInt[] sHash; //頭から何文字 static ModInt[] tHash; static void Main() { powMemo[0] = 1; for (int i = 1; i < powMemo.Length; i++) { powMemo[i] = powMemo[i - 1] * 27; } s = Console.ReadLine(); t = Console.ReadLine(); memo = Enumerable.Repeat(-1, s.Length).ToArray(); calling = new bool[s.Length]; sHash = CreateHash(s); tHash = CreateHash(t); // s.length <= t.lengthの場合、i=2で成立する場合は全て成立 ほんとか いいえ // シミュレーションができる うん できるね †rolling hash† var res = 0; for (int i = 0; i < s.Length; i++) { res = Max(res, Solve(i)); if (inf) { Console.WriteLine(-1); return; } } Console.WriteLine(res); } static ModInt[] powMemo = new ModInt[500001]; static ModInt Slice(this ModInt[] hash, int begin, int length) { return hash[begin + length] - hash[begin] * powMemo[length]; } static ModInt[] CreateHash(string s) { var hash = new ModInt[s.Length + 1]; for (int i = 0; i < s.Length; i++) { hash[i + 1] = hash[i] * 27 + (s[i] - 96); } return hash; } // sの何番目からtを取り始めたら何個行けるか static int Solve(int begin) { if (calling[begin]) { inf = true; return 0; } calling[begin] = true; var tPlace = 0; var sPlace = begin; var remainLength = t.Length; while (remainLength != 0) { var nextLength = Min(remainLength, Min(t.Length - tPlace, s.Length - sPlace)); if (sHash.Slice(sPlace, nextLength) != tHash.Slice(tPlace, nextLength)) { calling[begin] = false; return memo[begin] = 0; } remainLength -= nextLength; sPlace += nextLength; tPlace += nextLength; if (sPlace == s.Length) sPlace = 0; if (tPlace == s.Length) tPlace = 0; } var res = memo[tPlace] != -1 ? memo[tPlace] : Solve(tPlace) + 1; calling[begin] = false; return memo[begin] = res; } } struct ModInt { const int MOD = 745731223; long Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt modInt) => modInt.Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long val) => new ModInt(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, int b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= MOD ? res - MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, long b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, long b) => a.Data - b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, int b) => new ModInt() { Data = a.Data * b % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, long b) => a * new ModInt(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { Data = a.Data * GetInverse(b) % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => Data.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GetInverse(long a) { long div, p = MOD, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + MOD; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + MOD; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } }
using System; using System.IO; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static bool inf = false; static string s; static string t; //実はループするから目も入らない TLEしたら消す static int[] memo; static bool[] calling; //頭から何文字 static ModInt[] sHash; //頭から何文字 static ModInt[] tHash; static void Main() { powMemo[0] = 1; for (int i = 1; i < powMemo.Length; i++) { powMemo[i] = powMemo[i - 1] * 27; } s = Console.ReadLine(); t = Console.ReadLine(); memo = Enumerable.Repeat(-1, s.Length).ToArray(); calling = new bool[s.Length]; sHash = CreateHash(s); tHash = CreateHash(t); // s.length <= t.lengthの場合、i=2で成立する場合は全て成立 ほんとか いいえ // シミュレーションができる うん できるね †rolling hash† var res = 0; for (int i = 0; i < s.Length; i++) { res = Max(res, Solve(i)); if (inf) { Console.WriteLine(-1); return; } } Console.WriteLine(res); } static ModInt[] powMemo = new ModInt[500001]; static ModInt Slice(this ModInt[] hash, int begin, int length) { return hash[begin + length] - hash[begin] * powMemo[length]; } static ModInt[] CreateHash(string s) { var hash = new ModInt[s.Length + 1]; for (int i = 0; i < s.Length; i++) { hash[i + 1] = hash[i] * 27 + (s[i] - 96); } return hash; } // sの何番目からtを取り始めたら何個行けるか static int Solve(int begin) { if (calling[begin]) { inf = true; return memo[begin] = 0; } int loop = 1; calling[begin] = true; var tPlace = 0; var sPlace = begin; var remainLength = t.Length; while (remainLength != 0) { var nextLength = Min(remainLength, Min(t.Length - tPlace, s.Length - sPlace)); if (sHash.Slice(sPlace, nextLength) != tHash.Slice(tPlace, nextLength)) { calling[begin] = false; return memo[begin] = 0; } remainLength -= nextLength; sPlace += nextLength; tPlace += nextLength; if (sPlace == s.Length) sPlace = 0; if (tPlace == t.Length) tPlace = 0; } var res = (memo[sPlace] != -1 ? memo[sPlace] : Solve(sPlace)) + 1; calling[begin] = false; return memo[begin] = res; } } struct ModInt { const int MOD = 745731223; long Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt modInt) => modInt.Data; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long val) => new ModInt(val); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, int b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, ModInt b) { long res = a.Data + b.Data; return new ModInt() { Data = res >= MOD ? res - MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt a, long b) => a.Data + b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, ModInt b) { long res = a.Data - b.Data; return new ModInt() { Data = res < 0 ? res + MOD : res }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt a, long b) => a.Data - b; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, int b) => new ModInt() { Data = a.Data * b % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, long b) => a * new ModInt(b); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { Data = a.Data * GetInverse(b) % MOD }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public override string ToString() => Data.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static long GetInverse(long a) { long div, p = MOD, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + MOD; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + MOD; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } }
[["+", 64, 196, 0, 37, 0, 11, 31, 204, 205, 22], ["+", 0, 37, 0, 11, 31, 204, 206, 207, 0, 70], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 37, 0, 11, 31, 204, 206, 207, 0, 73], ["+", 64, 196, 0, 37, 0, 11, 0, 202, 0, 32], ["+", 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, 57, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 41, 64, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 41, 64, 204, 206, 207, 0, 28, 0, 22], ["-", 75, 16, 31, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 41, 75, 213, 3, 4, 0, 28, 0, 22], ["+", 31, 23, 0, 41, 75, 213, 3, 4, 0, 25]]
8
1,153
20
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_135 { class F { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { string s = Read(); string t = Read(); string ss = s; while (ss.Length < s.Length + t.Length - 1) ss += ss; WriteLine(-1); return; RollingHash rollingHash = new RollingHash(ss); long[] hash = rollingHash.GetStringHash(t); int[] graph = new int[s.Length]; for (int i = 0; i < s.Length; i++) graph[i] = -1; for (int i = 0; i < s.Length; i++) { if (rollingHash.ValidateRange(i, t.Length, hash)) { graph[i] = (i + t.Length) % s.Length; } } int[] lengthes = new int[s.Length]; for (int i = 0; i < s.Length; i++) lengthes[i] = -1; for (int i = 0; i < s.Length; i++) // from leaf { if (graph[i] >= 0) continue; int cnt = 0; lengthes[i] = cnt; int now = (i - t.Length % s.Length + s.Length) % s.Length; while (graph[now] >= 0) { cnt++; lengthes[now] = cnt; now = (now - t.Length % s.Length + s.Length) % s.Length; } } int res = 0; for (int i = 0; i < s.Length; i++) { if (lengthes[i] == -1) { WriteLine(-1); return; } res = Max(res, lengthes[i]); } WriteLine(res); } class RollingHash { long mod = 1000000007; long[] bases = new long[3] { 1009, 2003, 3001 }; long[,] pows; long[,] hashes; public RollingHash(string s) { pows = new long[s.Length, bases.Length]; hashes = new long[s.Length, bases.Length]; for (int i = 0; i < s.Length; i++) { for (int j = 0; j < bases.Length; j++) { if (i == 0) pows[i, j] = 1; else pows[i, j] = (pows[i - 1, j] * bases[j]) % mod; } } for (int i = 0; i < s.Length; i++) { for (int j = 0; j < bases.Length; j++) { if (i > 0) hashes[i, j] = (hashes[i - 1, j] * bases[j]) % mod; hashes[i, j] += s[i]; hashes[i, j] %= mod; } } } public long[] GetRangeHash(int l, int r) { long[] hash = new long[bases.Length]; for (int i = 0; i < bases.Length; i++) { hash[i] = hashes[r, i]; if (l > 0) { hash[i] += mod - (hashes[l - 1, i] * pows[r - l + 1, i]) % mod; hash[i] %= mod; } } return hash; } public bool ValidateRange(int l, int length, long[] hash) { int r = l + length - 1; long[] rangeHash = GetRangeHash(l, l + length - 1); for (int i = 0; i < bases.Length; i++) { if (rangeHash[i] != hash[i]) return false; } return true; } public long[] GetStringHash(string s) { long[] vals = new long[bases.Length]; for (int i = 0; i < s.Length; i++) { for (int j = 0; j < bases.Length; j++) { vals[j] = (vals[j] * bases[j] + s[i]) % mod; } } return vals; } public string ToHashString(long[] hash) { string val = ""; for (int i = 0; i < bases.Length; i++) val += hash[i].ToString(); return val; } } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using static System.Console; using static System.Math; namespace AtTest.ABC_135 { class F { static void Main(string[] args) { var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }; SetOut(sw); Method(args); Out.Flush(); } static void Method(string[] args) { string s = Read(); string t = Read(); StringBuilder ss = new StringBuilder(s); while (ss.Length < s.Length + t.Length - 1) { ss.Append(s); } RollingHash rollingHash = new RollingHash(ss.ToString()); long[] hash = rollingHash.GetStringHash(t); int[] graph = new int[s.Length]; for (int i = 0; i < s.Length; i++) graph[i] = -1; for (int i = 0; i < s.Length; i++) { if (rollingHash.ValidateRange(i, t.Length, hash)) { graph[i] = (i + t.Length) % s.Length; } } int[] lengthes = new int[s.Length]; for (int i = 0; i < s.Length; i++) lengthes[i] = -1; for (int i = 0; i < s.Length; i++) // from leaf { if (graph[i] >= 0) continue; int cnt = 0; lengthes[i] = cnt; int now = (i - t.Length % s.Length + s.Length) % s.Length; while (graph[now] >= 0) { cnt++; lengthes[now] = cnt; now = (now - t.Length % s.Length + s.Length) % s.Length; } } int res = 0; for (int i = 0; i < s.Length; i++) { if (lengthes[i] == -1) { WriteLine(-1); return; } res = Max(res, lengthes[i]); } WriteLine(res); } class RollingHash { long mod = 1000000007; long[] bases = new long[3] { 1009, 2003, 3001 }; long[,] pows; long[,] hashes; public RollingHash(string s) { pows = new long[s.Length, bases.Length]; hashes = new long[s.Length, bases.Length]; for (int i = 0; i < s.Length; i++) { for (int j = 0; j < bases.Length; j++) { if (i == 0) pows[i, j] = 1; else pows[i, j] = (pows[i - 1, j] * bases[j]) % mod; } } for (int i = 0; i < s.Length; i++) { for (int j = 0; j < bases.Length; j++) { if (i > 0) hashes[i, j] = (hashes[i - 1, j] * bases[j]) % mod; hashes[i, j] += s[i]; hashes[i, j] %= mod; } } } public long[] GetRangeHash(int l, int r) { long[] hash = new long[bases.Length]; for (int i = 0; i < bases.Length; i++) { hash[i] = hashes[r, i]; if (l > 0) { hash[i] += mod - (hashes[l - 1, i] * pows[r - l + 1, i]) % mod; hash[i] %= mod; } } return hash; } public bool ValidateRange(int l, int length, long[] hash) { int r = l + length - 1; long[] rangeHash = GetRangeHash(l, l + length - 1); for (int i = 0; i < bases.Length; i++) { if (rangeHash[i] != hash[i]) return false; } return true; } public long[] GetStringHash(string s) { long[] vals = new long[bases.Length]; for (int i = 0; i < s.Length; i++) { for (int j = 0; j < bases.Length; j++) { vals[j] = (vals[j] * bases[j] + s[i]) % mod; } } return vals; } public string ToHashString(long[] hash) { string val = ""; for (int i = 0; i < bases.Length; i++) val += hash[i].ToString(); return val; } } private static string Read() { return ReadLine(); } private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); } private static int ReadInt() { return int.Parse(Read()); } private static long ReadLong() { return long.Parse(Read()); } private static double ReadDouble() { return double.Parse(Read()); } private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); } private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); } private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 39, 22], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 45], ["-", 0, 52, 8, 1, 0, 11, 0, 202, 0, 107], ["-", 8, 196, 0, 52, 8, 1, 0, 11, 12, 22], ["-", 0, 195, 8, 196, 0, 52, 8, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 241, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 35], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46], ["+", 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
1,202
23
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; using Number = System.Int32; using System.Numerics; class Solver { public void Solve() { int num; long k; Input.Make(out num, out k); var ar = Input.ar; var lg = 0; for (var pp = num * k; pp > 0; pp >>= 1) lg++; var db = Create(lg, () => Create(num, () => -1L)); var next = Create(2 * (int)1e5 + 1, () => -1); for (var i = num - 1; i >= 0; i--) next[ar[i]] = i + num; for (var i = num - 1; i >= 0; i--) { db[0][i] = next[ar[i]] + 1 - i; next[ar[i]] = i; } for (var p = 1; p < lg; p++) for (var i = 0; i < num; i++) db[p][i] = db[p - 1][i] + db[p - 1][(i + db[p - 1][i]) % num]; long idx = 0L; Fail(""); while (true) { var m = idx % num; for (var i = lg - 1; i >= 0; i--) if (db[i][m] > 0 && db[i][m] + idx <= num * k - 1) { idx += db[i][m]; goto END; } break; END:; } var use = new bool[2 * (int)1e5 + 1]; var st = new Stack<int>(); for (var i = (int)(idx % num); i < num; i++) { var v = ar[i]; if (use[v]) { while (st.Peek() != v) use[st.Pop()] = false; use[st.Pop()] = false; } else { st.Push(v); use[v] = true; } } var res = new List<int>(); while (st.Any()) res.Add(st.Pop()); res.Reverse(); if (res.Count != 0) Console.WriteLine(string.Join(" ", res)); } } #region Template public class Template { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == 1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == -1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) => Enumerable.Repeat(0, n).Select(_ => f()).ToArray(); public static void Fail() => Fail("No"); public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var p = new Solver(); for (var i = 1; i > 0; --i) p.Solve(); Console.Out.Flush(); } } public class Input { public static string read => Console.ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => Convert.ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => Convert.ToInt64(read); public static char[][] grid(int h) => Create(h, () => read.ToCharArray()); public static int[] ar1D(int n) => Create(n, () => num); public static long[] arL1D(int n) => Create(n, () => numL); public static string[] strs(int n) => Create(n, () => read); public static int[][] ar2D(int n) => Create(n, () => ar); public static long[][] arL2D(int n) => Create(n, () => arL); public static List<T>[] edge<T>(int n) => Create(n, () => new List<T>()); public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } static Input() { sc = new Queue<string>(); dic = new Dictionary<Type, Func<string, object>>(); dic[typeof(int)] = s => int.Parse(s); dic[typeof(long)] = s => long.Parse(s); dic[typeof(char)] = s => char.Parse(s); dic[typeof(double)] = s => double.Parse(s); dic[typeof(uint)] = s => uint.Parse(s); dic[typeof(ulong)] = s => ulong.Parse(s); dic[typeof(string)] = s => s; } private static Dictionary<Type, Func<string, object>> dic; private static Queue<string> sc; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T Next<T>() { if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item); return (T)dic[typeof(T)](sc.Dequeue()); } public const int MOD = 1000000007; } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() { v1 = default(T1); v2 = default(T2); } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() { v3 = default(T3); } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using static Template; using static System.Console; using static System.Convert; using static System.Math; using Pi = Pair<int, int>; using Number = System.Int32; using System.Numerics; class Solver { public void Solve() { int num; long k; Input.Make(out num, out k); var ar = Input.ar; var lg = 0; for (var pp = num * k; pp > 0; pp >>= 1) lg++; var db = Create(lg, () => Create(num, () => 0L)); var next = Create(2 * (int)1e5 + 1, () => 0); for (var i = num - 1; i >= 0; i--) next[ar[i]] = i + num; for (var i = num - 1; i >= 0; i--) { db[0][i] = next[ar[i]] + 1 - i; next[ar[i]] = i; } for (var p = 1; p < lg; p++) for (var i = 0; i < num; i++) if (db[p - 1][i] >= 0) db[p][i] = db[p - 1][i] + db[p - 1][(i + db[p - 1][i]) % num]; long idx = 0L; while (true) { var m = idx % num; for (var i = lg - 1; i >= 0; i--) if (db[i][m] > 0 && db[i][m] + idx <= num * k - 1) { idx += db[i][m]; goto END; } break; END:; } var use = new bool[2 * (int)1e5 + 1]; var st = new Stack<int>(); for (var i = (int)(idx % num); i < num; i++) { var v = ar[i]; if (use[v]) { while (st.Peek() != v) use[st.Pop()] = false; use[st.Pop()] = false; } else { st.Push(v); use[v] = true; } } var res = new List<int>(); while (st.Any()) res.Add(st.Pop()); res.Reverse(); if (res.Count != 0) Console.WriteLine(string.Join(" ", res)); } } #region Template public class Template { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == 1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T num, T val) where T : IComparable<T> { if (num.CompareTo(val) == -1) { num = val; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T v1, ref T v2) { var t = v2; v2 = v1; v1 = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) => Enumerable.Repeat(0, n).Select(_ => f()).ToArray(); public static void Fail() => Fail("No"); public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var p = new Solver(); for (var i = 1; i > 0; --i) p.Solve(); Console.Out.Flush(); } } public class Input { public static string read => Console.ReadLine().Trim(); public static int[] ar => read.Split(' ').Select(int.Parse).ToArray(); public static int num => Convert.ToInt32(read); public static long[] arL => read.Split(' ').Select(long.Parse).ToArray(); public static long numL => Convert.ToInt64(read); public static char[][] grid(int h) => Create(h, () => read.ToCharArray()); public static int[] ar1D(int n) => Create(n, () => num); public static long[] arL1D(int n) => Create(n, () => numL); public static string[] strs(int n) => Create(n, () => read); public static int[][] ar2D(int n) => Create(n, () => ar); public static long[][] arL2D(int n) => Create(n, () => arL); public static List<T>[] edge<T>(int n) => Create(n, () => new List<T>()); public static void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public static void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public static void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public static void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public static void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } static Input() { sc = new Queue<string>(); dic = new Dictionary<Type, Func<string, object>>(); dic[typeof(int)] = s => int.Parse(s); dic[typeof(long)] = s => long.Parse(s); dic[typeof(char)] = s => char.Parse(s); dic[typeof(double)] = s => double.Parse(s); dic[typeof(uint)] = s => uint.Parse(s); dic[typeof(ulong)] = s => ulong.Parse(s); dic[typeof(string)] = s => s; } private static Dictionary<Type, Func<string, object>> dic; private static Queue<string> sc; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T Next<T>() { if (sc.Count == 0) foreach (var item in read.Split(' ')) sc.Enqueue(item); return (T)dic[typeof(T)](sc.Dequeue()); } public const int MOD = 1000000007; } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() { v1 = default(T1); v2 = default(T2); } public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() { v3 = default(T3); } public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; } #endregion
[["-", 3, 4, 0, 28, 0, 218, 8, 241, 0, 33], ["-", 3, 4, 0, 28, 0, 218, 8, 241, 0, 203], ["+", 8, 213, 3, 4, 0, 28, 0, 218, 8, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 218, 8, 203], ["+", 0, 195, 8, 196, 0, 7, 8, 7, 0, 25], ["+", 8, 196, 0, 7, 8, 7, 8, 57, 0, 121], ["+", 8, 196, 0, 7, 8, 7, 8, 57, 0, 24], ["+", 8, 57, 15, 16, 31, 204, 205, 204, 205, 22], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 70], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 205, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 15, 16, 31, 204, 205, 204, 206, 207, 0, 73], ["+", 8, 57, 15, 16, 31, 204, 206, 207, 0, 70], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 8, 57, 15, 16, 31, 204, 206, 207, 0, 73], ["+", 0, 7, 8, 7, 8, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 7, 8, 57, 15, 16, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 1, 0, 213, 63, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
2,028
26
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class AGC036B { static public void Solve() { var N = NN; var K = NN; var AList = NNList(N); var dblCnt = (long)(Log(N * K) / Log(2)) + 1; var gotoCount = new long[N, dblCnt]; var colorTable = new long?[200001]; for (var i = 0; i < N * 2; i++) { var num = AList[i % N]; if (colorTable[num].HasValue) { gotoCount[colorTable[num].Value, 0] = i + 1 - colorTable[num].Value; colorTable[num] = null; } if (i < N) { colorTable[num] = i; } } for (var i = 1; i < dblCnt; i++) { var ok = true; for (var j = 0; j < N; j++) { gotoCount[j, i] = gotoCount[(gotoCount[j, i - 1] + j) % N, i - 1] + gotoCount[j, i - 1]; if (gotoCount[j, i] > 1000000000000000000) { ok = false; break; } } if (!ok) { dblCnt = i; break; } } var nowDist = 0L; for (var i = dblCnt - 1; i >= 0; i--) { while (nowDist + gotoCount[nowDist % N, i] < N * K) { nowDist += gotoCount[nowDist % N, i]; } } var outNum = new long[N]; var idx = 0L; colorTable = new long?[200001]; for (var i = nowDist; i <= N * K; i++) { var num = AList[i % N]; if (colorTable[num].HasValue && colorTable[num] < idx) { idx = colorTable[num].Value; } else { colorTable[outNum[idx]] = null; outNum[idx] = num; colorTable[num] = idx; ++idx; } } var first = true; for (var i = 0; i < idx; i++) { if (!first) Console.Write(" "); first = false; Console.Write(outNum[i]); } Console.WriteLine(); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { 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); [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 _B(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) { _B(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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } class PQ<T> where T : IComparable { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; [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; } [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<TK, TV> where TK : IComparable { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((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(TK k, TV v) => q.Push(Tuple.Create(k, v)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UF(long s) { d = Repeat(-1L, s).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsSame(long x, long y) => Root(x) == Root(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Count(long x) => -d[Root(d[x])]; } struct Mod : IEquatable<object> { static public long _mod = 1000000007; 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) { var t = x._val + y._val; return t >= _mod ? new Mod { _val = t - _mod } : new Mod { _val = t }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) { var t = x._val - y._val; return t < 0 ? new Mod { _val = t + _mod } : new Mod { _val = t }; } [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 List<Mod> _fact = new List<Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void B(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) { B(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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } struct Mat<T> { 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; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; } Comparison<T> c; Node r; bool ch; T lm; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT(Comparison<T> _c) { c = _c; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT() : this((x, y) => x.CompareTo(y)) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] bool R(Node n) => n != null && !n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] bool B(Node n) => n != null && n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(T x) { r = A(r, x); r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); return Bl(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RmM(Node n) { if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(T x) { var t = FindUpper(x); return t.Item1 && t.Item2.CompareTo(x) == 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindUpper(T x, bool findSame = true) { var v = FU(r, x, findSame); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FU(Node n, T x, bool s) { if (n == null) return null; var r = c(x, n.v); if (r < 0) { var v = FU(n.l, x, s); return v == null ? Tuple.Create(true, n.v) : v; } if (r > 0 || !s && r == 0) return FU(n.r, x, s); return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindLower(T x, bool findSame = true) { var v = FL(r, x, findSame); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FL(Node n, T x, bool s) { if (n == null) return null; var r = c(x, n.v); if (r < 0 || !s && r == 0) return FL(n.l, x, s); if (r > 0) { var v = FL(n.r, x, s); return v == null ? Tuple.Create(true, n.v) : v; } return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => r != null; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountSlow() => L(r).Count(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<T> List() => L(r); [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } class Dict<K, V> : Dictionary<K, V> { Func<K, V> d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dict(Func<K, V> _d) { d = _d; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dict() : this(_ => default(V)) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } } } class Deque<T> { T[] b; int o, c; public int Count; public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Deque(int cap = 16) { b = new T[c = cap]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; } public T Front => b[o]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; } public T Back => b[gi(Count - 1)]; [MethodImpl(MethodImplOptions.AggressiveInlining)] void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class AGC036B { static public void Solve() { var N = NN; var K = NN; var AList = NNList(N); var dblCnt = (long)(Log(N * K) / Log(2)) + 1; var gotoCount = new long[N, dblCnt]; var colorTable = new long?[200001]; for (var i = 0; i < N * 2; i++) { var num = AList[i % N]; if (colorTable[num].HasValue) { gotoCount[colorTable[num].Value, 0] = i + 1 - colorTable[num].Value; colorTable[num] = null; } if (i < N) { colorTable[num] = i; } } for (var i = 1; i < dblCnt; i++) { var ok = true; for (var j = 0; j < N; j++) { gotoCount[j, i] = gotoCount[(gotoCount[j, i - 1] + j) % N, i - 1] + gotoCount[j, i - 1]; if (gotoCount[j, i] > 1000000000000000000) { ok = false; break; } } if (!ok) { dblCnt = i; break; } } var nowDist = 0L; for (var i = dblCnt - 1; i >= 0; i--) { while (nowDist + gotoCount[nowDist % N, i] < N * K) { nowDist += gotoCount[nowDist % N, i]; } } var outNum = new long[N]; var idx = 0L; colorTable = new long?[200001]; for (var i = nowDist; i < N * K; i++) { var num = AList[i % N]; if (colorTable[num].HasValue && colorTable[num] < idx) { var newidx = colorTable[num].Value; for (var j = newidx; j < idx; j++) { colorTable[outNum[j]] = null; } idx = newidx; } else { outNum[idx] = num; colorTable[num] = idx; ++idx; } } var first = true; for (var i = 0; i < idx; i++) { if (!first) Console.Write(" "); first = false; Console.Write(outNum[i]); } Console.WriteLine(); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static Random rand = new Random(); static class Console_ { 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); [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 _B(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) { _B(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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } class PQ<T> where T : IComparable { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; [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; } [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<TK, TV> where TK : IComparable { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((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(TK k, TV v) => q.Push(Tuple.Create(k, v)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UF(long s) { d = Repeat(-1L, s).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsSame(long x, long y) => Root(x) == Root(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Count(long x) => -d[Root(d[x])]; } struct Mod : IEquatable<object> { static public long _mod = 1000000007; 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) { var t = x._val + y._val; return t >= _mod ? new Mod { _val = t - _mod } : new Mod { _val = t }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) { var t = x._val - y._val; return t < 0 ? new Mod { _val = t + _mod } : new Mod { _val = t }; } [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 List<Mod> _fact = new List<Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void B(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) { B(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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } struct Mat<T> { 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; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; } Comparison<T> c; Node r; bool ch; T lm; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT(Comparison<T> _c) { c = _c; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT() : this((x, y) => x.CompareTo(y)) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] bool R(Node n) => n != null && !n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] bool B(Node n) => n != null && n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(T x) { r = A(r, x); r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); return Bl(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RmM(Node n) { if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(T x) { var t = FindUpper(x); return t.Item1 && t.Item2.CompareTo(x) == 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindUpper(T x, bool findSame = true) { var v = FU(r, x, findSame); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FU(Node n, T x, bool s) { if (n == null) return null; var r = c(x, n.v); if (r < 0) { var v = FU(n.l, x, s); return v == null ? Tuple.Create(true, n.v) : v; } if (r > 0 || !s && r == 0) return FU(n.r, x, s); return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindLower(T x, bool findSame = true) { var v = FL(r, x, findSame); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FL(Node n, T x, bool s) { if (n == null) return null; var r = c(x, n.v); if (r < 0 || !s && r == 0) return FL(n.l, x, s); if (r > 0) { var v = FL(n.r, x, s); return v == null ? Tuple.Create(true, n.v) : v; } return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => r != null; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CountSlow() => L(r).Count(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<T> List() => L(r); [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } class Dict<K, V> : Dictionary<K, V> { Func<K, V> d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dict(Func<K, V> _d) { d = _d; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dict() : this(_ => default(V)) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } } } class Deque<T> { T[] b; int o, c; public int Count; public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Deque(int cap = 16) { b = new T[c = cap]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; } public T Front => b[o]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; } public T Back => b[gi(Count - 1)]; [MethodImpl(MethodImplOptions.AggressiveInlining)] void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; } } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 64, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 88], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 24], ["+", 64, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["+", 64, 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, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 35], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 29], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 25], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 57, 64, 196, 0, 7, 8, 196, 0, 46], ["+", 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, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45]]
8
8,607
31
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int N = int.Parse(str[0]); long K = long.Parse(str[1]); int[] A = new int[N]; string[] str2 = Console.ReadLine().Split(); for (var i = 0; i < N; i++) { A[i] = int.Parse(str2[i]); } var dic = new Dictionary<int, int>(); var dic2 = new Dictionary<int, int>(); var dics = new Dictionary<int, int>(); int[] B = new int[N]; int[] B2 = new int[N]; int[] BS = new int[N]; for (var i = 0; i < N; i++) { if (dic.ContainsKey(A[i])) { dic[A[i]]++; B2[i] = dic2[A[i]]; } else { dic[A[i]] = 1; B2[i] = -1; dics[A[i]] = i; } dic2[A[i]] = i; B[i] = dic[A[i]]; } var dic3 = new Dictionary<int, int>(); var dic4 = new Dictionary<int, int>(); int[] B3 = new int[N]; int[] B4 = new int[N]; for (var i = N - 1; i >= 0; i--) { if (dic3.ContainsKey(A[i])) { dic3[A[i]]++; B4[i] = dic4[A[i]]; } else { dic3[A[i]] = 1; B4[i] = -1; } dic4[A[i]] = i; B3[i] = dic3[A[i]]; } int di = 0; long[] L = new long[N]; var ans = new List<int>(); while (true) { // Console.Error.WriteLine(K+" "+di); if (L[di] > 0) { if (K % (L[di] - K) == 0) { K = K % (L[di] - K) + (L[di] - K); } else { K = K % (L[di] - K); } } L[di] = K; int T = dic[A[di]]; int T2 = B4[di]; // Console.Error.WriteLine(T+" "+T2); if (T2 == -1) { if (K == 1) { for (var i = di; i < N; i++) { ans.Add(A[i]); } break; } else { if (T == 1) { K -= 1; di += 1; } else { K -= 1; di = dics[A[di]] + 1; if (di == N) { K -= 1; di = 0; if (K == 0) { break; } } } } } else { di = T2; di = di + 1; if (di == N) { K -= 1; di = 0; if (K == 0) { break; } } } } if (ans.Count > 0) { var dic5 = new Dictionary<int, int>(); int[] B5 = new int[N]; for (var i = ans.Count - 1; i >= 0; i--) { if (dic5.ContainsKey(ans[i])) { dic5[ans[i]]++; B5[i] = dic5[ans[i]]; } else { dic5[ans[i]] = 1; B5[i] = 1; } } var ans2 = new List<int>(); int flag = -1; for (var i = 0; i < ans.Count; i++) { if (flag == -1) { if (B5[i] == 1) { ans2.Add(ans[i]); } else { flag = ans[i]; } } else { if (ans[i] == flag) { flag = -1; } } } if (ans2.Count > 0) { Console.Write(ans2[0]); for (var i = 1; i < ans2.Count; i++) { Console.Write(" " + ans2[i]); } } } } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { string[] str = Console.ReadLine().Split(); int N = int.Parse(str[0]); long K = long.Parse(str[1]); int[] A = new int[N]; string[] str2 = Console.ReadLine().Split(); for (var i = 0; i < N; i++) { A[i] = int.Parse(str2[i]); } var dic = new Dictionary<int, int>(); var dic2 = new Dictionary<int, int>(); var dics = new Dictionary<int, int>(); int[] B = new int[N]; int[] B2 = new int[N]; for (var i = 0; i < N; i++) { if (dic.ContainsKey(A[i])) { dic[A[i]]++; B2[i] = dic2[A[i]]; } else { dic[A[i]] = 1; B2[i] = -1; dics[A[i]] = i; } dic2[A[i]] = i; B[i] = dic[A[i]]; } var dic3 = new Dictionary<int, int>(); var dic4 = new Dictionary<int, int>(); int[] B3 = new int[N]; int[] B4 = new int[N]; for (var i = N - 1; i >= 0; i--) { if (dic3.ContainsKey(A[i])) { dic3[A[i]]++; B4[i] = dic4[A[i]]; } else { dic3[A[i]] = 1; B4[i] = -1; } dic4[A[i]] = i; B3[i] = dic3[A[i]]; } int di = 0; long[] L = new long[N]; var ans = new List<int>(); while (true) { // Console.Error.WriteLine(K+" "+di); if (L[di] > 0) { if (K % (L[di] - K) == 0) { K = K % (L[di] - K) + (L[di] - K); } else { K = K % (L[di] - K); } } L[di] = K; int T = dic[A[di]]; int T2 = B4[di]; // Console.Error.WriteLine(T+" "+T2); if (T2 == -1) { if (K == 1) { for (var i = di; i < N; i++) { ans.Add(A[i]); } break; } else { if (T == 1) { K -= 1; di += 1; if (di == N) { K -= 1; di = 0; if (K == 0) { break; } } } else { K -= 1; di = dics[A[di]] + 1; if (di == N) { K -= 1; di = 0; if (K == 0) { break; } } } } } else { di = T2; di = di + 1; if (di == N) { K -= 1; di = 0; if (K == 0) { break; } } } } if (ans.Count > 0) { var dic5 = new Dictionary<int, int>(); int[] B5 = new int[N]; for (var i = ans.Count - 1; i >= 0; i--) { if (dic5.ContainsKey(ans[i])) { dic5[ans[i]]++; B5[i] = dic5[ans[i]]; } else { dic5[ans[i]] = 1; B5[i] = 1; } } var ans2 = new List<int>(); int flag = -1; for (var i = 0; i < ans.Count; i++) { if (flag == -1) { if (B5[i] == 1) { ans2.Add(ans[i]); } else { flag = ans[i]; } } else { if (ans[i] == flag) { flag = -1; } } } if (ans2.Count > 0) { Console.Write(ans2[0]); for (var i = 1; i < ans2.Count; i++) { Console.Write(" " + ans2[i]); } } } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 70], ["-", 0, 197, 0, 198, 39, 224, 225, 226, 0, 73], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 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], ["+", 75, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 75, 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, 60], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 22], ["+", 75, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 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, 110], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 64, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 12, 203], ["+", 64, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 64, 196, 0, 57, 64, 196, 0, 93, 0, 35], ["+", 0, 57, 64, 196, 0, 57, 64, 196, 0, 46]]
8
978
37
using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.IO; using System.Linq; using System.Text; class Program { private int N; private long K; private int[] A; static void Main(string[] args) { new Program().Solve(); } public void Solve() { var sc = new Scanner(); N = sc.NextInt(); K = sc.NextLong(); A = sc.IntArray(); var nextIndex = new int[N]; var map = new Dictionary<int, int>(); var b = new bool[N]; for (int i = 0; i < N; i++) { int o; if (map.TryGetValue(A[i], out o)) { nextIndex[o] = i; b[o] = true; } map[A[i]] = i; } for (int i = 0; i < N; i++) { int o; if (map.TryGetValue(A[i], out o)) { if (!b[o]) { nextIndex[o] = i + N; b[o] = true; } } } int index = 0; long cnt = 1; bool flag = false; while (true) { int next = nextIndex[index]; // Console.WriteLine($"{index} {next}"); if (next % N == N - 1) { break; } if (next >= N) { cnt++; // Console.WriteLine($"I {next}"); } index = (next + 1) % N; } K %= cnt; // Console.WriteLine(cnt); index = 0; cnt = 0; if (K == 0) { Console.WriteLine(); } while (true) { int next = nextIndex[index]; if (next >= N) { cnt++; } if (cnt >= K) { break; } index = (next + 1) % N; } // Console.WriteLine(index); var stack = new Stack<int>(); var hs = new HashSet<int>(); for (int i = index; i < N; i++) { if (hs.Add(A[i])) { stack.Push(A[i]); } else { while (true) { int p = stack.Pop(); hs.Remove(p); if (p == A[i]) { break; } } } } Console.WriteLine(string.Join(" ", hs)); } } class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; } const char Separator = ' '; private readonly StreamReader _stream; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = _stream.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = _stream.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.IO; using System.Linq; using System.Text; class Program { private int N; private long K; private int[] A; static void Main(string[] args) { new Program().Solve(); } public void Solve() { var sc = new Scanner(); N = sc.NextInt(); K = sc.NextLong(); A = sc.IntArray(); var nextIndex = new int[N]; var map = new Dictionary<int, int>(); var b = new bool[N]; for (int i = 0; i < N; i++) { int o; if (map.TryGetValue(A[i], out o)) { nextIndex[o] = i; b[o] = true; } map[A[i]] = i; } for (int i = 0; i < N; i++) { int o; if (map.TryGetValue(A[i], out o)) { if (!b[o]) { nextIndex[o] = i + N; b[o] = true; } } } int index = 0; long cnt = 1; bool flag = false; while (true) { int next = nextIndex[index]; // Console.WriteLine($"{index} {next}"); if (next >= N) { cnt++; // Console.WriteLine($"I {next}"); } if (next % N == N - 1) { break; } index = (next + 1) % N; } K %= cnt; // Console.WriteLine(cnt); index = 0; cnt = 0; if (K == 0) { Console.WriteLine(); return; } while (true) { int next = nextIndex[index]; if (next >= N) { cnt++; } if (cnt >= K) { break; } index = (next + 1) % N; } // Console.WriteLine(index); var stack = new Stack<int>(); var hs = new HashSet<int>(); for (int i = index; i < N; i++) { if (hs.Add(A[i])) { stack.Push(A[i]); } else { while (true) { int p = stack.Pop(); hs.Remove(p); if (p == A[i]) { break; } } } } Console.WriteLine(string.Join(" ", hs)); } } class Scanner { public Scanner() { _stream = new StreamReader(Console.OpenStandardInput()); _pos = 0; _line = new string[0]; } const char Separator = ' '; private readonly StreamReader _stream; private int _pos; private string[] _line; #region スペース区切りで取得 public string Next() { if (_pos >= _line.Length) { _line = _stream.ReadLine().Split(Separator); _pos = 0; } return _line[_pos++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } #endregion #region 型変換 private int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (int i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion #region 配列取得 public string[] Array() { if (_pos >= _line.Length) _line = _stream.ReadLine().Split(Separator); _pos = _line.Length; return _line; } public int[] IntArray() { return ToIntArray(Array()); } public long[] LongArray() { return ToLongArray(Array()); } public double[] DoubleArray() { return ToDoubleArray(Array()); } #endregion }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 109], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["-", 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, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
8
954
20
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace A { partial class Program { public IEnumerable<string> Solve() { var n = Scan; var k = Scan; var a = ScanLongs(n); // var r = new Random((int)DateTime.Now.Ticks); // k = r.Next(int.MaxValue) * int.MaxValue; // a = Loop(200001).Select(_ => (long)r.Next(200000) + 1).ToList(); // a = Loop(200001).Select(_ => (long)_).ToList(); // n = a.Count; // k = 1; var nexts = Loop((int)n).Select(_ => -1L).ToArray(); { var tails = Loop(200002).Select(_ => -1L).ToArray(); long memoCount = 0; long pointer = 0; while (memoCount < n) { var aa = a[(int)pointer]; if (tails[aa] >= 0 && nexts[tails[aa]] < 0) { nexts[tails[aa]] = (pointer + 1) % n; memoCount++; } tails[aa] = pointer; pointer++; pointer %= n; } } long mod = 0; { var pointer = 0L; do { var t = nexts[pointer]; if (pointer >= t - 1) mod++; pointer = t; } while (pointer != 0); } { var current = 0L; var kk = (k + mod - 1) % mod; var pointer = 0L; do { var t = nexts[pointer]; if (pointer >= t - 1) { current++; if (current > kk) break; } pointer = t; } while (true); var res = new List<long>(); var memo = new Dictionary<long, int>(); var memoRev = new Dictionary<int, long>(); int tail = -1; for (long i = pointer; i < n; i++) { var aa = a[(int)i]; if (memo.ContainsKey(aa) && memo[aa] >= 0) { var t = memo[aa] - 1; for (int x = t + 1; x <= tail; x++) { memo[memoRev[x]] = -1; } tail = t; } else { tail++; if (tail < res.Count) res[tail] = aa; else res.Add(aa); memo[aa] = tail; memoRev[tail] = aa; } } foreach (var x in res.Take(tail + 1)) { yield return x.ToString(); yield return " "; } } //{ // var res = new List<long>(); // var memo = new Dictionary<long, int>(); // var memoRev = new Dictionary<int, long>(); // int tail = -1; // for (long j = 0; j < k; j++) // { // for (long i = 0; i < n; i++) // { // var aa = a[(int)i]; // if (memo.ContainsKey(aa) && memo[aa] >= 0) // { // var t = memo[aa] - 1; // for (int x = t + 1; x <= tail; x++) // { // memo[memoRev[x]] = -1; // } // tail = t; // } // else // { // tail++; // if (tail < res.Count) // res[tail] = aa; // else // res.Add(aa); // memo[aa] = tail; // memoRev[tail] = aa; // } // } // } // yield return "\n"; // foreach (var x in res.Take(tail + 1)) // { // yield return x.ToString(); // yield return " "; // } //} } } class StartingPoint { static void Main(string[] args) { if (args?.Any() == true) { var assembly = Assembly.GetEntryAssembly(); var resourceName = "AtCoderCSharp.In.txt"; var stream = assembly.GetManifestResourceStream(resourceName); var streamReader = new StreamReader(stream, Encoding.UTF8); var str = streamReader.ReadToEnd(); var textReader = new StringReader(str); Console.SetIn(textReader); } try { foreach (var s in new Program().Solve()) { Console.Write(s); } } catch (Exception e) { Console.WriteLine(e); if (args?.Any() != true) throw e; } if (args?.Any() == true) Console.ReadKey(); } } partial class Program { public List<int> ScanInts(int count) => Enumerable.Range(0, count).Select(_ => ScanInt).ToList(); public List<int> ScanInts(long count) => ScanInts((int)count); public List<long> ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList(); public List<long> ScanLongs(long count) => ScanLongs((int)count); public int ScanInt => int.Parse(Str); public long Scan => long.Parse(Str); public double ScanDouble => (double)Scan; StringBuilder sb = new StringBuilder(); public string Str => ScanStr(); public string ScanStr() { sb.Clear(); int r = 0; bool? b = null; do { r = Console.Read(); b = IsBreak(r); } while (b == true); if (b == null) throw new Exception("input error: unexpected end of stream"); do { sb.Append((char)r); r = Console.Read(); b = IsBreak(r); } while (b == false); return sb.ToString(); } bool? IsBreak(int c) { switch (c) { case -1: return null; case (int)' ': case (int)'\n': case (int)'\r': return true; default: return false; } } public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count); public IEnumerable<int> Loop(int from, int to) => Enumerable.Range(from, to - from + 1); public string YesNo(bool isYes) => isYes ? "Yes" : "No"; public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts); public int Gcm(int a, int b) { if (a < b) return GcmImpl(b, a); else return GcmImpl(a, b); } int GcmImpl(int a, int b) { var remainder = a % b; if (remainder == 0) return b; else return GcmImpl(b, remainder); } public int Lcm(int a, int b) { return a / Gcm(a, b) * b; } int GetFirstIndexGreater(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } int GetFirstIndexGreater(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } int GetLastIndexLess(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } int GetLastIndexLess(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } class Mod { readonly int _divider = 1000000007; public Mod(int divider = 1000000007) { _divider = divider; } public int Add(int a, int b) => (int)Add((long)a, (long)b); public int Sub(int a, int b) => (int)Sub((long)a, (long)b); public int Mul(int a, int b) => (int)Mul((long)a, (long)b); public int Div(int a, int b) => (int)Div((long)a, (long)b); public int Pow(int a, int p) => (int)Pow((long)a, (long)p); public long Add(long a, long b) => (a + b) % _divider; public long Sub(long a, long b) { var t = (a - b) % _divider; if (t < 0) t += _divider; return t; } public long Mul(long a, long b) => (a * b) % _divider; public long Div(long a, long b) => Mul(a, Inv(b)); public long Pow(long a, long p) { switch (p) { case 0: return 1; case 1: return a; default: var halfP = p / 2; var halfPowered = Pow(a, halfP); var powered = Mul(halfPowered, halfPowered); return p % 2 == 0 ? powered : Mul(powered, a); } } readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); long Inv(long a) { long cache = 0L; if (invCache.TryGetValue(a, out cache)) return cache; var result = Pow(a, _divider - 2); invCache.Add(a, result); return result; } readonly List<int> facCache = new List<int>() { 1 }; public int Fac(int a) { if (a < facCache.Count) return facCache[a]; var val = facCache.Last(); var start = facCache.Count; for (int i = start; i <= a; i++) { val = Mul(val, i); facCache.Add(val); } return val; } public int Perm(int n, int r) { if (n < r) return 0; if (r <= 0) return 1; int nn = Fac(n); int nr = Fac(n - r); return Div(nn, nr); } public int Comb(int n, int r) { if (n < r) return 0; if (n == r) return 1; int nn = Fac(n); int nr = Fac(n - r); int rr = Fac(r); return Div(Div(nn, nr), rr); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace A { partial class Program { public IEnumerable<string> Solve() { var n = Scan; var k = Scan; var a = ScanLongs(n); // var r = new Random((int)DateTime.Now.Ticks); // k = r.Next(5); // a = Loop(5).Select(_ => (long)r.Next(5) + 1).ToList(); ////a = Loop(200001).Select(_ => (long)_).ToList(); // n = a.Count; ////k = 1; var nexts = Loop((int)n).Select(_ => -1L).ToArray(); { var tails = Loop(200002).Select(_ => -1L).ToArray(); long memoCount = 0; long pointer = 0; while (memoCount < n) { var aa = a[(int)pointer]; if (tails[aa] >= 0 && nexts[tails[aa]] < 0) { nexts[tails[aa]] = (pointer + 1) % n; memoCount++; } tails[aa] = pointer; pointer++; pointer %= n; } } long mod = 0; { var pointer = 0L; do { var t = nexts[pointer]; if (pointer >= t - 1) { mod++; if (pointer == n - 1 && t == 0) mod++; } pointer = t; } while (pointer != 0); } { var current = 0L; var kk = k % mod; if (kk == 0) yield break; var pointer = 0L; do { var t = nexts[pointer]; if (pointer >= t - 1) { current++; if (current >= kk) break; } pointer = t; } while (true); var res = new List<long>(); var memo = new Dictionary<long, int>(); var memoRev = new Dictionary<int, long>(); int tail = -1; for (long i = pointer; i < n; i++) { var aa = a[(int)i]; if (memo.ContainsKey(aa) && memo[aa] >= 0) { var t = memo[aa] - 1; for (int x = t + 1; x <= tail; x++) { memo[memoRev[x]] = -1; } tail = t; } else { tail++; if (tail < res.Count) res[tail] = aa; else res.Add(aa); memo[aa] = tail; memoRev[tail] = aa; } } foreach (var x in res.Take(tail + 1)) { yield return x.ToString(); yield return " "; } } //{ // var res = new List<long>(); // var memo = new Dictionary<long, int>(); // var memoRev = new Dictionary<int, long>(); // int tail = -1; // for (long j = 0; j < k; j++) // { // for (long i = 0; i < n; i++) // { // var aa = a[(int)i]; // if (memo.ContainsKey(aa) && memo[aa] >= 0) // { // var t = memo[aa] - 1; // for (int x = t + 1; x <= tail; x++) // { // memo[memoRev[x]] = -1; // } // tail = t; // } // else // { // tail++; // if (tail < res.Count) // res[tail] = aa; // else // res.Add(aa); // memo[aa] = tail; // memoRev[tail] = aa; // } // } // } // yield return "\n"; // foreach (var x in res.Take(tail + 1)) // { // yield return x.ToString(); // yield return " "; // } //} } } class StartingPoint { static void Main(string[] args) { if (args?.Any() == true) { var assembly = Assembly.GetEntryAssembly(); var resourceName = "AtCoderCSharp.In.txt"; var stream = assembly.GetManifestResourceStream(resourceName); var streamReader = new StreamReader(stream, Encoding.UTF8); var str = streamReader.ReadToEnd(); var textReader = new StringReader(str); Console.SetIn(textReader); } try { foreach (var s in new Program().Solve()) { Console.Write(s); } } catch (Exception e) { Console.WriteLine(e); if (args?.Any() != true) throw e; } if (args?.Any() == true) Console.ReadKey(); } } partial class Program { public List<int> ScanInts(int count) => Enumerable.Range(0, count).Select(_ => ScanInt).ToList(); public List<int> ScanInts(long count) => ScanInts((int)count); public List<long> ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList(); public List<long> ScanLongs(long count) => ScanLongs((int)count); public int ScanInt => int.Parse(Str); public long Scan => long.Parse(Str); public double ScanDouble => (double)Scan; StringBuilder sb = new StringBuilder(); public string Str => ScanStr(); public string ScanStr() { sb.Clear(); int r = 0; bool? b = null; do { r = Console.Read(); b = IsBreak(r); } while (b == true); if (b == null) throw new Exception("input error: unexpected end of stream"); do { sb.Append((char)r); r = Console.Read(); b = IsBreak(r); } while (b == false); return sb.ToString(); } bool? IsBreak(int c) { switch (c) { case -1: return null; case (int)' ': case (int)'\n': case (int)'\r': return true; default: return false; } } public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count); public IEnumerable<int> Loop(int from, int to) => Enumerable.Range(from, to - from + 1); public string YesNo(bool isYes) => isYes ? "Yes" : "No"; public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts); public int Gcm(int a, int b) { if (a < b) return GcmImpl(b, a); else return GcmImpl(a, b); } int GcmImpl(int a, int b) { var remainder = a % b; if (remainder == 0) return b; else return GcmImpl(b, remainder); } public int Lcm(int a, int b) { return a / Gcm(a, b) * b; } int GetFirstIndexGreater(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } int GetFirstIndexGreater(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return 0; if (listOrdered[count - 1] <= x) return count; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high) / 2; if (listOrdered[mid] > x) high = mid; else low = mid + 1; } return low; } int GetLastIndexLess(long x, ref List<long> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } int GetLastIndexLess(int x, ref List<int> listOrdered) { var count = listOrdered.Count; if (count == 0) return -1; if (listOrdered[0] >= x) return -1; int low = 0; int high = listOrdered.Count - 1; while (low < high) { var mid = (low + high + 1) / 2; if (listOrdered[mid] < x) low = mid; else high = mid - 1; } return low; } } class Mod { readonly int _divider = 1000000007; public Mod(int divider = 1000000007) { _divider = divider; } public int Add(int a, int b) => (int)Add((long)a, (long)b); public int Sub(int a, int b) => (int)Sub((long)a, (long)b); public int Mul(int a, int b) => (int)Mul((long)a, (long)b); public int Div(int a, int b) => (int)Div((long)a, (long)b); public int Pow(int a, int p) => (int)Pow((long)a, (long)p); public long Add(long a, long b) => (a + b) % _divider; public long Sub(long a, long b) { var t = (a - b) % _divider; if (t < 0) t += _divider; return t; } public long Mul(long a, long b) => (a * b) % _divider; public long Div(long a, long b) => Mul(a, Inv(b)); public long Pow(long a, long p) { switch (p) { case 0: return 1; case 1: return a; default: var halfP = p / 2; var halfPowered = Pow(a, halfP); var powered = Mul(halfPowered, halfPowered); return p % 2 == 0 ? powered : Mul(powered, a); } } readonly Dictionary<long, long> invCache = new Dictionary<long, long>(); long Inv(long a) { long cache = 0L; if (invCache.TryGetValue(a, out cache)) return cache; var result = Pow(a, _divider - 2); invCache.Add(a, result); return result; } readonly List<int> facCache = new List<int>() { 1 }; public int Fac(int a) { if (a < facCache.Count) return facCache[a]; var val = facCache.Last(); var start = facCache.Count; for (int i = start; i <= a; i++) { val = Mul(val, i); facCache.Add(val); } return val; } public int Perm(int n, int r) { if (n < r) return 0; if (r <= 0) return 1; int nn = Fac(n); int nr = Fac(n - r); return Div(nn, nr); } public int Comb(int n, int r) { if (n < r) return 0; if (n == r) return 1; int nn = Fac(n); int nr = Fac(n - r); int rr = Fac(r); return Div(Div(nn, nr), rr); } } }
[["+", 0, 82, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 60], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 12, 203], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 98], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["+", 64, 196, 0, 57, 64, 1, 0, 223, 0, 22], ["+", 64, 196, 0, 57, 64, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 196, 0, 57, 64, 1, 0, 35], ["+", 0, 82, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["-", 0, 16, 31, 23, 0, 16, 31, 16, 17, 72], ["-", 0, 16, 31, 23, 0, 16, 31, 16, 12, 22], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 25], ["+", 0, 195, 8, 196, 0, 196, 0, 197, 0, 35], ["+", 0, 195, 8, 196, 0, 196, 0, 57, 0, 121], ["+", 0, 195, 8, 196, 0, 196, 0, 57, 0, 24], ["+", 8, 196, 0, 196, 0, 57, 15, 16, 31, 22], ["+", 8, 196, 0, 196, 0, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 196, 0, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 196, 0, 57, 0, 25], ["+", 8, 196, 0, 196, 0, 57, 64, 285, 0, 286], ["+", 8, 196, 0, 196, 0, 57, 64, 285, 0, 94], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 57, 64, 196, 0, 57, 15, 16, 17, 20]]
8
2,240
34
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int m = 0; static int r = 0; static int c = 0; static int x = 0; static int y = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static bool flg2 = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static int mod = 1000000007; static long[] arr; static char[,] map; static int[,] imap; public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(int def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } #endregion static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); Solve(); Console.Out.Flush(); } static int[] used; public static void Solve() { int n = Int(); var dic = new Dictionary<string, long>(); for (int i = 0; i < n; i++) { s = Text(); char[] c = s.ToArray(); Array.Sort(c); s = new string(c); if (dic.ContainsKey(s)) { dic[s] *= 2; } else { dic.Add(s, 1); } } foreach (var kv in dic) { if (kv.Value > 1) sum += kv.Value - 1; } Sum(); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { #region library static int n = 0; static int m = 0; static int r = 0; static int c = 0; static int x = 0; static int y = 0; static string s = ""; static string[] ss; static long sum = 0; static long cnt = 0; static long max = -1; static long min = 2147483647; static bool flg = false; static bool flg2 = false; static string alpha = "abcdefghijklmnopqrstuvwxyz"; static int mod = 1000000007; static long[] arr; static char[,] map; static int[,] imap; public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } } static Input input; static int Int() { return input.NextInt(); } static long Long() { return input.NextLong(); } static double Double() { return input.NextDouble(); } static string Text() { return input.Next(); } static void wl(object obj = null) { Console.WriteLine(obj); } static void w(object obj) { Console.Write(obj); } static void Yes() { wl("YES"); } static void No() { wl("NO"); } static void Sum() { wl(sum); } static void Cnt() { wl(cnt); } static void SetArray(long num = -1) { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { if (num == -1) arr[i] = Int(); else arr[i] = num; } } static void SetMap(char def = '@') { if (r == 0 && c == 0) { r = Int(); c = Int(); } map = new char[r, c]; for (int i = 0; i < r; i++) { if (def == '@') s = Text(); for (int j = 0; j < c; j++) { map[i, j] = (def == '@') ? s[j] : def; } } } static void SetIMap(int def = -1) { if (r == 0 && c == 0) { r = Int(); c = Int(); } imap = new int[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = (def == -1) ? Int() : def; } } } #endregion static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); Solve(); Console.Out.Flush(); } static int[] used; public static void Solve() { int n = Int(); var dic = new Dictionary<string, long>(); for (int i = 0; i < n; i++) { s = Text(); char[] c = s.ToArray(); Array.Sort(c); s = new string(c); if (dic.ContainsKey(s)) { dic[s]++; } else { dic.Add(s, 1); } } foreach (var kv in dic) { if (kv.Value > 1) sum += f(kv.Value - 1); } Sum(); } static long f(long n) { if (n == 1) return 1; return n + f(n - 1); } }
[["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 108], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["+", 0, 57, 64, 1, 0, 11, 12, 213, 63, 22], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 64, 1, 0, 11, 12, 213, 3, 4, 0, 25], ["+", 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], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 46], ["+", 0, 235, 8, 201, 0, 195, 0, 251, 0, 115], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 0, 208, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 0, 235, 8, 201, 0, 195, 54, 55, 0, 24], ["+", 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, 25], ["+", 0, 235, 8, 201, 0, 195, 8, 196, 0, 45], ["+", 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, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 31, 22], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 17, 72], ["+", 8, 196, 0, 37, 0, 16, 12, 213, 63, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
1,360
34
using Atcoder; using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); string preStr = string.Empty; Dictionary<string, long> strHash = new Dictionary<string, long>(); for (int i = 0; i < N; i++) { var tmp = Console.ReadLine().OrderBy(x => x).ToArray(); var s = new string(tmp); if (!strHash.ContainsKey(s)) { strHash.Add(s, 0); } else { strHash[s] += strHash[s] + 1; } } Console.WriteLine(strHash.Values.Sum()); } } }
using Atcoder; using System; using System.Collections.Generic; using System.ComponentModel.Design; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); long ret = 0; Dictionary<string, long> strHash = new Dictionary<string, long>(); for (int i = 0; i < N; i++) { var tmp = Console.ReadLine().OrderBy(x => x).ToArray(); var s = new string(tmp); if (!strHash.ContainsKey(s)) { strHash.Add(s, 0); } else { strHash[s]++; } ret += strHash[s]; } Console.WriteLine(ret); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 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, 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], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 28, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 28, 0, 213, 63, 214, 205, 214, 0, 131], ["-", 0, 28, 0, 213, 63, 214, 205, 214, 141, 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], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
199
23
using System; using System.Collections.Generic; using System.Linq; namespace CSharp { class Program { public static void Main() { var N = int.Parse(Console.ReadLine()); var dic = new Dictionary<string, int>(); var result = 0L; for (int i = 0; i < N; i++) { var s = Console.ReadLine(); s = s.ToCharArray().OrderBy(x => x).ToArray().ToString(); if (dic.ContainsKey(s)) { dic[s]++; } else { dic[s] = 0; } result += dic[s]; } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; namespace CSharp { class Program { public static void Main() { var N = int.Parse(Console.ReadLine()); var dic = new Dictionary<string, int>(); var result = 0L; for (int i = 0; i < N; i++) { var s = Console.ReadLine(); var array = s.ToCharArray(); Array.Sort(array); s = new string(array); if (dic.ContainsKey(s)) { dic[s]++; } else { dic[s] = 0; } result += dic[s]; } Console.WriteLine(result); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["-", 205, 213, 3, 4, 0, 28, 0, 218, 8, 22], ["-", 205, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 12, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 0, 131], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 141, 22], ["+", 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, 230, 0, 228], ["+", 8, 196, 0, 1, 0, 11, 12, 230, 39, 199], ["+", 0, 11, 12, 230, 3, 4, 0, 28, 0, 22]]
8
152
23
using System; using System.Linq; using System.Collections.Generic; namespace ABC137 { class C { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); Dictionary<string, int> dic = new Dictionary<string, int>(); string[] ss = new string[N]; for (int i = 0; i < N; i++) { string s = Console.ReadLine(); ss[i] = String.Concat(s.OrderBy(a => a)); } int res = 0; for (int i = 0; i < N; i++) { if (dic.ContainsKey(ss[i])) { dic[ss[i]]++; } else { dic.Add(ss[i], 0); } } foreach (int i in dic.Values) { int temp = i; while (1 <= temp) { res += temp; temp--; } } Console.WriteLine(res); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC137 { class C { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); Dictionary<string, long> dic = new Dictionary<string, long>(); string[] ss = new string[N]; for (int i = 0; i < N; i++) { string s = Console.ReadLine(); ss[i] = String.Concat(s.OrderBy(a => a)); } for (int i = 0; i < N; i++) { if (dic.ContainsKey(ss[i])) { dic[ss[i]]++; } else { dic.Add(ss[i], 0); } } long res = 0; foreach (int i in dic.Values) { long temp = i; while (1 <= temp) { res += temp; temp--; } } Console.WriteLine(res); } } }
[["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 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, 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, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199]]
8
218
16
using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { var n = int.Parse(Console.ReadLine()); var input = new Dictionary<string, int>(); for (var count = 0; count < n; count++) { var value = string.Join("", Console.ReadLine().OrderBy(charactor => charactor)); if (input.ContainsKey(value)) { input[value]++; } else { input.Add(value, 1); } } var result = 0; foreach (var value in input.Values) { result += Enumerable.Range(0, value).Sum(); } Console.WriteLine(result); } }
using System; using System.Collections.Generic; using System.Linq; public class Program { public static void Main() { var n = int.Parse(Console.ReadLine()); var input = new Dictionary<string, long>(); for (var count = 0; count < n; count++) { var value = string.Join("", Console.ReadLine().OrderBy(charactor => charactor)); if (input.ContainsKey(value)) { input[value]++; } else { input.Add(value, 1); } } long result = 0; foreach (var value in input.Values) { long temp = value; while (temp > 1) { temp--; result += temp; } } Console.WriteLine(result); } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 210, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 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], ["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["-", 12, 213, 63, 214, 205, 213, 3, 4, 0, 21], ["+", 0, 210, 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], ["-", 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], ["+", 8, 196, 0, 210, 8, 196, 0, 197, 0, 35], ["+", 8, 196, 0, 210, 8, 196, 0, 52, 0, 89], ["+", 0, 210, 8, 196, 0, 52, 15, 16, 31, 22], ["+", 0, 210, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 210, 8, 196, 0, 52, 15, 16, 12, 203], ["+", 0, 210, 8, 196, 0, 52, 8, 196, 0, 45], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 52, 8, 196, 0, 1, 0, 223, 0, 68], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35], ["+", 0, 210, 8, 196, 0, 52, 8, 196, 0, 46]]
8
162
31
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var strs = new Dictionary<string, int>(); long ans = 0; for (int i = 0; i < n; i++) { string str = new string( Console.ReadLine().ToCharArray().OrderBy(x => x).ToArray()); if (strs.ContainsKey(str)) { ans -= Combination(strs[str], 2); strs[str]++; ans += Combination(strs[str], 2); } else { strs.Add(str, 1); } } Console.WriteLine(ans); } static int Combination(int n, int r) { return Permutation(n, r) / Permutation(r, r); } static int Permutation(int n, int r) { int ans = 1; for (int a = 0; a < r; a++) { ans *= n - a; } return ans; } } }
using System; using System.Collections.Generic; using System.Linq; namespace Atcoder { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var strs = new Dictionary<string, long>(); long ans = 0; for (int i = 0; i < n; i++) { string str = new string( Console.ReadLine().ToCharArray().OrderBy(x => x).ToArray()); if (strs.ContainsKey(str)) { ans -= Combination(strs[str], 2); strs[str]++; ans += Combination(strs[str], 2); } else { strs.Add(str, 1); } } Console.WriteLine(ans); } static long Combination(long n, long r) { return Permutation(n, r) / Permutation(r, r); } static long Permutation(long n, long r) { long ans = 1; for (int a = 0; a < r; a++) { ans *= n - a; } return ans; } } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
239
16
using System.Collections.Generic; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var d = new Dictionary<string, int>(); for (int i = 0; i < n; i++) { var s = Console.ReadLine().Trim(); var sa = s.ToCharArray(); Array.Sort(sa); var sb = new string(sa); if (d.ContainsKey(sb)) d[sb]++; else d[sb] = 1; } getAns(d); } static void getAns(Dictionary<string, int> d) { var ans = 0L; foreach (var x in d) ans += (x.Value) * (x.Value - 1) / 2; Console.WriteLine(ans); } }
using System.Collections.Generic; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var d = new Dictionary<string, int>(); for (int i = 0; i < n; i++) { var s = Console.ReadLine().Trim(); var sa = s.ToCharArray(); Array.Sort(sa); var sb = new string(sa); if (d.ContainsKey(sb)) d[sb]++; else d[sb] = 1; } getAns(d); } static void getAns(Dictionary<string, int> d) { var ans = 0L; foreach (var x in d) ans += ((long)x.Value) * ((long)x.Value - 1) / 2L; Console.WriteLine(ans); } }
[["+", 12, 16, 31, 16, 31, 23, 0, 74, 0, 24], ["+", 12, 16, 31, 16, 31, 23, 0, 74, 39, 199], ["+", 12, 16, 31, 16, 31, 23, 0, 74, 0, 25], ["+", 0, 11, 12, 16, 31, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 23, 0, 16, 31, 74, 39, 199], ["+", 31, 16, 12, 23, 0, 16, 31, 74, 0, 25], ["-", 0, 210, 8, 1, 0, 11, 12, 16, 12, 203], ["+", 0, 210, 8, 1, 0, 11, 12, 16, 12, 203]]
8
187
8
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary] int n = int.Parse(Console.ReadLine()); var words = new List<string>(); for (int i = 0; i < n; i++) { var chars = new Dictionary<char, int>(); var s = Console.ReadLine(); foreach (var c in s) { if (chars.ContainsKey(c)) { chars[c]++; } else { chars.Add(c, 1); } } var query = chars.OrderBy(x => x.Key); string word = ""; foreach (var q in query) { word += q.Key + q.Value; } words.Add(word); } var dic = new Dictionary<string, int>(); foreach (var word in words) { if (dic.ContainsKey(word)) { dic[word]++; } else { dic.Add(word, 1); } } long count = 0; for (int i = 0; i < n; i++) { dic[words[i]]--; count += dic[words[i]]; } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { //[summary]C - Green Bin int n = int.Parse(Console.ReadLine()); var words = new List<string>(); for (int i = 0; i < n; i++) { var chars = new Dictionary<string, int>(); var s = Console.ReadLine(); foreach (var c in s) { var si = c.ToString(); if (chars.ContainsKey(si)) { chars[si]++; } else { chars.Add(si, 1); } } var query = chars.OrderBy(x => x.Key); string word = ""; foreach (var q in query) { word += q.Key + q.Value; } words.Add(word); } var dic = new Dictionary<string, int>(); foreach (var word in words) { if (dic.ContainsKey(word)) { dic[word]++; } else { dic.Add(word, 1); } } long count = 0; for (int i = 0; i < n; i++) { dic[words[i]]--; count += dic[words[i]]; } Console.WriteLine(count); } } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 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, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 0, 131], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 210, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 15, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 22], ["-", 0, 223, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 223, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
280
17
using System; using System.Collections.Generic; // list用 using System.Text.RegularExpressions; //正規表現用 using System.Text; // StringBuilder用 using System.Collections; class Program { static List<int> s = new List<int>(); static long result; static Hashtable ht = new Hashtable(); public static int CountChar(string s, char c) { return s.Length - s.Replace(c.ToString(), "").Length; } static void Main() { string tmp1 = Console.ReadLine(); int x = int.Parse(tmp1); string[] tmp2 = new string[x]; string[] kazu = new string[10]; for (int i = 0; i < x; i++) { tmp2[i] = Console.ReadLine(); for (int j = 0; j < 10; j++) { kazu[j] = tmp2[i][j].ToString(); } Array.Sort(kazu); tmp2[i] = kazu[0] + kazu[1] + kazu[2] + kazu[3] + kazu[4] + kazu[5] + kazu[6] + kazu[7] + kazu[8] + kazu[9]; } result = 0; for (int i = 0; i < x; i++) { if (ht.ContainsKey(tmp2[i])) { result += (long)ht[tmp2[i]]; ht[tmp2[i]] = (long)(ht[tmp2[i]]) + 1; } else { ht[tmp2[i]] = (long)0; } } result = (long)ht[tmp2[0]]; Console.WriteLine(result.ToString()); } }
using System; using System.Collections.Generic; // list用 using System.Text.RegularExpressions; //正規表現用 using System.Text; // StringBuilder用 using System.Collections; class Program { static List<int> s = new List<int>(); static long result; static Hashtable ht = new Hashtable(); public static int CountChar(string s, char c) { return s.Length - s.Replace(c.ToString(), "").Length; } static void Main() { string tmp1 = Console.ReadLine(); int x = int.Parse(tmp1); string[] tmp2 = new string[x]; string[] kazu = new string[10]; for (int i = 0; i < x; i++) { tmp2[i] = Console.ReadLine(); for (int j = 0; j < 10; j++) { kazu[j] = tmp2[i][j].ToString(); } Array.Sort(kazu); tmp2[i] = kazu[0] + kazu[1] + kazu[2] + kazu[3] + kazu[4] + kazu[5] + kazu[6] + kazu[7] + kazu[8] + kazu[9]; } result = 0; long temp; for (int i = 0; i < x; i++) { if (ht.ContainsKey(tmp2[i])) { temp = (long)ht[tmp2[i]] + 1; result += temp; ht[tmp2[i]] = temp; } else { ht[tmp2[i]] = (long)0; } } Console.WriteLine(result.ToString()); } }
[["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 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, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 0, 25], ["-", 0, 11, 12, 16, 31, 74, 51, 23, 0, 24], ["-", 12, 16, 31, 74, 51, 23, 0, 204, 205, 22], ["-", 31, 74, 51, 23, 0, 204, 206, 207, 0, 70], ["-", 0, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 70], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 206, 207, 0, 28, 0, 204, 206, 207, 0, 73], ["-", 31, 74, 51, 23, 0, 204, 206, 207, 0, 73], ["-", 0, 11, 12, 16, 31, 74, 51, 23, 0, 25], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["-", 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, 74, 0, 24], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 8, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 0, 1, 0, 11, 12, 74, 51, 204, 205, 22], ["-", 0, 11, 12, 74, 51, 204, 206, 207, 0, 70], ["-", 51, 204, 206, 207, 0, 28, 0, 204, 205, 22], ["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 11, 12, 74, 51, 204, 206, 207, 0, 73], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
376
41
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { // var exStdIn = new System.IO.StreamReader("stdin.txt"); // System.Console.SetIn(exStdIn); int N = int.Parse(Console.ReadLine()); string[] s = new string[N]; Hashtable h = new Hashtable(); int hit = 0; for (int i = 0; i < N; i++) { s[i] = Console.ReadLine(); s[i] = sort(s[i]); if (h.ContainsKey(s[i])) { hit += (int)h[s[i]]; h[s[i]] = (int)h[s[i]] + 1; ; } else { h.Add(s[i], 1); } } Console.WriteLine(hit); } static string sort(string s) { string[] c = new string[10]; for (int i = 0; i < 10; i++) { c[i] = s.Substring(i, 1); } StringComparer cmp = StringComparer.OrdinalIgnoreCase; Array.Sort(c, cmp); s = ""; for (int i = 0; i < 10; i++) { s += c[i]; } return s; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { // var exStdIn = new System.IO.StreamReader("stdin.txt"); // System.Console.SetIn(exStdIn); long N = long.Parse(Console.ReadLine()); string[] s = new string[N]; Dictionary<string, long> h = new Dictionary<string, long>(); long hit = 0; for (long i = 0; i < N; i++) { s[i] = Console.ReadLine(); s[i] = sort(s[i]); if (h.ContainsKey(s[i])) { hit += h[s[i]]; h[s[i]] = h[s[i]] + 1; ; } else { h.Add(s[i], 1); } } Console.WriteLine(hit); } static string sort(string s) { string[] c = new string[10]; for (int i = 0; i < 10; i++) { c[i] = s.Substring(i, 1); } StringComparer cmp = StringComparer.OrdinalIgnoreCase; Array.Sort(c, cmp); s = ""; for (int i = 0; i < 10; i++) { s += c[i]; } return s; } } }
[["-", 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], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["+", 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, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 21], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 47], ["-", 0, 198, 0, 200, 0, 212, 0, 230, 39, 22], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 21], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 64, 196, 0, 1, 0, 11, 12, 74, 0, 24], ["-", 64, 196, 0, 1, 0, 11, 12, 74, 39, 199], ["-", 64, 196, 0, 1, 0, 11, 12, 74, 0, 25], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 0, 24], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 39, 199], ["-", 0, 1, 0, 11, 12, 16, 31, 74, 0, 25]]
8
299
28
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace Sandbox { internal class ProgramC { private static void Main(string[] args) { var scanner = new Scanner(); var n = scanner.GetNextAsInt(); var sDic = new Dictionary<string, int>(); for (var i = 0; i < n; i++) { var s = scanner.GetNext(); var ss = new string(s.OrderBy(c => c).ToArray()); if (sDic.ContainsKey(ss)) { sDic[ss] = 1; } else { sDic[ss]++; } } var counter = 0L; foreach (var kv in sDic) { var count = kv.Value; if (count <= 1) { continue; } counter += nCm(count, 2); } Console.WriteLine(counter); } public static long nCm(long n, long m) { m = Math.Min(m, n - m); if (m == 0) return 1; if (n == 0) return 0; var output = 1L; for (var i = 0; i < m; i++) { output *= (n - i) / (i + 1); } return output; } #region String Scanner public class Scanner { private const char Separator = ' '; private readonly StreamReader _Stream = new StreamReader(Console.OpenStandardInput()); private int _Pos; private string[] _Line = new string[0]; #region get a element public string GetNext() { // ReSharper disable once InvertIf if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); this._Pos = 0; } return this._Line[this._Pos++]; } public int GetNextAsInt() { return int.Parse(this.GetNext()); } public long GetNextAsLong() { return long.Parse(this.GetNext()); } public double GetNextAsDouble() { return double.Parse(this.GetNext()); } #endregion #region get array public string[] ToArrayFromNextLine() { if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); } this._Pos = this._Line.Length; return this._Line; } public int[] ToIntArrayFromNextLine() { return ToIntArray(this.ToArrayFromNextLine()); } public long[] ToLongArrayFromNextLine() { return ToLongArray(this.ToArrayFromNextLine()); } public double[] ToDoubleArrayFromNextLine() { return ToDoubleArray(this.ToArrayFromNextLine()); } #endregion #region convert array private static int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private static long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private static double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion } #endregion } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace Sandbox { internal class ProgramC { private static void Main(string[] args) { var scanner = new Scanner(); var n = scanner.GetNextAsInt(); var sDic = new Dictionary<string, int>(); for (var i = 0; i < n; i++) { var s = scanner.GetNext(); var ss = new string(s.OrderBy(c => c).ToArray()); if (sDic.ContainsKey(ss)) { sDic[ss]++; } else { sDic[ss] = 1; } } var counter = 0L; foreach (var kv in sDic) { var count = (long)kv.Value; if (count <= 1) { continue; } counter += GetCombination(count, 2); } Console.WriteLine(counter); } public static long GetCombination(long n, long m) { // if (n == 0) return 0; m = Math.Min(m, n - m); var output = 1L; for (var i = 0; i < m; i++) { output = output * (n - i) / (i + 1); } return output; } #region String Scanner public class Scanner { private const char Separator = ' '; private readonly StreamReader _Stream = new StreamReader(Console.OpenStandardInput()); private int _Pos; private string[] _Line = new string[0]; #region get a element public string GetNext() { // ReSharper disable once InvertIf if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); this._Pos = 0; } return this._Line[this._Pos++]; } public int GetNextAsInt() { return int.Parse(this.GetNext()); } public long GetNextAsLong() { return long.Parse(this.GetNext()); } public double GetNextAsDouble() { return double.Parse(this.GetNext()); } #endregion #region get array public string[] ToArrayFromNextLine() { if (this._Pos >= this._Line.Length) { // ReSharper disable once PossibleNullReferenceException this._Line = this._Stream.ReadLine().Split(Separator); } this._Pos = this._Line.Length; return this._Line; } public int[] ToIntArrayFromNextLine() { return ToIntArray(this.ToArrayFromNextLine()); } public long[] ToLongArrayFromNextLine() { return ToLongArray(this.ToArrayFromNextLine()); } public double[] ToDoubleArrayFromNextLine() { return ToDoubleArray(this.ToArrayFromNextLine()); } #endregion #region convert array private static int[] ToIntArray(string[] array) { var result = new int[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = int.Parse(array[i]); } return result; } private static long[] ToLongArray(string[] array) { var result = new long[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = long.Parse(array[i]); } return result; } private static double[] ToDoubleArray(string[] array) { var result = new double[array.Length]; for (var i = 0; i < array.Length; i++) { result[i] = double.Parse(array[i]); } return result; } #endregion } #endregion } }
[["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 64, 196, 0, 1, 0, 223, 0, 29], ["-", 0, 57, 75, 196, 0, 1, 0, 223, 0, 29], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["-", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 141, 22], ["-", 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, 37, 0, 38], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["-", 0, 195, 8, 196, 0, 57, 64, 37, 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, 0, 202, 0, 108], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48]]
8
747
35
using System; using System.Linq; using System.Collections.Generic; public class Program { public static void Main() { int N = int.Parse(Console.ReadLine()); string[] s = new string[N]; int ans = 0; var dict = new Dictionary<string, int>(); for (int i = 0; i < N; i++) { char[] a = Console.ReadLine().ToCharArray(); Array.Sort(a); s[i] = new String(a); } for (int j = 0; j < N; j++) { if (dict.ContainsKey(s[j])) { ans += dict[s[j]]; dict[s[j]]++; } else { dict.Add(s[j], 1); } } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; public class Program { public static void Main() { int N = int.Parse(Console.ReadLine()); string[] s = new string[N]; long ans = 0; var dict = new Dictionary<string, int>(); for (int i = 0; i < N; i++) { char[] a = Console.ReadLine().ToCharArray(); Array.Sort(a); s[i] = new String(a); if (dict.ContainsKey(s[i])) { ans += dict[s[i]]; dict[s[i]]++; } else { dict.Add(s[i], 1); } } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 7, 8, 196, 0, 1, 0, 35], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 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, 28, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 22]]
8
191
26
using System; using System.Collections.Generic; using System.Linq; namespace cs { public class Program { public static void Main(string[] args) { /* var N = long.Parse(Console.ReadLine()); var cities = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var brave = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); */ // Console.WriteLine(outer); // SLV(new long[]{13, 3}); SLV(Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse)); // SLV(Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse)); // SLV(Console.ReadLine()); Console.ReadKey(); } public static void SLV(long[] input) { /* var deadLine = input[1]; var N = input[0]; var list = new List<work>(); long[] x; for(int i = 0; i < N; i++){ x = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); list.Add(new work(x[0],x[1])); } list.Sort(); foreach(var tgt in list){ Console.WriteLine(tgt.profitDay + " " + tgt.profit); } long value = 0; int deadDay = 0; for(int i = 0; i <= deadLine; i++){ for(int k = deadDay; k < list.Count; k++){ if(list[k].profitDay+i > deadLine){ continue; } value += list[k].profit; deadDay = k+1; break; } } Console.WriteLine(value); */ // var alph = "abcdefghijklmnopqrstuvwxyz".ToCharArray(); var N = input[0]; var x = new Dictionary<String, long>(); char[] str; string str1; for (int i = 0; i < N; i++) { str = Console.ReadLine().ToCharArray(); Array.Sort(str); str1 = new string(str); // Console.WriteLine(str1); if (x.ContainsKey(str1)) x[str1] += ++x[str1]; else x[str1] = 0; } Console.WriteLine(x.Values.Sum()); return; } private class work : IComparable<work> { public long profitDay { get; set; } public long profit { get; set; } public work(long x, long y) { this.profitDay = x; this.profit = y; } public int CompareTo(work input) { if (this.profit > input.profit) return -1; if (this.profit == input.profit) { if (this.profitDay == input.profitDay) return 0; if (this.profitDay > input.profitDay) return -1; } return 1; } } public static long modder() { return (long)Math.Pow(10, 9) + 7; } public static long GCD(long n, long m) { if (m % n == 0) return n; else return GCD(m % n, n); } public static long LCD(long n, long m) { return m * n / GCD(n, m); } // いやなんか違うけどねこれ public static long lower_bound(long[] array, long input) { var left = 0; var right = array.Length - 1; var mid = 0; while (right >= left) { mid = left + (right - left) / 2; if (array[mid] == input) { return mid; } if (array[mid] > input) { right = mid - 1; } else { left = mid + 1; } } return right; } class UfTree { public long[] parents { get; set; } public long[] size { get; set; } // sizeはrootのみが最新のものを保持する public UfTree(long n) { parents = new long[n]; size = new long[n]; for (long i = 0; i < n; i++) { parents[i] = i; size[i] = 1; } } public long getRoot(long x) { if (parents[x] == x) { return x; } else { parents[x] = getRoot(parents[x]); return parents[x]; } } public long unite(long x, long y) { var rx = getRoot(x); var ry = getRoot(y); if (rx == ry) { return rx; } else { var sx = getSize(rx); var sy = getSize(ry); if (sx > sy) { size[rx] = sx + sy; parents[ry] = rx; return rx; } else { size[ry] = sx + sy; parents[rx] = ry; return ry; } } } public long getSize(long x) { return size[getRoot(x)]; } public bool isSameTree(long x, long y) { return getRoot(x) == getRoot(y); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace cs { public class Program { public static void Main(string[] args) { /* var N = long.Parse(Console.ReadLine()); var cities = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var brave = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); */ // Console.WriteLine(outer); // SLV(new long[]{13, 3}); SLV(Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse)); // SLV(Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse)); // SLV(Console.ReadLine()); Console.ReadKey(); } public static void SLV(long[] input) { /* var deadLine = input[1]; var N = input[0]; var list = new List<List<long>>(); for(int i = 1; i <= deadLine; i++){ list[i] = new List<long>(); } long[] x; for(int i = 0; i < N; i++){ x = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); list[int.Parse(x[0].ToString())].Add(x[1]); } var count = new int[deadLine+1]; var max = new long[deadLine+1]; max[0] = int.MinValue; for(int i = 1; i <= deadLine; i++){ list[i].Sort(); count[i] = list[i].Count; if(count[i] != 0){ } } for(int i = 1; i <= deadLine; i++){ if(count[i] == 0) continue; } */ // var alph = "abcdefghijklmnopqrstuvwxyz".ToCharArray(); var N = input[0]; var x = new Dictionary<String, long>(); var count = new Dictionary<String, long>(); char[] str; string str1; for (int i = 0; i < N; i++) { str = Console.ReadLine().ToCharArray(); Array.Sort(str); str1 = new string(str); // Console.WriteLine(str1); if (x.ContainsKey(str1)) { x[str1] += ++count[str1]; } else { x[str1] = 0; count[str1] = 0; } } Console.WriteLine(x.Values.Sum()); return; } private class work : IComparable<work> { public long profitDay { get; set; } public long profit { get; set; } public work(long x, long y) { this.profitDay = x; this.profit = y; } public int CompareTo(work input) { if (this.profit > input.profit) return -1; if (this.profit < input.profit) return 1; if (this.profitDay == input.profitDay) return 0; return this.profitDay < input.profitDay ? -1 : 1; } } public static long modder() { return (long)Math.Pow(10, 9) + 7; } public static long GCD(long n, long m) { if (m % n == 0) return n; else return GCD(m % n, n); } public static long LCD(long n, long m) { return m * n / GCD(n, m); } // いやなんか違うけどねこれ public static long lower_bound(long[] array, long input) { var left = 0; var right = array.Length - 1; var mid = 0; while (right >= left) { mid = left + (right - left) / 2; if (array[mid] == input) { return mid; } if (array[mid] > input) { right = mid - 1; } else { left = mid + 1; } } return right; } class UfTree { public long[] parents { get; set; } public long[] size { get; set; } // sizeはrootのみが最新のものを保持する public UfTree(long n) { parents = new long[n]; size = new long[n]; for (long i = 0; i < n; i++) { parents[i] = i; size[i] = 1; } } public long getRoot(long x) { if (parents[x] == x) { return x; } else { parents[x] = getRoot(parents[x]); return parents[x]; } } public long unite(long x, long y) { var rx = getRoot(x); var ry = getRoot(y); if (rx == ry) { return rx; } else { var sx = getSize(rx); var sy = getSize(ry); if (sx > sy) { size[rx] = sx + sy; parents[ry] = rx; return rx; } else { size[ry] = sx + sy; parents[rx] = ry; return ry; } } } public long getSize(long x) { return size[getRoot(x)]; } public bool isSameTree(long x, long y) { return getRoot(x) == getRoot(y); } } } }
[["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["+", 0, 198, 0, 200, 0, 212, 0, 230, 0, 228], ["+", 0, 200, 0, 212, 0, 230, 39, 236, 141, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 18], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 22], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 21], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 47], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 24], ["+", 0, 200, 0, 212, 0, 230, 3, 4, 0, 25], ["+", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 64, 1, 0, 11, 12, 241, 0, 204, 205, 22], ["+", 0, 1, 0, 11, 12, 241, 0, 204, 205, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 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], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 57, 75, 196, 0, 1, 0, 35], ["+", 75, 196, 0, 1, 0, 11, 31, 204, 205, 22], ["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 60], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 45], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 203], ["+", 0, 195, 8, 196, 0, 57, 64, 37, 0, 35], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 121], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 24], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 0, 57, 64, 196, 0, 57, 15, 16, 17, 47], ["+", 8, 196, 0, 37, 0, 41, 15, 16, 17, 18], ["-", 8, 196, 0, 57, 64, 196, 0, 57, 0, 25], ["-", 0, 57, 64, 196, 0, 57, 64, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 37, 0, 41, 0, 101], ["-", 0, 57, 64, 196, 0, 57, 64, 37, 0, 35], ["-", 0, 195, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 0, 195, 8, 196, 0, 37, 0, 41, 0, 102]]
8
773
44
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var dict = new Dictionary<string, int>(); for (var i = 0; i < N; i++) { var tmp = Console.ReadLine().ToCharArray(); Array.Sort(tmp); var s = string.Join("", tmp); if (dict.ContainsKey(s)) dict[s]++; else dict[s] = 1; } var total = 0L; foreach (var d in dict) { if (d.Value >= 2) { total += Enumerable.Range(1, d.Value - 1).Sum(); } } Console.WriteLine(total); } } }
using System; using System.Linq; using System.Collections.Generic; namespace Algorithm { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var dict = new Dictionary<string, int>(); for (var i = 0; i < N; i++) { var tmp = Console.ReadLine().ToCharArray(); Array.Sort(tmp); var s = string.Join("", tmp); if (dict.ContainsKey(s)) dict[s]++; else dict[s] = 1; } var total = 0L; foreach (var d in dict) { if (d.Value >= 2) { for (var i = 1; i <= d.Value - 1; i++) total += i; // total += Enumerable.Range(1, d.Value - 1).Sum(); } } Console.WriteLine(total); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["-", 64, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["-", 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], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 88], ["+", 64, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["+", 64, 196, 0, 7, 10, 198, 0, 200, 141, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 32], ["-", 12, 213, 63, 214, 205, 213, 3, 4, 0, 21], ["+", 8, 196, 0, 57, 64, 196, 0, 7, 0, 35], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 31, 22], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 19], ["-", 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, 57, 64, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 57, 64, 196, 0, 7, 26, 223, 0, 29], ["+", 64, 196, 0, 7, 8, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 1, 0, 11, 0, 202, 0, 107], ["+", 64, 196, 0, 7, 8, 1, 0, 11, 12, 22]]
8
183
23
using System; using System.Collections.Generic; using System.Linq; public class Contest { public static void Main() { /* int n = a[0]; int[][] e = new int[n][]; for(int i=0; i<n; i++) MyIO.ReadArray(out e[i]); int[] a; MyIO.ReadArray(out a); long a,b,c,d,e,f; MyIO.ReadMulti(out a, out b, out c, out d, out e, out f); MyIO.WriteArray(ans); */ int n; MyIO.ReadMulti(out n); string[] s = new string[n]; for (int i = 0; i < n; i++) { string id; MyIO.ReadMulti(out id); char[] sd = id.ToCharArray(); Array.Sort(sd); s[i] = new string(sd); } Array.Sort(s); int[] a = new int[n]; String bs = ""; int k = 0; for (int i = 0; i < n; i++) { if (bs == s[i]) { a[k]++; } else { k++; } bs = s[i]; } long ans = 0; for (int i = 0; i < n; i++) { ans += a[i] * (a[i] + 1) / 2; } Console.Write(ans); } } public static class MyIO { private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); a = System.Array.ConvertAll(ar, new Converter<string, T>(cv<T>)); return ar; } public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static void WriteArray<T>(T[] a) { Console.WriteLine(string.Join(" ", Array.ConvertAll(a, x => x.ToString()))); } }
using System; using System.Collections.Generic; using System.Linq; public class Contest { public static void Main() { /* int n = a[0]; int[][] e = new int[n][]; for(int i=0; i<n; i++) MyIO.ReadArray(out e[i]); int[] a; MyIO.ReadArray(out a); long a,b,c,d,e,f; MyIO.ReadMulti(out a, out b, out c, out d, out e, out f); MyIO.WriteArray(ans); */ int n; MyIO.ReadMulti(out n); string[] s = new string[n]; for (int i = 0; i < n; i++) { string id; MyIO.ReadMulti(out id); char[] sd = id.ToCharArray(); Array.Sort(sd); s[i] = new string(sd); } Array.Sort(s); int[] a = new int[n]; String bs = ""; int k = 0; for (int i = 0; i < n; i++) { if (bs == s[i]) { a[k]++; } else { k++; } bs = s[i]; } long ans = 0; for (int i = 0; i <= Math.Min(k, n - 1); i++) { long w = (long)a[i]; ans += w * (w + 1) / 2; } Console.Write(ans); } } public static class MyIO { private static bool eq<T, U>() => typeof(T).Equals(typeof(U)); private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); private static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); public static string[] ReadArray<T>(out T[] a) { var ar = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); a = System.Array.ConvertAll(ar, new Converter<string, T>(cv<T>)); return ar; } public static string[] ReadMulti<T>(out T a) { var ar = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); a = cv<T>(ar[0]); return ar; } public static string[] ReadMulti<T, U>(out T a, out U b) { var ar = ReadMulti<T>(out a); b = cv<U>(ar[1]); return ar; } public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) { var ar = ReadMulti<T, U>(out a, out b); c = cv<V>(ar[2]); return ar; } public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = ReadMulti<T, U, V>(out a, out b, out c); d = cv<W>(ar[3]); return ar; } public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); e = cv<X>(ar[4]); return ar; } public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); f = cv<Y>(ar[5]); return ar; } public static void WriteArray<T>(T[] a) { Console.WriteLine(string.Join(" ", Array.ConvertAll(a, x => x.ToString()))); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 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], ["+", 15, 16, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 21], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 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, 198, 0, 200, 0, 212, 0, 74, 0, 24], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 39, 199], ["+", 0, 198, 0, 200, 0, 212, 0, 74, 0, 25], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 31, 22], ["-", 31, 16, 12, 23, 0, 16, 31, 204, 205, 22], ["-", 12, 23, 0, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 23, 0, 16, 31, 204, 206, 207, 0, 73], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 31, 22]]
8
938
28
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class ABC137C { static public void Solve() { var N = NN; var sList = NSList(N); var sortedList = new string[N]; for (var i = 0; i < N; i++) { sortedList[i] = new string(sList[i].OrderBy(e => e).ToArray()); } var counter = new Dict<string, long>(); foreach (var item in sortedList) { counter[item]++; } var ans = 0L; foreach (var item in counter) { ans += Comb(item.Value, 2); } Console.WriteLine(ans); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static class Console_ { 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(_ => xorshift); [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; } } static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = 0; while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } [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); [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 _B(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) { _B(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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } class PQ<T> where T : IComparable { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; [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; } [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<TK, TV> where TK : IComparable { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((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(TK k, TV v) => q.Push(Tuple.Create(k, v)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UF(long s) { d = Repeat(-1L, s).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsSame(long x, long y) => Root(x) == Root(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Count(long x) => -d[Root(d[x])]; } struct Mod : IEquatable<object> { static public long _mod = 1000000007; 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) { var t = x._val + y._val; return t >= _mod ? new Mod { _val = t - _mod } : new Mod { _val = t }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) { var t = x._val - y._val; return t < 0 ? new Mod { _val = t + _mod } : new Mod { _val = t }; } [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 List<Mod> _fact = new List<Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void B(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) { B(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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } struct Mat<T> { 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; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; public int c; } Comparison<T> c; Node r; bool ch; T lm; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT(Comparison<T> _c) { c = _c; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT() : this((x, y) => x.CompareTo(y)) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] bool R(Node n) => n != null && !n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] bool B(Node n) => n != null && n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(T x) { r = A(r, x); r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x, c = 1 }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); n.c++; return Bl(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } n.c--; var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RmM(Node n) { n.c--; if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } public T this[long i] { get { return At(r, i); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] T At(Node n, long i) { if (n == null) return default(T); if (n.l == null) if (i == 0) return n.v; else return At(n.r, i - 1); if (n.l.c == i) return n.v; if (n.l.c > i) return At(n.l, i); return At(n.r, i - n.l.c - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(T x) { var t = FindUpper(x); return t.Item1 && t.Item2.CompareTo(x) == 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindUpper(T x, bool findSame = true) { var v = FU(r, x, findSame); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FU(Node n, T x, bool s) { if (n == null) return null; var r = c(x, n.v); if (r < 0) { var v = FU(n.l, x, s); return v == null ? Tuple.Create(true, n.v) : v; } if (r > 0 || !s && r == 0) return FU(n.r, x, s); return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindLower(T x, bool findSame = true) { var v = FL(r, x, findSame); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FL(Node n, T x, bool s) { if (n == null) return null; var r = c(x, n.v); if (r < 0 || !s && r == 0) return FL(n.l, x, s); if (r > 0) { var v = FL(n.r, x, s); return v == null ? Tuple.Create(true, n.v) : v; } return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => r != null; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() => r?.c ?? 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<T> List() => L(r); [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } class Dict<K, V> : Dictionary<K, V> { Func<K, V> d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dict(Func<K, V> _d) { d = _d; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dict() : this(_ => default(V)) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } } } class Deque<T> { T[] b; int o, c; public int Count; public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Deque(int cap = 16) { b = new T[c = cap]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; } public T Front => b[o]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; } public T Back => b[gi(Count - 1)]; [MethodImpl(MethodImplOptions.AggressiveInlining)] void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; } } class ImplicitTreep<T, E> where T : IEquatable<T> where E : IEquatable<E> { class Node { public E value; public T acc; public E lazy; public uint priority; public int cnt; public bool rev; public Node l; public Node r; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Node(E val, E ei, T ti) { priority = xorshift; value = val; acc = ti; lazy = ei; cnt = 1; rev = false; l = null; r = null; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node CreateNode(E val) => new Node(val, ei, ti); T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; Node root = null; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ImplicitTreep(T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { ti = _ti; ei = _ei; f = _f; g = _g; h = _h; } [MethodImpl(MethodImplOptions.AggressiveInlining)] int Count(Node n) => n?.cnt ?? 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] T Acc(Node n) => n == null ? ti : n.acc; [MethodImpl(MethodImplOptions.AggressiveInlining)] void UpdateCount(Node n) { if (n != null) n.cnt = 1 + Count(n.l) + Count(n.r); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void UpdateAcc(Node n) { if (n != null) n.acc = f(Acc(n.l), f(g(ti, n.value), Acc(n.r))); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Pushup(Node n) { UpdateCount(n); UpdateAcc(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Pushdown(Node n) { if (n?.rev ?? false) { n.rev = false; var t = n.l; n.l = n.r; n.r = t; if (n.l != null) n.l.rev ^= true; if (n.r != null) n.r.rev ^= true; } if (n != null && !n.lazy.Equals(ei)) { Action<Node> apply = t => { if (t == null) return; t.lazy = h(t.lazy, n.lazy); t.acc = g(t.acc, n.lazy); }; apply(n.l); apply(n.r); n.value = h(n.value, n.lazy); n.lazy = ei; } Pushup(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Split(Node n, long key, out Node l, out Node r) { if (n == null) { l = r = null; return; } Pushdown(n); var implicitKey = Count(n.l) + 1; if (key < implicitKey) { Split(n.l, key, out l, out n.l); r = n; } else { Split(n.r, key - implicitKey, out n.r, out r); l = n; } Pushup(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Insert(ref Node n, long key, Node x) { if (n == null) { n = x; return; } Pushdown(n); if (Count(n.l) == key || x.priority > n.priority) { Split(n, key, out x.l, out x.r); n = x; } else { if (Count(n.l) > key) { Insert(ref n.l, key, x); } else { Insert(ref n.r, key - Count(n.l) - 1, x); } } Pushup(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Merge(out Node n, Node l, Node r) { Pushdown(l); Pushdown(r); if (l == null || r == null) { n = l != null ? l : r; } else if (l.priority > r.priority) { Merge(out l.r, l.r, r); n = l; } else { Merge(out r.l, l, r.l); n = r; } Pushup(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Erase(ref Node n, long key) { Pushdown(n); if (Count(n.l) == key) { Merge(out n, n.l, n.r); } else { if (Count(n.l) > key) { Erase(ref n.l, key); } else { Erase(ref n.r, key - Count(n.l) - 1); } } Pushup(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Update(Node n, long l, long r, E x) { Node n1, n2, n3; Split(n, l, out n1, out n2); Split(n2, r - l, out n2, out n3); n2.lazy = h(n2.lazy, x); Merge(out n2, n2, n3); Merge(out n, n1, n2); } [MethodImpl(MethodImplOptions.AggressiveInlining)] T Query(Node n, long l, long r) { Node n1, n2, n3; Split(n, l, out n1, out n2); Split(n2, r - l, out n2, out n3); var ret = Acc(n2); Merge(out n2, n2, n3); Merge(out n, n1, n2); return ret; } [MethodImpl(MethodImplOptions.AggressiveInlining)] long Find(Node n, T x, long offset, bool left = true) { if (f(Acc(n), x).Equals(x)) { return -1; } else { if (left) { if (n.l != null && !f(n.l.acc, x).Equals(x)) { return Find(n.l, x, offset, left); } else { return (!f(g(ti, n.value), x).Equals(x)) ? offset + Count(n.l) : Find(n.r, x, offset + Count(n.l) + 1, left); } } else { if (n.r != null && !f(n.r.acc, x).Equals(x)) { return Find(n.r, x, offset + Count(n.l) + 1, left); } else { return (!f(g(ti, n.value), x).Equals(x)) ? offset + Count(n.l) : Find(n.l, x, offset, left); } } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Reverse(Node n, long l, long r) { if (l >= r) return; Node n1, n2, n3; Split(n, l, out n1, out n2); Split(n2, r - l, out n2, out n3); n2.rev ^= true; Merge(out n2, n2, n3); Merge(out n, n1, n2); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Rotate(Node n, long l, long m, long r) { Reverse(n, l, r); Reverse(n, l, l + r - m); Reverse(n, l + r - m, r); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Insert(long idx, E x) => Insert(ref root, idx, CreateNode(x)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(E x) => Insert(Count(), x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(long l, long r, E x) => Update(root, l, r, x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(long l, long r) => Query(root, l, r); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Find(long l, long r, T x, bool left = true) { Node n1, n2, n3; Split(root, l, out n1, out n2); Split(n2, r - l, out n2, out n3); var ret = Find(n2, x, l, left); Merge(out n2, n2, n3); Merge(out root, n1, n2); return ret < 0 ? r : ret; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Erase(long idx) => Erase(ref root, idx); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Reverse(long l, long r) => Reverse(root, l, r); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Rotate(long l, long m, long r) => Rotate(root, l, m, r); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() => Count(root); public E this[long idx] { get { Node n1, n2, n3; Split(root, idx + 1, out n1, out n2); Split(n1, idx, out n1, out n3); var ret = n3.value; Merge(out n1, n1, n3); Merge(out root, n1, n2); return ret; } private set {} } } class SegTree<T> { int n; T ti; Func<T, T, T> f; T[] dat; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegTree(long _n, T _ti, Func<T, T, T> _f) { n = 1; while (n < _n) n <<= 1; ti = _ti; f = _f; dat = Repeat(ti, n << 1).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(long i, T v) { dat[i += n] = v; while ((i >>= 1) > 0) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(long l, long r) { var vl = ti; var vr = ti; for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, dat[li++]); if ((ri & 1) == 1) vr = f(dat[--ri], vr); } return f(vl, vr); } public T this[long idx] { get { return dat[idx + n]; } set { Update(idx, value); } } } class LazySegTree<T, E> where T : IEquatable<T> where E : IEquatable<E> { int n, height; T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; T[] dat; E[] laz; [MethodImpl(MethodImplOptions.AggressiveInlining)] public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { n = 1; height = 0; while (n < _n) { n <<= 1; ++height; } ti = _ti; ei = _ei; f = _f; g = _g; h = _h; dat = Repeat(ti, n << 1).ToArray(); laz = Repeat(ei, n << 1).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) : this(l.Count, _ti, _ei, _f, _g, _h) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]); [MethodImpl(MethodImplOptions.AggressiveInlining)] void Eval(long i) { if (laz[i].Equals(ei)) return; laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]); laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]); dat[i] = Reflect(i); laz[i] = ei; } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Thrust(long i) { for (var j = height; j > 0; j--) Eval(i >> j); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Recalc(long i) { while ((i >>= 1) > 0) dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(long l, long r, E v) { Thrust(l += n); Thrust(r += n - 1); for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) { laz[li] = h(laz[li], v); ++li; } if ((ri & 1) == 1) { --ri; laz[ri] = h(laz[ri], v); } } Recalc(l); Recalc(r); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(long l, long r) { Thrust(l += n); Thrust(r += n - 1); var vl = ti; var vr = ti; for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, Reflect(li++)); if ((ri & 1) == 1) vr = f(Reflect(--ri), vr); } return f(vl, vr); } public T this[long idx] { get { Thrust(idx += n); return dat[idx] = Reflect(idx); } set { Thrust(idx += n); dat[idx] = value; laz[idx] = ei; Recalc(idx); } } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using static System.Math; using System.Text; using System.Threading; namespace Program { public static class ABC137C { static public void Solve() { var N = NN; var sList = NSList(N); var sortedList = new string[N]; for (var i = 0; i < N; i++) { sortedList[i] = new string(sList[i].OrderBy(e => e).ToArray()); } var counter = new Dict<string, long>(); foreach (var item in sortedList) { counter[item]++; } var ans = 0L; foreach (var item in counter) { ans += item.Value * (item.Value - 1) / 2; } Console.WriteLine(ans); } static public void Main(string[] args) { if (args.Length == 0) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); } static class Console_ { 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(_ => xorshift); [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; } } static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } } static IEnumerator<uint> _xsi = _xsc(); [MethodImpl(MethodImplOptions.AggressiveInlining)] static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = 0; while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } } [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); [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 _B(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) { _B(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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static long Perm(long n, long k) { _B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<TR> Lambda<TR>(Func<Func<TR>, TR> f) { Func<TR> t = () => default(TR); return t = () => f(t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, TR> Lambda<T1, TR>(Func<T1, Func<T1, TR>, TR> f) { Func<T1, TR> t = x1 => default(TR); return t = x1 => f(x1, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, TR> Lambda<T1, T2, TR>(Func<T1, T2, Func<T1, T2, TR>, TR> f) { Func<T1, T2, TR> t = (x1, x2) => default(TR); return t = (x1, x2) => f(x1, x2, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, TR> Lambda<T1, T2, T3, TR>(Func<T1, T2, T3, Func<T1, T2, T3, TR>, TR> f) { Func<T1, T2, T3, TR> t = (x1, x2, x3) => default(TR); return t = (x1, x2, x3) => f(x1, x2, x3, t); } [MethodImpl(MethodImplOptions.AggressiveInlining)] static Func<T1, T2, T3, T4, TR> Lambda<T1, T2, T3, T4, TR>( Func<T1, T2, T3, T4, Func<T1, T2, T3, T4, TR>, TR> f) { Func<T1, T2, T3, T4, TR> t = (x1, x2, x3, x4) => default(TR); return t = (x1, x2, x3, x4) => f(x1, x2, x3, x4, t); } class PQ<T> where T : IComparable { List<T> h; Comparison<T> c; public T Peek => h[0]; public int Count => h.Count; [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; } [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<TK, TV> where TK : IComparable { PQ<Tuple<TK, TV>> q; public Tuple<TK, TV> Peek => q.Peek; public int Count => q.Count; [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(int cap, Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>(cap, (x, y) => c(x.Item1, y.Item1), asc); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public PQ(Comparison<TK> c, bool asc = true) { q = new PQ<Tuple<TK, TV>>((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(TK k, TV v) => q.Push(Tuple.Create(k, v)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<TK, TV> Pop() => q.Pop(); } public class UF { long[] d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public UF(long s) { d = Repeat(-1L, s).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Unite(long x, long y) { x = Root(x); y = Root(y); if (x != y) { if (d[y] < d[x]) { var t = y; y = x; x = t; } d[x] += d[y]; d[y] = x; } return x != y; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool IsSame(long x, long y) => Root(x) == Root(y); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Root(long x) => d[x] < 0 ? x : d[x] = Root(d[x]); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Count(long x) => -d[Root(d[x])]; } struct Mod : IEquatable<object> { static public long _mod = 1000000007; 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) { var t = x._val + y._val; return t >= _mod ? new Mod { _val = t - _mod } : new Mod { _val = t }; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod operator -(Mod x, Mod y) { var t = x._val - y._val; return t < 0 ? new Mod { _val = t + _mod } : new Mod { _val = t }; } [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 List<Mod> _fact = new List<Mod>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] static void B(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) { B(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]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] static public Mod Perm(long n, long k) { B(n); if (n == 0 && k == 0) return 1; if (n < k || n < 0) return 0; return _fact[(int)n] / _fact[(int)(n - k)]; } } struct Mat<T> { 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; } } class Tree { long N; int l; List<long>[] p; int[] d; long[][] pr; long r; Tuple<long, long, int>[] e; Tuple<long, long>[] b; bool lca; bool euler; bool bfs; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tree(List<long>[] p_, long r_) { N = p_.Length; p = p_; r = r_; lca = false; euler = false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] BFSRoot() { if (!bfs) { var nb = new List<Tuple<long, long>>(); var q = new Queue<long>(); var d = new bool[N]; nb.Add(Tuple.Create(r, -1L)); d[r] = true; q.Enqueue(r); while (q.Count > 0) { var w = q.Dequeue(); foreach (var i in p[w]) { if (d[i]) continue; d[i] = true; q.Enqueue(i); nb.Add(Tuple.Create(i, w)); } } b = nb.ToArray(); bfs = true; } return b; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long>[] BFSLeaf() => BFSRoot().Reverse().ToArray(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<long, long, int>[] Euler() { if (!euler) { var ne = new List<Tuple<long, long, int>>(); var s = new Stack<Tuple<long, long>>(); var d = new bool[N]; d[r] = true; s.Push(Tuple.Create(r, -1L)); while (s.Count > 0) { var w = s.Peek(); var ad = true; foreach (var i in p[w.Item1]) { if (d[i]) continue; d[i] = true; ad = false; s.Push(Tuple.Create(i, w.Item1)); } if (!ad || p[w.Item1].Count == 1) ne.Add(Tuple.Create(w.Item1, w.Item2, 1)); if (ad) { s.Pop(); ne.Add(Tuple.Create(w.Item1, w.Item2, -1)); } } e = ne.ToArray(); euler = true; } return e; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public long LCA(long u, long v) { if (!lca) { l = 0; while (N > (1 << l)) l++; d = new int[N]; pr = Repeat(0, l).Select(_ => new long[N]).ToArray(); d[r] = 0; pr[0][r] = -1; var q = new Stack<long>(); q.Push(r); while (q.Count > 0) { var w = q.Pop(); foreach (var i in p[w]) { if (i == pr[0][w]) continue; q.Push(i); d[i] = d[w] + 1; pr[0][i] = w; } } for (var k = 0; k + 1 < l; k++) for (var w = 0; w < N; w++) if (pr[k][w] < 0) pr[k + 1][w] = -1; else pr[k + 1][w] = pr[k][pr[k][w]]; lca = true; } if (d[u] > d[v]) { var t = u; u = v; v = t; } for (var k = 0; k < l; k++) if ((((d[v] - d[u]) >> k) & 1) != 0) v = pr[k][v]; if (u == v) return u; for (var k = l - 1; k >= 0; k--) if (pr[k][u] != pr[k][v]) { u = pr[k][u]; v = pr[k][v]; } return pr[0][u]; } } class BT<T> where T : IComparable { class Node { public Node l; public Node r; public T v; public bool b; public int c; } Comparison<T> c; Node r; bool ch; T lm; [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT(Comparison<T> _c) { c = _c; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public BT() : this((x, y) => x.CompareTo(y)) {} [MethodImpl(MethodImplOptions.AggressiveInlining)] bool R(Node n) => n != null && !n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] bool B(Node n) => n != null && n.b; [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtL(Node n) { Node m = n.r, t = m.l; m.l = n; n.r = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtR(Node n) { Node m = n.l, t = m.r; m.r = n; n.l = t; n.c -= m.c - (t?.c ?? 0); m.c += n.c - (t?.c ?? 0); return m; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtLR(Node n) { n.l = RtL(n.l); return RtR(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RtRL(Node n) { n.r = RtR(n.r); return RtL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(T x) { r = A(r, x); r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node A(Node n, T x) { if (n == null) { ch = true; return new Node() { v = x, c = 1 }; } if (c(x, n.v) < 0) n.l = A(n.l, x); else n.r = A(n.r, x); n.c++; return Bl(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Bl(Node n) { if (!ch) return n; if (!B(n)) return n; if (R(n.l) && R(n.l.l)) { n = RtR(n); n.l.b = true; } else if (R(n.l) && R(n.l.r)) { n = RtLR(n); n.l.b = true; } else if (R(n.r) && R(n.r.l)) { n = RtRL(n); n.r.b = true; } else if (R(n.r) && R(n.r.r)) { n = RtL(n); n.r.b = true; } else ch = false; return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Remove(T x) { r = Rm(r, x); if (r != null) r.b = true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node Rm(Node n, T x) { if (n == null) { ch = false; return n; } n.c--; var r = c(x, n.v); if (r < 0) { n.l = Rm(n.l, x); return BlL(n); } if (r > 0) { n.r = Rm(n.r, x); return BlR(n); } if (n.l == null) { ch = n.b; return n.r; } n.l = RmM(n.l); n.v = lm; return BlL(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node RmM(Node n) { n.c--; if (n.r != null) { n.r = RmM(n.r); return BlR(n); } lm = n.v; ch = n.b; return n.l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlL(Node n) { if (!ch) return n; if (B(n.r) && R(n.r.l)) { var b = n.b; n = RtRL(n); n.b = b; n.l.b = true; ch = false; } else if (B(n.r) && R(n.r.r)) { var b = n.b; n = RtL(n); n.b = b; n.r.b = true; n.l.b = true; ch = false; } else if (B(n.r)) { ch = n.b; n.b = true; n.r.b = false; } else { n = RtL(n); n.b = true; n.l.b = false; n.l = BlL(n.l); ch = false; } return n; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node BlR(Node n) { if (!ch) return n; if (B(n.l) && R(n.l.r)) { var b = n.b; n = RtLR(n); n.b = b; n.r.b = true; ch = false; } else if (B(n.l) && R(n.l.l)) { var b = n.b; n = RtR(n); n.b = b; n.l.b = true; n.r.b = true; ch = false; } else if (B(n.l)) { ch = n.b; n.b = true; n.l.b = false; } else { n = RtR(n); n.b = true; n.r.b = false; n.r = BlR(n.r); ch = false; } return n; } public T this[long i] { get { return At(r, i); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] T At(Node n, long i) { if (n == null) return default(T); if (n.l == null) if (i == 0) return n.v; else return At(n.r, i - 1); if (n.l.c == i) return n.v; if (n.l.c > i) return At(n.l, i); return At(n.r, i - n.l.c - 1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Have(T x) { var t = FindUpper(x); return t.Item1 && t.Item2.CompareTo(x) == 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindUpper(T x, bool findSame = true) { var v = FU(r, x, findSame); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FU(Node n, T x, bool s) { if (n == null) return null; var r = c(x, n.v); if (r < 0) { var v = FU(n.l, x, s); return v == null ? Tuple.Create(true, n.v) : v; } if (r > 0 || !s && r == 0) return FU(n.r, x, s); return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Tuple<bool, T> FindLower(T x, bool findSame = true) { var v = FL(r, x, findSame); return v == null ? Tuple.Create(false, default(T)) : v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] Tuple<bool, T> FL(Node n, T x, bool s) { if (n == null) return null; var r = c(x, n.v); if (r < 0 || !s && r == 0) return FL(n.l, x, s); if (r > 0) { var v = FL(n.r, x, s); return v == null ? Tuple.Create(true, n.v) : v; } return Tuple.Create(true, n.v); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Min() { Node n = r, p = null; while (n != null) { p = n; n = n.l; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Max() { Node n = r, p = null; while (n != null) { p = n; n = n.r; } return p == null ? default(T) : p.v; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Any() => r != null; [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() => r?.c ?? 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] public IEnumerable<T> List() => L(r); [MethodImpl(MethodImplOptions.AggressiveInlining)] IEnumerable<T> L(Node n) { if (n == null) yield break; foreach (var i in L(n.l)) yield return i; yield return n.v; foreach (var i in L(n.r)) yield return i; } } class Dict<K, V> : Dictionary<K, V> { Func<K, V> d; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dict(Func<K, V> _d) { d = _d; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Dict() : this(_ => default(V)) {} new public V this[K i] { get { V v; return TryGetValue(i, out v) ? v : base[i] = d(i); } set { base[i] = value; } } } class Deque<T> { T[] b; int o, c; public int Count; public T this[int i] { get { return b[gi(i)]; } set { b[gi(i)] = value; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Deque(int cap = 16) { b = new T[c = cap]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] int gi(int i) { if (i >= c) throw new Exception(); var r = o + i; return r >= c ? r - c : r; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PushFront(T x) { if (Count == c) e(); if (--o < 0) o += b.Length; b[o] = x; ++Count; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T PopFront() { if (Count-- == 0) throw new Exception(); var r = b[o++]; if (o >= c) o -= c; return r; } public T Front => b[o]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public void PushBack(T x) { if (Count == c) e(); var i = o + Count++; b[i >= c ? i - c : i] = x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T PopBack() { if (Count == 0) throw new Exception(); return b[gi(--Count)]; } public T Back => b[gi(Count - 1)]; [MethodImpl(MethodImplOptions.AggressiveInlining)] void e() { T[] nb = new T[c << 1]; if (o > c - Count) { var l = b.Length - o; Array.Copy(b, o, nb, 0, l); Array.Copy(b, 0, nb, l, Count - l); } else Array.Copy(b, o, nb, 0, Count); b = nb; o = 0; c <<= 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Insert(int i, T x) { if (i > Count) throw new Exception(); this.PushFront(x); for (int j = 0; j < i; j++) this[j] = this[j + 1]; this[i] = x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T RemoveAt(int i) { if (i < 0 || i >= Count) throw new Exception(); var r = this[i]; for (int j = i; j > 0; j--) this[j] = this[j - 1]; this.PopFront(); return r; } } class ImplicitTreep<T, E> where T : IEquatable<T> where E : IEquatable<E> { class Node { public E value; public T acc; public E lazy; public uint priority; public int cnt; public bool rev; public Node l; public Node r; [MethodImpl(MethodImplOptions.AggressiveInlining)] public Node(E val, E ei, T ti) { priority = xorshift; value = val; acc = ti; lazy = ei; cnt = 1; rev = false; l = null; r = null; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] Node CreateNode(E val) => new Node(val, ei, ti); T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; Node root = null; [MethodImpl(MethodImplOptions.AggressiveInlining)] public ImplicitTreep(T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { ti = _ti; ei = _ei; f = _f; g = _g; h = _h; } [MethodImpl(MethodImplOptions.AggressiveInlining)] int Count(Node n) => n?.cnt ?? 0; [MethodImpl(MethodImplOptions.AggressiveInlining)] T Acc(Node n) => n == null ? ti : n.acc; [MethodImpl(MethodImplOptions.AggressiveInlining)] void UpdateCount(Node n) { if (n != null) n.cnt = 1 + Count(n.l) + Count(n.r); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void UpdateAcc(Node n) { if (n != null) n.acc = f(Acc(n.l), f(g(ti, n.value), Acc(n.r))); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Pushup(Node n) { UpdateCount(n); UpdateAcc(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Pushdown(Node n) { if (n?.rev ?? false) { n.rev = false; var t = n.l; n.l = n.r; n.r = t; if (n.l != null) n.l.rev ^= true; if (n.r != null) n.r.rev ^= true; } if (n != null && !n.lazy.Equals(ei)) { Action<Node> apply = t => { if (t == null) return; t.lazy = h(t.lazy, n.lazy); t.acc = g(t.acc, n.lazy); }; apply(n.l); apply(n.r); n.value = h(n.value, n.lazy); n.lazy = ei; } Pushup(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Split(Node n, long key, out Node l, out Node r) { if (n == null) { l = r = null; return; } Pushdown(n); var implicitKey = Count(n.l) + 1; if (key < implicitKey) { Split(n.l, key, out l, out n.l); r = n; } else { Split(n.r, key - implicitKey, out n.r, out r); l = n; } Pushup(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Insert(ref Node n, long key, Node x) { if (n == null) { n = x; return; } Pushdown(n); if (Count(n.l) == key || x.priority > n.priority) { Split(n, key, out x.l, out x.r); n = x; } else { if (Count(n.l) > key) { Insert(ref n.l, key, x); } else { Insert(ref n.r, key - Count(n.l) - 1, x); } } Pushup(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Merge(out Node n, Node l, Node r) { Pushdown(l); Pushdown(r); if (l == null || r == null) { n = l != null ? l : r; } else if (l.priority > r.priority) { Merge(out l.r, l.r, r); n = l; } else { Merge(out r.l, l, r.l); n = r; } Pushup(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Erase(ref Node n, long key) { Pushdown(n); if (Count(n.l) == key) { Merge(out n, n.l, n.r); } else { if (Count(n.l) > key) { Erase(ref n.l, key); } else { Erase(ref n.r, key - Count(n.l) - 1); } } Pushup(n); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Update(Node n, long l, long r, E x) { Node n1, n2, n3; Split(n, l, out n1, out n2); Split(n2, r - l, out n2, out n3); n2.lazy = h(n2.lazy, x); Merge(out n2, n2, n3); Merge(out n, n1, n2); } [MethodImpl(MethodImplOptions.AggressiveInlining)] T Query(Node n, long l, long r) { Node n1, n2, n3; Split(n, l, out n1, out n2); Split(n2, r - l, out n2, out n3); var ret = Acc(n2); Merge(out n2, n2, n3); Merge(out n, n1, n2); return ret; } [MethodImpl(MethodImplOptions.AggressiveInlining)] long Find(Node n, T x, long offset, bool left = true) { if (f(Acc(n), x).Equals(x)) { return -1; } else { if (left) { if (n.l != null && !f(n.l.acc, x).Equals(x)) { return Find(n.l, x, offset, left); } else { return (!f(g(ti, n.value), x).Equals(x)) ? offset + Count(n.l) : Find(n.r, x, offset + Count(n.l) + 1, left); } } else { if (n.r != null && !f(n.r.acc, x).Equals(x)) { return Find(n.r, x, offset + Count(n.l) + 1, left); } else { return (!f(g(ti, n.value), x).Equals(x)) ? offset + Count(n.l) : Find(n.l, x, offset, left); } } } } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Reverse(Node n, long l, long r) { if (l >= r) return; Node n1, n2, n3; Split(n, l, out n1, out n2); Split(n2, r - l, out n2, out n3); n2.rev ^= true; Merge(out n2, n2, n3); Merge(out n, n1, n2); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Rotate(Node n, long l, long m, long r) { Reverse(n, l, r); Reverse(n, l, l + r - m); Reverse(n, l + r - m, r); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Insert(long idx, E x) => Insert(ref root, idx, CreateNode(x)); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Add(E x) => Insert(Count(), x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(long l, long r, E x) => Update(root, l, r, x); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(long l, long r) => Query(root, l, r); [MethodImpl(MethodImplOptions.AggressiveInlining)] public long Find(long l, long r, T x, bool left = true) { Node n1, n2, n3; Split(root, l, out n1, out n2); Split(n2, r - l, out n2, out n3); var ret = Find(n2, x, l, left); Merge(out n2, n2, n3); Merge(out root, n1, n2); return ret < 0 ? r : ret; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Erase(long idx) => Erase(ref root, idx); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Reverse(long l, long r) => Reverse(root, l, r); [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Rotate(long l, long m, long r) => Rotate(root, l, m, r); [MethodImpl(MethodImplOptions.AggressiveInlining)] public int Count() => Count(root); public E this[long idx] { get { Node n1, n2, n3; Split(root, idx + 1, out n1, out n2); Split(n1, idx, out n1, out n3); var ret = n3.value; Merge(out n1, n1, n3); Merge(out root, n1, n2); return ret; } private set {} } } class SegTree<T> { int n; T ti; Func<T, T, T> f; T[] dat; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegTree(long _n, T _ti, Func<T, T, T> _f) { n = 1; while (n < _n) n <<= 1; ti = _ti; f = _f; dat = Repeat(ti, n << 1).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegTree(List<T> l, T _ti, Func<T, T, T> _f) : this(l.Count, _ti, _f) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(long i, T v) { dat[i += n] = v; while ((i >>= 1) > 0) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(long l, long r) { var vl = ti; var vr = ti; for (long li = n + l, ri = n + r; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, dat[li++]); if ((ri & 1) == 1) vr = f(dat[--ri], vr); } return f(vl, vr); } public T this[long idx] { get { return dat[idx + n]; } set { Update(idx, value); } } } class LazySegTree<T, E> where T : IEquatable<T> where E : IEquatable<E> { int n, height; T ti; E ei; Func<T, T, T> f; Func<T, E, T> g; Func<E, E, E> h; T[] dat; E[] laz; [MethodImpl(MethodImplOptions.AggressiveInlining)] public LazySegTree(long _n, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) { n = 1; height = 0; while (n < _n) { n <<= 1; ++height; } ti = _ti; ei = _ei; f = _f; g = _g; h = _h; dat = Repeat(ti, n << 1).ToArray(); laz = Repeat(ei, n << 1).ToArray(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public LazySegTree(List<T> l, T _ti, E _ei, Func<T, T, T> _f, Func<T, E, T> _g, Func<E, E, E> _h) : this(l.Count, _ti, _ei, _f, _g, _h) { for (var i = 0; i < l.Count; i++) dat[n + i] = l[i]; for (var i = n - 1; i > 0; i--) dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] T Reflect(long i) => laz[i].Equals(ei) ? dat[i] : g(dat[i], laz[i]); [MethodImpl(MethodImplOptions.AggressiveInlining)] void Eval(long i) { if (laz[i].Equals(ei)) return; laz[(i << 1) | 0] = h(laz[(i << 1) | 0], laz[i]); laz[(i << 1) | 1] = h(laz[(i << 1) | 1], laz[i]); dat[i] = Reflect(i); laz[i] = ei; } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Thrust(long i) { for (var j = height; j > 0; j--) Eval(i >> j); } [MethodImpl(MethodImplOptions.AggressiveInlining)] void Recalc(long i) { while ((i >>= 1) > 0) dat[i] = f(Reflect((i << 1) | 0), Reflect((i << 1) | 1)); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(long l, long r, E v) { Thrust(l += n); Thrust(r += n - 1); for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) { laz[li] = h(laz[li], v); ++li; } if ((ri & 1) == 1) { --ri; laz[ri] = h(laz[ri], v); } } Recalc(l); Recalc(r); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(long l, long r) { Thrust(l += n); Thrust(r += n - 1); var vl = ti; var vr = ti; for (long li = l, ri = r + 1; li < ri; li >>= 1, ri >>= 1) { if ((li & 1) == 1) vl = f(vl, Reflect(li++)); if ((ri & 1) == 1) vr = f(Reflect(--ri), vr); } return f(vl, vr); } public T this[long idx] { get { Thrust(idx += n); return dat[idx] = Reflect(idx); } set { Thrust(idx += n); dat[idx] = value; laz[idx] = ei; Recalc(idx); } } } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 213, 63, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 205, 22], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 0, 131], ["+", 0, 11, 12, 16, 31, 16, 31, 214, 141, 22], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 213, 3, 4, 0, 21], ["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
12,015
11
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC137D { class Program { static void Main(string[] args) { var N = RInt; var M = RInt; jobs = new List<int> [M].Select(x => new List<int>()).ToArray(); for (int i = 0; i < N; i++) { int day = M - RInt; if (day >= 0) jobs[day].Add(RInt); } PriorityQueue<long> que = new PriorityQueue<long>(1); long ans = Solve(M - 1, que); Console.WriteLine(ans); } static List<int>[] jobs; static long Solve(int day, PriorityQueue<long> que) { if (day < 0) return 0; foreach (var j in jobs[day]) { que.Push(j); } long ret = que.Count() != 0 ? que.Pop() : 0; return ret + Solve(day - 1, que); } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(IComparer<T> comparer) { _heap = new T[128]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int type = 0) { _heap = new T[128]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; if (_count > _heap.Length) { var newheap = new T[_heap.Length * 2]; for (int n = 0; n < _heap.Length; n++) newheap[n] = _heap[n]; _heap = newheap; } // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } } 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(); } 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; using System.Collections; namespace ABC137D { class Program { static void Main(string[] args) { var N = RInt; var M = RInt; jobs = new List<int> [M].Select(x => new List<int>()).ToArray(); for (int i = 0; i < N; i++) { int day = M - RInt; int b = RInt; if (day >= 0) jobs[day].Add(b); } PriorityQueue<long> que = new PriorityQueue<long>(1); long ans = Solve(M - 1, que); Console.WriteLine(ans); } static List<int>[] jobs; static long Solve(int day, PriorityQueue<long> que) { if (day < 0) return 0; foreach (var j in jobs[day]) { que.Push(j); } return (que.Count() != 0 ? que.Pop() : 0) + Solve(day - 1, que); } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private int _type = 0; private T[] _heap; private int _sz = 0; private int _count = 0; /// <summary> /// Priority Queue with custom comparer /// </summary> public PriorityQueue(IComparer<T> comparer) { _heap = new T[128]; _comparer = comparer; } /// <summary> /// Priority queue /// </summary> /// <param name="type">0: asc, 1:desc</param> public PriorityQueue(int type = 0) { _heap = new T[128]; _type = type; } private int Compare(T x, T y) { if (_comparer != null) return _comparer.Compare(x, y); return _type == 0 ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { _count++; if (_count > _heap.Length) { var newheap = new T[_heap.Length * 2]; for (int n = 0; n < _heap.Length; n++) newheap[n] = _heap[n]; _heap = newheap; } // node number var i = _sz++; while (i > 0) { // parent node number var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) break; _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { _count--; T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { // children int a = i * 2 + 1; int b = i * 2 + 2; if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b; if (Compare(_heap[a], x) >= 0) break; _heap[i] = _heap[a]; i = a; } _heap[i] = x; return ret; } public int Count() { return _count; } public T Peek() { return _heap[0]; } public bool Contains(T x) { for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true; return false; } public void Clear() { while (this.Count() > 0) this.Pop(); } public IEnumerator<T> GetEnumerator() { var ret = new List<T>(); while (this.Count() > 0) { ret.Add(this.Pop()); } foreach (var r in ret) { this.Push(r); yield return r; } } public T[] ToArray() { T[] array = new T[_sz]; int i = 0; foreach (var r in this) { array[i++] = r; } return array; } } } 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(); } 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 } } }
[["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 233], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 234, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 0, 131], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 36, 36, 0, 208, 0, 231, 0, 35], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 22], ["+", 8, 196, 0, 7, 8, 196, 0, 197, 0, 35], ["+", 0, 7, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 64, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 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], ["+", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 37, 0, 16, 31, 23, 0, 24], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 8, 201, 0, 195, 8, 196, 0, 37, 0, 38], ["-", 0, 195, 8, 196, 0, 37, 0, 16, 31, 22], ["+", 8, 196, 0, 37, 0, 16, 31, 23, 0, 25]]
8
1,450
21