buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = GetInputInt(); int[] input = GetInputsInt(); if (input[0] != 1) input[0]--; for (int i = 1; i < N; i++) { if (input[i - 1] < input[i]) { input[i] -= 1; } else if (input[i - 1] > input[i]) { Console.WriteLine("NO"); return; } } Console.WriteLine("YES"); } public static int GetInputInt() { return int.Parse(Console.ReadLine()); } public static int[] GetInputsInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static List<int> GetInputsIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } public static long GetInputLong() { return long.Parse(Console.ReadLine()); } public static long[] GetInputsLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int N = GetInputInt(); int[] input = GetInputsInt(); if (input[0] != 1) input[0]--; for (int i = 1; i < N; i++) { if (input[i - 1] < input[i]) { input[i] -= 1; } else if (input[i - 1] > input[i]) { Console.WriteLine("No"); return; } } Console.WriteLine("Yes"); } public static int GetInputInt() { return int.Parse(Console.ReadLine()); } public static int[] GetInputsInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static List<int> GetInputsIntList() { return Console.ReadLine().Split(' ').Select(int.Parse).ToList(); } public static long GetInputLong() { return long.Parse(Console.ReadLine()); } public static long[] GetInputsLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
295
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp14 { class Class23 { static void Main() { string S = Console.ReadLine(); int[] ans = new int[S.Length]; for (int i = 0; i < S.Length; i++) ans[i] = 0; for (int i = 0; i < S.Length;) { int R = 0; int L = 0; int check = S.Length - 1; for (; i < S.Length; i++) { if (S[i] == 'R') R++; else break; } check = i; for (; i < S.Length; i++) { if (S[i] == 'L') L++; else break; } if (check == 0 | check == S.Length - 1) ans[check] = L + R; else { ans[check - 1] = R / 2 + L / 2 + R % 2; ans[check] = L / 2 + R / 2 + L % 2; } } Console.WriteLine(string.Join(" ", ans)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp14 { class Class23 { static void Main() { string S = Console.ReadLine(); int[] ans = new int[S.Length]; for (int i = 0; i < S.Length; i++) ans[i] = 0; for (int i = 0; i < S.Length;) { int R = 0; int L = 0; int check = S.Length - 1; for (; i < S.Length; i++) { if (S[i] == 'R') R++; else break; } check = i; for (; i < S.Length; i++) { if (S[i] == 'L') L++; else break; } if (check == 0 | check == S.Length - 1 && R == 0) ans[check] = L + R; else { ans[check - 1] = R / 2 + L / 2 + R % 2; ans[check] = L / 2 + R / 2 + L % 2; } } Console.WriteLine(string.Join(" ", ans)); } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
266
4
using System; class c { static void Main() { var s = Console.ReadLine(); int n = s.Length; var ans = new int[n]; int cnt = 0; for (int i = 0; i < n; i++) { if (s[i] == 'R') cnt++; else { ans[i - 1] = cnt; cnt = 0; } } for (int i = n - 1; i > 0; i--) { if (s[i] == 'L') cnt++; else if (ans[i + 1] == 0) { ans[i + 1] = cnt; cnt = 0; } } for (int i = 0; i < n; i++) { if (ans[i] != 0) { int sum = ans[i] + ans[i + 1]; if (sum % 2 == 0) { ans[i] = sum / 2; ans[i + 1] = sum / 2; } else { ans[i] = sum / 2 + ans[i] % 2; ans[i + 1] = sum / 2 + ans[i + 1] % 2; } i++; } } foreach (var x in ans) Console.Write("{0} ", x); } }
using System; class c { static void Main() { var s = Console.ReadLine(); int n = s.Length; var ans = new int[n]; int cnt = 0; for (int i = 0; i < n; i++) { if (s[i] == 'R') cnt++; else { ans[i - 1] = cnt; cnt = 0; } } for (int i = n - 1; i >= 0; i--) { if (s[i] == 'L') cnt++; else if (ans[i + 1] == 0) { ans[i + 1] = cnt; cnt = 0; } } for (int i = 0; i < n; i++) { if (ans[i] != 0) { int sum = ans[i] + ans[i + 1]; if (sum % 2 == 0) { ans[i] = sum / 2; ans[i + 1] = sum / 2; } else { ans[i] = sum / 2 + ans[i] % 2; ans[i + 1] = sum / 2 + ans[i + 1] % 2; } i++; } } foreach (var x in ans) Console.Write("{0} ", x); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 20]]
8
281
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long bmod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { var S = GetStr(); var A = Enumerable.Repeat(0, S.Length).ToArray(); var cnt = 0; for (int i = 0; i < S.Length - 1; i++) { if (S[i] == 'R') { cnt++; } else { A[i - 1] += (cnt + 1) / 2; A[i] += cnt / 2; cnt = 0; } } for (int i = S.Length - 1; 0 < i; i--) { if (S[i] == 'L') { cnt++; } else { A[i + 1] += (cnt + 1) / 2; A[i] += cnt / 2; cnt = 0; } } WriteObjects(A); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long bmod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { var S = GetStr(); var A = Enumerable.Repeat(0, S.Length).ToArray(); var cnt = 0; for (int i = 0; i < S.Length; i++) { if (S[i] == 'R') { cnt++; } else { A[i - 1] += (cnt + 1) / 2; A[i] += cnt / 2; cnt = 0; } } for (int i = S.Length - 1; 0 <= i; i--) { if (S[i] == 'L') { cnt++; } else { A[i + 1] += (cnt + 1) / 2; A[i] += cnt / 2; cnt = 0; } } WriteObjects(A); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
1,619
4
using System; class ProgramD { static void Main(string[] args) { string input = Console.ReadLine(); int frag_L = 0; int count_R = 0; int count_L = 0; for (int i = 0; i < input.Length; i++) { string s1 = input.Substring(i, 1); if (s1 == "R") { if (frag_L == 1) { int count = count_R + count_L; if (count % 2 == 0) { for (int j = 0; j < count; j++) { if (j == count_R - 1 || j == count_R) Console.Write(count / 2); else Console.Write("0"); Console.Write(" "); } } else { int judge = 0; if (count_L > count_R) { judge = count_L % 2; } else { judge = count_R % 2 + 1; } if (judge == 0) { for (int j = 0; j < count; j++) { if (j == count_R - 1) Console.Write(count / 2 + 1); else if (j == count_R) Console.Write(count / 2); else Console.Write("0"); Console.Write(" "); } } else { for (int j = 0; j < count; j++) { if (j == count_R - 1) Console.Write(count / 2); else if (j == count_R) Console.Write(count / 2 + 1); else Console.Write("0"); Console.Write(" "); } } } frag_L = 0; count_L = 0; count_R = 0; } count_R++; } else { frag_L = 1; count_L++; if (i == input.Length - 1) { int count = count_R + count_L; if (count % 2 == 0) { for (int j = 0; j < count; j++) { if (j == count_R - 1 || j == count_R) Console.Write(count / 2); else Console.Write("0"); Console.Write(" "); } } else { int judge = 0; if (count_L > count_R) { judge = count_L % 2; } else { judge = (count_R % 2 + 1) % 2; } if (judge == 0) { for (int j = 0; j < count; j++) { if (j == count_R - 1) Console.Write(count / 2 + 1); else if (j == count_R) Console.Write(count / 2); else Console.Write("0"); Console.Write(" "); } } else { for (int j = 0; j < count; j++) { if (j == count_R - 1) Console.Write(count / 2); else if (j == count_R) Console.Write(count / 2 + 1); else Console.Write("0"); Console.Write(" "); } } } frag_L = 0; count_L = 0; count_R = 0; } } } } }
using System; class ProgramD { static void Main(string[] args) { string input = Console.ReadLine(); int frag_L = 0; int count_R = 0; int count_L = 0; for (int i = 0; i < input.Length; i++) { string s1 = input.Substring(i, 1); if (s1 == "R") { if (frag_L == 1) { int count = count_R + count_L; if (count % 2 == 0) { for (int j = 0; j < count; j++) { if (j == count_R - 1 || j == count_R) Console.Write(count / 2); else Console.Write("0"); Console.Write(" "); } } else { int judge = 0; if (count_L > count_R) { judge = count_L % 2; } else { judge = (count_R % 2 + 1) % 2; } if (judge == 0) { for (int j = 0; j < count; j++) { if (j == count_R - 1) Console.Write(count / 2 + 1); else if (j == count_R) Console.Write(count / 2); else Console.Write("0"); Console.Write(" "); } } else { for (int j = 0; j < count; j++) { if (j == count_R - 1) Console.Write(count / 2); else if (j == count_R) Console.Write(count / 2 + 1); else Console.Write("0"); Console.Write(" "); } } } frag_L = 0; count_L = 0; count_R = 0; } count_R++; } else { frag_L = 1; count_L++; if (i == input.Length - 1) { int count = count_R + count_L; if (count % 2 == 0) { for (int j = 0; j < count; j++) { if (j == count_R - 1 || j == count_R) Console.Write(count / 2); else Console.Write("0"); Console.Write(" "); } } else { int judge = 0; if (count_L > count_R) { judge = count_L % 2; } else { judge = (count_R % 2 + 1) % 2; } if (judge == 0) { for (int j = 0; j < count; j++) { if (j == count_R - 1) Console.Write(count / 2 + 1); else if (j == count_R) Console.Write(count / 2); else Console.Write("0"); Console.Write(" "); } } else { for (int j = 0; j < count; j++) { if (j == count_R - 1) Console.Write(count / 2); else if (j == count_R) Console.Write(count / 2 + 1); else Console.Write("0"); Console.Write(" "); } } } frag_L = 0; count_L = 0; count_R = 0; } } } } }
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
657
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; using static System.Console; namespace AtCoder_1 { class Program { static void Main(string[] args) { var N = CinT(); long[] f = CinLAr(); int c = 0; int max = 0; for (int i = 0; i < N - 1; i++) { if (f[i] >= f[i + 1]) { c++; max = Math.Max(max, c); } else { max = Math.Max(max, c); c = 0; } } Cout(c); Cin(); } static int GCD(int a, int b) { if (a < b) { swap(ref a, ref b); } if (a % b == 0) { return b; } else { return GCD(b, a % b); } } static void swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static readonly int MOD10E9 = (1000000000 + 7); static bool isInt(double d) { return (int)d == d; } static string Cin() { return ReadLine(); } static string[] CinAr() { return ReadLine().Split(' '); } static int CinT() { return S2i(Cin()); } static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); } static long CinL() { return S2L(Cin()); } static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); } static double CinD() { return S2D(Cin()); } static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); } static int S2i(string s) { return int.Parse(s); } static long S2L(string s) { return long.Parse(s); } static double S2D(string s) { return double.Parse(s); } static void Cout(object s) { WriteLine(s); } static int[] yakusuu(int n) { if (n == 1) { return new int[] { 1 }; } HashSet<int> res = new HashSet<int>(); for (int i = 1; i < Math.Ceiling(n / 2.0); i++) { if (n % i == 0) { res.Add(i); res.Add(n / i); } } return res.ToArray(); } static void CoutAr<Type>(IEnumerable<Type> types) { string text = string.Join(" ", types); WriteLine(text); } public static long nCr(int n, int r) { // naive: return Factorial(n) / (Factorial(r) * Factorial(n - r)); return nPr(n, r) / Factorial(r); } public static long nPr(int n, int r) { // naive: return Factorial(n) / Factorial(n - r); return FactorialDivision(n, n - r); } private static long FactorialDivision(int topFactorial, int divisorFactorial) { long result = 1; for (int i = topFactorial; i > divisorFactorial; i--) result *= i; return result; } private static long Factorial(int i) { if (i <= 1) return 1; return i * Factorial(i - 1); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; using static System.Console; namespace AtCoder_1 { class Program { static void Main(string[] args) { var N = CinT(); long[] f = CinLAr(); int c = 0; int max = 0; for (int i = 0; i < N - 1; i++) { if (f[i] >= f[i + 1]) { c++; max = Math.Max(max, c); } else { max = Math.Max(max, c); c = 0; } } Cout(max); Cin(); } static int GCD(int a, int b) { if (a < b) { swap(ref a, ref b); } if (a % b == 0) { return b; } else { return GCD(b, a % b); } } static void swap<T>(ref T a, ref T b) { T t = a; a = b; b = t; } static readonly int MOD10E9 = (1000000000 + 7); static bool isInt(double d) { return (int)d == d; } static string Cin() { return ReadLine(); } static string[] CinAr() { return ReadLine().Split(' '); } static int CinT() { return S2i(Cin()); } static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); } static long CinL() { return S2L(Cin()); } static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); } static double CinD() { return S2D(Cin()); } static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); } static int S2i(string s) { return int.Parse(s); } static long S2L(string s) { return long.Parse(s); } static double S2D(string s) { return double.Parse(s); } static void Cout(object s) { WriteLine(s); } static int[] yakusuu(int n) { if (n == 1) { return new int[] { 1 }; } HashSet<int> res = new HashSet<int>(); for (int i = 1; i < Math.Ceiling(n / 2.0); i++) { if (n % i == 0) { res.Add(i); res.Add(n / i); } } return res.ToArray(); } static void CoutAr<Type>(IEnumerable<Type> types) { string text = string.Join(" ", types); WriteLine(text); } public static long nCr(int n, int r) { // naive: return Factorial(n) / (Factorial(r) * Factorial(n - r)); return nPr(n, r) / Factorial(r); } public static long nPr(int n, int r) { // naive: return Factorial(n) / Factorial(n - r); return FactorialDivision(n, n - r); } private static long FactorialDivision(int topFactorial, int divisorFactorial) { long result = 1; for (int i = topFactorial; i > divisorFactorial; i--) result *= i; return result; } private static long Factorial(int i) { if (i <= 1) return 1; return i * Factorial(i - 1); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
775
2
using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Xml; class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long ans = ((N - 1) * (N - 2)) / 2; Console.WriteLine(ans); } } // string s = Console.ReadLine(); // int[] intArray = Console.ReadLine().Split(' ').Select(i => // int.Parse(i)).ToArray(); int H = intArray[0]; int W = intArray[1]; int N = // int.Parse(Console.ReadLine()); List<int> A = new // List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray()); // Boolean ok = false; // Console.WriteLine(ans); // Console.WriteLine("Yes"); // Console.WriteLine("No"); // Console.ReadKey(); // string[] strArray = Console.ReadLine().Split(' ').ToArray(); // string S = strArray[0]; // string T = strArray[1];
using System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Xml; class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long ans = ((N - 1) * N) / 2; Console.WriteLine(ans); } } // string s = Console.ReadLine(); // int[] intArray = Console.ReadLine().Split(' ').Select(i => // int.Parse(i)).ToArray(); int H = intArray[0]; int W = intArray[1]; int N = // int.Parse(Console.ReadLine()); List<int> A = new // List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray()); // Boolean ok = false; // Console.WriteLine(ans); // Console.WriteLine("Yes"); // Console.WriteLine("No"); // Console.ReadKey(); // string[] strArray = Console.ReadLine().Split(' ').ToArray(); // string S = strArray[0]; // string T = strArray[1];
[["-", 0, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["-", 31, 23, 0, 16, 12, 23, 0, 16, 17, 33], ["-", 31, 23, 0, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
8
102
4
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { static void Main(string[] args) { var n = Read().Int(); var ans = (1 + n) * n / 2 - n; WriteRead(ans); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { static void Main(string[] args) { var n = Read().Long(); var ans = (1 + n) * n / 2 - n; WriteRead(ans); } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
400
2
using System; using System.Collections.Generic; using System.Linq; class Test { public static void Main() { var n = int.Parse(Console.ReadLine()); long sum = 0; if (n == 1) { sum = 0; } else if (n == 2) { sum = 1; } else sum = (n - 1) * (n) / 2; Console.Write(sum); } }
using System; using System.Collections.Generic; using System.Linq; class Test { public static void Main() { var n = long.Parse(Console.ReadLine()); long sum = 0; if (n == 1) { sum = 0; } else if (n == 2) { sum = 1; } else sum = (n - 1) * (n) / 2; Console.Write(sum); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
93
2
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace atcoder { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); Console.WriteLine((n - 1) * n / 2); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Numerics; namespace atcoder { class Program { static void Main(string[] args) { var n = long.Parse(Console.ReadLine()); Console.WriteLine((n - 1) * n / 2); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
68
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.D { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var N = ReadLong(); if (N == 1) return 0; if (N == 2) return 1; return (N - 1) * N / 2 - 1 + N % 2; } #region Console public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.D { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var N = ReadLong(); if (N == 1) return 0; if (N == 2) return 1; return (N - 1) * N / 2 - 1 + 1; } #region Console public static string ReadText() { return Console.ReadLine(); } public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }
[["-", 8, 196, 0, 37, 0, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 37, 0, 16, 12, 16, 17, 109], ["-", 8, 196, 0, 37, 0, 16, 12, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 37, 0, 16, 12, 203]]
8
220
4
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramB { static void Main() { int n = NextInt; System.Console.WriteLine(n * (n - 1) / 2); } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } } namespace Library { class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } public static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, mod - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % mod)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } } } namespace Library { class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } public static long Nck(int n, int k) { if (k == 0) return 1; if (n == 0) return 0; return n * Nck(n - 1, k - 1) / k; } } } namespace Library { public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } } namespace Library { public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using Library; using static Library.Input; namespace AtCoderTemplate { class ProgramB { static void Main() { long n = NextInt; System.Console.WriteLine(n * (n - 1) / 2); } } } namespace Library { class Input { static IEnumerator<string> enumerator = new string[] {}.AsEnumerable().GetEnumerator(); public static string Line => Console.ReadLine(); public static string[] StrArr => Line.Split(' '); public static int NextInt => int.Parse(NextWord()); public static long NextLong => long.Parse(NextWord()); public static List<int> IntList => StrArr.Select(int.Parse).ToList(); public static List<long> LongList => StrArr.Select(long.Parse).ToList(); public static IEnumerable<long[]> TakeLine(int N) { return Enumerable.Repeat(0, N).Select( _ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray()); } public static string NextWord() { while (!enumerator.MoveNext()) { enumerator = StrArr.AsEnumerable().GetEnumerator(); } return enumerator.Current; } } } namespace Library { class Modular { public const int mod = 1000000007; public readonly long value; public Modular(long value) { this.value = value; } public static implicit operator Modular(long a) { var m = a % mod; return new Modular((m < 0) ? m + mod : m); } public static Modular operator +(Modular a, Modular b) { return a.value + b.value; } public static Modular operator -(Modular a, Modular b) { return a.value - b.value; } public static Modular operator *(Modular a, Modular b) { return a.value * b.value; } public static Modular Pow(Modular a, int n) { switch (n) { case 0: return 1; case 1: return a; default: var p = Pow(a, n / 2); return p * p * Pow(a, n % 2); } } public static Modular operator /(Modular a, Modular b) { return a * Pow(b, mod - 2); } private static readonly List<int> facs = new List<int> { 1 }; private static Modular Fac(int n) { for (int i = facs.Count; i <= n; ++i) { facs.Add((int)(Math.BigMul(facs.Last(), i) % mod)); } return facs[n]; } public static Modular Ncr(int n, int r) { return (n < r) ? 0 : (n == r) ? 1 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(Modular a) { return (int)a.value; } } } namespace Library { class MyMath { public static long Gcd(long a, long b) { return b == 0 ? a : Gcd(b, a % b); } public static long Sqrt(long n) { if (n < 0) return 0; long a = 0, tmp = 0, b = 0; for (int i = 62; i >= 0; i -= 2) { tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0; a = a << 1 | tmp; n -= (((b << 1) + 1) * tmp) << i; b = (b << 1) + tmp + tmp; } return a; } public static long Nck(int n, int k) { if (k == 0) return 1; if (n == 0) return 0; return n * Nck(n - 1, k - 1) / k; } } } namespace Library { public class PriorityQueue<T> { readonly List<T> _heap = new List<T>(); readonly Comparison<T> _comparison; public PriorityQueue(Comparison<T> comparison) { _comparison = comparison; } public PriorityQueue() : this(Comparer<T>.Default.Compare) {} public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare) {} public void Enqueue(T item) { _heap.Add(item); int childID = _heap.Count - 1; int parentID = (childID - 1) / 2; while (childID > 0 && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); childID = parentID; parentID = (parentID - 1) / 2; } } public T Dequeue() { var first = _heap.First(); _heap[0] = _heap.Last(); _heap.RemoveAt(_heap.Count - 1); int parentID = 0; int childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; while (childID < _heap.Count && _comparison(_heap[parentID], _heap[childID]) > 0) { Swap(parentID, childID); parentID = childID; childID = parentID * 2 + 2; if (childID >= _heap.Count || _comparison(_heap[childID], _heap[childID - 1]) > 0) childID--; } return first; } void Swap(int parent, int child) { var tmp = _heap[parent]; _heap[parent] = _heap[child]; _heap[child] = tmp; } public T Peek() { return _heap[0]; } public int Count => _heap.Count; public bool Any() { return _heap.Any(); } public List<T> Data => _heap; } } namespace Library { public class UnionFind { public int[] Parents { get; set; } public UnionFind(int size) { Parents = Enumerable.Repeat(-1, size).ToArray(); } public int Find(int num) { if (Parents[num] < 0) return num; Parents[num] = Find(Parents[num]); return Parents[num]; } public int Size(int num) { return -Parents[Find(num)]; } public bool Same(int a, int b) { return Find(a) == Find(b); } public void Unite(int a, int b) { int x = Find(a), y = Find(b); if (Size(x) > Size(y)) { Parents[x] += Parents[y]; Parents[y] = x; } else { Parents[y] += Parents[x]; Parents[x] = y; } } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
1,451
2
using System; class c { static void Main() { int n = int.Parse(Console.ReadLine()); Console.WriteLine(n * (n - 1) / 2); } }
using System; class c { static void Main() { var n = long.Parse(Console.ReadLine()); Console.WriteLine(n * (n - 1) / 2); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
43
4
using AtCoderBeginnerContest139.Questions; using AtCoderBeginnerContest139.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace AtCoderBeginnerContest139.Questions { public class QuestionD : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { var n = inputStream.ReadInt(); yield return n * (n - 1) / 2; } } } namespace AtCoderBeginnerContest139 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace AtCoderBeginnerContest139.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace AtCoderBeginnerContest139.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
using AtCoderBeginnerContest139.Questions; using AtCoderBeginnerContest139.Extensions; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace AtCoderBeginnerContest139.Questions { public class QuestionD : AtCoderQuestionBase { public override IEnumerable<object> Solve(TextReader inputStream) { long n = inputStream.ReadLong(); yield return n * (n - 1) / 2; } } } namespace AtCoderBeginnerContest139 { class Program { static void Main(string[] args) { IAtCoderQuestion question = new QuestionD(); // 問題に合わせて書き換え var answers = question.Solve(Console.In); foreach (var answer in answers) { Console.WriteLine(answer); } } } } #region Base Classes namespace AtCoderBeginnerContest139.Questions { public interface IAtCoderQuestion { IEnumerable<object> Solve(string input); IEnumerable<object> Solve(TextReader inputStream); } public abstract class AtCoderQuestionBase : IAtCoderQuestion { public IEnumerable<object> Solve(string input) { var stream = new MemoryStream(Encoding.Unicode.GetBytes(input)); var reader = new StreamReader(stream, Encoding.Unicode); return Solve(reader); } public abstract IEnumerable<object> Solve(TextReader inputStream); } } #endregion #region Extensions namespace AtCoderBeginnerContest139.Extensions { internal static class TextReaderExtensions { internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader)); internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader)); internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader)); internal static string ReadString(this TextReader reader) => reader.ReadLine(); internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray(); internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray(); internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray(); internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator); } } #endregion
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
475
4
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace D { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var n = int.Parse(Console.ReadLine()); // (n - 1) % n, n % 1 Console.WriteLine((n - 1) * n / 2); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace D { public class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } public static void Solve() { var n = long.Parse(Console.ReadLine()); // (n - 1) % n, n % 1 Console.WriteLine((n - 1) * n / 2); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
120
2
using System; namespace _139d { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); Console.WriteLine((1 + N - 1) * (N - 1) / 2); // long M_total = 0; // // float[] N_array = new float[N]; // for(int i = 0; i < N;i++){ // // N_array[i] = i+1; // if(i != N-1){ // M_total += i+1; // } // } // // for(int i = 0; i < N ; i++){ // // if(i != N-1){ // // M_total += N_array[i]%N_array[i+1]; // // } // // } // Console.WriteLine(M_total); } } }
using System; namespace _139d { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); Console.WriteLine((1 + N - 1) * (N - 1) / 2); // long M_total = 0; // // float[] N_array = new float[N]; // for(long i = 0; i < N;i++){ // // N_array[i] = i+1; // if(i != N-1){ // M_total += i+1; // } // } // // for(int i = 0; i < N ; i++){ // // if(i != N-1){ // // M_total += N_array[i]%N_array[i+1]; // // } // // } // Console.WriteLine(M_total); } } }
[["-", 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
71
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long bmod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N = GetInt(); var ans = N * (N - 1) / 2; Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long bmod = 1000000007; static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { long N = GetInt(); var ans = N * (N - 1) / 2; Console.WriteLine(ans); } } //拡張メソッド public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); } public static string yesno(this bool b) { return b ? "yes" : "no"; } public static string YesNo(this bool b) { return b ? "Yes" : "No"; } public static string YESNO(this bool b) { return b ? "YES" : "NO"; } } partial class Program { static public string GetStr() { return Console.ReadLine().Trim(); } static public char GetChar() { return Console.ReadLine().Trim()[0]; } static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } static public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } static public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } static public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } static public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } static public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } static public void WriteObjects<T>(IReadOnlyCollection<T> values) { var array = values.ToArray(); var num = array.Length; if (num == 0) return; Console.Write(array[0]); for (int i = 1; i < num; i++) { Console.Write(" " + array[i]); } Console.WriteLine(); } static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); static void Multi<T>(out T a) => a = cv<T>(GetStr()); static void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } static void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
1,477
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { static class DModSum { static void Main(string[] args) { var n = decimal.Parse(Console.ReadLine()); if (n == 1) { Console.WriteLine(0); Console.ReadLine(); } Console.WriteLine(n * (n - 1) / 2); Console.ReadLine(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { static class DModSum { static void Main(string[] args) { var n = decimal.Parse(Console.ReadLine()); if (n == 1) { Console.WriteLine(0); Console.ReadLine(); return; } Console.WriteLine(n * (n - 1) / 2); Console.ReadLine(); } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
8
103
2
using System; namespace abc139D { class MainClass { public static void Main(string[] args) { int N = Int32.Parse(Console.ReadLine()); int M = N * (N - 1); int L = M / 2; Console.WriteLine(L.ToString()); } } }
using System; namespace abc139D { class MainClass { public static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long M = N * (N - 1); long L = M / 2; Console.WriteLine(L.ToString()); } } }
[["-", 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, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
66
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp10 { class Program { static void MainA(string[] args) { Console.WriteLine( Console.ReadLine() .ToCharArray() .Zip(Console.ReadLine().ToCharArray(), (x, y) => x == y) .Count(x => x)); } static void MainB() { var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var ans = (arr[1] - 1 + arr[0] - 2) / (arr[0] - 1); Console.WriteLine(ans); } static void MainC() { Console.ReadLine(); var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int cnt = 0; int cntmax = 0; for (int i = 0; i < arr.Length - cntmax - 1; i++) { cnt = 0; for (int j = i + 1; j < arr.Length; j++) { if (arr[j - 1] >= arr[j]) cnt++; else { break; } } if (cnt > cntmax) cntmax = cnt; } Console.WriteLine(cntmax); } static void Main() { int n = int.Parse(Console.ReadLine()) - 1; Console.WriteLine((n * n + n) / 2); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp10 { class Program { static void MainA(string[] args) { Console.WriteLine( Console.ReadLine() .ToCharArray() .Zip(Console.ReadLine().ToCharArray(), (x, y) => x == y) .Count(x => x)); } static void MainB() { var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var ans = (arr[1] - 1 + arr[0] - 2) / (arr[0] - 1); Console.WriteLine(ans); } static void MainC() { Console.ReadLine(); var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); int cnt = 0; int cntmax = 0; for (int i = 0; i < arr.Length - cntmax - 1; i++) { cnt = 0; for (int j = i + 1; j < arr.Length; j++) { if (arr[j - 1] >= arr[j]) cnt++; else { break; } } if (cnt > cntmax) cntmax = cnt; } Console.WriteLine(cntmax); } static void Main() { long n = int.Parse(Console.ReadLine()) - 1; Console.WriteLine((n * n + n) / 2); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
343
2
using System; class Program { static void Main(string[] args) { // 整数の入力 int N = int.Parse(Console.ReadLine()); // スペース区切りの整数の入力 // string[] input = Console.ReadLine().Split(' '); // int[] H = new int[N]; // for (int i = 0;i<N;i++){ // H[i] = int.Parse(input[i]); //} // int A = int.Parse(input[0]); // int B = int.Parse(input[1]); // 文字列の入力 // string s = Console.ReadLine(); //出力 Console.WriteLine(N * (N - 1) / 2); } }
using System; class Program { static void Main(string[] args) { // 整数の入力 int N = int.Parse(Console.ReadLine()); // スペース区切りの整数の入力 // string[] input = Console.ReadLine().Split(' '); // int[] H = new int[N]; // for (int i = 0;i<N;i++){ // H[i] = int.Parse(input[i]); //} // int A = int.Parse(input[0]); // int B = int.Parse(input[1]); // 文字列の入力 // string s = Console.ReadLine(); //出力 Console.WriteLine((long)N * (N - 1) / 2); } }
[["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 25]]
8
59
3
using System; class Program { static void Main() { int N = int.Parse(Console.ReadLine()); Console.WriteLine(N * (N - 1) / 2); } }
using System; class Program { static void Main() { long N = long.Parse(Console.ReadLine()); Console.WriteLine(N * (N - 1) / 2); } }
[["-", 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
43
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace ConsoleApp1 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Console.WriteLine(n * (n - 1) / 2); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; namespace ConsoleApp1 { class Program { static void Main(string[] args) { long n = long.Parse(Console.ReadLine()); Console.WriteLine(n * (n - 1) / 2); } } }
[["-", 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
80
4
using System; using System.Linq; class Program { static void Main(string[] argv) { var r = int.Parse(Console.ReadLine()); r = (r - 1) * r / 2; Console.WriteLine(r); return; } }
using System; using System.Linq; class Program { static void Main(string[] argv) { var r = long.Parse(Console.ReadLine()); r = (r - 1) * r / 2; Console.WriteLine(r); return; } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
58
2
using System; using System.Text; using System.Collections.Generic; class Program { const int MOD = (int)1e9 + 7; // const int MOD = (int) 998244353; const int INT_MAX = 2147483647; static void Main(string[] args) { int n = Scan.Int(); long ans = n * (n - 1) / 2; Out.Ln(ans); } } public class Scan { public static string Strln() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static long Long() { return long.Parse(Console.ReadLine()); } public static string[] StringArray(int lines) { string[] str = new string[lines]; for (int i = 0; i < lines; i++) { str[i] = Console.ReadLine(); } return str; } public static int[] IntArray(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; } public static string[] StringArrayInLine(int t) { string[] str = Console.ReadLine().Split(' '); return str; } public static Tuple<int, int> Tuple() { int[] tmp = Scan.IntArray(2); return new Tuple<int, int>(tmp[0], tmp[1]); } public static long[] LongArray(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; } public static double[] DoubleArray(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; } public static int[,] IntSquareArray(int h, int w) { int[,] resAr = new int[h, w]; for (int i = 0; i < h; i++) { int[] ar = Scan.IntArray(w); for (int j = 0; j < w; j++) { resAr[i, j] = ar[j]; } } return resAr; } } public class Out { public static void Str(string s) { Console.Write(s); } public static void Ln<T>(T s) { Console.WriteLine(s); } public static void YESNO(bool f) { Console.WriteLine(f ? "YES" : "NO"); } public static void YesNo(bool f) { Console.WriteLine(f ? "Yes" : "No"); } public static void Array<T>(T[] a) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < a.Length; i++) { sb.Append(a[i]); if (i != a.Length - 1) { sb.Append(" "); } } string s = sb.ToString(); Console.WriteLine(s); } public static void List<T>(List<T> a) { for (int i = 0; i < a.Count; i++) { Console.Write(a[i]); if (i != a.Count - 1) { Console.Write(" "); } } Console.WriteLine(""); } } public class Str { public static string Connect(string a, string b) { StringBuilder sb = new StringBuilder(a); sb.Append(b); return sb.ToString(); } } public class UnionFind { public int[] parent; public int[] rank; public long[] weightDiff; public void Init(int size) { parent = new int[size + 5]; rank = new int[size + 5]; weightDiff = new long[size + 5]; for (int i = 0; i < size; i++) { parent[i] = i; rank[i] = 0; weightDiff[i] = 0; } } public int Root(int x) { if (parent[x] == x) { return x; } else { int r = Root(parent[x]); weightDiff[x] += weightDiff[parent[x]]; return parent[x] = r; } } public bool Unite(int x, int y, long w) // Add edge x <- y (weight: w) { w = w + GetWeight(x) - GetWeight(y); x = Root(x); y = Root(y); if (x == y) return false; if (rank[x] < rank[y]) { int tmp = x; x = y; y = tmp; w *= -1; } if (rank[x] == rank[y]) { ++rank[x]; } parent[y] = x; weightDiff[y] = w; return true; } public bool Same(int x, int y) { return Root(x) == Root(y); } public long GetWeight(int x) { Root(x); return weightDiff[x]; } public long Diff(int x, int y) // x -> y { return GetWeight(y) - GetWeight(x); } } public class SegmentTree<Monoid> { private bool debug = false; // 0-indexed SegmentTree public int size; Monoid[] segTree; Monoid unit; public SegmentTree(int inSize, Monoid unit) { this.unit = unit; size = 2; while (size < inSize) size *= 2; segTree = new Monoid[2 * size]; for (int i = 0; i < segTree.Length; i++) { segTree[i] = unit; // 単位元なので全部に代入しておけばよい } } public int BinarySearch(int x) { int high = size; int low = 0; int mid = (high + low) / 2; while (low < high) { // Console.WriteLine(low + " " + high); Monoid cmp = NonRecursiveQuery(0, mid); // Console.WriteLine("[ 0, " + mid + " ] -> " + cmp); if ((dynamic)cmp >= x) { high = mid; } else if ((dynamic)cmp < x) { low = mid + 1; } mid = (high + low) / 2; } return mid; } public void set(int iter, Monoid val) { segTree[iter + size - 1] = val; } public Monoid GetMonoid(int index) { return segTree[index + size - 1]; } public void add(int iter, Monoid val) { update(iter, (dynamic)segTree[iter + size - 1] + (dynamic)val); } public void build() { // 2段目より上の構築 for (int k = size - 2; k >= 0; k--) { segTree[k] = F(segTree[2 * k + 1], segTree[2 * k + 2]); } } public Monoid F(Monoid m1, Monoid m2) { Monoid res = Algo.GCD(m1, m2); return res; } public Monoid Query(int ql, int qr, int index, int nl, int nr) { // Recursive // [ql, qr)について考える // index に対応する範囲 nl <= x <= nr if (nr <= ql || qr <= nl) { if (debug) Console.WriteLine("Out: [l , r), [" + nl + " ," + nr + "), " + "index: " + index + " ,unit:" + unit); return unit; } if (ql <= nl && nr <= qr) { if (debug) Console.WriteLine("All in [l , r): [" + nl + " ," + nr + "), " + "index: " + index + ",rangeAns:" + segTree[index]); return segTree[index]; } else { Monoid vl = Query(ql, qr, index * 2 + 1, nl, (nl + nr) / 2); Monoid vr = Query(ql, qr, index * 2 + 2, (nl + nr) / 2, nr); if (debug) Console.WriteLine("Recursive: [l , r),+: [" + nl + ", " + nr + "), index->" + index); if (debug) Console.WriteLine("(vl, vr): (" + vl + ", " + vr + ")"); return F(vl, vr); } } public Monoid NonRecursiveQuery(int l, int r) { // 区間 -> [ l , r ] // 非再帰 int L = l + size - 1; int R = r + size - 1; Monoid s = unit; while (L <= R) { if (L % 2 == 0) { s = F(s, segTree[L]); L++; } if (R % 2 == 1) { s = F(s, segTree[R]); } L /= 2; R /= 2; R--; } return s; } public void update(int k, Monoid x) { k += size - 1; segTree[k] = x; while (true) { k = (k - 1) / 2; segTree[k] = F(segTree[k * 2 + 1], segTree[k * 2 + 2]); if (k == 0) { break; } } } public void print() { Console.Write("Print:"); for (int i = 0; i < segTree.Length; i++) { Console.Write(segTree[i] + " "); } Console.WriteLine(""); } } // 計算量: 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 Algo { public const long MOD = (long)1e9 + 7; public 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; } public static bool IsPrime(int a) // O(sqrt N) { int max = (int)Math.Sqrt(a); if (a <= 1) return false; for (int i = 2; i <= max; i++) { if (a % i == 0) { return false; } } return true; } public static T GCD<T>(T a, T b) { if ((dynamic)b == 0) { return a; } else { return Algo.GCD((dynamic)b, (dynamic)a % (dynamic)b); } } 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; } }
using System; using System.Text; using System.Collections.Generic; class Program { const int MOD = (int)1e9 + 7; // const int MOD = (int) 998244353; const int INT_MAX = 2147483647; static void Main(string[] args) { long n = Scan.Long(); long ans = n * (n - 1) / 2; Out.Ln(ans); } } public class Scan { public static string Strln() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static long Long() { return long.Parse(Console.ReadLine()); } public static string[] StringArray(int lines) { string[] str = new string[lines]; for (int i = 0; i < lines; i++) { str[i] = Console.ReadLine(); } return str; } public static int[] IntArray(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; } public static string[] StringArrayInLine(int t) { string[] str = Console.ReadLine().Split(' '); return str; } public static Tuple<int, int> Tuple() { int[] tmp = Scan.IntArray(2); return new Tuple<int, int>(tmp[0], tmp[1]); } public static long[] LongArray(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; } public static double[] DoubleArray(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; } public static int[,] IntSquareArray(int h, int w) { int[,] resAr = new int[h, w]; for (int i = 0; i < h; i++) { int[] ar = Scan.IntArray(w); for (int j = 0; j < w; j++) { resAr[i, j] = ar[j]; } } return resAr; } } public class Out { public static void Str(string s) { Console.Write(s); } public static void Ln<T>(T s) { Console.WriteLine(s); } public static void YESNO(bool f) { Console.WriteLine(f ? "YES" : "NO"); } public static void YesNo(bool f) { Console.WriteLine(f ? "Yes" : "No"); } public static void Array<T>(T[] a) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < a.Length; i++) { sb.Append(a[i]); if (i != a.Length - 1) { sb.Append(" "); } } string s = sb.ToString(); Console.WriteLine(s); } public static void List<T>(List<T> a) { for (int i = 0; i < a.Count; i++) { Console.Write(a[i]); if (i != a.Count - 1) { Console.Write(" "); } } Console.WriteLine(""); } } public class Str { public static string Connect(string a, string b) { StringBuilder sb = new StringBuilder(a); sb.Append(b); return sb.ToString(); } } public class UnionFind { public int[] parent; public int[] rank; public long[] weightDiff; public void Init(int size) { parent = new int[size + 5]; rank = new int[size + 5]; weightDiff = new long[size + 5]; for (int i = 0; i < size; i++) { parent[i] = i; rank[i] = 0; weightDiff[i] = 0; } } public int Root(int x) { if (parent[x] == x) { return x; } else { int r = Root(parent[x]); weightDiff[x] += weightDiff[parent[x]]; return parent[x] = r; } } public bool Unite(int x, int y, long w) // Add edge x <- y (weight: w) { w = w + GetWeight(x) - GetWeight(y); x = Root(x); y = Root(y); if (x == y) return false; if (rank[x] < rank[y]) { int tmp = x; x = y; y = tmp; w *= -1; } if (rank[x] == rank[y]) { ++rank[x]; } parent[y] = x; weightDiff[y] = w; return true; } public bool Same(int x, int y) { return Root(x) == Root(y); } public long GetWeight(int x) { Root(x); return weightDiff[x]; } public long Diff(int x, int y) // x -> y { return GetWeight(y) - GetWeight(x); } } public class SegmentTree<Monoid> { private bool debug = false; // 0-indexed SegmentTree public int size; Monoid[] segTree; Monoid unit; public SegmentTree(int inSize, Monoid unit) { this.unit = unit; size = 2; while (size < inSize) size *= 2; segTree = new Monoid[2 * size]; for (int i = 0; i < segTree.Length; i++) { segTree[i] = unit; // 単位元なので全部に代入しておけばよい } } public int BinarySearch(int x) { int high = size; int low = 0; int mid = (high + low) / 2; while (low < high) { // Console.WriteLine(low + " " + high); Monoid cmp = NonRecursiveQuery(0, mid); // Console.WriteLine("[ 0, " + mid + " ] -> " + cmp); if ((dynamic)cmp >= x) { high = mid; } else if ((dynamic)cmp < x) { low = mid + 1; } mid = (high + low) / 2; } return mid; } public void set(int iter, Monoid val) { segTree[iter + size - 1] = val; } public Monoid GetMonoid(int index) { return segTree[index + size - 1]; } public void add(int iter, Monoid val) { update(iter, (dynamic)segTree[iter + size - 1] + (dynamic)val); } public void build() { // 2段目より上の構築 for (int k = size - 2; k >= 0; k--) { segTree[k] = F(segTree[2 * k + 1], segTree[2 * k + 2]); } } public Monoid F(Monoid m1, Monoid m2) { Monoid res = Algo.GCD(m1, m2); return res; } public Monoid Query(int ql, int qr, int index, int nl, int nr) { // Recursive // [ql, qr)について考える // index に対応する範囲 nl <= x <= nr if (nr <= ql || qr <= nl) { if (debug) Console.WriteLine("Out: [l , r), [" + nl + " ," + nr + "), " + "index: " + index + " ,unit:" + unit); return unit; } if (ql <= nl && nr <= qr) { if (debug) Console.WriteLine("All in [l , r): [" + nl + " ," + nr + "), " + "index: " + index + ",rangeAns:" + segTree[index]); return segTree[index]; } else { Monoid vl = Query(ql, qr, index * 2 + 1, nl, (nl + nr) / 2); Monoid vr = Query(ql, qr, index * 2 + 2, (nl + nr) / 2, nr); if (debug) Console.WriteLine("Recursive: [l , r),+: [" + nl + ", " + nr + "), index->" + index); if (debug) Console.WriteLine("(vl, vr): (" + vl + ", " + vr + ")"); return F(vl, vr); } } public Monoid NonRecursiveQuery(int l, int r) { // 区間 -> [ l , r ] // 非再帰 int L = l + size - 1; int R = r + size - 1; Monoid s = unit; while (L <= R) { if (L % 2 == 0) { s = F(s, segTree[L]); L++; } if (R % 2 == 1) { s = F(s, segTree[R]); } L /= 2; R /= 2; R--; } return s; } public void update(int k, Monoid x) { k += size - 1; segTree[k] = x; while (true) { k = (k - 1) / 2; segTree[k] = F(segTree[k * 2 + 1], segTree[k * 2 + 2]); if (k == 0) { break; } } } public void print() { Console.Write("Print:"); for (int i = 0; i < segTree.Length; i++) { Console.Write(segTree[i] + " "); } Console.WriteLine(""); } } // 計算量: 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 Algo { public const long MOD = (long)1e9 + 7; public 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; } public static bool IsPrime(int a) // O(sqrt N) { int max = (int)Math.Sqrt(a); if (a <= 1) return false; for (int i = 2; i <= max; i++) { if (a % i == 0) { return false; } } return true; } public static T GCD<T>(T a, T b) { if ((dynamic)b == 0) { return a; } else { return Algo.GCD((dynamic)b, (dynamic)a % (dynamic)b); } } 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; } }
[["-", 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, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
2,964
4
using System; using System.Text.RegularExpressions; namespace ConsoleApp3 { class Program { static void Main(string[] args) { double num = Convert.ToDouble(Console.ReadLine()); num -= 1; Console.WriteLine(num * (num + 1) / 2); } } }
using System; using System.Text.RegularExpressions; namespace ConsoleApp3 { class Program { static void Main(string[] args) { decimal num = Convert.ToDecimal(Console.ReadLine()); num -= 1; Console.WriteLine(num * (num + 1) / 2); } } }
[["-", 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, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
62
4
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); if (n == 1) { Console.WriteLine(0); goto exit; } long ans = (n + 1) * (n - 2) / 2 + 1; Console.WriteLine(ans); exit:; } }
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); if (n == 1) { Console.WriteLine(0); goto exit; } long ans = (n + 1L) * (n - 2L) / 2L + 1L; Console.WriteLine(ans); exit:; } }
[["-", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 31, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["-", 31, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 31, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 12, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
81
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemD { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var ret = 0; if (N != 1) { // ret = 1 + (((N - 1) + 2) * (N - 2)) / 2; ret = N * (N - 1) / 2; } Console.WriteLine(ret); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProblemD { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); long ret = 0; if (N != 1) { // ret = 1 + (((N - 1) + 2) * (N - 2)) / 2; ret = N * (N - 1) / 2; } Console.WriteLine(ret); } } }
[["-", 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, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
93
4
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); decimal sum = N * (N - 1) / 2; Console.WriteLine(sum); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var N = decimal.Parse(Console.ReadLine()); decimal sum = N * (N - 1) / 2; Console.WriteLine(sum); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
68
2
using System; class Program { static void Main(string[] args) {   int n, b; n = int.Parse(Console.ReadLine()); Console.WriteLine(n * (n - 1) / 2); } }
using System; class Program { static void Main(string[] args) {   long n, b; n = long.Parse(Console.ReadLine()); Console.WriteLine(n * (n - 1) / 2); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
8
52
4
using System; namespace pro { class MainClass { public static void Main() { int n = int.Parse(Console.ReadLine()); int x = n * (n - 1) / 2; Console.WriteLine(x); } } }
using System; namespace pro { class MainClass { public static void Main() { long n = int.Parse(Console.ReadLine()); long x = n * (n - 1) / 2; Console.WriteLine(x); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
53
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace AtCoder { class Program { static int n; static void Main(string[] args) { n = int.Parse(Console.ReadLine()); long ans = n * (n - 1) / 2; // for (int i = 1; i < n; i++) { // ans += i % (i + 1); //} Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace AtCoder { class Program { static long n; static void Main(string[] args) { n = long.Parse(Console.ReadLine()); long ans = n * (n - 1) / 2; // for (int i = 1; i < n; i++) { // ans += i % (i + 1); //} Console.WriteLine(ans); } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199]]
8
93
4
using System; using System.Linq; public class Test { public static void Main() { // your code goes here long n = long.Parse(Console.ReadLine()); long ans = (n * (n - 1) / 2) + 1; Console.WriteLine(ans); } }
using System; using System.Linq; public class Test { public static void Main() { // your code goes here long n = long.Parse(Console.ReadLine()); long ans = n * (n - 1) / 2; Console.WriteLine(ans); } }
[["-", 0, 200, 0, 212, 0, 16, 31, 23, 0, 24], ["-", 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
60
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A { class Program { /// <summary> /// The main entry point for the application /// </summary> [STAThread] public static void Main(string[] args) { string str = Console.ReadLine(); int n = int.Parse(str); Console.Write("{0}", n * (n - 1) / 2); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A { class Program { /// <summary> /// The main entry point for the application /// </summary> [STAThread] public static void Main(string[] args) { string str = Console.ReadLine(); long n = long.Parse(str); Console.Write("{0}", n * (n - 1) / 2); } } }
[["-", 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
91
4
using System; using System.Linq; public class Test { public static void Main() { int N = int.Parse(Console.ReadLine().Trim()); int answer = (N * (N - 1)) / 2; Console.WriteLine(answer); } }
using System; using System.Linq; public class Test { public static void Main() { long N = long.Parse(Console.ReadLine().Trim()); long answer = (N * (N - 1)) / 2; Console.WriteLine(answer); } }
[["-", 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
61
6
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { // input int N = Convert.ToInt32(Console.ReadLine()); Console.WriteLine((N - 1) * N / 2); } } }
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { // input long N = Convert.ToInt32(Console.ReadLine()); Console.WriteLine((N - 1) * N / 2); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
52
2
using System; namespace ConsoleApp4 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int m = n - 1; int ret = (1 + m) * m / 2; Console.WriteLine(ret); } } }
using System; namespace ConsoleApp4 { class Program { static void Main(string[] args) { long n = long.Parse(Console.ReadLine()); long m = n - 1; long ret = (1 + m) * m / 2; Console.WriteLine(ret); } } }
[["-", 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
63
8
using System; namespace abc139_d { static class Program { static void Main(string[] args) { var n = Console.ReadLine().ToInteger(); // 9 % 1 = 0 // 8 % 9 = 8 // 7 % 8 = 7 // : // 2 % 3 = 2 // 1 % 2 = 1 // 8 7 6 5 4 3 2 1 // (8 + 1) * 4 // 7 6 5 4 3 2 1 // (7 + 1) * 3 + 4 // (7 + 1) * 3.5 // ((n - 1) + 1) * ((n - 1) / 2) var m = n * (n - 1) / 2; Console.WriteLine($"{m}"); } static int ToInteger(this string s) { return int.Parse(s); } } }
using System; namespace abc139_d { static class Program { static void Main(string[] args) { var n = Console.ReadLine().ToLong(); // 9 % 1 = 0 // 8 % 9 = 8 // 7 % 8 = 7 // : // 2 % 3 = 2 // 1 % 2 = 1 // 8 7 6 5 4 3 2 1 // (8 + 1) * 4 // 7 6 5 4 3 2 1 // (7 + 1) * 3 + 4 // (7 + 1) * 3.5 // ((n - 1) + 1) * ((n - 1) / 2) var m = n * (n - 1) / 2; Console.WriteLine($"{m}"); } static long ToLong(this string s) { return long.Parse(s); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 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]]
8
90
8
using System; using System.Collections.Generic; namespace abc139_d { class Program { static void Main(string[] args) { var n = CIn.ReadInt(); Console.WriteLine(n * (n - 1) / 2); } } class CIn { private static readonly Queue<string> fieldBuffer = new Queue<string>(); public static string Read() { if (fieldBuffer.Count == 0) { foreach (var field in Console.ReadLine().Split()) { fieldBuffer.Enqueue(field); } } return fieldBuffer.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static string[] ReadStringArray(long n) { var array = new string[n]; for (var i = 0; i < n; i++) { array[i] = Read(); } return array; } public static int[] ReadIntArray(long n) { var array = new int[n]; for (var i = 0; i < n; i++) { array[i] = ReadInt(); } return array; } public static long[] ReadLongArray(long n) { var array = new long[n]; for (var i = 0; i < n; i++) { array[i] = ReadLong(); } return array; } public static double[] ReadDoubleArray(long n) { var array = new double[n]; for (var i = 0; i < n; i++) { array[i] = ReadDouble(); } return array; } } }
using System; using System.Collections.Generic; namespace abc139_d { class Program { static void Main(string[] args) { var n = CIn.ReadInt(); Console.WriteLine((long)n * (n - 1) / 2); } } class CIn { private static readonly Queue<string> fieldBuffer = new Queue<string>(); public static string Read() { if (fieldBuffer.Count == 0) { foreach (var field in Console.ReadLine().Split()) { fieldBuffer.Enqueue(field); } } return fieldBuffer.Dequeue(); } public static int ReadInt() => int.Parse(Read()); public static long ReadLong() => long.Parse(Read()); public static double ReadDouble() => double.Parse(Read()); public static string[] ReadStringArray(long n) { var array = new string[n]; for (var i = 0; i < n; i++) { array[i] = Read(); } return array; } public static int[] ReadIntArray(long n) { var array = new int[n]; for (var i = 0; i < n; i++) { array[i] = ReadInt(); } return array; } public static long[] ReadLongArray(long n) { var array = new long[n]; for (var i = 0; i < n; i++) { array[i] = ReadLong(); } return array; } public static double[] ReadDoubleArray(long n) { var array = new double[n]; for (var i = 0; i < n; i++) { array[i] = ReadDouble(); } return array; } } }
[["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 25]]
8
367
3
using System; class D { static void Main() { var n = int.Parse(Console.ReadLine()); Console.WriteLine(n * (n - 1) / 2); } }
using System; class D { static void Main() { var n = long.Parse(Console.ReadLine()); Console.WriteLine(n * (n - 1) / 2); } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
43
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { void Solve() { var N = ToInts()[0]; Console.WriteLine(N * (N - 1) / 2); ; } static int[] ToInts() { var ss = Console.ReadLine().Split(); var ret = new /**/ int[ss.Length]; for (int i = 0; i < ss.Length; i++) { ret[i] = /**/ int.Parse(ss[i]); } return ret; } static void Main(string[] args) { new Program().Solve(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { void Solve() { var N = ToInts()[0]; Console.WriteLine((long)N * (N - 1) / 2); ; } static int[] ToInts() { var ss = Console.ReadLine().Split(); var ret = new /**/ int[ss.Length]; for (int i = 0; i < ss.Length; i++) { ret[i] = /**/ int.Parse(ss[i]); } return ret; } static void Main(string[] args) { new Program().Solve(); } }
[["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 28, 0, 16, 31, 16, 31, 74, 0, 25]]
8
154
3
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var n = N - 1; WriteLine((n * (n + 1)) / 2); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using static System.Console; using static System.Math; namespace AtCoder { public class Program { public static void Main(string[] args) { new Program().Solve(new ConsoleInput(Console.In, ' ')); } public void Solve(ConsoleInput cin) { var N = cin.ReadLong; var n = N - 1; WriteLine((n * (n + 1)) / 2); } } public class ConsoleInput { private readonly System.IO.TextReader _stream; private char _separator = ' '; private Queue<string> inputStream; public ConsoleInput(System.IO.TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22]]
8
453
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var x = sc.IntArr; int n = x[0]; if (n == 1) wr.wri(0); else wr.wri((n - 1) * n / 2); } } class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); Math2 mmath = new Math2(); //ここから var x = sc.IntArr; long n = x[0]; if (n == 1) wr.wri(0); else wr.wri((n - 1) * n / 2L); } } class PriorityQueue<T> { private readonly List<T> heap; private readonly Comparison<T> compare; private int size; public PriorityQueue() : this(Comparer<T>.Default) {} public PriorityQueue(IComparer<T> comparer) : this(16, comparer.Compare) {} public PriorityQueue(Comparison<T> comparison) : this(16, comparison) {} public PriorityQueue(int capacity, Comparison<T> comparison) { this.heap = new List<T>(capacity); this.compare = comparison; } public void Enqueue(T item) { this.heap.Add(item); var i = size++; while (i > 0) { var p = (i - 1) >> 1; if (compare(this.heap[p], item) <= 0) break; this.heap[i] = heap[p]; i = p; } this.heap[i] = item; } public T Dequeue() { var ret = this.heap[0]; var x = this.heap[--size]; var i = 0; while ((i << 1) + 1 < size) { var a = (i << 1) + 1; var b = (i << 1) + 2; if (b < size && compare(heap[b], heap[a]) < 0) a = b; if (compare(heap[a], x) >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(size); return ret; } public T Peek() { return heap[0]; } public int Count { get { return size; } } public bool Any() { return size > 0; } } class Math2 { public long[] Fact; // Nまでの階乗 public long[] invFact; //階乗の逆元 public void FactoricalModSet(long N, long MOD = 1000000007) { Fact = new long[N + 1]; invFact = new long[N + 1]; Fact[0] = 1; for (long i = 1; i <= N; ++i) { Fact[i] = Fact[i - 1] * i % MOD; } invFact[N] = powMOD(Fact[N], MOD - 2); for (long i = N; i > 0; --i) { invFact[i - 1] = invFact[i] * i % MOD; } } public long nCrMod(long n, long r, long MOD = 1000000007) { return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD); } public long powMOD(long x, long n, long MOD = 1000000007) { long res = 1; while (n > 0) { if ((n & 1) != 0) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } static long GCD(long x, long y) { if (y == 0) return x; return GCD(y, x % y); } static long LCM(long x, long y) { return x * y / GCD(x, y); } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
932
4
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { // 各種変数の読み込み var n = int.Parse(Console.ReadLine()); Console.WriteLine(n * (n - 1) / 2); #if DEBUG Console.ReadKey(); #endif } } }
using System; using System.Collections.Generic; namespace ConsoleApp1 { class Program { static void Main(string[] args) { // 各種変数の読み込み var n = int.Parse(Console.ReadLine()); Console.WriteLine(((long)n) * (n - 1) / 2); #if DEBUG Console.ReadKey(); #endif } } }
[["+", 0, 28, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 74, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 74, 39, 199], ["+", 0, 16, 31, 16, 31, 23, 0, 74, 0, 25], ["+", 0, 28, 0, 16, 31, 16, 31, 23, 0, 25]]
8
70
5
using System; namespace D { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); Console.WriteLine(N * (N - 1) / 2); } } }
using System; namespace D { class Program { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); Console.WriteLine(N * (N - 1) / 2); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199]]
8
51
2
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class D { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { int N = GetInt(); Console.WriteLine((N * (N - 1)) / 2); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray(); public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray(); }
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Linq; using static MyIO; public class D { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { long N = GetInt(); Console.WriteLine((N * (N - 1)) / 2); } } public static class MyIO { private static string[] args = null; private static int num = -1; private static int used = -1; private static string getArg() { if (used == num) { args = Console.ReadLine().Split(' '); num = args.Length; used = 0; } return args[used++]; } public static int GetInt() => int.Parse(getArg()); public static long GetLong() => long.Parse(getArg()); public static double GetDouble() => double.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray(); public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray(); }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
372
2
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); double[][] A = new double [N][]; var list1 = new List<int>(); var list2 = new List<int>(); var list3 = new List<int>(); var list4 = new List<int>(); for (var i = 0; i < N; i++) { string[] str = Console.ReadLine().Split(); A[i] = new double[2] { double.Parse(str[0]), double.Parse(str[1]) }; if (A[i][0] > 0 && A[i][1] >= 0) { list1.Add(i); } else if (A[i][0] <= 0 && A[i][1] > 0) { list2.Add(i); } else if (A[i][0] < 0 && A[i][1] <= 0) { list3.Add(i); } else { list4.Add(i); } } list1.Sort((x, y) => (A[x][1] / A[x][0]).CompareTo(A[y][1] / A[y][0])); list2.Sort((x, y) => (-A[x][0] / A[x][1]).CompareTo(-A[y][0] / A[y][1])); list3.Sort((x, y) => (A[x][1] / A[x][0]).CompareTo(A[x][1] / A[x][0])); list4.Sort((x, y) => (-A[x][0] / A[x][1]).CompareTo(-A[x][0] / A[x][1])); var list = new List<int>(); list.AddRange(list1); list.AddRange(list2); list.AddRange(list3); list.AddRange(list4); double ans = 0; for (var i = 0; i < N; i++) { for (var j = 0; j < N; j++) { double a1x = 0; double a1y = 0; for (var k = i; k <= i + j; k++) { a1x += A[list[k % N]][0]; a1y += A[list[k % N]][1]; } double a1 = a1x * a1x + a1y * a1y; ans = Math.Max(ans, a1); } } ans = Math.Pow(ans, 0.5); Console.WriteLine(ans); } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); double[][] A = new double [N][]; var list1 = new List<int>(); var list2 = new List<int>(); var list3 = new List<int>(); var list4 = new List<int>(); for (var i = 0; i < N; i++) { string[] str = Console.ReadLine().Split(); A[i] = new double[2] { double.Parse(str[0]), double.Parse(str[1]) }; if (A[i][0] > 0 && A[i][1] >= 0) { list1.Add(i); } else if (A[i][0] <= 0 && A[i][1] > 0) { list2.Add(i); } else if (A[i][0] < 0 && A[i][1] <= 0) { list3.Add(i); } else { list4.Add(i); } } list1.Sort((x, y) => (A[x][1] / A[x][0]).CompareTo(A[y][1] / A[y][0])); list2.Sort((x, y) => (-A[x][0] / A[x][1]).CompareTo(-A[y][0] / A[y][1])); list3.Sort((x, y) => (A[x][1] / A[x][0]).CompareTo(A[y][1] / A[y][0])); list4.Sort((x, y) => (-A[x][0] / A[x][1]).CompareTo(-A[y][0] / A[y][1])); var list = new List<int>(); list.AddRange(list1); list.AddRange(list2); list.AddRange(list3); list.AddRange(list4); double ans = 0; for (var i = 0; i < N; i++) { for (var j = 0; j < N; j++) { double a1x = 0; double a1y = 0; for (var k = i; k <= i + j; k++) { a1x += A[list[k % N]][0]; a1y += A[list[k % N]][1]; } double a1 = a1x * a1x + a1y * a1y; ans = Math.Max(ans, a1); } } ans = Math.Pow(ans, 0.5); Console.WriteLine(ans); } }
[["-", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 204, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 204, 205, 204, 206, 207, 0, 28, 0, 22]]
8
636
8
using System; class a { public static void Main() { string[] str = Console.ReadLine().Split(' '); int m = int.Parse(str[0]); int d = int.Parse(str[1]); int d10 = 0; while (d >= 10) { d -= 10; d10++; } int d1 = d; int count = 0; for (int i = 2; i < d10; i++) { for (int j = 2; j < 10; j++) { if (i * j <= m) { count++; } else { break; } } } for (int i = 2; i < d1 && d10 > 1; i++) { if (i * d10 <= m) { count++; } } Console.WriteLine(count); } }
using System; class a { public static void Main() { string[] str = Console.ReadLine().Split(' '); int m = int.Parse(str[0]); int d = int.Parse(str[1]); int d10 = 0; while (d >= 10) { d -= 10; d10++; } int d1 = d; int count = 0; for (int i = 2; i < d10; i++) { for (int j = 2; j < 10; j++) { if (i * j <= m) { count++; } else { break; } } } for (int i = 2; i <= d1 && d10 > 1; i++) { if (i * d10 <= m) { count++; } } Console.WriteLine(count); } }
[["-", 8, 196, 0, 7, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 31, 16, 17, 19]]
8
179
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray(); int m = s[0]; int d = s[1]; long ans = 0; for (int i = 1; i <= m; i++) { for (int j = 10; j < d; j++) { int d1 = j % 10; int d2 = j / 10; if (d1 >= 2 && d2 >= 2 && d1 * d2 == i) { ans++; } } } WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using static System.Console; using static System.Math; namespace AtCodeeeer { class AtCOOOOOOOOOOOder { static void Main(string[] args) { int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray(); int m = s[0]; int d = s[1]; long ans = 0; for (int i = 1; i <= m; i++) { for (int j = 10; j <= d; j++) { int d1 = j % 10; int d2 = j / 10; if (d1 >= 2 && d2 >= 2 && d1 * d2 == i) { ans++; } } } WriteLine(ans); } } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
176
2
using System; using System.Text; using System.Linq; class AtCoder { static void Main() { int seki = 0; string[] tmp = Console.ReadLine().Split(); int m = int.Parse(tmp[0]); int d = int.Parse(tmp[1]); for (int cnt1 = 1; cnt1 <= m; cnt1++) { for (int cnt2 = 1; cnt2 < d; cnt2++) { if (2 <= (cnt2) % 10 && 2 <= (cnt2 / 10) && (((cnt2 % 10) * (cnt2 / 10)) == cnt1)) { seki += 1; } } } Console.Write(seki.ToString()); } }
using System; using System.Text; using System.Linq; class AtCoder { static void Main() { int seki = 0; string[] tmp = Console.ReadLine().Split(); int m = int.Parse(tmp[0]); int d = int.Parse(tmp[1]); for (int cnt1 = 1; cnt1 <= m; cnt1++) { for (int cnt2 = 1; cnt2 <= d; cnt2++) { if (2 <= (cnt2) % 10 && 2 <= (cnt2 / 10) && (((cnt2 % 10) * (cnt2 / 10)) == cnt1)) { seki += 1; } } } Console.Write(seki.ToString()); } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
155
2
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { static List<int> Divisor(int input) { List<int> result = new List<int>(); for (int i = 1; i * i <= input; i++) { if (0 == input % i) { result.Add(i); if (i * i != input) { result.Add(input / i); } } } return result; } static int M; static int D; static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); M = int.Parse(s[0]); D = int.Parse(s[1]); int ans = 0; for (int i = 4; i <= M; i++) { List<int> d = Divisor(i); foreach (int t in d) { if (t >= 2 && t <= 9) { int o = M / t; if (o < 10 && t * 10 + o <= D) { ans++; } } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { static List<int> Divisor(int input) { List<int> result = new List<int>(); for (int i = 1; i * i <= input; i++) { if (0 == input % i) { result.Add(i); if (i * i != input) { result.Add(input / i); } } } return result; } static int M; static int D; static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); M = int.Parse(s[0]); D = int.Parse(s[1]); int ans = 0; for (int i = 4; i <= M; i++) { List<int> d = Divisor(i); foreach (int t in d) { if (t >= 2 && t <= 9) { int o = i / t; if (o >= 2 && o < 10 && t * 10 + o <= D) { ans++; } } } } Console.WriteLine(ans); } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 98]]
8
263
6
using System; namespace A___Takahashi_Calendar { class Program { static void Main(string[] args) { var MD = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var count = 0; for (int m = 1; m <= MD[0]; m++) { for (int d = 22; d < MD[1]; d++) { var d1 = d % 10; var d10 = d / 10; if (d1 >= 2 && d10 >= 2 && d1 * d10 == m) count++; } } Console.WriteLine(count); } } }
using System; namespace A___Takahashi_Calendar { class Program { static void Main(string[] args) { var MD = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); var count = 0; for (int m = 1; m <= MD[0]; m++) { for (int d = 22; d <= MD[1]; d++) { var d1 = d % 10; var d10 = d / 10; if (d1 >= 2 && d10 >= 2 && d1 * d10 == m) count++; } } Console.WriteLine(count); } } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
130
2
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; public class Solver { public void Solve() { int m = ri, d = ri; int p = 0; for (int i = 1; i <= m; i++) { for (int j = 22; j <= d; j++) { if (j % 10 >= 2 && i == (j % 20) * (j - j % 10) / 10) { p++; } } } Write(p); } int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); private const long mod = 1000000007; long Reverse(long n) { return Pow(n, mod - 2); } int Sign(int n) { return n == 0 ? 0 : n > 0 ? 1 : -1; } int Abs(int n) { return (n > 0) ? n : -n; } int Gcd(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); } int Lcm(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } int Lcm(int a, int b) { return a * b / Gcd(a, b); } int Max(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } int Min(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } long Mul(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p * n[i]) % mod; } return p; } long Pow(long n, long p) { long t = n, q = 1; while (p > 0) { if (p % 2 == 1) { q = (q * t) % mod; } t = (t * t) % mod; p >>= 1; } return q; } long PowUpper(long n, long b) { long p = 1; while (p <= n) { p *= b; } return p; } long Sign(long n) { return n == 0 ? 0 : n > 0 ? 1 : -1; } long Abs(long n) { return (n > 0) ? n : -n; } long Gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } long Gcd(long a, long b) { return (a == 0) ? b : Gcd(b % a, a); } long Lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } long Lcm(long a, long b) { return a * b / Gcd(a, b); } long Max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } long Min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } void Write<T>(T t) { Console.WriteLine(t.ToString()); } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan()); } }
using System; using System.Linq; using System.Numerics; using System.Collections.Generic; using System.IO; using System.Text; public class Solver { public void Solve() { int m = ri, d = ri; int p = 0; for (int i = 1; i <= m; i++) { for (int j = 22; j <= d; j++) { if (j % 10 >= 2 && i == (j % 10) * (j - j % 10) / 10) { p++; } } } Write(p); } int ri { get { return sc.Integer(); } } long rl { get { return sc.Long(); } } double rd { get { return sc.Double(); } } string rs { get { return sc.Scan(); } } public StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); private const long mod = 1000000007; long Reverse(long n) { return Pow(n, mod - 2); } int Sign(int n) { return n == 0 ? 0 : n > 0 ? 1 : -1; } int Abs(int n) { return (n > 0) ? n : -n; } int Gcd(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } int Gcd(int a, int b) { return (a == 0) ? b : Gcd(b % a, a); } int Lcm(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } int Lcm(int a, int b) { return a * b / Gcd(a, b); } int Max(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } int Min(params int[] n) { int p = n[0]; for (int i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } long Mul(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p * n[i]) % mod; } return p; } long Pow(long n, long p) { long t = n, q = 1; while (p > 0) { if (p % 2 == 1) { q = (q * t) % mod; } t = (t * t) % mod; p >>= 1; } return q; } long PowUpper(long n, long b) { long p = 1; while (p <= n) { p *= b; } return p; } long Sign(long n) { return n == 0 ? 0 : n > 0 ? 1 : -1; } long Abs(long n) { return (n > 0) ? n : -n; } long Gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = Gcd(p, n[i]); } return p; } long Gcd(long a, long b) { return (a == 0) ? b : Gcd(b % a, a); } long Lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = Lcm(p, n[i]); } return p; } long Lcm(long a, long b) { return a * b / Gcd(a, b); } long Max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p > n[i]) ? p : n[i]; } return p; } long Min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p < n[i]) ? p : n[i]; } return p; } void Write<T>(T t) { Console.WriteLine(t.ToString()); } void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); } void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); } void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); } } static class Program { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public int Integer() { return (int)Long(); } public double Double() { return double.Parse(Scan()); } }
[["-", 12, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 12, 203]]
8
1,515
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; public class Hello { public static void Main() { int[] read = inta(); int[] list = inta(); int fir = 0; int sec = 0; for (int i = 0; i < read[0]; i++) { for (int j = i + 1; j < read[0]; j++) { if (list[i] > list[j]) { fir++; } } } for (int i = 0; i < read[0]; i++) { for (int j = 0; j < read[0]; j++) { if (list[i] > list[j]) { sec++; } } } // fir * n + sec * 1/2 * n * n-1 long ans = 0; ans += (fir * read[1]) % 1000000007; ans += (read[1] * (read[1] - 1) / 2) % 1000000007 * sec; WriteLine(ans % 1000000007); } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // A/B小数点以下切上 static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // スタック -> 深さ優先 ???
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; public class Hello { public static void Main() { long[] read = longa(); int[] list = inta(); long fir = 0; long sec = 0; for (int i = 0; i < read[0]; i++) { for (int j = i + 1; j < read[0]; j++) { if (list[i] > list[j]) { fir++; } } } for (int i = 0; i < read[0]; i++) { for (int j = 0; j < read[0]; j++) { if (list[i] > list[j]) { sec++; } } } // WriteLine(fir); // WriteLine(sec); // fir * n + sec * 1/2 * n * n-1 long ans = 0; ans += (fir * read[1]) % 1000000007; ans += (read[1] * (read[1] - 1) / 2) % 1000000007 * sec; WriteLine(ans % 1000000007); } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // A/B小数点以下切上 static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // スタック -> 深さ優先 ???
[["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["+", 0, 198, 0, 200, 0, 212, 0, 213, 63, 22], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
758
8
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { var RL = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); var N = RL[0]; var K = RL[1]; var A = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); var mod = 1000000007; var a1 = new long[N]; var a2 = new long[N]; for (var i = 0; i < N; i++) { a1[i] = A.Skip(i).Take((int)N - i).Count(x => x < A[i]); a2[i] = A.Count(x => x < A[i]); } var t1 = ((a1.Sum() * K)) % mod; var t2 = (a2.Sum() * (((K - 1) * K) % mod) / 2) % mod; var ans = (t1 + t2) % mod; Console.Write(ans); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class1 { static void Main(string[] args) { var RL = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); var N = RL[0]; var K = RL[1]; var A = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); var mod = 1000000007; var a1 = new long[N]; var a2 = new long[N]; for (var i = 0; i < N; i++) { a1[i] = A.Skip(i).Take((int)N - i).Count(x => x < A[i]); a2[i] = A.Count(x => x < A[i]); } var t1 = ((a1.Sum() * K)) % mod; var t2 = (a2.Sum() * (((K - 1) * K) / 2 % mod)) % mod; var ans = (t1 + t2) % mod; Console.Write(ans); } } }
[["+", 0, 16, 12, 23, 0, 16, 31, 16, 17, 85], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 17, 85], ["-", 0, 212, 0, 16, 31, 23, 0, 16, 12, 203]]
8
263
4
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var NK = Sarray(); var N = NK[0]; var K = NK[1]; var Ai = Sarray(); var ans = 0L; for (var i = 0; i < N; ++i) { ans = (ans + Ai.Count(a => Ai[i] > a) * ((K - 1) * K / 2) % Mod) % Mod; ans = (ans + Ai.Skip(i).Count(a => Ai[i] > a) * K % Mod) % Mod; } WriteLine(ans); // Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var NK = Sarray(); var N = NK[0]; var K = NK[1]; var Ai = Sarray(); var ans = 0L; for (var i = 0; i < N; ++i) { ans = (ans + (Ai.Count(a => Ai[i] > a) * ((K - 1) * K / 2 % Mod)) % Mod) % Mod; ans = (ans + Ai.Skip(i).Count(a => Ai[i] > a) * K % Mod) % Mod; } WriteLine(ans); // Out.Flush(); } } }
[["+", 31, 23, 0, 16, 12, 16, 31, 23, 0, 24], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 17, 109], ["+", 31, 23, 0, 16, 12, 23, 0, 16, 12, 22], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
8
253
4
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var NK = Sarray(); var N = NK[0]; var K = NK[1]; var Ai = Sarray(); var ans = 0L; for (var i = 0; i < N; ++i) { //くり返し部分 var rep = 0L; for (var j = i + 1; j < i + N; ++j) if (Ai[i] > Ai[j % N]) ++rep; //しっぽの部分 var zan = 0L; for (var j = i + 1; j < N; ++j) if (Ai[i] > Ai[j % N]) ++zan; ans = (ans + (zan * K) % Mod) % Mod; ans = (ans + (rep * (K * (K - 1) / 2) % Mod) % Mod) % Mod; } WriteLine(ans % Mod); // Out.Flush(); } } }
using System; using System.Linq; using System.Collections.Generic; using static System.Console; using System.Text; using System.IO; using static System.Math; namespace AtCoder { class Program { static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); } static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); } static long Mod = (long)1e9 + 7; static void Main(string[] args) { // SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var NK = Sarray(); var N = NK[0]; var K = NK[1]; var Ai = Sarray(); var ans = 0L; for (var i = 0; i < N; ++i) { //くり返し部分 var rep = 0L; for (var j = i + 1; j < i + N; ++j) if (Ai[i] > Ai[j % N]) ++rep; //しっぽの部分 var zan = 0L; for (var j = i + 1; j < N; ++j) if (Ai[i] > Ai[j % N]) ++zan; ans = (ans + (zan * K) % Mod) % Mod; ans = (ans + (rep * ((K * (K - 1) / 2) % Mod)) % Mod) % Mod; } WriteLine(ans % Mod); // Out.Flush(); } } }
[["+", 0, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
8
312
2
using System; public class Hello { public static int MOD = 1000000007; static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); var s = Console.ReadLine().Trim(); line = s.Split(' '); var a = Array.ConvertAll(line, int.Parse); var count = 0; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) if (a[i] > a[j]) count++; line = (s + " " + s).Split(' '); var b = Array.ConvertAll(line, int.Parse); var count2 = 0; for (int i = 0; i < n; i++) for (int j = n; j < 2 * n; j++) if (b[i] > b[j]) count2++; var ans = 43 * (long)k % MOD; var ans2 = 45 * (long)k % MOD; ans2 *= k - 1; ans2 %= MOD; var Inv2 = getInv(2, MOD); ans2 = ans2 * Inv2 % MOD; ans += ans2; ans %= MOD; Console.WriteLine(ans); } public static long getInv(int a, int m) { var x = 0L; var y = 1L; var gcd = (long)m; var px = 1L; var py = 0L; var pgcd = (long)a; var temp = 0L; while (gcd > 0) { var quotient = pgcd / gcd; temp = x; x = px - quotient * temp; px = temp; temp = y; y = py - quotient * temp; py = temp; temp = gcd; gcd = pgcd - quotient * temp; pgcd = temp; } return px < 0 ? px + m : px; } }
using System; public class Hello { public static int MOD = 1000000007; static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var k = int.Parse(line[1]); var s = Console.ReadLine().Trim(); line = s.Split(' '); var a = Array.ConvertAll(line, int.Parse); var count = 0; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) if (a[i] > a[j]) count++; line = (s + " " + s).Split(' '); var b = Array.ConvertAll(line, int.Parse); var count2 = 0; for (int i = 0; i < n; i++) for (int j = n; j < 2 * n; j++) if (b[i] > b[j]) count2++; var ans = count * (long)k % MOD; var ans2 = count2 * (long)k % MOD; ans2 *= k - 1; ans2 %= MOD; var Inv2 = getInv(2, MOD); ans2 = ans2 * Inv2 % MOD; ans += ans2; ans %= MOD; Console.WriteLine(ans); } public static long getInv(int a, int m) { var x = 0L; var y = 1L; var gcd = (long)m; var px = 1L; var py = 0L; var pgcd = (long)a; var temp = 0L; while (gcd > 0) { var quotient = pgcd / gcd; temp = x; x = px - quotient * temp; px = temp; temp = y; y = py - quotient * temp; py = temp; temp = gcd; gcd = pgcd - quotient * temp; pgcd = temp; } return px < 0 ? px + m : px; } }
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 31, 203], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 31, 22]]
8
438
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { Scanner cin = new Scanner(); long n = cin.Long(); long k = cin.Long(); long[] a = cin.ArrayLong((int)n); long[] pre = new long[n]; long[] post = new long[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) { continue; } if (j < i) { if (a[i] > a[j]) { pre[i]++; } } else { if (a[i] > a[j]) { post[i]++; } } } } long ans = 0; for (int i = 0; i < n; i++) { ans = (ans + (((k * (k + 1) / 2) * MOD) * post[i] % MOD)) % MOD; ans = (ans + (((k * (k - 1) / 2) % MOD) * pre[i] % MOD)) % MOD; } Console.WriteLine(ans); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { const long MOD = 1000000007; static void Main(string[] args) { Scanner cin = new Scanner(); long n = cin.Long(); long k = cin.Long(); long[] a = cin.ArrayLong((int)n); long[] pre = new long[n]; long[] post = new long[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) { continue; } if (j < i) { if (a[i] > a[j]) { pre[i]++; } } else { if (a[i] > a[j]) { post[i]++; } } } } long ans = 0; for (int i = 0; i < n; i++) { ans = (ans + (((k * (k + 1) / 2) % MOD) * post[i] % MOD)) % MOD; ans = (ans + (((k * (k - 1) / 2) % MOD) * pre[i] % MOD)) % MOD; } Console.WriteLine(ans); } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
[["-", 0, 16, 31, 16, 31, 23, 0, 16, 17, 48], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 109]]
8
664
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { string[] p2 = Console.ReadLine().Split(' '); int N = int.Parse(p2[0]); int K = int.Parse(p2[1]); string[] As = Console.ReadLine().Split(' '); int[] A = new int[N]; int[] T = new int[N]; int[] L = new int[N]; for (var i = 0; i < N; i++) { A[i] = int.Parse(As[i]); } for (var i = 0; i < N; i++) { for (var j = 0; j < N; j++) { if (A[j] < A[i]) { if (j < i) L[i]++; T[i]++; } } } long ans = 0; long it = (long)(K + 1) * K / 2; it = it % 1000000007; for (var i = 0; i < N; i++) { long add = ((it * T[i]) % 1000000007 + 1000000007) - (K * L[i]) % 1000000007; ans += add % 1000000007; ans = ans % 1000000007; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace AtCoder { class Program { static void Main(string[] args) { string[] p2 = Console.ReadLine().Split(' '); int N = int.Parse(p2[0]); int K = int.Parse(p2[1]); string[] As = Console.ReadLine().Split(' '); int[] A = new int[N]; int[] T = new int[N]; int[] L = new int[N]; for (var i = 0; i < N; i++) { A[i] = int.Parse(As[i]); } for (var i = 0; i < N; i++) { for (var j = 0; j < N; j++) { if (A[j] < A[i]) { if (j < i) L[i]++; T[i]++; } } } long ans = 0; long it = (long)(K + 1) * K / 2; it = it % 1000000007; for (var i = 0; i < N; i++) { long add = ((it * T[i]) % 1000000007 + 1000000007) - ((long)K * L[i]) % 1000000007; ans += add % 1000000007; ans = ans % 1000000007; } Console.WriteLine(ans); } } }
[["+", 12, 16, 31, 23, 0, 16, 31, 74, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 31, 74, 39, 199], ["+", 12, 16, 31, 23, 0, 16, 31, 74, 0, 25]]
8
320
3
using System; namespace B___Kleene_Inversion { class Program { static void Main(string[] args) { var NK = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var N = NK[0]; var K = NK[1]; var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var MOD = 1000000007; var invert = new long[N]; for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) if (A[i] > A[j]) invert[i]++; var lessCount = new long[N]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (i != j && A[i] > A[j]) lessCount[i]++; long result = 0; for (int i = 0; i < N; i++) { result = (result + (invert[i] * K) % MOD) % MOD; result = (result + (lessCount[i] * ((K * K - K) % MOD) / 2) % MOD) % MOD; } Console.WriteLine(result); } } }
using System; namespace B___Kleene_Inversion { class Program { static void Main(string[] args) { var NK = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var N = NK[0]; var K = NK[1]; var A = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse); var MOD = 1000000007; var invert = new long[N]; for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) if (A[i] > A[j]) invert[i]++; var lessCount = new long[N]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (i != j && A[i] > A[j]) lessCount[i]++; long result = 0; for (int i = 0; i < N; i++) { result = (result + (invert[i] * K) % MOD) % MOD; result = (result + (lessCount[i] * ((K * K - K) / 2 % MOD)) % MOD) % MOD; } Console.WriteLine(result % MOD); } } }
[["+", 0, 16, 12, 23, 0, 16, 31, 16, 17, 85], ["+", 0, 16, 12, 23, 0, 16, 31, 16, 12, 203], ["-", 0, 16, 12, 16, 31, 23, 0, 16, 17, 85], ["-", 0, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
287
6
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { int[] tmp = ReadIntArray(); int n = tmp[0], k = tmp[1]; int[] a = ReadIntArray(); const int M = 1000000007; long na = 0, nb = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) na++; if (a[i] < a[j]) nb++; } } long ans = (k * (k - 1) / 2 * (na + nb)) % M + k * na % M; WriteLine(ans % M); } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Runtime.CompilerServices; using static MyUtil; class MyUtil { public static int[] ReadIntArray() { return ReadLine().Split().Select(x => int.Parse(x)).ToArray(); } } class Program { public static void Main() { int[] tmp = ReadIntArray(); long n = tmp[0], k = tmp[1]; int[] a = ReadIntArray(); const int M = 1000000007; long na = 0, nb = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) na++; if (a[i] < a[j]) nb++; } } long ans = k * (k - 1) / 2 % M * (na + nb) % M + k * na % M; WriteLine(ans % M); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 212, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["-", 31, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
8
233
6
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { private const int M = 1000000007; // 素数(int範囲) static int N; static int K; static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); N = int.Parse(s[0]); K = int.Parse(s[1]); int[] v = new int[N]; s = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { v[i] = int.Parse(s[i]); } int left = 0; int right = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (v[i] < v[j]) { left++; } else if (v[i] > v[j]) { right++; } } } int ans; checked { int m = K; m *= (K + 1); m /= 2; m %= M; int m0 = (K - 1); m0 *= K; m0 /= 2; m0 %= M; ans = right * m; ans %= M; ans += left * m0; ans %= M; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Text; using System.Numerics; using System.IO; namespace SolutionCS { class Program { private const long M = 1000000007; // 素数(int範囲) static int N; static int K; static void Main(string[] args) { string[] s = Console.ReadLine().Split(' '); N = int.Parse(s[0]); K = int.Parse(s[1]); int[] v = new int[N]; s = Console.ReadLine().Split(' '); for (int i = 0; i < N; i++) { v[i] = int.Parse(s[i]); } int left = 0; int right = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if (v[i] < v[j]) { left++; } else if (v[i] > v[j]) { right++; } } } long ans; checked { long m = K; m *= (K + 1); m /= 2; m %= M; long m0 = (K - 1); m0 *= K; m0 /= 2; m0 %= M; ans = right * m; ans %= M; ans += left * m0; ans %= M; } Console.WriteLine(ans); } } }
[["-", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["+", 0, 235, 8, 201, 0, 124, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 287, 0, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 287, 0, 196, 0, 197, 0, 198, 39, 199]]
8
313
8
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { partial class Program { static void Main(string[] args) { //↓ var nk = ReadIntArray(); var n = nk[0]; long k = nk[1]; var aas = ReadIntArray(); var p = 1000000000 + 7; var l = new List<int>(); long r = 0; long kkm12, kkp12; if (k % 2 == 0) { kkm12 = k / 2 * (k - 1) % p; kkp12 = k / 2 * (k + 1) % p; } else { kkm12 = k * (k - 1) / 2 % p; kkp12 = k * (k + 1) / 2 % p; } for (int i = 0; i < n; i++) { var c = aas[i]; long scount = -1; long lcount = -1; for (int j = 0; j < l.Count; j++) { var cc = l[j]; if (scount < 0) { if (j == l.Count - 1 && cc < c) { scount = l.Count; } else if (cc >= c) { scount = j; } } if (cc > c) { lcount = l.Count - j; break; } } scount = Math.Max(scount, 0); lcount = Math.Max(lcount, 0); l.Insert(Math.Max((int)scount - 1, 0), c); r = (r + (scount * kkm12 % p)) % p; r = (r + (lcount * kkp12 % p)) % p; } Console.WriteLine(r); //↑ } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).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; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> 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); } 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() { 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; } } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { partial class Program { static void Main(string[] args) { //↓ var nk = ReadIntArray(); var n = nk[0]; long k = nk[1]; var aas = ReadIntArray(); var p = 1000000000 + 7; var l = new List<int>(); long r = 0; long kkm12, kkp12; if (k % 2 == 0) { kkm12 = k / 2 * (k - 1) % p; kkp12 = k / 2 * (k + 1) % p; } else { kkm12 = k * (k - 1) / 2 % p; kkp12 = k * (k + 1) / 2 % p; } for (int i = 0; i < n; i++) { var c = aas[i]; long scount = -1; long lcount = -1; for (int j = 0; j < l.Count; j++) { var cc = l[j]; if (scount < 0) { if (j == l.Count - 1 && cc < c) { scount = l.Count; } else if (cc >= c) { scount = j; } } if (cc > c) { lcount = l.Count - j; break; } } scount = Math.Max(scount, 0); lcount = Math.Max(lcount, 0); l.Insert(Math.Max((int)scount, 0), c); r = (r + (scount * kkm12 % p)) % p; r = (r + (lcount * kkp12 % p)) % p; } Console.WriteLine(r); //↑ } static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).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; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> 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); } 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() { 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; } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
988
2
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp11 { class Class35 { static void Main() { int N = int.Parse(Console.ReadLine()); Dictionary<string, int> Table = new Dictionary<string, int>(); for (int i = 0; i < N; i++) { string read = string.Join("", Console.ReadLine().OrderBy(x => x).ToArray()); if (Table.Keys.Contains(read)) { Table[read] += 1; } else { Table[read] = 0; } } long ans = Table.Values.Sum(x => x * (x + 1) / 2); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApp11 { class Class35 { static void Main() { int N = int.Parse(Console.ReadLine()); Dictionary<string, long> Table = new Dictionary<string, long>(); for (int i = 0; i < N; i++) { string read = string.Join("", Console.ReadLine().OrderBy(x => x).ToArray()); if (Table.Keys.Contains(read)) { Table[read] += 1; } else { Table[read] = 0; } } long ans = Table.Values.Sum(x => x * (x + 1) / 2); Console.WriteLine(ans); } } }
[["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
165
4
using System; using System.Collections.Generic; using System.Linq; using System.Diagnostics; class Program { static void Main(string[] args) { const long MOD = 1000000007; var sc = new Scanner(); int n = sc.nextInt(); var s = new Dictionary<string, int>(); for (int i = 0; i < n; i++) { char[] cin = sc.next().ToCharArray(); Array.Sort(cin); if (s.ContainsKey(new string(cin))) s[new string(cin)]++; else s.Add(new string(cin), 1); } long ans = 0; foreach (var item in s) { if (item.Value != 1) ans += (item.Value) * (item.Value - 1) / 2; } Console.SetOut(new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }); Console.WriteLine(ans); Console.Out.Flush(); } } // chokudai's Scanner 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.Generic; using System.Linq; using System.Diagnostics; class Program { static void Main(string[] args) { const long MOD = 1000000007; var sc = new Scanner(); int n = sc.nextInt(); var s = new Dictionary<string, long>(); for (int i = 0; i < n; i++) { char[] cin = sc.next().ToCharArray(); Array.Sort(cin); if (s.ContainsKey(new string(cin))) s[new string(cin)]++; else s.Add(new string(cin), 1); } long ans = 0; foreach (var item in s) { if (item.Value != 1) ans += (item.Value) * (item.Value - 1) / 2; } Console.SetOut(new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }); Console.WriteLine(ans); Console.Out.Flush(); } } // chokudai's Scanner 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, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
576
2
using System; using System.Collections.Generic; namespace CSharp { class Program { public static void Main() { var N = int.Parse(Console.ReadLine()); var dic = new Dictionary<string, int>(); var result = 0; 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); } } }
using System; using System.Collections.Generic; namespace CSharp { class Program { public static void Main() { var N = int.Parse(Console.ReadLine()); var dic = new Dictionary<string, int>(); long result = 0; 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); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
148
2
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("3"); WillReturn.Add("acornistnt"); WillReturn.Add("peanutbomb"); WillReturn.Add("constraint"); // 1 } else if (InputPattern == "Input2") { WillReturn.Add("2"); WillReturn.Add("oneplustwo"); WillReturn.Add("ninemodsix"); // 0 } else if (InputPattern == "Input3") { WillReturn.Add("5"); WillReturn.Add("abaaaaaaaa"); WillReturn.Add("oneplustwo"); WillReturn.Add("aaaaaaaaba"); WillReturn.Add("twoplusone"); WillReturn.Add("aaaabaaaaa"); // 4 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { checked { List<string> InputList = GetInputList(); var SDict = new Dictionary<string, int>(); for (int I = 1; I <= InputList.Count - 1; I++) { char[] wkArr = InputList[I].ToCharArray(); Array.Sort(wkArr); string SortedStr = new string(wkArr); if (SDict.ContainsKey(SortedStr)) { SDict[SortedStr]++; } else { SDict[SortedStr] = 1; } } int MaxCnt = SDict.Values.Max(); //三角数の値を求める var SankakuDict = new Dictionary<int, int>(); int SankakuSum = 0; for (int I = 1; I <= MaxCnt; I++) { SankakuSum += I; SankakuDict[I] = SankakuSum; } long Answer = 0; foreach (var EachPair in SDict) { if (EachPair.Value == 1) continue; Answer += SankakuDict[EachPair.Value - 1]; } Console.WriteLine(Answer); } } }
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("3"); WillReturn.Add("acornistnt"); WillReturn.Add("peanutbomb"); WillReturn.Add("constraint"); // 1 } else if (InputPattern == "Input2") { WillReturn.Add("2"); WillReturn.Add("oneplustwo"); WillReturn.Add("ninemodsix"); // 0 } else if (InputPattern == "Input3") { WillReturn.Add("5"); WillReturn.Add("abaaaaaaaa"); WillReturn.Add("oneplustwo"); WillReturn.Add("aaaaaaaaba"); WillReturn.Add("twoplusone"); WillReturn.Add("aaaabaaaaa"); // 4 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { checked { List<string> InputList = GetInputList(); var SDict = new Dictionary<string, int>(); for (int I = 1; I <= InputList.Count - 1; I++) { char[] wkArr = InputList[I].ToCharArray(); Array.Sort(wkArr); string SortedStr = new string(wkArr); if (SDict.ContainsKey(SortedStr)) { SDict[SortedStr]++; } else { SDict[SortedStr] = 1; } } int MaxCnt = SDict.Values.Max(); //三角数の値を求める var SankakuDict = new Dictionary<int, long>(); long SankakuSum = 0; for (int I = 1; I <= MaxCnt; I++) { SankakuSum += I; SankakuDict[I] = SankakuSum; } long Answer = 0; foreach (var EachPair in SDict) { if (EachPair.Value == 1) continue; Answer += SankakuDict[EachPair.Value - 1]; } Console.WriteLine(Answer); } } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 0, 287, 0, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 287, 0, 196, 0, 197, 0, 198, 39, 199]]
8
439
4
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var sArray = new string[n]; for (var i = 0; i < n; i++) { var arr = Console.ReadLine().ToArray(); Array.Sort(arr); sArray[i] = new string(arr); } // var count = (long)0; // for (int i = 0; i < n - 1; i++) //{ // var si = sArray[i]; // for (int j = i + 1; j < n; j++) // { // var sj = sArray[j]; // if (si == sj) // { // count++; // } // } //} long count = 0; var groups = sArray.GroupBy(s => s); foreach (var group in groups) { var groupCount = group.Count(); count += groupCount * (groupCount - 1) / 2; } //出力 Console.WriteLine(count.ToString()); // Console.ReadLine(); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var sArray = new string[n]; for (var i = 0; i < n; i++) { var arr = Console.ReadLine().ToArray(); Array.Sort(arr); sArray[i] = new string(arr); } long count = 0; var groups = sArray.GroupBy(s => s); foreach (var group in groups) { long groupCount = group.Count(); count += groupCount * (groupCount - 1) / (long)2; } //出力 Console.WriteLine(count.ToString()); // Console.ReadLine(); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 39, 199], ["+", 0, 1, 0, 11, 12, 16, 12, 74, 0, 25]]
8
177
5
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(); var dict = new Dictionary<string, int>(); var ans = 0; for (int i = 0; i < n; i++) { var s = cin.next().ToCharArray(); Array.Sort(s); var ss = new string(s); if (dict.ContainsKey(ss)) { dict[ss]++; ans += dict[ss]; } else { dict.Add(ss, 0); } } Console.WriteLine(ans); } } static class C { public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } } static class Subsequence { /// <summary> /// 最長増加部分列 /// </summary> /// <param name="a">long[]</param> /// <returns></returns> public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[C.LowerBound(dp, a[i])] = a[i]; } return C.LowerBound(dp, long.MaxValue - 1); } } 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(); var dict = new Dictionary<string, long>(); long ans = 0; for (int i = 0; i < n; i++) { var s = cin.next().ToCharArray(); Array.Sort(s); var ss = new string(s); if (dict.ContainsKey(ss)) { dict[ss]++; ans += dict[ss]; } else { dict.Add(ss, 0); } } Console.WriteLine(ans); } } static class C { public static long LowerBound(long[] a, long key) { long l = 0; long r = a.Length; long mid; while (l < r) { mid = ((r - l) / 2) + l; if (a[mid] <= key) l = mid + 1; else r = mid; } return l; } } static class Subsequence { /// <summary> /// 最長増加部分列 /// </summary> /// <param name="a">long[]</param> /// <returns></returns> public static long LIS(long[] a) { var dp = Enumerable.Range(0, a.Length).Select(x => long.MaxValue).ToArray(); for (int i = 0; i < a.Length; i++) { dp[C.LowerBound(dp, a[i])] = a[i]; } return C.LowerBound(dp, long.MaxValue - 1); } } 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, 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]]
8
705
4
using System; using System.Linq; using System.Collections.Generic; class Program { public static void Main() { int N = Int32.Parse(Console.ReadLine()); string[] stList = new string[N]; Dictionary<string, int> checkList = new Dictionary<string, int>(); for (int i = 0; i < N; i++) { stList[i] = Console.ReadLine(); } int ans = 0; for (int j = 0; j < N; j++) { var h1 = stList[j].ToArray(); Array.Sort(h1); string k = String.Join("", (h1)); if (checkList.ContainsKey(k)) { ans += checkList[k]; checkList[k] += 1; } else { checkList.Add(k, 1); } } Console.WriteLine(ans); } }
using System; using System.Linq; using System.Collections.Generic; class Program { public static void Main() { long N = long.Parse(Console.ReadLine()); string[] stList = new string[N]; Dictionary<string, long> checkList = new Dictionary<string, long>(); for (int i = 0; i < N; i++) { stList[i] = Console.ReadLine(); } long ans = 0; for (int j = 0; j < N; j++) { var h1 = stList[j].ToArray(); Array.Sort(h1); string k = String.Join("", (h1)); if (checkList.ContainsKey(k)) { ans += checkList[k]; checkList[k] += 1; } else { checkList.Add(k, 1); } } Console.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, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
196
10
using System; using System.Collections.Generic; using System.Globalization; namespace AtCoder { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Dictionary<string, int> dic = new Dictionary<string, int>(); long cnt = 0L; for (int i = 0; i < n; i++) { char[] arr = Console.ReadLine().ToCharArray(); Array.Sort(arr); string str = new string(arr); if (dic.ContainsKey(str)) { dic[str]++; } else { dic.Add(str, 0); } } foreach (string s in dic.Keys) { int num = dic[s]; cnt += num * (num + 1) / 2; } Console.WriteLine(cnt); } } }
using System; using System.Collections.Generic; using System.Globalization; namespace AtCoder { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Dictionary<string, int> dic = new Dictionary<string, int>(); long cnt = 0L; for (int i = 0; i < n; i++) { char[] arr = Console.ReadLine().ToCharArray(); Array.Sort(arr); string str = new string(arr); if (dic.ContainsKey(str)) { dic[str]++; } else { dic.Add(str, 0); } } foreach (string s in dic.Keys) { long num = dic[s]; cnt += num * (num + 1) / 2; } Console.WriteLine(cnt); } } }
[["-", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 210, 8, 196, 0, 197, 0, 198, 39, 199]]
8
185
2
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { int N = int.Parse(Console.ReadLine().Trim()); // List<string> str = new List<string>(); var str = new Dictionary<string, int>(); // string[] str = new string[N]; int count = 0; for (var i = 0; i < N; i++) { string s = Console.ReadLine().Trim(); char[] c = new char[s.Length]; c = s.ToCharArray(); Array.Sort(c); s = new string(c); if (str.ContainsKey(s)) { count += str[s]; str[s] += 1; } else { str.Add(s, 1); } // count += str.Count(x => x == s); // str.Add(s); // str[i] = s; } Console.WriteLine(count); } }
using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { int N = int.Parse(Console.ReadLine().Trim()); var str = new Dictionary<string, long>(); long count = 0; for (var i = 0; i < N; i++) { string s = Console.ReadLine().Trim(); char[] c = new char[s.Length]; c = s.ToCharArray(); Array.Sort(c); s = new string(c); if (str.ContainsKey(s)) { count += str[s]; str[s] += 1; } else { str.Add(s, 1); } } Console.WriteLine(count); } }
[["-", 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], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
176
4
using System; using System.Collections.Generic; class project { static void Main() { int num = int.Parse(Console.ReadLine()); var result = new Dictionary<string, int>(); for (int i = 1; i < num + 1; i++) { char[] input = Console.ReadLine().ToCharArray(); Array.Sort(input); string sortedInput = string.Join("", input); if (!result.ContainsKey(sortedInput)) { result.Add(sortedInput, 1); } else { result[sortedInput]++; } } long count = 0; foreach (int val in result.Values) { if (val != 0) { count += val * (val - 1) / 2; } } Console.WriteLine(count); } }
using System; using System.Collections.Generic; class project { static void Main() { int num = int.Parse(Console.ReadLine()); var result = new Dictionary<string, long>(); for (long i = 1; i < num + 1; i++) { char[] input = Console.ReadLine().ToCharArray(); Array.Sort(input); string sortedInput = string.Join("", input); if (!result.ContainsKey(sortedInput)) { result.Add(sortedInput, 1); } else { result[sortedInput]++; } } long count = 0; foreach (long val in result.Values) { if (val != 0) { count += val * (val - 1) / 2; } } Console.WriteLine(count); } }
[["-", 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, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199], ["+", 8, 201, 0, 195, 8, 196, 0, 210, 39, 199]]
8
174
6
using System; using System.Collections.Generic; using System.Linq; namespace C { class Program { static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine()); string[] S = new string[N]; for (var i = 0; i < N; i++) { char[] c = Console.ReadLine().ToCharArray(); Array.Sort(c); S[i] = new string(c); } Dictionary<string, int> dict = new Dictionary<string, int>(); for (var i = 0; i < N; i++) { if (dict.ContainsKey(S[i])) { dict[S[i]]++; } else { dict[S[i]] = 1; } } int res = 0; foreach (var i in dict) { if (i.Value > 1) { res += i.Value * (i.Value - 1) / 2; } } Console.WriteLine(res); } } }
using System; using System.Collections.Generic; using System.Linq; namespace C { class Program { static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine()); string[] S = new string[N]; for (var i = 0; i < N; i++) { char[] c = Console.ReadLine().ToCharArray(); Array.Sort(c); S[i] = new string(c); } Dictionary<string, long> dict = new Dictionary<string, long>(); for (var i = 0; i < N; i++) { if (dict.ContainsKey(S[i])) { dict[S[i]]++; } else { dict[S[i]] = 1L; } } long res = 0L; foreach (var i in dict) { if (i.Value > 1) { res += i.Value * (i.Value - 1) / 2; } } 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, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 203], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
225
10
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; void calc() { cin = new Scanner(); int N = cin.nextInt(); var x = new Dictionary<string, long>(); long ans = 0; for (int i = 0; i < N; i++) { char[] s = cin.next().ToCharArray(); Array.Sort(s); string s2 = new String(s); if (x.ContainsKey(s2)) { ans += x[s2]; x[s2]++; } else x.Add(s2, 0); } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
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; void calc() { cin = new Scanner(); int N = cin.nextInt(); var x = new Dictionary<string, long>(); long ans = 0; for (int i = 0; i < N; i++) { char[] s = cin.next().ToCharArray(); Array.Sort(s); string s2 = new String(s); if (x.ContainsKey(s2)) { ans += x[s2]; x[s2]++; } else x.Add(s2, 1); } Console.WriteLine(ans); } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; string st = Console.ReadLine(); while (st == "") st = Console.ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); if (s.Length == 0) return next(); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = nextInt() + add; } return Array; } public long nextLong() { return long.Parse(next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = nextLong() + add; } return Array; } public double nextDouble() { return double.Parse(next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = nextDouble() + add; } return Array; } } class Answer { public static void Int2DArrayAns(int[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } // Answer.IntArrayAns(x); public static void Char2DArrayAns(char[,] x, char c) { for (int i = 0; i < x.GetLength(0); i++) { for (int j = 0; j < x.GetLength(1) - 1; j++) { Console.Write(x[i, j]); Console.Write(c); } Console.WriteLine(x[i, x.GetLength(1) - 1]); } } } class Func { public long GCDLong(long a, long b) { while (a != 0) { long t = a; a = b % a; b = t; } return b; } }
[["-", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 75, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
791
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); var N = sc.Int1; var s = new Dictionary<string, int>(); for (int i = 0; i < N; ++i) { var ss = sc.Str.ToCharArray(); Array.Sort(ss); var sss = new string(ss); if (!s.ContainsKey(sss)) s.Add(sss, 1); else s[sss]++; } long ans = 0; foreach (var x in s) { ans += x.Value * (x.Value - 1) / 2; } wr.wri(ans); } static int factmod(int X) { int ret = 1; for (int i = 1; i <= X; ++i) { ret *= i; ret %= MOD; } return ret; } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { const int MOD = 1000000007; const int INF = 1 << 30; static void Main(string[] args) { Solve(); } static void Solve() { Scaner sc = new Scaner(); write wr = new write(); //ここから var N = sc.Int1; var s = new Dictionary<string, long>(); for (int i = 0; i < N; ++i) { var ss = sc.Str.ToCharArray(); Array.Sort(ss); var sss = new string(ss); if (!s.ContainsKey(sss)) s.Add(sss, 1); else s[sss]++; } long ans = 0; foreach (var x in s) { ans += (x.Value * (x.Value - 1) / 2); } wr.wri(ans); //ここまで } static int factmod(int X) { int ret = 1; for (int i = 1; i <= X; ++i) { ret *= i; ret %= MOD; } return ret; } } class Scaner { public string Str => Console.ReadLine(); public string[] StrArr => Str.Split(' '); public long[] LongArr => StrArr.Select(long.Parse).ToArray(); public int[] IntArr => StrArr.Select(int.Parse).ToArray(); public char[] CharArr => Str.ToArray(); public long Long1 => LongArr[0]; public int Int1 => IntArr[0]; } class write { public void wri<T>(T x) { Console.WriteLine(x); } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 24], ["+", 8, 196, 0, 1, 0, 11, 12, 23, 0, 25]]
8
370
4
using System; using System.Collections.Generic; using System.Linq; class Procon { public Procon() {} static void Main(string[] agrs) { new Procon().Do(); } Scanner cin; public void Do() { cin = new Scanner(); int N = cin.nextInt(); Dictionary<string, int> dict = new Dictionary<string, int>(); for (int i = 0; i < N; i++) { string s = cin.nextString(); var c = s.ToCharArray(); Array.Sort(c); string s2 = new String(c); if (dict.ContainsKey(s2)) { dict[s2]++; } else { dict[s2] = 1; } } int[] num = dict.Values.ToArray(); long ans = 0; for (int i = 0; i < num.Length; i++) { ans += (num[i] * (num[i] - 1)) / 2; } Console.WriteLine(ans); } } class Scanner { string[] s; int i; int max_i; public Scanner() { s = new string[0]; max_i = 0; i = 0; } public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } else { return s[i++]; } } public int nextInt() { return int.Parse(nextString()); } public long nextLong() { return long.Parse(nextString()); } public double nextDouble() { return double.Parse(nextString()); } public string[] arrayString() { return Console.ReadLine().Split(' '); } public int[] arrayInt() { string[] str = Console.ReadLine().Split(' '); int[] array = new int[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = int.Parse(str[i]); } return array; } public long[] arrayLong() { string[] str = Console.ReadLine().Split(' '); long[] array = new long[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = long.Parse(str[i]); } return array; } public double[] arrayDouble() { string[] str = Console.ReadLine().Split(' '); double[] array = new double[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = double.Parse(str[i]); } return array; } }
using System; using System.Collections.Generic; using System.Linq; class Procon { public Procon() {} static void Main(string[] agrs) { new Procon().Do(); } Scanner cin; public void Do() { cin = new Scanner(); int N = cin.nextInt(); Dictionary<string, long> dict = new Dictionary<string, long>(); for (int i = 0; i < N; i++) { string s = cin.nextString(); var c = s.ToCharArray(); Array.Sort(c); string s2 = new String(c); if (dict.ContainsKey(s2)) { dict[s2]++; } else { dict[s2] = 1; } } long[] num = dict.Values.ToArray(); long ans = 0; for (int i = 0; i < num.Length; i++) { ans += (num[i] * (num[i] - 1)) / 2; } Console.WriteLine(ans); } } class Scanner { string[] s; int i; int max_i; public Scanner() { s = new string[0]; max_i = 0; i = 0; } public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } else { return s[i++]; } } public int nextInt() { return int.Parse(nextString()); } public long nextLong() { return long.Parse(nextString()); } public double nextDouble() { return double.Parse(nextString()); } public string[] arrayString() { return Console.ReadLine().Split(' '); } public int[] arrayInt() { string[] str = Console.ReadLine().Split(' '); int[] array = new int[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = int.Parse(str[i]); } return array; } public long[] arrayLong() { string[] str = Console.ReadLine().Split(' '); long[] array = new long[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = long.Parse(str[i]); } return array; } public double[] arrayDouble() { string[] str = Console.ReadLine().Split(' '); double[] array = new double[str.Length]; for (int i = 0; i < str.Length; i++) { array[i] = double.Parse(str[i]); } return array; } }
[["-", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["+", 0, 197, 0, 198, 39, 236, 237, 238, 0, 199], ["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199]]
8
639
6
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Console; namespace ConsoleApplication1 { internal class Program { public static void Main(string[] args) { var n = int.Parse(ReadLine()); var dic = new Dictionary<string, int>(); var cnt = 0; for (var i = 0; i < n; i++) { var input = ReadLine(); var key = string.Concat(input.OrderBy(c => c)); if (dic.ContainsKey(key)) { cnt += dic[key]; dic[key]++; } else { dic.Add(key, 1); } } WriteLine(cnt); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using static System.Console; namespace ConsoleApplication1 { internal class Program { public static void Main(string[] args) { var n = int.Parse(ReadLine()); var dic = new Dictionary<string, int>(); var cnt = 0l; for (var i = 0; i < n; i++) { var input = ReadLine(); var key = string.Concat(input.OrderBy(c => c)); if (dic.ContainsKey(key)) { cnt += dic[key]; dic[key]++; } else { dic.Add(key, 1); } } WriteLine(cnt); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
158
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int ct = int.Parse(Console.ReadLine()); Dictionary<string, int> string_set = new Dictionary<string, int>(); for (var i = 0; i < ct; i++) { string s = Console.ReadLine(); var ss = s.ToCharArray().ToList(); ss.Sort(); string input = string.Join("", ss); if (string_set.ContainsKey(input)) { string_set[input]++; } else { string_set.Add(input, 0); } } long ans = 0; foreach (var v in string_set.Values) { ans += v * (v + 1) / 2; } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { int ct = int.Parse(Console.ReadLine()); Dictionary<string, int> string_set = new Dictionary<string, int>(); for (var i = 0; i < ct; i++) { string s = Console.ReadLine(); var ss = s.ToCharArray().ToList(); ss.Sort(); string input = string.Join("", ss); if (string_set.ContainsKey(input)) { string_set[input]++; } else { string_set.Add(input, 0); } } long ans = 0; foreach (var v in string_set.Values) { ans += (long)v * (v + 1) / 2; } Console.WriteLine(ans); } }
[["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 25]]
8
183
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC137 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); List<string> s = new List<string>(); for (int i = 0; i < n; i++) { var p = String.Concat(Console.ReadLine().OrderBy(c => c)); s.Add(p); } var tmp = s.GroupBy(x => x) .Select(x => new { x, Count = x.Count() }) .Where(x => x.Count > 1); long allcount = tmp.Sum(x => x.Count * (x.Count - 1) / 2); Console.WriteLine(allcount); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC137 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); List<string> s = new List<string>(); for (int i = 0; i < n; i++) { var p = String.Concat(Console.ReadLine().OrderBy(c => c)); s.Add(p); } var tmp = s.GroupBy(x => x) .Select(x => new { x, Count = x.LongCount() }) .Where(x => x.Count > 1); long allcount = tmp.Sum(x => x.Count * (x.Count - 1) / 2); Console.WriteLine(allcount); } } }
[["-", 0, 218, 8, 312, 0, 213, 63, 214, 141, 22], ["+", 0, 218, 8, 312, 0, 213, 63, 214, 141, 22]]
8
190
2
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { partial class Program { static void Main(string[] args) { //↓ var n = int.Parse(Console.ReadLine()); long total = 0; var dict = new Dictionary<string, int>(); for (int i = 0; i < n; i++) { var s = Console.ReadLine(); s = new String(s.OrderBy(c => c).ToArray()); if (dict.ContainsKey(s)) { dict[s] += 1; } else { dict[s] = 1; } } foreach (var kv in dict) { var c = kv.Value; long comb = c * (c - 1) / 2; total += comb; } Console.WriteLine(total); //↑ } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder { partial class Program { static void Main(string[] args) { //↓ var n = int.Parse(Console.ReadLine()); long total = 0; var dict = new Dictionary<string, int>(); for (int i = 0; i < n; i++) { var s = Console.ReadLine(); s = new String(s.OrderBy(c => c).ToArray()); if (dict.ContainsKey(s)) { dict[s] += 1; } else { dict[s] = 1; } } foreach (var kv in dict) { var c = kv.Value; long comb = (long)c * ((long)c - 1) / 2; total += comb; } Console.WriteLine(total); //↑ } } }
[["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 212, 0, 16, 31, 16, 31, 74, 0, 25], ["+", 0, 212, 0, 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]]
8
181
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { //入力 long N = long.Parse(Console.ReadLine()); string[] s = new string[N]; string[] joinString = new string[N]; for (long i = 0; i < N; i++) { s[i] = Console.ReadLine(); var list = new List<char>(); for (int a = 0; a < 10; a++) { list.Add(s[i][a]); } list.Sort(); joinString[i] = string.Join("", list); } //カウンタ long counter = 0; //検証 var sortedList = joinString.ToList() .GroupBy(x => x) .Select(g => new { number = g.Key, duplicationCount = g.Count() }) .ToList(); var sortedList_ordered = sortedList.OrderByDescending(g => g.duplicationCount) .Where(g => g.duplicationCount >= 2) .ToArray(); for (long i = 0; i < sortedList_ordered.Count(); i++) { counter += sortedList_ordered[i].duplicationCount * (sortedList_ordered[i].duplicationCount - 1) / 2; } //出力 Console.WriteLine(counter); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { //入力 long N = long.Parse(Console.ReadLine()); string[] s = new string[N]; string[] joinString = new string[N]; for (long i = 0; i < N; i++) { s[i] = Console.ReadLine(); var list = new List<char>(); for (int a = 0; a < 10; a++) { list.Add(s[i][a]); } list.Sort(); joinString[i] = string.Join("", list); } //カウンタ long counter = 0; //検証 var sortedList = joinString.ToList() .GroupBy(x => x) .Select(g => new { number = g.Key, duplicationCount = g.Count() }) .ToList(); var sortedList_ordered = sortedList.OrderByDescending(g => g.duplicationCount) .Where(g => g.duplicationCount >= 2) .ToArray(); for (long i = 0; i < sortedList_ordered.Count(); i++) { counter += sortedList_ordered[i].duplicationCount * (sortedList_ordered[i].duplicationCount - 1L) / 2L; } //出力 Console.WriteLine(counter); } }
[["-", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["+", 12, 16, 31, 16, 12, 23, 0, 16, 12, 203], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
295
4
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; namespace C_ABC137 { class MainClass { static int[] s; public static void Main(string[] args) { s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse); var sl = new List<string>(); var al = new List<string>(); var alcnt = new List<int>(); for (int i = 0; i < s[0]; i++) { string str = ReadLine(); var carr = str.ToCharArray(); Array.Sort(carr); string cs = new string(carr); al.Add(cs); // WriteLine(cs); } var algrp = al.GroupBy(a => a).Select(col => new { p = col.Key, e = col.Count() }); var alst = algrp.ToList(); long ans = 0; for (int i = 0; i < alst.Count; i++) { // WriteLine(alst[i].e); if (alst[i].e - 1 != 0) { ans += ((alst[i].e) * (alst[i].e - 1)) / 2; } } WriteLine(ans); } public static bool Permutation(string a, string b) { if (a.Length != b.Length) { return false; } int[] letters = new int[256]; char[] s_array = a.ToCharArray(); foreach (char c in s_array) { letters[(int)c]++; } for (int i = 0; i < b.Length; i++) { int c = (int)b[i]; if (--letters[c] < 0) { return false; } } return true; } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; namespace C_ABC137 { class MainClass { static int[] s; public static void Main(string[] args) { s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse); var sl = new List<string>(); var al = new List<string>(); var alcnt = new List<int>(); for (int i = 0; i < s[0]; i++) { string str = ReadLine(); var carr = str.ToCharArray(); Array.Sort(carr); string cs = new string(carr); al.Add(cs); // WriteLine(cs); } var algrp = al.GroupBy(a => a).Select(col => new { p = col.Key, e = col.Count() }); var alst = algrp.ToList(); long ans = 0; for (int i = 0; i < alst.Count; i++) { // WriteLine(alst[i].e); if (alst[i].e - 1 != 0) { ans += ((long)(alst[i].e) * (long)(alst[i].e - 1)) / 2; } } WriteLine(ans); } public static bool Permutation(string a, string b) { if (a.Length != b.Length) { return false; } int[] letters = new int[256]; char[] s_array = a.ToCharArray(); foreach (char c in s_array) { letters[(int)c]++; } for (int i = 0; i < b.Length; i++) { int c = (int)b[i]; if (--letters[c] < 0) { return false; } } return true; } } }
[["+", 12, 16, 31, 23, 0, 16, 31, 74, 39, 199], ["+", 12, 16, 31, 23, 0, 16, 31, 74, 0, 25], ["+", 31, 23, 0, 16, 31, 74, 51, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 12, 74, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 12, 74, 39, 199], ["+", 12, 16, 31, 23, 0, 16, 12, 74, 0, 25]]
8
396
6
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static Library.Comfort; using static Library.Math; using static Library.Algorithm; using static System.Math; namespace AtCoderer { public class App { public static void Solve() { Hashtable h = new Hashtable(); int n = In(); string[] a = new string[n]; long l = 0; for (int i = 0; i < n; i++) { var r = string.Join("", Console.ReadLine().OrderBy(c => c)); if (h.ContainsKey(r)) { h[r] = ((int)h[r]) + 1; } else { h.Add(r, 1); } } foreach (var v in h.Values) { l += nCm((int)v, 2); } cout = l; } public static void Main(string[] args) { #if DEBUG while (true) { Solve(); } #else Solve(); #endif } } } namespace Library { public static class Comfort { public const int mod = 1000000007; public class Point { public int a; public int b; public Point(int a, int b) { this.a = a; this.b = b; } } public static void DWrite<T>(T o) { #if DEBUG Console.WriteLine(o); #endif } public static int[] OrderBy(this int[] IArr) { int[] arr = new int[IArr.Length]; Array.Copy(IArr, arr, IArr.Length); Array.Sort(arr); return arr; } public static int Max(params int[] p) => p.Max(); public static long Max(params long[] p) => p.Max(); public static int Min(params int[] p) => p.Min(); public static long Min(params long[] p) => p.Min(); public static int In() { return int.Parse(Console.ReadLine()); } public static int Inl() { return int.Parse(Console.ReadLine()); } public static int[] Parse() { return Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); } public static long[] Parsel() { return Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); } public static void Parse(out int a, out int b) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; } public static void Parse(out int a, out int b, out int c) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; } public static void Parse(out int a, out int b, out int c, out int d) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; d = r[3]; } public static void Parse(out long a, out long b) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; } public static void Parse(out long a, out long b, out long c) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; } public static void Parse(out long a, out long b, out long c, out long d) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; d = r[3]; } public static string ToString(this IEnumerable<char> v) { return string.Join("", v); } public static string Join<T>(this IEnumerable<T> v) { return string.Join(" ", v); } public static string Join<T>(this IEnumerable<T> v, char c) { return string.Join(c.ToString(), v); } public static string Join<T>(this IEnumerable<T> v, string s) { return string.Join(s, v); } public static object cout { set { Console.WriteLine(value); } } public static object dout { set { DWrite(value); } } } public static class Math { public static bool IsNatural(this float v) => v - (int)v == 0; public static bool IsNatural(this double v) => v - (int)v == 0; public static long nCm(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m % 1000000007; } public static IEnumerable<int> Factor(int n) { int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; yield return i; } else { i++; } } if (tmp != 1) yield return tmp; } public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static int GcdRecursive(int x, int y) => y == 0 ? x : GcdRecursive(y, x % y); public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static long GcdRecursive(long x, long y) => y == 0 ? x : GcdRecursive(y, x % y); public static long Lcm(int a, int b) => ((long)a) * b / Gcd(a, b); } public static class Algorithm { public class EnumAll { bool Over = false; int UpperValue; int Dimension; public int[] Current { private set; get; } public EnumAll(int MaxValue, int Dimension) { this.Dimension = Dimension; UpperValue = MaxValue; Current = new int[Dimension]; Current[0] = -1; } public bool Next() { if (Over) return false; bool flag = false; for (int i = 0; i < Dimension; i++) { if (++Current[i] >= UpperValue) Current[i] = 0; else { flag = true; break; } } if (!flag) { Over = true; return false; } return true; } } public class Graph { public int Count = -1; private HashSet<int>[] Joined; public static Graph GenerateComplete(int size) { throw new NotImplementedException(); } public Graph(int size) { Joined = new HashSet<int>[size]; for (int i = 0; i < Joined.Length; i++) Joined[i] = new HashSet<int>(); Count = size; } public int[] GetConnected(int index) { return Joined[index].ToArray(); } public void AddEdge(int a, int b) { if (a == b) DWrite("ループを追加することはできません A:" + a + " B:" + b); else { if (!Joined[a].Add(b)) DWrite("多重辺を追加することはできません A:" + a + " B:" + b); else Joined[b].Add(a); } } public int[] ToTree(int Root) { var ar = new int[Count]; for (int i = 0; i < ar.Length; i++) ar[i] = -10000000; ar[Root] = -1; Queue<int> bfs = new Queue<int>(); bfs.Enqueue(Root); while (bfs.Count != 0) { var t = bfs.Dequeue(); foreach (var v in Joined[t]) { bfs.Enqueue(v); if (ar[v] == -10000000) ar[v] = t; } } return ar; } } public class UnionFind { private int[] Parent; private int GetRoot(int v) { if (Parent[v] < 0) return v; else return Parent[v] = GetRoot(Parent[v]); } public UnionFind(int size) { Parent = new int[size]; for (int i = 0; i < size; i++) Parent[i] = -1; } public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); } public void Connect(int a, int b) { a = GetRoot(a); b = GetRoot(b); if (a == b) return; if (Parent[b] < Parent[a]) { Parent[b] += Parent[a]; Parent[a] = b; } else { Parent[a] += Parent[b]; Parent[b] = a; } } public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; } } } }
using System; using System.Linq; using System.Collections; using System.Collections.Generic; using static Library.Comfort; using static Library.Math; using static Library.Algorithm; using static System.Math; namespace AtCoderer { public class App { public static void Solve() { Hashtable h = new Hashtable(); int n = In(); string[] a = new string[n]; long l = 0; for (int i = 0; i < n; i++) { var r = string.Join("", Console.ReadLine().OrderBy(c => c)); if (h.ContainsKey(r)) { h[r] = ((int)h[r]) + 1; } else { h.Add(r, 1); } } foreach (var v in h.Values) { l += nCm((int)v, 2); } cout = l; } public static void Main(string[] args) { #if DEBUG while (true) { Solve(); } #else Solve(); #endif } } } namespace Library { public static class Comfort { public const int mod = 1000000007; public class Point { public int a; public int b; public Point(int a, int b) { this.a = a; this.b = b; } } public static void DWrite<T>(T o) { #if DEBUG Console.WriteLine(o); #endif } public static int[] OrderBy(this int[] IArr) { int[] arr = new int[IArr.Length]; Array.Copy(IArr, arr, IArr.Length); Array.Sort(arr); return arr; } public static int Max(params int[] p) => p.Max(); public static long Max(params long[] p) => p.Max(); public static int Min(params int[] p) => p.Min(); public static long Min(params long[] p) => p.Min(); public static int In() { return int.Parse(Console.ReadLine()); } public static int Inl() { return int.Parse(Console.ReadLine()); } public static int[] Parse() { return Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); } public static long[] Parsel() { return Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); } public static void Parse(out int a, out int b) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; } public static void Parse(out int a, out int b, out int c) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; } public static void Parse(out int a, out int b, out int c, out int d) { var r = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; d = r[3]; } public static void Parse(out long a, out long b) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; } public static void Parse(out long a, out long b, out long c) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; } public static void Parse(out long a, out long b, out long c, out long d) { var r = Console.ReadLine().Split().Select(v => long.Parse(v)).ToArray(); a = r[0]; b = r[1]; c = r[2]; d = r[3]; } public static string ToString(this IEnumerable<char> v) { return string.Join("", v); } public static string Join<T>(this IEnumerable<T> v) { return string.Join(" ", v); } public static string Join<T>(this IEnumerable<T> v, char c) { return string.Join(c.ToString(), v); } public static string Join<T>(this IEnumerable<T> v, string s) { return string.Join(s, v); } public static object cout { set { Console.WriteLine(value); } } public static object dout { set { DWrite(value); } } } public static class Math { public static bool IsNatural(this float v) => v - (int)v == 0; public static bool IsNatural(this double v) => v - (int)v == 0; public static long nCm(long n, long m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } public static IEnumerable<int> Factor(int n) { int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; yield return i; } else { i++; } } if (tmp != 1) yield return tmp; } public static int Gcd(int a, int b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static int GcdRecursive(int x, int y) => y == 0 ? x : GcdRecursive(y, x % y); public static long Gcd(long a, long b) => a > b? GcdRecursive(a, b) : GcdRecursive(b, a); private static long GcdRecursive(long x, long y) => y == 0 ? x : GcdRecursive(y, x % y); public static long Lcm(int a, int b) => ((long)a) * b / Gcd(a, b); } public static class Algorithm { public class EnumAll { bool Over = false; int UpperValue; int Dimension; public int[] Current { private set; get; } public EnumAll(int MaxValue, int Dimension) { this.Dimension = Dimension; UpperValue = MaxValue; Current = new int[Dimension]; Current[0] = -1; } public bool Next() { if (Over) return false; bool flag = false; for (int i = 0; i < Dimension; i++) { if (++Current[i] >= UpperValue) Current[i] = 0; else { flag = true; break; } } if (!flag) { Over = true; return false; } return true; } } public class Graph { public int Count = -1; private HashSet<int>[] Joined; public static Graph GenerateComplete(int size) { throw new NotImplementedException(); } public Graph(int size) { Joined = new HashSet<int>[size]; for (int i = 0; i < Joined.Length; i++) Joined[i] = new HashSet<int>(); Count = size; } public int[] GetConnected(int index) { return Joined[index].ToArray(); } public void AddEdge(int a, int b) { if (a == b) DWrite("ループを追加することはできません A:" + a + " B:" + b); else { if (!Joined[a].Add(b)) DWrite("多重辺を追加することはできません A:" + a + " B:" + b); else Joined[b].Add(a); } } public int[] ToTree(int Root) { var ar = new int[Count]; for (int i = 0; i < ar.Length; i++) ar[i] = -10000000; ar[Root] = -1; Queue<int> bfs = new Queue<int>(); bfs.Enqueue(Root); while (bfs.Count != 0) { var t = bfs.Dequeue(); foreach (var v in Joined[t]) { bfs.Enqueue(v); if (ar[v] == -10000000) ar[v] = t; } } return ar; } } public class UnionFind { private int[] Parent; private int GetRoot(int v) { if (Parent[v] < 0) return v; else return Parent[v] = GetRoot(Parent[v]); } public UnionFind(int size) { Parent = new int[size]; for (int i = 0; i < size; i++) Parent[i] = -1; } public bool AreGrouped(int a, int b) { return GetRoot(a) == GetRoot(b); } public void Connect(int a, int b) { a = GetRoot(a); b = GetRoot(b); if (a == b) return; if (Parent[b] < Parent[a]) { Parent[b] += Parent[a]; Parent[a] = b; } else { Parent[a] += Parent[b]; Parent[b] = a; } } public int GetGroupSize(int a) { return -Parent[GetRoot(a)]; } } } }
[["-", 0, 195, 8, 196, 0, 37, 0, 16, 17, 109], ["-", 0, 195, 8, 196, 0, 37, 0, 16, 12, 203]]
8
2,088
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC137_C { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var dic = new Dictionary<string, int>(); for (int i = 0; i < N; i++) { var line = new string( Console.ReadLine().ToCharArray().OrderBy(x => x).ToArray()); if (dic.ContainsKey(line)) { dic[line]++; } else { dic.Add(line, 1); } } long ans = 0; foreach (var d in dic) { if (d.Value <= 1) continue; ans += d.Value * (d.Value - 1) / 2; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC137_C { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var dic = new Dictionary<string, long>(); for (int i = 0; i < N; i++) { var line = new string( Console.ReadLine().ToCharArray().OrderBy(x => x).ToArray()); if (dic.ContainsKey(line)) { dic[line]++; } else { dic.Add(line, 1); } } long ans = 0; foreach (var d in dic) { if (d.Value <= 1) continue; ans += d.Value * (d.Value - 1) / 2; } Console.WriteLine(ans); } } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
193
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; namespace Contest { class Program { static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); List<string> ls = new List<string>(); int kq = 0; while (n-- > 0) { var v = Console.ReadLine().ToCharArray(); Array.Sort(v); string s = new string(v); ls.Add(s); } var a = ls.GroupBy(x => x) .Select(x => x.Count() * (x.Count() - 1) / 2) .ToList(); Console.WriteLine(a.Sum()); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; namespace Contest { class Program { static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); List<string> ls = new List<string>(); int kq = 0; while (n-- > 0) { var v = Console.ReadLine().ToCharArray(); Array.Sort(v); string s = new string(v); ls.Add(s); } var a = ls.GroupBy(x => x) .Select(x => (long)x.Count() * (x.Count() - 1) / 2) .ToList(); Console.WriteLine(a.Sum()); } } }
[["+", 0, 218, 8, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 218, 8, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 218, 8, 16, 31, 16, 31, 74, 0, 25]]
8
172
3
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace ABC137 { class Program3 { static void Main() { var N = int.Parse(Console.ReadLine()); var s = new string[N]; for (int i = 0; i < N; i++) { s[i] = Console.ReadLine(); } var dic = new Dictionary<string, int>(); foreach (var item in s) { var c = item.ToCharArray(); Array.Sort(c); var ss = new string(c); if (dic.ContainsKey(ss)) { dic[ss]++; } else { dic.Add(ss, 1); } } var ans = 0L; foreach (var i in dic) { if (i.Value <= 1) continue; ans += i.Value * (i.Value - 1) / 2; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace ABC137 { class Program3 { static void Main() { var N = int.Parse(Console.ReadLine()); var s = new string[N]; for (int i = 0; i < N; i++) { s[i] = Console.ReadLine(); } var dic = new Dictionary<string, int>(); foreach (var item in s) { var c = item.ToCharArray(); Array.Sort(c); var ss = new string(c); if (dic.ContainsKey(ss)) { dic[ss]++; } else { dic.Add(ss, 1); } } var ans = 0L; foreach (var i in dic) { if (i.Value <= 1) continue; ans += (long)i.Value * ((long)i.Value - 1) / 2; } Console.WriteLine(ans); } } }
[["+", 0, 11, 12, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 11, 12, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 11, 12, 16, 31, 16, 31, 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]]
8
208
6
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } private const int MOD = 1000000007; private const int MAX = 100001; static long[] fac = new long[MAX]; static long[] finv = new long[MAX]; static long[] inv = new long[MAX]; static void Solve() { var n = Input.NextInt(); var dic = new Dictionary<string, int>(); var list = new List<char>(10); for (int i = 0; i < n; ++i) { var tmp = Input.Next(); list.Clear(); list.AddRange(tmp.ToCharArray()); list.Sort(); string s = new string(list.ToArray()); if (!dic.ContainsKey(s)) { dic.Add(s, 0); } dic[s]++; } long ans = 0; foreach (var kv in dic) { ans += kv.Value * (kv.Value - 1) / 2; } Console.WriteLine(ans); } /// <summary> /// /// </summary> /// <param name="x">約数x</param> /// <returns></returns> private static int CalcX(int x, List<int> a, int k) { var b = new List<int>(a); for (int i = 0; i < b.Count; ++i) { b[i] %= x; } b.Sort(); int tot = b.Sum(); int l = b.Count - tot / x; int need = 0; for (int i = 0; i < l; ++i) { need += b[i]; } return need; } #region よく使う便利関数 static void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 static long COM(long n, long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } static class Input { static char[] separator = { ' ' }; public static bool IsEof { get; set; } static Queue<string> q { get; set; } static Input() { IsEof = false; q = new Queue<string>(); } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public static void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> static bool read() { var s = Console.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public static string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public static int NextInt() => int.Parse(Next()); public static long NextLong() => long.Parse(Next()); public static double NextDouble() => double.Parse(Next()); public static List<string> Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList(); public static List<int> NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList(); public static List<long> NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList(); public static List<double> NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList(); public static List<string> NextLine() => Console.ReadLine() .Trim() .Split(separator, StringSplitOptions.RemoveEmptyEntries) .ToList(); public static List<int> NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList(); public static List<long> NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList(); public static List<double> NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList(); } private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static void Swap<T>(ref T x, ref T y) { T t = x; x = y; y = t; } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } public class DisjointSet { private int[] rank; private int[] p; private int[] size; public DisjointSet(int n) { rank = new int[n]; p = new int[n]; size = new int[n]; for (int i = 0; i < n; ++i) { MakeSet(i); } } public void MakeSet(int x) { p[x] = x; rank[x] = 0; size[x] = 1; } public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); } public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); } public void Link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; size[x] += size[y]; size[y] = 0; } else { p[x] = y; size[y] += size[x]; size[x] = 0; if (rank[x] == rank[y]) { rank[y]++; } } } public int FindSet(int x) { if (x != p[x]) { p[x] = FindSet(p[x]); } return p[x]; } public int Size(int x) { int root = FindSet(x); return size[root]; } } 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; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> 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); } 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() { 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; } } }
using System; using System.Collections.Generic; using System.Text; using System.Linq; namespace Practice { class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } private const int MOD = 1000000007; private const int MAX = 100001; static long[] fac = new long[MAX]; static long[] finv = new long[MAX]; static long[] inv = new long[MAX]; static void Solve() { var n = Input.NextInt(); var dic = new Dictionary<string, long>(); var list = new List<char>(10); for (int i = 0; i < n; ++i) { var tmp = Input.Next(); list.Clear(); list.AddRange(tmp.ToCharArray()); list.Sort(); string s = new string(list.ToArray()); if (!dic.ContainsKey(s)) { dic.Add(s, 0); } dic[s]++; } long ans = 0; foreach (var kv in dic) { ans += kv.Value * (kv.Value - 1) / 2; } Console.WriteLine(ans); } /// <summary> /// /// </summary> /// <param name="x">約数x</param> /// <returns></returns> private static int CalcX(int x, List<int> a, int k) { var b = new List<int>(a); for (int i = 0; i < b.Count; ++i) { b[i] %= x; } b.Sort(); int tot = b.Sum(); int l = b.Count - tot / x; int need = 0; for (int i = 0; i < l; ++i) { need += b[i]; } return need; } #region よく使う便利関数 static void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 static long COM(long n, long k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } static class Input { static char[] separator = { ' ' }; public static bool IsEof { get; set; } static Queue<string> q { get; set; } static Input() { IsEof = false; q = new Queue<string>(); } /// <summary> /// 入力予約 /// </summary> /// <param name="items"></param> public static void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } /// <summary> /// 入力予約 /// </summary> /// <param name="s"></param> /// <returns></returns> public static bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } return true; } /// <summary> /// 内部queueに入力からの値をsplitして格納する /// </summary> /// <returns></returns> static bool read() { var s = Console.ReadLine(); if (s == null) return false; foreach (var elem in s.Trim().Split( separator, StringSplitOptions.RemoveEmptyEntries)) { q.Enqueue(elem); } if (!q.Any()) return read(); return true; } /// <summary> /// 次のstringを一つ読み込む /// </summary> /// <returns></returns> public static string Next() { if (!q.Any()) { if (!read()) { IsEof = true; return ""; } } return q.Dequeue(); } public static int NextInt() => int.Parse(Next()); public static long NextLong() => long.Parse(Next()); public static double NextDouble() => double.Parse(Next()); public static List<string> Next(int n) => Enumerable.Range(0, n).Select(_ => Next()).ToList(); public static List<int> NextInt(int n) => Next(n).Select(x => int.Parse(x)).ToList(); public static List<long> NextLong(int n) => Next(n).Select(x => long.Parse(x)).ToList(); public static List<double> NextDouble(int n) => Next(n).Select(x => double.Parse(x)).ToList(); public static List<string> NextLine() => Console.ReadLine() .Trim() .Split(separator, StringSplitOptions.RemoveEmptyEntries) .ToList(); public static List<int> NextIntLine() => NextLine().Select(x => int.Parse(x)).ToList(); public static List<long> NextLongLine() => NextLine().Select(x => long.Parse(x)).ToList(); public static List<double> NextDoubleLine() => NextLine().Select(x => double.Parse(x)).ToList(); } private static bool isPrime(long x) { if (x == 2) { return true; } if (x < 2 || x % 2 == 0) { return false; } long i = 3; while (i * i <= x) { if (x % i == 0) { return false; } i = i + 2; } return true; } private static long lcm(long x, long y) { return x / gcd(x, y) * y; } private static long gcd(long x, long y) { return y > 0 ? gcd(y, x % y) : x; } private static long pow(long x, long n) { if (n == 0) { return 1; } long res = pow(x * x % MOD, n / 2); if (n % 2 == 1) { res = res * x % MOD; } return res; } private static void Swap<T>(ref T x, ref T y) { T t = x; x = y; y = t; } /// <summary> /// 指定した値以上の先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値以上の先頭のインデクス</returns> public static int LowerBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) < 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int LowerBound<T>(IReadOnlyList<T> arr, T value) where T : IComparable { return LowerBound(arr, 0, arr.Count, value, Comparer<T>.Default); } /// <summary> /// 指定した値より大きい先頭のインデクスを返す /// </summary> /// <typeparam name="T">比較する値の型</typeparam> /// <param name="arr">対象の配列(※ソート済みであること)</param> /// <param name="start">開始インデクス [inclusive]</param> /// <param name="end">終了インデクス [exclusive]</param> /// <param name="value">検索する値</param> /// <param name="comparer">比較関数(インターフェイス)</param> /// <returns>指定した値より大きい先頭のインデクス</returns> public static int UpperBound<T>(IReadOnlyList<T> arr, int start, int end, T value, IComparer<T> comparer) { int low = start; int high = end; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (comparer.Compare(arr[mid], value) <= 0) low = mid + 1; else high = mid; } return low; } //引数省略のオーバーロード public static int UpperBound<T>(IReadOnlyList<T> arr, T value) { return UpperBound(arr, 0, arr.Count, value, Comparer<T>.Default); } #endregion } public class DisjointSet { private int[] rank; private int[] p; private int[] size; public DisjointSet(int n) { rank = new int[n]; p = new int[n]; size = new int[n]; for (int i = 0; i < n; ++i) { MakeSet(i); } } public void MakeSet(int x) { p[x] = x; rank[x] = 0; size[x] = 1; } public bool IsSame(int x, int y) { return FindSet(x) == FindSet(y); } public void Unite(int x, int y) { Link(FindSet(x), FindSet(y)); } public void Link(int x, int y) { if (rank[x] > rank[y]) { p[y] = x; size[x] += size[y]; size[y] = 0; } else { p[x] = y; size[y] += size[x]; size[x] = 0; if (rank[x] == rank[y]) { rank[y]++; } } } public int FindSet(int x) { if (x != p[x]) { p[x] = FindSet(p[x]); } return p[x]; } public int Size(int x) { int root = FindSet(x); return size[root]; } } 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; } /// <summary> /// Priority queue /// </summary> /// <param name="maxSize">max size</param> /// <param name="type">0: asc, 1:desc</param> 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); } 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() { 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; } } }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199]]
8
2,544
2
using System; using System.Linq; namespace ABC137C { class Program { static void Main(string[] args) { int N = CIN.Int(); string[] S = new string[N]; for (int i = 0; i < N; i++) { char[] A = CIN.String().ToCharArray(); Array.Sort(A); S[i] = new string(A); } Array.Sort(S); string first = S[0]; long ans = 0; int cur = 0; for (int i = 1; i < N; i++) { if (first.Equals(S[i])) { cur++; continue; } first = S[i]; ans += (cur + 1) * cur / 2; cur = 0; } ans += (cur + 1) * cur / 2; Console.WriteLine(ans); } } internal static class CIN { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
using System; using System.Linq; namespace ABC137C { class Program { static void Main(string[] args) { long N = CIN.Int(); string[] S = new string[N]; for (int i = 0; i < N; i++) { char[] A = CIN.String().ToCharArray(); Array.Sort(A); S[i] = new string(A); } Array.Sort(S); string first = S[0]; long ans = 0; long cur = 0; for (int i = 1; i < N; i++) { if (first.Equals(S[i])) { cur++; continue; } first = S[i]; ans += (cur + 1) * cur / 2; cur = 0; } ans += (cur + 1) * cur / 2; Console.WriteLine(ans); } } internal static class CIN { public static string String() { return Console.ReadLine(); } public static int Int() { return int.Parse(Console.ReadLine()); } public static int[] IntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long Long() { return long.Parse(Console.ReadLine()); } public static long[] LongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static double[] DoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
364
4
using System; using System.Collections; using System.Collections.Generic; using System.Linq; // namespaceの値をコンテスト名にして運用 namespace ABC137D { class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public string String() { return Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public string[] ArrayString(int rowNumber) { string[] s = new string[rowNumber]; for (int i = 0; i < rowNumber; i++) { s[i] = String(); } return s; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public int Int() { return int.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の配列</returns> public int[] ArrayInt() { return Split().Select(int.Parse).ToArray(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <param name="rowNumber">行数</param> /// <returns>int型の配列</returns> public int[] ArrayInt(int rowNumber) { int[] ints = new int[rowNumber]; for (int i = 0; i < rowNumber; i++) { ints[i] = Int(); } return ints; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の値</returns> public long Long() { return long.Parse(String()); } /// <summary> /// 2つの整数が1行に書かれている入力を、2つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> public void Longs(ref long A, ref long B) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; } /// <summary> /// 3つの整数が1行に書かれている入力を、3つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> public void Longs(ref long A, ref long B, ref long C) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; C = longs[2]; } /// <summary> /// 4つの整数が1行に書かれている入力を、4つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> /// <param name="D"></param> public void Longs(ref long A, ref long B, ref long C, ref long D) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; C = longs[2]; D = longs[3]; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の配列</returns> public long[] ArrayLong() { return Split().Select(long.Parse).ToArray(); } public long[] ArrayLong(int rowNumber) { long[] longs = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { longs[i] = Long(); } return longs; } public void LongsArray(int rowNumber, ref long[] A, ref long[] B) { A = new long[rowNumber]; B = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { var l = ArrayLong(); A[i] = l[0]; B[i] = l[1]; } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public double Double() { return double.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public double[] ArrayDouble() { return Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { return String().Split(' '); } } class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> data = new List<T>(); private readonly IComparer<T> comparer; private readonly bool isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { this.comparer = comparer; this.isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { data.Add(item); var childIndex = data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(data[childIndex], data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { if (Count < 1) { throw new Exception("キューに値が入っていません"); } var lastIndex = data.Count - 1; var firstItem = data[0]; data[0] = data[lastIndex]; data.RemoveAt(lastIndex); lastIndex--; var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) { break; } var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(data[rightChild], data[childIndex]) < 0) { childIndex = rightChild; } if (Compare(data[parentIndex], data[childIndex]) <= 0) { break; } Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return data[0]; } private void Swap(int a, int b) { var tmp = data[a]; data[a] = data[b]; data[b] = tmp; } private int Compare(T a, T b) { return isDescending ? comparer.Compare(b, a) : comparer.Compare(a, b); } public int Count => data.Count; public IEnumerator<T> GetEnumerator() { return data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } class Program { static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { public Solver() { Input input = new Input(); input.Longs(ref N, ref M); input.LongsArray((int)N, ref A, ref B); } private long N; private long M; private long[] A; private long[] B; public void Solve() { //最後の日から順番に取得したい // <日数、<報酬>> Dictionary<long, HashSet<long>> tasks = new Dictionary<long, HashSet<long>>(); for (int i = 1; i <= M; i++) { tasks.Add(i, new HashSet<long>()); } for (int i = 0; i < N; i++) { if (!tasks.ContainsKey(A[i])) { continue; } tasks[A[i]].Add(B[i]); } PriorityQueue<long> pq = new PriorityQueue<long>(); long ans = 0; for (int i = 1; i <= M; i++) { foreach (long l in tasks[i]) { pq.Enqueue(l); } if (pq.Count < 1) { continue; } ans += pq.Dequeue(); } Console.WriteLine(ans); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; // namespaceの値をコンテスト名にして運用 namespace ABC137D { class Input { /// <summary> /// 1行の入力を取得する /// </summary> /// <returns>文字列</returns> public string String() { return Console.ReadLine(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <returns>文字列の配列</returns> public string[] ArrayString(int rowNumber) { string[] s = new string[rowNumber]; for (int i = 0; i < rowNumber; i++) { s[i] = String(); } return s; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の値</returns> public int Int() { return int.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>int型の配列</returns> public int[] ArrayInt() { return Split().Select(int.Parse).ToArray(); } /// <summary> /// 複数行の入力を取得 /// </summary> /// <param name="rowNumber">行数</param> /// <returns>int型の配列</returns> public int[] ArrayInt(int rowNumber) { int[] ints = new int[rowNumber]; for (int i = 0; i < rowNumber; i++) { ints[i] = Int(); } return ints; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の値</returns> public long Long() { return long.Parse(String()); } /// <summary> /// 2つの整数が1行に書かれている入力を、2つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> public void Longs(ref long A, ref long B) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; } /// <summary> /// 3つの整数が1行に書かれている入力を、3つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> public void Longs(ref long A, ref long B, ref long C) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; C = longs[2]; } /// <summary> /// 4つの整数が1行に書かれている入力を、4つのlongで受け取る /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <param name="C"></param> /// <param name="D"></param> public void Longs(ref long A, ref long B, ref long C, ref long D) { var longs = ArrayLong(); A = longs[0]; B = longs[1]; C = longs[2]; D = longs[3]; } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>long型の配列</returns> public long[] ArrayLong() { return Split().Select(long.Parse).ToArray(); } public long[] ArrayLong(int rowNumber) { long[] longs = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { longs[i] = Long(); } return longs; } public void LongsArray(int rowNumber, ref long[] A, ref long[] B) { A = new long[rowNumber]; B = new long[rowNumber]; for (int i = 0; i < rowNumber; i++) { var l = ArrayLong(); A[i] = l[0]; B[i] = l[1]; } } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の値</returns> public double Double() { return double.Parse(String()); } /// <summary> /// 1行の入力を取得 /// </summary> /// <returns>double型の配列</returns> public double[] ArrayDouble() { return Split().Select(double.Parse).ToArray(); } private IEnumerable<string> Split() { return String().Split(' '); } } class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> data = new List<T>(); private readonly IComparer<T> comparer; private readonly bool isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { this.comparer = comparer; this.isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) {} public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) {} public void Enqueue(T item) { data.Add(item); var childIndex = data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(data[childIndex], data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { if (Count < 1) { throw new Exception("キューに値が入っていません"); } var lastIndex = data.Count - 1; var firstItem = data[0]; data[0] = data[lastIndex]; data.RemoveAt(lastIndex); lastIndex--; var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) { break; } var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(data[rightChild], data[childIndex]) < 0) { childIndex = rightChild; } if (Compare(data[parentIndex], data[childIndex]) <= 0) { break; } Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return data[0]; } private void Swap(int a, int b) { var tmp = data[a]; data[a] = data[b]; data[b] = tmp; } private int Compare(T a, T b) { return isDescending ? comparer.Compare(b, a) : comparer.Compare(a, b); } public int Count => data.Count; public IEnumerator<T> GetEnumerator() { return data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } class Program { static void Main(string[] args) { Solver solver = new Solver(); solver.Solve(); } } class Solver { public Solver() { Input input = new Input(); input.Longs(ref N, ref M); input.LongsArray((int)N, ref A, ref B); } private long N; private long M; private long[] A; private long[] B; public void Solve() { //最後の日から順番に取得したい // <日数、<報酬>> Dictionary<long, List<long>> tasks = new Dictionary<long, List<long>>(); for (int i = 1; i <= M; i++) { tasks.Add(i, new List<long>()); } for (int i = 0; i < N; i++) { if (!tasks.ContainsKey(A[i])) { continue; } tasks[A[i]].Add(B[i]); } PriorityQueue<long> pq = new PriorityQueue<long>(); long ans = 0; for (int i = 1; i <= M; i++) { foreach (long l in tasks[i]) { pq.Enqueue(l); } if (pq.Count < 1) { continue; } ans += pq.Dequeue(); } Console.WriteLine(ans); } } }
[["-", 0, 198, 39, 236, 237, 238, 0, 236, 141, 22], ["+", 0, 198, 39, 236, 237, 238, 0, 236, 141, 22], ["-", 0, 230, 39, 236, 237, 238, 0, 236, 141, 22], ["+", 0, 230, 39, 236, 237, 238, 0, 236, 141, 22], ["-", 3, 4, 0, 28, 0, 230, 39, 236, 141, 22], ["+", 3, 4, 0, 28, 0, 230, 39, 236, 141, 22]]
8
1,377
6
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var nm = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var N = nm[0]; var M = nm[1]; var list = new List<int[]>(); var listCount = 0; for (int i = 0; i < N; ++i) { var ab = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); if (M < ab[0]) continue; list.Add(new int[] { ab[0], ab[1] }); listCount++; } list = list.OrderBy(x => x[0]).ToList(); var tempList = new List<int>(); var index = 0; var ans = 0; if (1 <= listCount) { for (int i = 1; i <= M; ++i) { while (index < listCount && list[index][0] <= i) { var ins = LowerBound(list[index][1], tempList); tempList.Insert(ins, list[index][1]); index++; } if (tempList.Any()) { var n = tempList.Last(); ans += n; tempList.RemoveAt(tempList.Count()); } } } Console.WriteLine(ans); } static int LowerBound(long value, List<int> array) { var low = 0; var high = array.Count(); while (low < high) { var middle = (high + low) / 2; if (value <= array[middle]) high = middle; else low = middle + 1; } return low; } }
using System; using System.Collections.Generic; using System.Linq; class Program { public static void Main() { var nm = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); var N = nm[0]; var M = nm[1]; var list = new List<int[]>(); var listCount = 0; for (int i = 0; i < N; ++i) { var ab = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray(); if (M < ab[0]) continue; list.Add(new int[] { ab[0], ab[1] }); listCount++; } list = list.OrderBy(x => x[0]).ToList(); var tempList = new List<int>(); var index = 0; var ans = 0; if (1 <= listCount) { for (int i = 1; i <= M; ++i) { while (index < listCount && list[index][0] <= i) { var ins = LowerBound(list[index][1], tempList); tempList.Insert(ins, list[index][1]); index++; } if (tempList.Any()) { var n = tempList.Last(); ans += n; tempList.RemoveAt(tempList.Count() - 1); } } } Console.WriteLine(ans); } static int LowerBound(long value, List<int> array) { var low = 0; var high = array.Count(); while (low < high) { var middle = (high + low) / 2; if (value <= array[middle]) high = middle; else low = middle + 1; } return low; } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
403
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Procon { static void Main(string[] agrs) { int N = Int(); int M = Int(); var tuples = new List<Tuple<int, int>>(); for (int i = 0; i < N; i++) { tuples.Add(Tuple.Create(Int(), Int())); } var sorted = tuples.OrderBy(v => v.Item1).ToList(); var pq = new PriorityQueue<int>(N, true); int cur = 0; int ans = 0; for (int i = 1; i <= M; i++) { while (cur < N && sorted[cur].Item1 <= i) { pq.Push(sorted[cur].Item2); cur++; } if (pq.Count() > 0) { ans += pq.Pop(); } Dbg(ans); } } static string String() => Scanner.nextString(); static int Int() => int.Parse(Scanner.nextString()); static long Long() => long.Parse(Scanner.nextString()); static double Double() => double.Parse(Scanner.nextString()); static char[] Chars() => String().ToCharArray(); static string[] Strings() => Console.ReadLine().Split(' '); static int[] Ints() => Strings().Select(v => int.Parse(v)).ToArray(); static long[] Longs() => Strings().Select(v => long.Parse(v)).ToArray(); static double[] Doubles() => Strings().Select(v => double.Parse(v)).ToArray(); const int M = 1000000007; static void Dbg(object a) => Console.WriteLine(a); static void Dbg(params object[] a) => Console.WriteLine(string.Join(" ", a)); static void Dbgs<T>(IEnumerable<T> a, string split = " ") => Console.WriteLine(string.Join(split, a)); static T Max<T>(params T[] a) => a.Max(); static T Min<T>(params T[] a) => a.Min(); } class PriorityQueue<T> where T : IComparable<T> { public T[] heap; public int size; public int sign; public PriorityQueue(int N, bool descend = false) { heap = new T[N]; if (descend) sign = -1; } public int Compare(T x, T y) { return x.CompareTo(y) * sign; } public void Push(T x) { int i = size++; while (i > 0) { int p = (i - 1) / 2; if (Compare(x, heap[p]) >= 0) { break; } heap[i] = heap[p]; i = p; } heap[i] = x; } public T Pop() { T ret = heap[0]; T x = heap[--size]; int i = 0; while (i * 2 + 1 < size) { int a = i * 2 + 1; int b = i * 2 + 2; if (b < size && Compare(heap[a], heap[b]) > 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 size; } } class Scanner { static string[] s = new string[0]; static int i = 0; static int max_i = 0; static public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } return s[i++]; } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Text; class Procon { static void Main(string[] agrs) { int N = Int(); int M = Int(); var tuples = new List<Tuple<int, int>>(); for (int i = 0; i < N; i++) { tuples.Add(Tuple.Create(Int(), Int())); } var sorted = tuples.OrderBy(v => v.Item1).ToList(); var pq = new PriorityQueue<int>(N, true); int cur = 0; int ans = 0; for (int i = 1; i <= M; i++) { while (cur < N && sorted[cur].Item1 <= i) { pq.Push(sorted[cur].Item2); cur++; } if (pq.Count() > 0) { ans += pq.Pop(); } } Dbg(ans); } static string String() => Scanner.nextString(); static int Int() => int.Parse(Scanner.nextString()); static long Long() => long.Parse(Scanner.nextString()); static double Double() => double.Parse(Scanner.nextString()); static char[] Chars() => String().ToCharArray(); static string[] Strings() => Console.ReadLine().Split(' '); static int[] Ints() => Strings().Select(v => int.Parse(v)).ToArray(); static long[] Longs() => Strings().Select(v => long.Parse(v)).ToArray(); static double[] Doubles() => Strings().Select(v => double.Parse(v)).ToArray(); const int M = 1000000007; static void Dbg(object a) => Console.WriteLine(a); static void Dbg(params object[] a) => Console.WriteLine(string.Join(" ", a)); static void Dbgs<T>(IEnumerable<T> a, string split = " ") => Console.WriteLine(string.Join(split, a)); static T Max<T>(params T[] a) => a.Max(); static T Min<T>(params T[] a) => a.Min(); } class PriorityQueue<T> where T : IComparable<T> { public T[] heap; public int size; public int sign; public PriorityQueue(int N, bool descend = false) { heap = new T[N]; if (descend) sign = -1; } public int Compare(T x, T y) { return x.CompareTo(y) * sign; } public void Push(T x) { int i = size++; while (i > 0) { int p = (i - 1) / 2; if (Compare(x, heap[p]) >= 0) { break; } heap[i] = heap[p]; i = p; } heap[i] = x; } public T Pop() { T ret = heap[0]; T x = heap[--size]; int i = 0; while (i * 2 + 1 < size) { int a = i * 2 + 1; int b = i * 2 + 2; if (b < size && Compare(heap[a], heap[b]) > 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 size; } } class Scanner { static string[] s = new string[0]; static int i = 0; static int max_i = 0; static public string nextString() { if (i >= s.Length) { s = Console.ReadLine().Split(' '); max_i = s.Length; i = 0; if (max_i == 0) { return ""; } return s[i++]; } return s[i++]; } }
[["+", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46], ["-", 0, 195, 8, 196, 0, 7, 8, 196, 0, 46]]
8
926
2
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC137E_2 { class Program { static void Main(string[] args) { var N = RInt; var M = RInt; var P = RInt; BellmanFord bf = new BellmanFord(N); for (int i = 0; i < M; i++) { var a = RInt - 1; var b = RInt - 1; var c = RInt; bf.AddEdge(a, b, P - c); } bool[] negative; var ans = bf.Start(0, out negative); if (!negative[N - 1]) Console.WriteLine(Math.Max(-ans[N - 1], 0)); else Console.WriteLine(-1); } } /// <summary> /// 単一始点最短経路 負の辺に対応 O(VE) /// </summary> class BellmanFord { public long BIG = long.MaxValue / 2; List<int> _start; List<int> _to; List<long> _cost; int _v; int _e; public BellmanFord(int V) { _v = V; _start = new List<int>(); _to = new List<int>(); _cost = new List<long>(); } public void AddEdge(int from, int to, long cost) { _start.Add(from); _to.Add(to); _cost.Add(cost); _e = _start.Count; } public long[] Start(int start, out bool[] negativeCycles) { //初期化・開始点の設定 long[] cost = new long[_v]; for (int i = 0; i < _v; i++) { cost[i] = BIG; } cost[start] = 0; //メインループ negativeCycles = new bool[_v]; for (int i = 0; i < 2 * _v; i++) { for (int e = 0; e < _e; e++) // 辺に関するループ { int f = _start[e]; int t = _to[e]; long c = _cost[e]; if (cost[f] > BIG / 2) continue; if (i <= _v - 1) { long cand = cost[f] + c; if (cand < cost[t]) // 更新条件 { cost[t] = cand; if (i == _v - 1) { negativeCycles[t] = true; } } else if (negativeCycles[f]) negativeCycles[t] = true; } } } for (int i = 0; i < _v; i++) { if (negativeCycles[i]) cost[i] = long.MaxValue; } return cost; } } } 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 ABC137E_2 { class Program { static void Main(string[] args) { var N = RInt; var M = RInt; var P = RInt; BellmanFord bf = new BellmanFord(N); for (int i = 0; i < M; i++) { var a = RInt - 1; var b = RInt - 1; var c = RInt; bf.AddEdge(a, b, P - c); } bool[] negative; var ans = bf.Start(0, out negative); if (!negative[N - 1]) Console.WriteLine(Math.Max(-ans[N - 1], 0)); else Console.WriteLine(-1); } } /// <summary> /// 単一始点最短経路 負の辺に対応 O(VE) /// </summary> class BellmanFord { public long BIG = long.MaxValue / 2; List<int> _start; List<int> _to; List<long> _cost; int _v; int _e; public BellmanFord(int V) { _v = V; _start = new List<int>(); _to = new List<int>(); _cost = new List<long>(); } public void AddEdge(int from, int to, long cost) { _start.Add(from); _to.Add(to); _cost.Add(cost); _e = _start.Count; } public long[] Start(int start, out bool[] negativeCycles) { //初期化・開始点の設定 long[] cost = new long[_v]; for (int i = 0; i < _v; i++) { cost[i] = BIG; } cost[start] = 0; //メインループ negativeCycles = new bool[_v]; for (int i = 0; i < 2 * _v; i++) { for (int e = 0; e < _e; e++) // 辺に関するループ { int f = _start[e]; int t = _to[e]; long c = _cost[e]; if (cost[f] > BIG / 2) continue; if (i <= _v - 1) { long cand = cost[f] + c; if (cand < cost[t]) // 更新条件 { cost[t] = cand; if (i == _v - 1) { negativeCycles[t] = true; } } } else if (negativeCycles[f]) negativeCycles[t] = true; } } for (int i = 0; i < _v; i++) { if (negativeCycles[i]) cost[i] = long.MaxValue; } return cost; } } } 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 } } }
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46], ["-", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
1,159
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { Scanner cin = new Scanner(); int n = cin.Int(); int m = cin.Int(); int p = cin.Int(); var bf = new BellmanFord(n); for (int i = 0; i < m; i++) { int a = cin.Int(); int b = cin.Int(); int c = cin.Int(); bf.AddEdge(a - 1, b - 1, -1 * (c - p)); } bool existsNegativeCycle; long ans = bf.CalculateDistance(0, n - 1, out existsNegativeCycle); if (existsNegativeCycle) { Console.WriteLine(-1); } ans *= -1; ans = Math.Max(0, ans); Console.WriteLine(ans); } } public class BellmanFord { private const long INFINITY = long.MaxValue; private readonly int count_; private readonly List<Edge> edges_; private readonly List<int>[] to_; private readonly List<int>[] from_; public BellmanFord(int count) { count_ = count; edges_ = new List<Edge>(count); to_ = Enumerable.Range(0, count).Select(x => new List<int>()).ToArray(); from_ = Enumerable.Range(0, count).Select(x => new List<int>()).ToArray(); } public void AddEdge(int from, int to, int cost) { edges_.Add(new Edge { From = from, To = to, Cost = cost }); to_[from].Add(to); from_[to].Add(from); } public long[] CalculateDistance(int startIndex, out bool existsNegativeCycle) { long[] distances = new long[count_]; for (int i = 0; i < count_; i++) { if (i != startIndex) { distances[i] = INFINITY; } } existsNegativeCycle = false; for (int i = 0; i < count_; i++) { bool changes = false; foreach (var edge in edges_) { if (distances[edge.From] != INFINITY) { long newDistance = distances[edge.From] + edge.Cost; if (newDistance < distances[edge.To]) { changes = true; distances[edge.To] = newDistance; } } } if (i == count_ - 1) { existsNegativeCycle = changes; } } return distances; } public long CalculateDistance(int startIndex, int endIndex, out bool existsNegativeCycle) { long[] distances = new long[count_]; for (int i = 0; i < count_; i++) { if (i != startIndex) { distances[i] = INFINITY; } } bool[] reachableFromStart = new bool[count_]; bool[] reachableFromEnd = new bool[count_]; DfsForTo(startIndex, reachableFromStart); DfsForFrom(endIndex, reachableFromEnd); bool[] enableds = new bool[count_]; for (int i = 0; i < count_; i++) { enableds[i] = reachableFromStart[i] & reachableFromEnd[i]; } existsNegativeCycle = false; for (int i = 0; i < count_; i++) { bool changes = false; foreach (var edge in edges_) { if (enableds[edge.From] == false || enableds[edge.To] == false) { continue; } if (distances[edge.From] != INFINITY) { long newDistance = distances[edge.From] + edge.Cost; if (newDistance < distances[edge.To]) { changes = true; distances[edge.To] = newDistance; } } } if (i == count_ - 1) { existsNegativeCycle = changes; } } return distances[endIndex]; } private void DfsForTo(int index, bool[] reachableFromStart) { if (reachableFromStart[index]) { return; } reachableFromStart[index] = true; foreach (int next in to_[index]) { DfsForTo(next, reachableFromStart); } } private void DfsForFrom(int index, bool[] reachableFromEnd) { if (reachableFromEnd[index]) { return; } reachableFromEnd[index] = true; foreach (int next in from_[index]) { DfsForFrom(next, reachableFromEnd); } } private struct Edge { public int From; public int To; public long Cost; } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCorder { public class Program { static void Main(string[] args) { Scanner cin = new Scanner(); int n = cin.Int(); int m = cin.Int(); int p = cin.Int(); var bf = new BellmanFord(n); for (int i = 0; i < m; i++) { int a = cin.Int(); int b = cin.Int(); int c = cin.Int(); bf.AddEdge(a - 1, b - 1, -1 * (c - p)); } bool existsNegativeCycle; long ans = bf.CalculateDistance(0, n - 1, out existsNegativeCycle); if (existsNegativeCycle) { Console.WriteLine(-1); return; } ans *= -1; ans = Math.Max(0, ans); Console.WriteLine(ans); } } public class BellmanFord { private const long INFINITY = long.MaxValue; private readonly int count_; private readonly List<Edge> edges_; private readonly List<int>[] to_; private readonly List<int>[] from_; public BellmanFord(int count) { count_ = count; edges_ = new List<Edge>(count); to_ = Enumerable.Range(0, count).Select(x => new List<int>()).ToArray(); from_ = Enumerable.Range(0, count).Select(x => new List<int>()).ToArray(); } public void AddEdge(int from, int to, int cost) { edges_.Add(new Edge { From = from, To = to, Cost = cost }); to_[from].Add(to); from_[to].Add(from); } public long[] CalculateDistance(int startIndex, out bool existsNegativeCycle) { long[] distances = new long[count_]; for (int i = 0; i < count_; i++) { if (i != startIndex) { distances[i] = INFINITY; } } existsNegativeCycle = false; for (int i = 0; i < count_; i++) { bool changes = false; foreach (var edge in edges_) { if (distances[edge.From] != INFINITY) { long newDistance = distances[edge.From] + edge.Cost; if (newDistance < distances[edge.To]) { changes = true; distances[edge.To] = newDistance; } } } if (i == count_ - 1) { existsNegativeCycle = changes; } } return distances; } public long CalculateDistance(int startIndex, int endIndex, out bool existsNegativeCycle) { long[] distances = new long[count_]; for (int i = 0; i < count_; i++) { if (i != startIndex) { distances[i] = INFINITY; } } bool[] reachableFromStart = new bool[count_]; bool[] reachableFromEnd = new bool[count_]; DfsForTo(startIndex, reachableFromStart); DfsForFrom(endIndex, reachableFromEnd); bool[] enableds = new bool[count_]; for (int i = 0; i < count_; i++) { enableds[i] = reachableFromStart[i] & reachableFromEnd[i]; } existsNegativeCycle = false; for (int i = 0; i < count_; i++) { bool changes = false; foreach (var edge in edges_) { if (enableds[edge.From] == false || enableds[edge.To] == false) { continue; } if (distances[edge.From] != INFINITY) { long newDistance = distances[edge.From] + edge.Cost; if (newDistance < distances[edge.To]) { changes = true; distances[edge.To] = newDistance; } } } if (i == count_ - 1) { existsNegativeCycle = changes; } } return distances[endIndex]; } private void DfsForTo(int index, bool[] reachableFromStart) { if (reachableFromStart[index]) { return; } reachableFromStart[index] = true; foreach (int next in to_[index]) { DfsForTo(next, reachableFromStart); } } private void DfsForFrom(int index, bool[] reachableFromEnd) { if (reachableFromEnd[index]) { return; } reachableFromEnd[index] = true; foreach (int next in from_[index]) { DfsForFrom(next, reachableFromEnd); } } private struct Edge { public int From; public int To; public long Cost; } } public class Scanner { private readonly char[] delimiter_ = new char[] { ' ' }; private string[] buf_; private int index_; public Scanner() { buf_ = new string[0]; index_ = 0; } public string Next() { if (index_ < buf_.Length) { return buf_[index_++]; } string st = Console.ReadLine(); while (st == "") { st = Console.ReadLine(); } buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries); if (buf_.Length == 0) { return Next(); } index_ = 0; return buf_[index_++]; } public int Int() { return int.Parse(Next()); } public int[] ArrayInt(int N, int add = 0) { int[] Array = new int[N]; for (int i = 0; i < N; i++) { Array[i] = Int() + add; } return Array; } public long Long() { return long.Parse(Next()); } public long[] ArrayLong(int N, long add = 0) { long[] Array = new long[N]; for (int i = 0; i < N; i++) { Array[i] = Long() + add; } return Array; } public double Double() { return double.Parse(Next()); } public double[] ArrayDouble(int N, double add = 0) { double[] Array = new double[N]; for (int i = 0; i < N; i++) { Array[i] = Double() + add; } return Array; } } }
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
8
1,303
2
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int C = int.Parse(str[2]); if ((A - B) >= C) { Console.WriteLine(C); } else { Console.WriteLine(C - (A - B)); } } } }
using System; using System.Linq; namespace Sample { class Sample { static void Main(string[] args) { string[] str = Console.ReadLine().Split(' '); int A = int.Parse(str[0]); int B = int.Parse(str[1]); int C = int.Parse(str[2]); if ((A - B) >= C) { Console.WriteLine(0); } else { Console.WriteLine(C - (A - B)); } } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
119
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; public class Hello { public static void Main() { int[] read = inta(); WriteLine(read[2] - read[0] + read[1]); } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // A/B小数点以下切上 static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // スタック -> 深さ優先 ???
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; public class Hello { public static void Main() { int[] read = inta(); WriteLine(Max(read[2] - read[0] + read[1], 0)); } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // A/B小数点以下切上 static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } } //知見 // (string) hogestr -> (char[]) hoge // char hoge = hogestr.ToCharArray(); // (char[]) hoge -> (string) hogestr // string hoge = new string(hoge); // Hashtable × Dictionary ○ // Dictionary hoge<string,int> // hoge.ContainsKey(string) -> return boolean // hoge[string] -> return int // hoge[int] -> CE // Dictionary hoge<int1,int2> // hoge<int1,int2>: hoge[int1] -> return int2 // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2 // SortedDictionary() > SortedList() ??? // キュー -> 幅優先 ??? // スタック -> 深さ優先 ???
[["+", 0, 213, 3, 4, 0, 28, 0, 213, 63, 22], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 24], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 21], ["+", 0, 28, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 213, 3, 4, 0, 25]]
8
595
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC136A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); d = b + c; if (d <= a) Console.WriteLine("0"); else Console.WriteLine(a - d); Console.ReadKey(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC136A { class Program { static void Main(string[] args) { int a, b, c, d; var word = Console.ReadLine().Split(' '); a = int.Parse(word[0]); b = int.Parse(word[1]); c = int.Parse(word[2]); d = b + c; if (d <= a) Console.WriteLine("0"); else Console.WriteLine(d - a); Console.ReadKey(); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
144
4
#if true && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Net.Mime; using System.Text; namespace UtakaApp { public partial class Program { public const string SiteName = "AtCoder"; public const string ContestName = "abc136"; public const string ProblemName = "A"; public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var console = new MyConsole(); new Program().Solve(System.Console.In, console); console.Flush(); #endif var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; } public void Solve(TextReader textReader, IConsole console) { var cin = new ConsoleInput(textReader); int A = cin.ReadInt; int B = cin.ReadInt; int C = cin.ReadInt; int rest = A - B; int add = Math.Max(C, rest); int ans = C - add; console.WriteLine(ans.ToString()); } } public class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var 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 IConsole { void Flush(); void Write(string str); void WriteLine(string str); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(string str) { Console.Write(str); } public void WriteLine(string str) { Console.WriteLine(str); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(string str) { mSb.Append(str); } public void WriteLine(string str) { mSb.AppendLine(str); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var debugConsoleWriter = new DebugConsole(); new Program().Solve(inputStream, debugConsoleWriter); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); 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 !!!!!!!!!"); } } } #endif #if UTAKA_LOCAL 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 && UTAKA_LOCAL //#if false #define UTAKA_DEBUG #endif using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Net.Mime; using System.Text; namespace UtakaApp { public partial class Program { public const string SiteName = "AtCoder"; public const string ContestName = "abc136"; public const string ProblemName = "A"; public static void Main(string[] args) { #if UTAKA_LOCAL //#if false new TestCaseCheckerForAtCoder().TestProblems(); #else var console = new MyConsole(); new Program().Solve(System.Console.In, console); console.Flush(); #endif var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; } public void Solve(TextReader textReader, IConsole console) { var cin = new ConsoleInput(textReader); int A = cin.ReadInt; int B = cin.ReadInt; int C = cin.ReadInt; int rest = A - B; int add = Math.Min(C, rest); int ans = C - add; console.WriteLine(ans.ToString()); } } public class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { _separator = separator; _stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) { return inputStream.Dequeue(); } var tmp = _stream.ReadLine().Split(_separator); for (var 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 IConsole { void Flush(); void Write(string str); void WriteLine(string str); } public class MyConsole : IConsole { public MyConsole() { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); } public void Flush() { Console.Out.Flush(); } public void Write(string str) { Console.Write(str); } public void WriteLine(string str) { Console.WriteLine(str); } } #if UTAKA_LOCAL public class DebugConsole : IConsole { private readonly StringBuilder mSb; public DebugConsole() { mSb = new StringBuilder(); } public void Flush() { // 何もしない } public void Write(string str) { mSb.Append(str); } public void WriteLine(string str) { mSb.AppendLine(str); } public string GetAllOutput() { return mSb.ToString(); } } #endif #if UTAKA_LOCAL public class TestCaseCheckerForAtCoder { private string GetDirectoryPath() { var problemPart = string.IsNullOrEmpty(Program.ProblemName) ? "" : $"/{Program.ProblemName}"; return $"{System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}/AlgorithmPrac/{Program.SiteName}/{Program.ContestName}{problemPart}"; } private string GetInputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.in"; } private string GetOutputFilePath(int testCaseNumber) { return $"{GetDirectoryPath()}/sample-{testCaseNumber}.out"; } public bool TestProblem(int testCaseNumber) { var inputFilePath = GetInputFilePath(testCaseNumber); var outputFilePath = GetOutputFilePath(testCaseNumber); TextReader inputStream = new StreamReader(inputFilePath); var debugConsoleWriter = new DebugConsole(); new Program().Solve(inputStream, debugConsoleWriter); var output = debugConsoleWriter.GetAllOutput(); TextReader outputStream = new StreamReader(outputFilePath); var outputAnswer = outputStream.ReadToEnd(); Dbg.WriteLine(output); Dbg.WriteLine(outputAnswer); 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 !!!!!!!!!"); } } } #endif #if UTAKA_LOCAL 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 }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22]]
8
1,174
2
// ABC136 A - Transfer // 20190905 using System; using System.Linq; namespace A { class Program { static void Main(string[] args) { // Console.WriteLine("Hello World!"); var INPUT = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = INPUT[0]; int B = INPUT[1]; int C = INPUT[2]; int OUTPUT = C - (A - B); Console.WriteLine(OUTPUT); } } }
// ABC136 A - Transfer // 20190905 using System; using System.Linq; namespace A { class Program { static void Main(string[] args) { // Console.WriteLine("Hello World!"); var INPUT = Console.ReadLine().Split().Select(int.Parse).ToArray(); int A = INPUT[0]; int B = INPUT[1]; int C = INPUT[2]; int OUTPUT = C - (A - B); Console.WriteLine(OUTPUT >= 0 ? OUTPUT : 0); } } }
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 101], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 22], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
96
6