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.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N = GetInt(); if (N < 10) { Console.WriteLine(N); return; } var que = new Queue<long>(); Enumerable.Range(1, 9).ToList().ForEach(i => que.Enqueue(i)); var cnt = 1; while (cnt < N) { var n = que.Dequeue(); var list = new List<long>(); if (n % 10 == 9) { que.Enqueue(n * 10 + n % 10 - 1); que.Enqueue(n * 10 + n % 10); } else if (n % 10 == 0) { que.Enqueue(n * 10 + n % 10); que.Enqueue(n * 10 + N % 10 + 1); } else { que.Enqueue(n * 10 + n % 10 - 1); que.Enqueue(n * 10 + n % 10); que.Enqueue(n * 10 + n % 10 + 1); } cnt++; } Console.WriteLine(que.Dequeue()); } } //拡張メソッド 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.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { int N = GetInt(); if (N < 10) { Console.WriteLine(N); return; } var que = new Queue<long>(); Enumerable.Range(1, 9).ToList().ForEach(i => que.Enqueue(i)); var cnt = 1; while (cnt < N) { var n = que.Dequeue(); var list = new List<long>(); if (n % 10 == 9) { que.Enqueue(n * 10 + n % 10 - 1); que.Enqueue(n * 10 + n % 10); } else if (n % 10 == 0) { que.Enqueue(n * 10 + n % 10); que.Enqueue(n * 10 + n % 10 + 1); } else { que.Enqueue(n * 10 + n % 10 - 1); que.Enqueue(n * 10 + n % 10); que.Enqueue(n * 10 + n % 10 + 1); } cnt++; } Console.WriteLine(que.Dequeue()); } } //拡張メソッド 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, 28, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 28, 0, 16, 31, 16, 12, 16, 31, 22]]
8
1,715
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { long N = GetLong(); if (N == 1) { Console.WriteLine(2); return; } long cnt = 0; for (int i = 2; i <= Math.Sqrt(N); i++) { var temp = N; if (temp % i != 0) continue; while (temp % i == 0) { temp /= i; } if (temp % i == 1) cnt++; } long cntt = 1; Factoring(N - 1).Values.Select(s => s + 1).ToList().ForEach(i => cntt *= i); cntt--; Console.WriteLine(cnt + cntt + 1); } static public Dictionary<long, int> Factoring(long num) { Dictionary<long, int> vs = new Dictionary<long, int>(); if (num == 1) { vs.Add(1, 1); return vs; } while (num % 2 == 0) { if (vs.ContainsKey(2) == false) { vs.Add(2, 0); } vs[2]++; num /= 2; } if (num == 1) { return vs; } int i = 3; while (i <= Math.Sqrt(num)) { if (num % i == 0) { if (vs.ContainsKey(i) == false) { vs.Add(i, 0); } vs[i]++; num /= i; } else { i += 2; } } if (vs.ContainsKey(num) == false) { vs.Add(num, 1); } else { vs[num]++; } return vs; } } //拡張メソッド 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.Numerics; using System.Text; using System.Threading.Tasks; namespace AtCoder { partial class Program { static long mod = 1000000007; static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(); Console.Out.Flush(); Console.ReadKey(); } //ここから static void Solve() { long N = GetLong(); if (N == 2) { Console.WriteLine(1); return; } long cnt = 0; for (int i = 2; i <= Math.Sqrt(N); i++) { var temp = N; if (temp % i != 0) continue; while (temp % i == 0) { temp /= i; } if (temp % i == 1) cnt++; } long cntt = 1; Factoring(N - 1).Values.Select(s => s + 1).ToList().ForEach(i => cntt *= i); cntt--; Console.WriteLine(cnt + cntt + 1); } static public Dictionary<long, int> Factoring(long num) { Dictionary<long, int> vs = new Dictionary<long, int>(); if (num == 1) { vs.Add(1, 1); return vs; } while (num % 2 == 0) { if (vs.ContainsKey(2) == false) { vs.Add(2, 0); } vs[2]++; num /= 2; } if (num == 1) { return vs; } int i = 3; while (i <= Math.Sqrt(num)) { if (num % i == 0) { if (vs.ContainsKey(i) == false) { vs.Add(i, 0); } vs[i]++; num /= i; } else { i += 2; } } if (vs.ContainsKey(num) == false) { vs.Add(num, 1); } else { vs[num]++; } return vs; } } //拡張メソッド 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, 57, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
1,832
4
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { long N; public void Solve(Scanner sc) { N = sc.Long; var res = 0; for (long i = 1L; i * i <= N - 1; i++) if ((N - 1) % i == 0) { if (i != 1) res++; if (i * i != N - 1) res++; } for (long i = 1L; i * i <= N; i++) if (N % i == 0) { if (i != 1 && ch(i)) res++; if (ch(N / i)) res++; } WriteLine(res); } bool ch(long k) { var a = N; while (a % k == 0) a /= k; return a % k == 1; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Runtime.CompilerServices; using System.Text; using System.Diagnostics; using System.Numerics; using static System.Console; using static System.Convert; using static System.Math; using static Template; using Pi = Pair<int, int>; class Solver { long N; public void Solve(Scanner sc) { N = sc.Long; var res = 0; for (long i = 1L; i * i <= N - 1; i++) if ((N - 1) % i == 0) { if (i != 1) res++; if (i * i != N - 1) res++; } for (long i = 1L; i * i <= N; i++) if (N % i == 0) { if (i != 1 && ch(i)) res++; if (i * i != N && ch(N / i)) res++; } WriteLine(res); } bool ch(long k) { var a = N; while (a % k == 0) a /= k; return a % k == 1; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new Solver().Solve(new Scanner()); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == 1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) == -1) { a = b; return true; } return false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(ref T a, ref T b) { var t = b; b = a; a = t; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void swap<T>(this IList<T> A, int i, int j) { var t = A[i]; A[i] = A[j]; A[j] = t; } public static T[] Shuffle<T>(this IList<T> A) { T[] rt = A.ToArray(); Random rnd = new Random(); for (int i = rt.Length - 1; i >= 1; i--) swap(ref rt[i], ref rt[rnd.Next(i + 1)]); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(); return rt; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static T[] Create<T>(int n, Func<int, T> f) { var rt = new T[n]; for (var i = 0; i < rt.Length; ++i) rt[i] = f(i); return rt; } public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); } } public class Scanner { public string Str => Console.ReadLine().Trim(); public int Int => int.Parse(Str); public long Long => long.Parse(Str); public double Double => double.Parse(Str); public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray(); public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray(); public char[][] Grid(int n) => Create(n, () => Str.ToCharArray()); public int[] ArrInt1D(int n) => Create(n, () => Int); public long[] ArrLong1D(int n) => Create(n, () => Long); public int[][] ArrInt2D(int n) => Create(n, () => ArrInt); public long[][] ArrLong2D(int n) => Create(n, () => ArrLong); private Queue<string> q = new Queue<string>(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); } public void Make<T1>(out T1 v1) => v1 = Next<T1>(); public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); } public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); } public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); } public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); } public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); } // public (T1, T2) Make<T1, T2>() { Make(out T1 v1, out T2 v2); return (v1, // v2); } public (T1, T2, T3) Make<T1, T2, T3>() { Make(out T1 v1, out T2 v2, // out T3 v3); return (v1, v2, v3); } public (T1, T2, T3, T4) Make<T1, T2, T3, // T4>() { Make(out T1 v1, out T2 v2, out T3 v3, out T4 v4); return (v1, v2, // v3, v4); } } public class Pair<T1, T2> : IComparable<Pair<T1, T2>> { public T1 v1; public T2 v2; public Pair() {} public Pair(T1 v1, T2 v2) { this.v1 = v1; this.v2 = v2; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2> p) { var c = Comparer<T1>.Default.Compare(v1, p.v1); if (c == 0) c = Comparer<T2>.Default.Compare(v2, p.v2); return c; } public override string ToString() => $"{v1.ToString()} {v2.ToString()}"; public void Deconstruct(out T1 a, out T2 b) { a = v1; b = v2; } } public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>> { public T3 v3; public Pair() : base() {} public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2) { this.v3 = v3; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(Pair<T1, T2, T3> p) { var c = base.CompareTo(p); if (c == 0) c = Comparer<T3>.Default.Compare(v3, p.v3); return c; } public override string ToString() => $"{base.ToString()} {v3.ToString()}"; public void Deconstruct(out T1 a, out T2 b, out T3 c) { Deconstruct(out a, out b); c = v3; } } #endregion
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 17, 79], ["+", 64, 196, 0, 57, 15, 16, 31, 16, 12, 22], ["+", 8, 57, 64, 196, 0, 57, 15, 16, 17, 98]]
8
1,710
6
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace A { class StartingPoint { static void Main(string[] args) { if (args?.Any() == true) { var assembly = Assembly.GetEntryAssembly(); var resourceName = "AtCoderCSharp.In.txt"; var stream = assembly.GetManifestResourceStream(resourceName); var streamReader = new StreamReader(stream, Encoding.UTF8); var str = streamReader.ReadToEnd(); var textReader = new StringReader(str); Console.SetIn(textReader); } try { foreach (var s in new Program().Solve()) { Console.WriteLine(s); } } catch (Exception e) { Console.WriteLine(e); if (args?.Any() != true) throw e; } if (args?.Any() == true) Console.ReadKey(); } } class Program { public List<int> ScanInts(int count) => Enumerable.Range(0, count).Select(_ => ScanInt).ToList(); public List<int> ScanInts(long count) => ScanInts((int)count); public List<long> ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList(); public List<long> ScanLongs(long count) => ScanLongs((int)count); public int ScanInt => int.Parse(Str); public long Scan => long.Parse(Str); public double ScanDouble => (double)Scan; StringBuilder sb = new StringBuilder(); public string Str => ScanStr(); public string ScanStr() { sb.Clear(); int r = 0; bool? b = null; do { r = Console.Read(); b = IsBreak(r); } while (b == true); if (b == null) throw new Exception("input error: unexpected end of stream"); do { sb.Append((char)r); r = Console.Read(); b = IsBreak(r); } while (b == false); return sb.ToString(); } bool? IsBreak(int c) { switch (c) { case -1: return null; case (int)' ': case (int)'\n': case (int)'\r': return true; default: return false; } } public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count); public IEnumerable<int> Loop(int from, int to) => Enumerable.Range(from, to - from + 1); public IEnumerable<long> Loop(long count) => Loop(0, count - 1); public IEnumerable<long> Loop(long from, long to) { for (long i = from; i <= to; i++) yield return i; } public string YesNo(bool isYes) => isYes ? "Yes" : "No"; public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts); bool Slv(long n, long k) { if (n < k) return n == 1; if (n % k == 0) return Slv(n / k, k); else return Slv(n % k, k); } long Slv2(long n) { var d = n; var dic = new Dictionary<long, long>(); for (long i = 2; i * i < n; i++) { while (d % i == 0) { d /= i; if (dic.ContainsKey(i)) dic[i]++; else dic.Add(i, 1); } } var res = 1L; foreach (var p in dic.Values) res *= (p + 1); if (d > 1) res *= 2; return res; } public IEnumerable<string> Solve() { var n = Scan; var n1 = n - 1; var res = 0L; for (long i = 2; i * i < n; i++) { if (n % i == 0) { if (Slv(n, i)) res++; } } res++; res += Slv2(n1) - 1; yield return res.ToString(); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Text; namespace A { class StartingPoint { static void Main(string[] args) { if (args?.Any() == true) { var assembly = Assembly.GetEntryAssembly(); var resourceName = "AtCoderCSharp.In.txt"; var stream = assembly.GetManifestResourceStream(resourceName); var streamReader = new StreamReader(stream, Encoding.UTF8); var str = streamReader.ReadToEnd(); var textReader = new StringReader(str); Console.SetIn(textReader); } try { foreach (var s in new Program().Solve()) { Console.WriteLine(s); } } catch (Exception e) { Console.WriteLine(e); if (args?.Any() != true) throw e; } if (args?.Any() == true) Console.ReadKey(); } } class Program { public List<int> ScanInts(int count) => Enumerable.Range(0, count).Select(_ => ScanInt).ToList(); public List<int> ScanInts(long count) => ScanInts((int)count); public List<long> ScanLongs(int count) => Enumerable.Range(0, count).Select(_ => Scan).ToList(); public List<long> ScanLongs(long count) => ScanLongs((int)count); public int ScanInt => int.Parse(Str); public long Scan => long.Parse(Str); public double ScanDouble => (double)Scan; StringBuilder sb = new StringBuilder(); public string Str => ScanStr(); public string ScanStr() { sb.Clear(); int r = 0; bool? b = null; do { r = Console.Read(); b = IsBreak(r); } while (b == true); if (b == null) throw new Exception("input error: unexpected end of stream"); do { sb.Append((char)r); r = Console.Read(); b = IsBreak(r); } while (b == false); return sb.ToString(); } bool? IsBreak(int c) { switch (c) { case -1: return null; case (int)' ': case (int)'\n': case (int)'\r': return true; default: return false; } } public IEnumerable<int> Loop(int count) => Enumerable.Range(0, count); public IEnumerable<int> Loop(int from, int to) => Enumerable.Range(from, to - from + 1); public IEnumerable<long> Loop(long count) => Loop(0, count - 1); public IEnumerable<long> Loop(long from, long to) { for (long i = from; i <= to; i++) yield return i; } public string YesNo(bool isYes) => isYes ? "Yes" : "No"; public HashSet<T> ToHashSet<T>(IEnumerable<T> ts) => new HashSet<T>(ts); bool Slv(long n, long k) { if (n < k) return n == 1; if (n % k == 0) return Slv(n / k, k); else return Slv(n % k, k); } long Slv2(long n) { var d = n; var dic = new Dictionary<long, long>(); for (long i = 2; i * i <= n; i++) { while (d % i == 0) { d /= i; if (dic.ContainsKey(i)) dic[i]++; else dic.Add(i, 1); } } var res = 1L; foreach (var p in dic.Values) res *= (p + 1); if (d > 1) res *= 2; return res; } public IEnumerable<string> Solve() { var n = Scan; var n1 = n - 1; var res = 0L; for (long i = 2; i * i <= n; i++) { if (n % i == 0) { if (Slv(n, i)) res++; } } res++; res += Slv2(n1) - 1; yield return res.ToString(); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
908
4
using System; using System.Collections.Generic; using static Assistant.Input; using static Assistant.Debug; using System.Linq; using Assistant; namespace ABC160A { class Program { static void Main(string[] args) { var S = Console.ReadLine(); if (S[2] == S[3] || S[4] == S[5]) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } } 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 ABC160A { class Program { static void Main(string[] args) { var S = Console.ReadLine(); if (S[2] == S[3] && S[4] == S[5]) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } } 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, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98]]
8
709
2
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); if (input.Length != 6 || input[2] != input[3] || input[4] != input[5]) Console.WriteLine("NO"); else Console.WriteLine("Yes"); } } }
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); if (input.Length != 6 || input[2] != input[3] || input[4] != input[5]) Console.WriteLine("No"); else Console.WriteLine("Yes"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
78
2
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); if (input.Length != 6) { Console.WriteLine("No"); return; } if (input[2] != input[3]) { Console.WriteLine("No"); return; } if (input[4] != input[5]) { Console.WriteLine("No"); return; } Console.WriteLine("No"); } } }
using System; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string input = Console.ReadLine(); if (input.Length != 6) { Console.WriteLine("No"); return; } if (input[2] != input[3]) { Console.WriteLine("No"); return; } if (input[4] != input[5]) { Console.WriteLine("No"); return; } Console.WriteLine("Yes"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
111
2
using System; using CompLib.Util; public class Program { public void Solve() { var sc = new Scanner(); int n = sc.NextInt(); long s = 0; for (int i = 0; i < n; i++) { if (i % 3 != 0 && i % 5 != 0) { s += i; } } Console.WriteLine(s); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using CompLib.Util; public class Program { public void Solve() { var sc = new Scanner(); int n = sc.NextInt(); long s = 0; for (int i = 1; i <= n; i++) { if (i % 3 != 0 && i % 5 != 0) { s += i; } } Console.WriteLine(s); } public static void Main(string[] args) => new Program().Solve(); } namespace CompLib.Util { using System; using System.Linq; class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
413
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.AtCoder_Begginer_Contest_162 { class C { static void Main(string[] args) { string input1 = Console.ReadLine(); long n = long.Parse(input1); long sum = 0; for (long i = 1; i <= n; i++) { for (long j = 1; j <= n; j++) { for (long k = 1; k <= n; k++) { sum += gcd(gcd(i, j), j); } } } Console.WriteLine(sum); // Console.ReadKey(); } static long gcd(long p, long q) { if (p % q == 0) return q; return gcd(q, p % q); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.AtCoder_Begginer_Contest_162 { class C { static void Main(string[] args) { string input1 = Console.ReadLine(); long n = long.Parse(input1); long sum = 0; for (long i = 1; i <= n; i++) { for (long j = 1; j <= n; j++) { for (long k = 1; k <= n; k++) { sum += gcd(gcd(i, j), k); } } } Console.WriteLine(sum); // Console.ReadKey(); } static long gcd(long p, long q) { if (p % q == 0) return q; return gcd(q, p % q); } } }
[["-", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 11, 12, 213, 3, 4, 0, 28, 0, 22]]
8
175
2
using System; using System.Linq; class D { static void Main() { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine() .Select(x => x == 'R' ? 0 : x == 'G' ? 1 : 2) .ToArray(); var dp = new int[n + 1, 3]; for (int i = n - 1; i >= 0; i--) for (int j = 0; j < 3; j++) dp[i, j] = dp[i + 1, j] + (s[i] == j ? 1 : 0); var r = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { if (s[i] == s[j]) continue; var sk = 3 - s[i] - s[j]; r += dp[j, sk]; if (2 * j - i < n && s[2 * j - i] == sk) r--; } Console.WriteLine(r); } }
using System; using System.Linq; class D { static void Main() { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine() .Select(x => x == 'R' ? 0 : x == 'G' ? 1 : 2) .ToArray(); var dp = new int[n + 1, 3]; for (int i = n - 1; i >= 0; i--) for (int j = 0; j < 3; j++) dp[i, j] = dp[i + 1, j] + (s[i] == j ? 1 : 0); var r = 0L; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { if (s[i] == s[j]) continue; var sk = 3 - s[i] - s[j]; r += dp[j, sk]; if (2 * j - i < n && s[2 * j - i] == sk) r--; } Console.WriteLine(r); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
247
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; class program { static public int mod = 1000000007; static void Main() { var n = rint(); var s = rstr(); int ct = 0; var isrgb = new int[n]; var rgbct = new int[n + 1, 3]; for (int i = n - 1; i >= 0; i--) { rgbct[i, 0] = rgbct[i + 1, 0]; rgbct[i, 1] = rgbct[i + 1, 1]; rgbct[i, 2] = rgbct[i + 1, 2]; if (s[i] == 'R') { rgbct[i, 0] = rgbct[i + 1, 0] + 1; isrgb[i] = 1; } if (s[i] == 'G') { rgbct[i, 1] = rgbct[i + 1, 1] + 1; isrgb[i] = 2; } if (s[i] == 'B') { rgbct[i, 2] = rgbct[i + 1, 2] + 1; isrgb[i] = 4; } } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (isrgb[i] != isrgb[j]) { int ij = j - i; ct += rgbct[j + 1, (7 - isrgb[i] - isrgb[j]) / 2]; if (j + ij < n) if (isrgb[j + ij] == 7 - isrgb[i] - isrgb[j]) ct--; } } } Write(ct); } static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static 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] = double.Parse(read_str_array[countup_i]); } return return_double_array; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; class program { static public int mod = 1000000007; static void Main() { var n = rint(); var s = rstr(); long ct = 0; var isrgb = new int[n]; var rgbct = new int[n + 1, 3]; for (int i = n - 1; i >= 0; i--) { rgbct[i, 0] = rgbct[i + 1, 0]; rgbct[i, 1] = rgbct[i + 1, 1]; rgbct[i, 2] = rgbct[i + 1, 2]; if (s[i] == 'R') { rgbct[i, 0] = rgbct[i + 1, 0] + 1; isrgb[i] = 1; } if (s[i] == 'G') { rgbct[i, 1] = rgbct[i + 1, 1] + 1; isrgb[i] = 2; } if (s[i] == 'B') { rgbct[i, 2] = rgbct[i + 1, 2] + 1; isrgb[i] = 4; } } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (isrgb[i] != isrgb[j]) { int ij = j - i; ct += rgbct[j + 1, (7 - isrgb[i] - isrgb[j]) / 2]; if (j + ij < n) if (isrgb[j + ij] == 7 - isrgb[i] - isrgb[j]) ct--; } } } Write(ct); } static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static 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] = double.Parse(read_str_array[countup_i]); } return return_double_array; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
1,054
2
using System; //(条件1)RGB全部異なる //(条件2)j-i!=k-j //まず(1)から考えると、#R*#G*#B(#は、~の数) //その中から(2)を抜く。N<=4000でi,jがわかるとkも決まるので計算量はO(n^2) //(2)変形するとk=2j-i class Program { static void Main() { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int[] A = new int[n]; int[] C = new int[3]; // 0=#B, 1=#R, 2=#G for (int i = 0; i < n; i++) { A[i] = s[i] % 3; //%3をとるとB(66)=0,G(71)=2,R(82)=1となる C[A[i]]++; } long ans = C[0] * C[1] * C[2]; for (int j = 0; j < n; j++) { for (int i = 0; i < j; i++) { int k = j + (j - i); if (k < n) { if (A[i] == A[j]) continue; if (A[i] == A[k]) continue; if (A[k] == A[j]) continue; ans--; } } } Console.WriteLine(ans); } } // class Program //{ // static void Main() // { // int n = int.Parse(Console.ReadLine()); // string s = Console.ReadLine(); // int r=0, g=0, b=0; // for(int i=0; i < n; i++) // { // switch (s[i]) // { // case 'R': // r++; // break; // case 'G': // g++; // break; // case 'B': // b++; // break; // } // } // long sum = r * g * b; // int sc = 0;//重複カウント // int temp; // for(int i = 0; i < n; i++) // { // for(int j = 0; j < n; j++) // { // temp = 2 * j - i; // if (!(2 <= temp && temp <n)) continue; // if (!(i < temp)) continue; // if (s[i] != s[j] && s[j] != s[temp]) sc++; // } // } // Console.WriteLine(sum - sc); // } //}
using System; //(条件1)RGB全部異なる //(条件2)j-i!=k-j //まず(1)から考えると、#R*#G*#B(#は、~の数) //その中から(2)を抜く。N<=4000でi,jがわかるとkも決まるので計算量はO(n^2) //(2)変形するとk=2j-i class Program { static void Main() { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int[] A = new int[n]; int[] C = new int[3]; // 0=#B, 1=#R, 2=#G for (int i = 0; i < n; i++) { A[i] = s[i] % 3; //%3をとるとB(66)=0,G(71)=2,R(82)=1となる C[A[i]]++; } long ans = (long)C[0] * C[1] * C[2]; // C[0]にlongつけないと計算過程でオーバーフローする for (int j = 0; j < n; j++) { for (int i = 0; i < j; i++) { int k = j + (j - i); if (k < n) { if (A[i] == A[j]) continue; if (A[i] == A[k]) continue; if (A[k] == A[j]) continue; ans--; } } } Console.WriteLine(ans); } } // class Program //{ // static void Main() // { // int n = int.Parse(Console.ReadLine()); // string s = Console.ReadLine(); // int r=0, g=0, b=0; // for(int i=0; i < n; i++) // { // switch (s[i]) // { // case 'R': // r++; // break; // case 'G': // g++; // break; // case 'B': // b++; // break; // } // } // long sum = r * g * b; // int sc = 0;//重複カウント // int temp; // for(int i = 0; i < n; i++) // { // for(int j = 0; j < n; j++) // { // temp = 2 * j - i; // if (!(2 <= temp && temp <n)) continue; // if (!(i < temp)) continue; // if (s[i] != s[j] && s[j] != s[temp]) sc++; // } // } // Console.WriteLine(sum - sc); // } //}
[["+", 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]]
8
262
3
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var S = Console.ReadLine(); var R = S.Where(_ => _ == 'R').Count(); var G = S.Where(_ => _ == 'G').Count(); var B = S.Where(_ => _ == 'B').Count(); var ans = R * G * B; for (var i = 1; i <= N / 2; i++) { for (var j = 0; j < N - (2 * i); j++) { if (S[j] != S[j + i] && S[j + i] != S[j + (2 * i)] && S[j] != S[j + (2 * i)]) { ans--; } } } Console.Write(ans); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class { static void Main(string[] args) { var N = long.Parse(Console.ReadLine()); var S = Console.ReadLine(); long R = S.Where(_ => _ == 'R').Count(); long G = S.Where(_ => _ == 'G').Count(); long B = S.Where(_ => _ == 'B').Count(); var ans = R * G * B; for (var i = 1; i <= N / 2; i++) { for (var j = 0; j < N - (2 * i); j++) { if (S[j] != S[j + i] && S[j + i] != S[j + (2 * i)] && S[j] != S[j + (2 * i)]) { ans--; } } } Console.Write(ans); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
227
6
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var N = LnInt(); var S = LnStr(); var r = S.Count(x => x == 'R'); var g = S.Count(x => x == 'G'); var v = S.Count(x => x == 'B'); long result = r * g * v; long count = 0; for (var i = 0; i <= N; i++) { for (var dif = 1; (i + dif + dif) < N; dif++) { var j = i + dif; var k = j + dif; if ((S[i] != S[j]) && (S[i] != S[k]) && (S[j] != S[k])) count++; } } Console.WriteLine(result - count); } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var N = LnInt(); var S = LnStr(); long r = S.Count(x => x == 'R'); long g = S.Count(x => x == 'G'); long v = S.Count(x => x == 'B'); long result = r * g * v; long count = 0; for (var i = 0; i <= N; i++) { for (var dif = 1; (i + dif + dif) < N; dif++) { var j = i + dif; var k = j + dif; if ((S[i] != S[j]) && (S[i] != S[k]) && (S[j] != S[k])) count++; } } Console.WriteLine(result - count); } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
399
6
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = rint(); var a = rstr(); var r = 0; var g = 0; var b = 0; for (int i = 0; i < n; i++) { if (a[i] == 'R') { r++; } else if (a[i] == 'G') { g++; } else { b++; } } long count = r * g * b; for (int i = 0; i < n - 2; i++) { for (int j = i + 1; j < n - 1; j++) { int sa = j - i; int k = j + sa; if (k < n) { if (a[i] != a[j] && a[j] != a[k] && a[k] != a[i]) { count--; } } } } WriteLine(count); } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; public class Solve { static public int mod = 1000000007; public static void Main() { // 方針 // var n = rint(); var a = rstr(); long r = 0; long g = 0; long b = 0; for (int i = 0; i < n; i++) { if (a[i] == 'R') { r++; } else if (a[i] == 'G') { g++; } else { b++; } } long count = r * g * b; for (int i = 0; i < n - 2; i++) { for (int j = i + 1; j < n - 1; j++) { int sa = j - i; int k = j + sa; if (k < n) { if (a[i] != a[j] && a[j] != a[k] && a[k] != a[i]) { count--; } } } } WriteLine(count); } // 1からaまでの数字並べ替え全通り返すやつ static List<string> permutation(int a) { var list = new List<string>(); if (a == 1) { list.Add("1"); return list; } else { foreach (var k in permutation(a - 1)) { var ch = k.ToCharArray(); for (int i = 0; i <= ch.Length; i++) { string intemp = ""; if (i == 0) { intemp += a.ToString(); } for (int j = 0; j < ch.Length; j++) { intemp += ch[j].ToString(); if (i == j + 1) { intemp += a.ToString(); } } list.Add(intemp); } } } return list; } public static void swap(ref int a, ref int b) { int temp = a; a = b; b = temp; } static void charswap(ref char a, ref char b) { char temp = a; a = b; b = temp; } static int ncr(int n, int r) { r = Min(r, n - r); long nn = 1; for (int i = n - r + 1; i <= n; i++) { nn = nn * i % mod; } long rr = 1; for (int i = 1; i <= r; i++) { rr = rr * i % mod; } rr = square((int)rr, mod - 2); nn = nn * rr % mod; return (int)nn; } // a^b mod static int square(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static int square2(int a, int b) { long output = 1; var list = new List<long>(); int sh = 1; long n = a; list.Add(a); while (sh < b) { sh *= 2; n = n * n % mod; list.Add(n); } for (int i = list.Count - 1; i >= 0; i--) { if (b > sh) { b -= sh; sh /= 2; output = output * list[i] % mod; } } return (int)output; } //各種読取 static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static int[,] inta2(int num_array, int in_array) { int[,] int_array2 = new int[num_array, in_array]; for (int i = 0; i < num_array; i++) { int[] temp_array = inta(); for (int j = 0; j < in_array; j++) { int_array2[i, j] = temp_array[j]; } } return int_array2; } static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; } static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_double_array; } // ----------------------------- static long divideup(long divided, long divid) { long temp_divide = divided / divid; if (divided % divid > 0) { temp_divide++; } return temp_divide; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
1,372
6
using System; using System.Collections.Generic; public class ABC162D { private static void Main(string[] args) { var n = ReadInt(); var s = ReadStr(); var dict = new Dictionary<char, int>() { { 'R', 0 }, { 'G', 0 }, { 'B', 0 } }; for (var i = 0; i < s.Length; i++) dict[s[i]]++; var answer = dict['R'] * dict['G'] * dict['B']; for (int i = 0; i <= n; i++) { for (int dif = 1; (i + dif + dif) < n; dif++) { var j = i + dif; var k = j + dif; if ((s[i] != s[j]) && (s[i] != s[k]) && (s[j] != s[k])) answer--; } } Console.WriteLine(answer); } private static string ReadStr() => Console.ReadLine().Trim(); private static int ReadInt() => int.Parse(Console.ReadLine().Trim()); }
using System; using System.Collections.Generic; public class ABC162D { private static void Main(string[] args) { var n = ReadInt(); var s = ReadStr(); var dict = new Dictionary<char, long>() { { 'R', 0 }, { 'G', 0 }, { 'B', 0 } }; for (var i = 0; i < n; i++) dict[s[i]]++; var answer = dict['R'] * dict['G'] * dict['B']; for (var i = 0; i <= n; i++) { for (var dif = 1; (i + dif + dif) < n; dif++) { var j = i + dif; var k = j + dif; if ((s[i] != s[j]) && (s[i] != s[k]) && (s[j] != s[k])) answer--; } } Console.WriteLine(answer); } private static string ReadStr() => Console.ReadLine().Trim(); private static int ReadInt() => int.Parse(Console.ReadLine().Trim()); }
[["-", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["+", 0, 212, 0, 230, 39, 236, 237, 238, 0, 199], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["-", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 8, 196, 0, 7, 10, 198, 39, 216, 0, 217], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199]]
8
267
10
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc162 { class Program { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc162D3(); // List<int> test = new List<int>(){1, 2, 2, 2, 3, 4, 5, 6 ,7}; // Console.WriteLine(binarySerachDown(test, 2)); Console.Out.Flush(); } /* https://atcoder.jp/contests/abc162/submissions/11804077 */ public static void solve_abc162D3() { int n = Convert.ToInt32(Console.ReadLine()); string s = Console.ReadLine(); int cr = 0; int cg = 0; int cb = 0; for (int i = 0; i < n; i++) { if (s[i] == 'R') { cr++; } if (s[i] == 'G') { cg++; } if (s[i] == 'B') { cb++; } } long ans = cr * cg * cb; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (s[i] != s[j] && 2 * j - i < n && s[i] != s[2 * j - i] && s[j] != s[2 * j - i]) { ans--; } } } Console.WriteLine(ans); } /* https://atcoder.jp/contests/abc162/submissions/11816716 */ public static void solve_abc162D2() { int n = Convert.ToInt32(Console.ReadLine()); char[] s = Console.ReadLine().ToCharArray(); int[,] cnt = new int[4005, 4]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cnt[i + 1, j] = cnt[i, j]; } if (s[i] == 'R') { s[i] = 'A'; } else if (s[i] == 'G') { s[i] = 'C'; } cnt[i + 1, s[i] - 'A']++; } long ans = 0; for (int i = 0; i < n; i++) { for (int k = i + 1; k < n; k++) { if (s[i] == s[k]) { continue; } int other = 3 - (s[i] - 'A') - (s[k] - 'A'); ans += cnt[k, other] - cnt[i + 1, other]; int j = (i + k) / 2; if (2 * j == i + k && s[j] - 'A' == other) { ans--; } } } Console.WriteLine(ans); } public static void solve_abc162D() { int n = Convert.ToInt32(Console.ReadLine()); string s = Console.ReadLine(); List<int> rs = new List<int>(); List<int> gs = new List<int>(); List<int> bs = new List<int>(); for (int i = 0; i < n; i++) { if (s[i] == 'R') { rs.Add(i); } if (s[i] == 'G') { gs.Add(i); } if (s[i] == 'B') { bs.Add(i); } } long cnt = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) { int idx = binarySerachDown(gs, j, j - i); cnt += gs.Count - idx; } else if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) { int idx = binarySerachDown(bs, j, j - i); cnt += bs.Count - idx; } else if ((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')) { int idx = binarySerachDown(rs, j, j - i); cnt += rs.Count - idx; } } } Console.WriteLine(cnt); } public static int binarySerachUp(List<int> list, int x, int diff) { int l = 0; int h = list.Count; while (l < h) { int mid = (l + h) / 2; if (x >= list[mid]) { l = mid + 1; } else { h = mid; } } return l; } public static int binarySerachDown(List<int> list, int x, int diff) { int l = 0; int h = list.Count; while (l < h) { int mid = (l + h) / 2; if (x <= list[mid]) { h = mid; } else { l = mid + 1; } } int ret = l; if (list[l] - x == diff) { if (l + 1 < list.Count) { ret = l + 1; } } return ret; } public static void solve_abc162C() { int n = Convert.ToInt32(Console.ReadLine()); int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= n; k++) { sum += gcd(i, gcd(j, k)); } } } Console.WriteLine(sum); } public static int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } public static void solve_abc162B() { int n = Convert.ToInt32(Console.ReadLine()); long sum = 0; for (int i = 1; i <= n; i++) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } Console.WriteLine(sum); } public static void solve_abc162A() { string s = Console.ReadLine(); Console.WriteLine(s.Contains("7") ? "Yes" : "No"); } } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc162 { class Program { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); if (File.Exists("input.txt")) { Console.SetIn(new StreamReader("input.txt")); } solve_abc162D3(); // List<int> test = new List<int>(){1, 2, 2, 2, 3, 4, 5, 6 ,7}; // Console.WriteLine(binarySerachDown(test, 2)); Console.Out.Flush(); } /* https://atcoder.jp/contests/abc162/submissions/11804077 */ public static void solve_abc162D3() { int n = Convert.ToInt32(Console.ReadLine()); string s = Console.ReadLine(); long cr = 0; long cg = 0; long cb = 0; for (int i = 0; i < n; i++) { if (s[i] == 'R') { cr++; } if (s[i] == 'G') { cg++; } if (s[i] == 'B') { cb++; } } long ans = cr * cg * cb; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (s[i] != s[j] && 2 * j - i < n && s[i] != s[2 * j - i] && s[j] != s[2 * j - i]) { ans--; } } } Console.WriteLine(ans); } /* https://atcoder.jp/contests/abc162/submissions/11816716 */ public static void solve_abc162D2() { int n = Convert.ToInt32(Console.ReadLine()); char[] s = Console.ReadLine().ToCharArray(); int[,] cnt = new int[4005, 4]; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cnt[i + 1, j] = cnt[i, j]; } if (s[i] == 'R') { s[i] = 'A'; } else if (s[i] == 'G') { s[i] = 'C'; } cnt[i + 1, s[i] - 'A']++; } long ans = 0; for (int i = 0; i < n; i++) { for (int k = i + 1; k < n; k++) { if (s[i] == s[k]) { continue; } int other = 3 - (s[i] - 'A') - (s[k] - 'A'); ans += cnt[k, other] - cnt[i + 1, other]; int j = (i + k) / 2; if (2 * j == i + k && s[j] - 'A' == other) { ans--; } } } Console.WriteLine(ans); } public static void solve_abc162D() { int n = Convert.ToInt32(Console.ReadLine()); string s = Console.ReadLine(); List<int> rs = new List<int>(); List<int> gs = new List<int>(); List<int> bs = new List<int>(); for (int i = 0; i < n; i++) { if (s[i] == 'R') { rs.Add(i); } if (s[i] == 'G') { gs.Add(i); } if (s[i] == 'B') { bs.Add(i); } } long cnt = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) { int idx = binarySerachDown(gs, j, j - i); cnt += gs.Count - idx; } else if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) { int idx = binarySerachDown(bs, j, j - i); cnt += bs.Count - idx; } else if ((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')) { int idx = binarySerachDown(rs, j, j - i); cnt += rs.Count - idx; } } } Console.WriteLine(cnt); } public static int binarySerachUp(List<int> list, int x, int diff) { int l = 0; int h = list.Count; while (l < h) { int mid = (l + h) / 2; if (x >= list[mid]) { l = mid + 1; } else { h = mid; } } return l; } public static int binarySerachDown(List<int> list, int x, int diff) { int l = 0; int h = list.Count; while (l < h) { int mid = (l + h) / 2; if (x <= list[mid]) { h = mid; } else { l = mid + 1; } } int ret = l; if (list[l] - x == diff) { if (l + 1 < list.Count) { ret = l + 1; } } return ret; } public static void solve_abc162C() { int n = Convert.ToInt32(Console.ReadLine()); int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= n; k++) { sum += gcd(i, gcd(j, k)); } } } Console.WriteLine(sum); } public static int gcd(int a, int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } public static void solve_abc162B() { int n = Convert.ToInt32(Console.ReadLine()); long sum = 0; for (int i = 1; i <= n; i++) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } Console.WriteLine(sum); } public static void solve_abc162A() { string s = Console.ReadLine(); Console.WriteLine(s.Contains("7") ? "Yes" : "No"); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
1,456
6
using System; using System.Linq; using System.Collections.Generic; namespace ABC162D { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var input = Console.ReadLine().ToCharArray(); var acumR = new int[n]; var acumG = new int[n]; var acumB = new int[n]; acumR[n - 1] = 0; acumG[n - 1] = 0; acumB[n - 1] = 0; for (int i = n - 2; i >= 0; i--) { switch (input[i + 1]) { case 'R': acumR[i] = acumR[i + 1] + 1; acumG[i] = acumG[i + 1]; acumB[i] = acumB[i + 1]; break; case 'G': acumR[i] = acumR[i + 1]; acumG[i] = acumG[i + 1] + 1; acumB[i] = acumB[i + 1]; break; case 'B': acumR[i] = acumR[i + 1]; acumG[i] = acumG[i + 1]; acumB[i] = acumB[i + 1] + 1; break; } } int sum = 0; for (int i = 0; i < n; i++) { switch (input[i]) { case 'R': for (int j = i + 1; j < n; j++) { if (input[j] == 'G') { sum += acumB[j]; } if (input[j] == 'B') { sum += acumG[j]; } int bad = j + j - i; if (bad < n && input[j] != 'R' && input[bad] != 'R' && input[j] != input[bad]) { sum--; } } break; case 'G': for (int j = i + 1; j < n; j++) { if (input[j] == 'B') { sum += acumR[j]; } if (input[j] == 'R') { sum += acumB[j]; } int bad = j + j - i; if (bad < n && input[j] != 'G' && input[bad] != 'G' && input[j] != input[bad]) { sum--; } } break; case 'B': for (int j = i + 1; j < n; j++) { if (input[j] == 'R') { sum += acumG[j]; } if (input[j] == 'G') { sum += acumR[j]; } int bad = j + j - i; if (bad < n && input[j] != 'B' && input[bad] != 'B' && input[j] != input[bad]) { sum--; } } break; } } Console.WriteLine($"{sum}"); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ABC162D { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var input = Console.ReadLine().ToCharArray(); var acumR = new int[n]; var acumG = new int[n]; var acumB = new int[n]; acumR[n - 1] = 0; acumG[n - 1] = 0; acumB[n - 1] = 0; for (int i = n - 2; i >= 0; i--) { switch (input[i + 1]) { case 'R': acumR[i] = acumR[i + 1] + 1; acumG[i] = acumG[i + 1]; acumB[i] = acumB[i + 1]; break; case 'G': acumR[i] = acumR[i + 1]; acumG[i] = acumG[i + 1] + 1; acumB[i] = acumB[i + 1]; break; case 'B': acumR[i] = acumR[i + 1]; acumG[i] = acumG[i + 1]; acumB[i] = acumB[i + 1] + 1; break; } } long sum = 0; for (int i = 0; i < n; i++) { switch (input[i]) { case 'R': for (int j = i + 1; j < n; j++) { if (input[j] == 'G') { sum += acumB[j]; } if (input[j] == 'B') { sum += acumG[j]; } int bad = j + j - i; if (bad < n && input[j] != 'R' && input[bad] != 'R' && input[j] != input[bad]) { sum--; } } break; case 'G': for (int j = i + 1; j < n; j++) { if (input[j] == 'B') { sum += acumR[j]; } if (input[j] == 'R') { sum += acumB[j]; } int bad = j + j - i; if (bad < n && input[j] != 'G' && input[bad] != 'G' && input[j] != input[bad]) { sum--; } } break; case 'B': for (int j = i + 1; j < n; j++) { if (input[j] == 'R') { sum += acumG[j]; } if (input[j] == 'G') { sum += acumR[j]; } int bad = j + j - i; if (bad < n && input[j] != 'B' && input[bad] != 'B' && input[j] != input[bad]) { sum--; } } break; } } Console.WriteLine($"{sum}"); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
659
2
/** * code generated by RHelper * More info: https://github.com/mkc1370/RHelper * @author */ using Task.DRGBTriplets; using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; namespace Task.DRGBTriplets { public class DRGBTriplets { public void Solve() { var n = CINL; var s = CINS; var sum = 0l; var rc = 0; var gc = 0; var bc = 0; foreach (var ss in s) { switch (ss) { case 'R': rc++; break; case 'G': gc++; break; case 'B': bc++; break; } } sum = rc * gc * bc; for (var i = 0; i < n; i++) { for (var j = i + 1; j < n; j++) { var k = 2 * (j + 1) - (i + 1); if (k - 1 < n && s[i] != s[j] && s[j] != s[k - 1] && s[k - 1] != s[i]) { sum--; } } } COUT(sum); } private readonly StringReader cin; private readonly StringWriter cout; private readonly Scanner scanner; public DRGBTriplets(StringReader cin, StringWriter cout) { this.cin = cin; this.cout = cout; scanner = new Scanner(cin); } private long CINL => scanner.Long(); private double CIND => scanner.Double(); private string CINS => scanner.String(); private static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat(v, (int)n); private List<long> CINVL(long n) => Repeat(0, n).Select(_ => CINL).ToList(); private List<double> CINVD(long n) => Repeat(0, n).Select(_ => CIND).ToList(); private List<string> CINVS(long n) => Repeat(0, n).Select(_ => CINS).ToList(); private void COUT(object o) => cout.WriteLine(o); } public class Scanner { public Scanner(StringReader stringReader) { this.stringReader = stringReader; } private readonly StringReader stringReader; private readonly char[] buffer = new char[1024]; private int len, ptr; private bool isEof; private char Read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = stringReader.Read(buffer, 0, 1024)) <= 0) { isEof = true; return '\0'; } } return buffer[ptr++]; } public char Char() { char b; do b = Read(); while (b < 33 || 126 < b); return b; } public string String() { var sb = new StringBuilder(); for (char b = Char(); b >= 33 && b <= 126; b = Read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; char b; var ng = false; do b = Read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = Read(); } for (;; b = Read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public double Double() { return double.Parse(String(), CultureInfo.InvariantCulture); } } public struct ModInt { public const int Mod = 1000000007; private const long Positivizer = ((long)Mod) << 31; private long data; public ModInt(long data) { if ((this.data = data % Mod) < 0) this.data += Mod; } public static implicit operator long(ModInt modInt) => modInt.data; public static implicit operator ModInt(long val) => new ModInt(val); public static ModInt operator +(ModInt a, int b) => new ModInt() { data = (a.data + b + Positivizer) % Mod }; public static ModInt operator +(ModInt a, long b) => new ModInt(a.data + b); public static ModInt operator +(ModInt a, ModInt b) { long res = a.data + b.data; return new ModInt() { data = res >= Mod ? res - Mod : res }; } public static ModInt operator -(ModInt a, int b) => new ModInt() { data = (a.data - b + Positivizer) % Mod }; public static ModInt operator -(ModInt a, long b) => new ModInt(a.data - b); public static ModInt operator -(ModInt a, ModInt b) { long res = a.data - b.data; return new ModInt() { data = res < 0 ? res + Mod : res }; } public static ModInt operator *(ModInt a, int b) => new ModInt(a.data * b); public static ModInt operator *(ModInt a, long b) => a * new ModInt(b); public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { data = a.data * b.data % Mod }; public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { data = a.data * GetInverse(b) % Mod }; public static bool operator ==(ModInt a, ModInt b) => a.data == b.data; public static bool operator !=(ModInt a, ModInt b) => a.data != b.data; public override string ToString() => data.ToString(); public override bool Equals(object obj) => obj != null && (ModInt)obj == this; public override int GetHashCode() => (int)data; private static long GetInverse(long a) { long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + Mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + Mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } } } public class Output { public static void Main() { var reader = new System.IO.StringReader(Console.In.ReadToEnd()); var writer = new System.IO.StringWriter(); var solver = new DRGBTriplets(reader, writer); solver.Solve(); System.Console.Write(writer.GetStringBuilder().ToString()); } }
/** * code generated by RHelper * More info: https://github.com/mkc1370/RHelper * @author */ using Task.DRGBTriplets; using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; namespace Task.DRGBTriplets { public class DRGBTriplets { public void Solve() { var n = CINL; var s = CINS; var sum = 0l; var rc = 0l; var gc = 0l; var bc = 0l; foreach (var ss in s) { switch (ss) { case 'R': rc++; break; case 'G': gc++; break; case 'B': bc++; break; } } sum = rc * gc * bc; for (var i = 0; i < n; i++) { for (var j = i + 1; j < n; j++) { var k = 2 * (j + 1) - (i + 1); if (k - 1 < n && s[i] != s[j] && s[j] != s[k - 1] && s[k - 1] != s[i]) { sum--; } } } COUT(sum); } private readonly StringReader cin; private readonly StringWriter cout; private readonly Scanner scanner; public DRGBTriplets(StringReader cin, StringWriter cout) { this.cin = cin; this.cout = cout; scanner = new Scanner(cin); } private long CINL => scanner.Long(); private double CIND => scanner.Double(); private string CINS => scanner.String(); private static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat(v, (int)n); private List<long> CINVL(long n) => Repeat(0, n).Select(_ => CINL).ToList(); private List<double> CINVD(long n) => Repeat(0, n).Select(_ => CIND).ToList(); private List<string> CINVS(long n) => Repeat(0, n).Select(_ => CINS).ToList(); private void COUT(object o) => cout.WriteLine(o); } public class Scanner { public Scanner(StringReader stringReader) { this.stringReader = stringReader; } private readonly StringReader stringReader; private readonly char[] buffer = new char[1024]; private int len, ptr; private bool isEof; private char Read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = stringReader.Read(buffer, 0, 1024)) <= 0) { isEof = true; return '\0'; } } return buffer[ptr++]; } public char Char() { char b; do b = Read(); while (b < 33 || 126 < b); return b; } public string String() { var sb = new StringBuilder(); for (char b = Char(); b >= 33 && b <= 126; b = Read()) sb.Append(b); return sb.ToString(); } public long Long() { long ret = 0; char b; var ng = false; do b = Read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = Read(); } for (;; b = Read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } public double Double() { return double.Parse(String(), CultureInfo.InvariantCulture); } } public struct ModInt { public const int Mod = 1000000007; private const long Positivizer = ((long)Mod) << 31; private long data; public ModInt(long data) { if ((this.data = data % Mod) < 0) this.data += Mod; } public static implicit operator long(ModInt modInt) => modInt.data; public static implicit operator ModInt(long val) => new ModInt(val); public static ModInt operator +(ModInt a, int b) => new ModInt() { data = (a.data + b + Positivizer) % Mod }; public static ModInt operator +(ModInt a, long b) => new ModInt(a.data + b); public static ModInt operator +(ModInt a, ModInt b) { long res = a.data + b.data; return new ModInt() { data = res >= Mod ? res - Mod : res }; } public static ModInt operator -(ModInt a, int b) => new ModInt() { data = (a.data - b + Positivizer) % Mod }; public static ModInt operator -(ModInt a, long b) => new ModInt(a.data - b); public static ModInt operator -(ModInt a, ModInt b) { long res = a.data - b.data; return new ModInt() { data = res < 0 ? res + Mod : res }; } public static ModInt operator *(ModInt a, int b) => new ModInt(a.data * b); public static ModInt operator *(ModInt a, long b) => a * new ModInt(b); public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { data = a.data * b.data % Mod }; public static ModInt operator /(ModInt a, ModInt b) => new ModInt() { data = a.data * GetInverse(b) % Mod }; public static bool operator ==(ModInt a, ModInt b) => a.data == b.data; public static bool operator !=(ModInt a, ModInt b) => a.data != b.data; public override string ToString() => data.ToString(); public override bool Equals(object obj) => obj != null && (ModInt)obj == this; public override int GetHashCode() => (int)data; private static long GetInverse(long a) { long div, p = Mod, x1 = 1, y1 = 0, x2 = 0, y2 = 1; while (true) { if (p == 1) return x2 + Mod; div = a / p; x1 -= x2 * div; y1 -= y2 * div; a %= p; if (a == 1) return x1 + Mod; div = p / a; x2 -= x1 * div; y2 -= y1 * div; p %= a; } } } } public class Output { public static void Main() { var reader = new System.IO.StringReader(Console.In.ReadToEnd()); var writer = new System.IO.StringWriter(); var solver = new DRGBTriplets(reader, writer); solver.Solve(); System.Console.Write(writer.GetStringBuilder().ToString()); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
1,447
6
using System; using System.Linq; namespace AtCoder { class Program { public static void Main() { var length = IO.ReadInt(); var chars = IO.ReadCharArray(); var lengths = new[] { chars.Count(iChar => iChar == 'R'), chars.Count(iChar => iChar == 'G'), chars.Count(iChar => iChar == 'B') }; var combiNum = lengths.Aggregate((iCurrent, iNext) => iCurrent * iNext); for (var iIndex0 = 0; iIndex0 < length; ++iIndex0) { for (var iIndex1 = iIndex0 + 1; iIndex1 < length; ++iIndex1) { if (chars[iIndex0] == chars[iIndex1]) { continue; } var lastIndex = (iIndex1 * 2) - iIndex0; if (lastIndex < length && chars[iIndex0] != chars[lastIndex] && chars[iIndex1] != chars[lastIndex]) { --combiNum; } } } IO.Write(combiNum); } } public static class IO { public static string Read() { return Console.ReadLine(); } public static string[] ReadArray(char iSplitter = ' ') { return Read().Split(iSplitter); } public static int ReadInt() { return int.Parse(Read()); } public static int[] ReadIntArray(char iSplitter = ' ') { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); } public static char[] ReadCharArray() { return Read().ToCharArray(); } public static void Write(string iValue) { Console.WriteLine(iValue); } public static void Write(int iValue) { Console.WriteLine(iValue); } public static void Write(long iValue) { Console.WriteLine(iValue); } public static void Write(decimal iValue) { Console.WriteLine(iValue); } public static void Write(bool iValue) { Console.WriteLine(iValue ? "Yes" : "No"); } } public static class Util { public static long Gcd(long i0, long i1) { return (i0 > i1) ? _Gcd(i0, i1) : _Gcd(i0, i1); } private static long _Gcd(long i0, long i1) { return (i1 == 0) ? i0 : _Gcd(i1, i0 % i1); } } }
using System; using System.Linq; namespace AtCoder { class Program { public static void Main() { var length = IO.ReadInt(); var chars = IO.ReadCharArray(); var lengths = new long[] { chars.Count(iChar => iChar == 'R'), chars.Count(iChar => iChar == 'G'), chars.Count(iChar => iChar == 'B') }; var combiNum = lengths.Aggregate((iCurrent, iNext) => iCurrent * iNext); for (var iIndex0 = 0; iIndex0 < length; ++iIndex0) { for (var iIndex1 = iIndex0 + 1; iIndex1 < length; ++iIndex1) { if (chars[iIndex0] == chars[iIndex1]) { continue; } var lastIndex = (iIndex1 * 2) - iIndex0; if (lastIndex < length && chars[iIndex0] != chars[lastIndex] && chars[iIndex1] != chars[lastIndex]) { --combiNum; } } } IO.Write(combiNum); } } public static class IO { public static string Read() { return Console.ReadLine(); } public static string[] ReadArray(char iSplitter = ' ') { return Read().Split(iSplitter); } public static int ReadInt() { return int.Parse(Read()); } public static int[] ReadIntArray(char iSplitter = ' ') { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); } public static char[] ReadCharArray() { return Read().ToCharArray(); } public static void Write(string iValue) { Console.WriteLine(iValue); } public static void Write(int iValue) { Console.WriteLine(iValue); } public static void Write(long iValue) { Console.WriteLine(iValue); } public static void Write(decimal iValue) { Console.WriteLine(iValue); } public static void Write(bool iValue) { Console.WriteLine(iValue ? "Yes" : "No"); } } public static class Util { public static long Gcd(long i0, long i1) { return (i0 > i1) ? _Gcd(i0, i1) : _Gcd(i0, i1); } private static long _Gcd(long i0, long i1) { return (i1 == 0) ? i0 : _Gcd(i1, i0 % i1); } } }
[["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
8
491
1
using System; using System.Linq; class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); long ans = 0; var tmpS = s.Skip(1).Reverse().Skip(1).ToArray(); int r = tmpS.Count(t => t == 'R'); int g = tmpS.Count(t => t == 'G'); int b = tmpS.Count(t => t == 'B'); int right = n - 1; int left = 0; if (n <= 3) { Console.WriteLine("1"); return; } // 区間を選択し、違うものを選ぶ // 区間の色違いの数を数える bool containR = false; bool containG = false; bool containB = false; if (s[left] == 'R' || s[right] == 'R') containR = true; if (s[left] == 'G' || s[right] == 'G') containG = true; if (s[left] == 'B' || s[right] == 'B') containB = true; while (true) { var saveRight = right; var saveLeft = left; var saveR = r; var saveG = g; var saveB = b; while (true) { if (s[left] != s[right] && Math.Abs(right - left) > 2) { if (s[left] == 'R' || s[right] == 'R') containR = true; else containR = false; if (s[left] == 'G' || s[right] == 'G') containG = true; else containG = false; if (s[left] == 'B' || s[right] == 'B') containB = true; else containB = false; var tmp = 0; if (containR == false) tmp = tmp + r; if (containG == false) tmp = tmp + g; if (containB == false) tmp = tmp + b; // 真ん中を取り除く if (Math.Abs(right - left) % 2 == 0) { if (s[left] == s[left + ((right - left) / 2)] || s[right] == s[left + ((right - left) / 2)]) tmp = tmp; else tmp = tmp - 1; } ans = ans + tmp; } right = right - 1; if (s[right] == 'R') r = r - 1; if (s[right] == 'G') g = g - 1; if (s[right] == 'B') b = b - 1; if (right - left == 2) break; if (right < left + 2) break; } // 最初のものから変更 right = saveRight; left = saveLeft; r = saveR; g = saveG; b = saveB; left = left + 1; if (s[left] == 'R') r = r - 1; if (s[left] == 'G') g = g - 1; if (s[left] == 'B') b = b - 1; if (right - left == 2) break; } Console.WriteLine(ans); } }
using System; using System.Linq; class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); long ans = 0; var tmpS = s.Skip(1).Reverse().Skip(1).ToArray(); int r = tmpS.Count(t => t == 'R'); int g = tmpS.Count(t => t == 'G'); int b = tmpS.Count(t => t == 'B'); int right = n - 1; int left = 0; if (n <= 3) { Console.WriteLine("0"); return; } // 区間を選択し、違うものを選ぶ // 区間の色違いの数を数える bool containR = false; bool containG = false; bool containB = false; if (s[left] == 'R' || s[right] == 'R') containR = true; if (s[left] == 'G' || s[right] == 'G') containG = true; if (s[left] == 'B' || s[right] == 'B') containB = true; while (true) { var saveRight = right; var saveLeft = left; var saveR = r; var saveG = g; var saveB = b; while (true) { if (s[left] != s[right] && Math.Abs(right - left) > 2) { if (s[left] == 'R' || s[right] == 'R') containR = true; else containR = false; if (s[left] == 'G' || s[right] == 'G') containG = true; else containG = false; if (s[left] == 'B' || s[right] == 'B') containB = true; else containB = false; var tmp = 0; if (containR == false) tmp = tmp + r; if (containG == false) tmp = tmp + g; if (containB == false) tmp = tmp + b; // 真ん中を取り除く if (Math.Abs(right - left) % 2 == 0) { if (s[left] == s[left + ((right - left) / 2)] || s[right] == s[left + ((right - left) / 2)]) tmp = tmp; else tmp = tmp - 1; } ans = ans + tmp; } right = right - 1; if (s[right] == 'R') r = r - 1; if (s[right] == 'G') g = g - 1; if (s[right] == 'B') b = b - 1; if (right - left == 2) break; if (right < left + 2) break; } // 最初のものから変更 right = saveRight; left = saveLeft; r = saveR; g = saveG; b = saveB; left = left + 1; if (s[left] == 'R') r = r - 1; if (s[left] == 'G') g = g - 1; if (s[left] == 'B') b = b - 1; if (right - left == 2) break; } Console.WriteLine(ans); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
681
2
using System; using static System.Console; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { int N = int.Parse(ReadLine()); char[] S = ReadLine().ToCharArray(); var rgb = new Dictionary<char, int> { { 'R', 0 }, { 'G', 0 }, { 'B', 0 } }; int tmp = 0; for (int i = 0; i < N; i++) { rgb[S[i]] += 1; for (int j = i + 1; j < N; j++) { if (S[i] != S[j] && j * 2 - i < N) { if (S[j * 2 - i] != S[i] && S[j * 2 - i] != S[j]) { tmp += 1; } } } } WriteLine(rgb['R'] * rgb['G'] * rgb['B'] - tmp); } } }
using System; using static System.Console; using System.Collections.Generic; namespace Main { class Program { static void Main(string[] args) { long N = long.Parse(ReadLine()); char[] S = ReadLine().ToCharArray(); var rgb = new Dictionary<char, long> { { 'R', 0 }, { 'G', 0 }, { 'B', 0 } }; int tmp = 0; for (long i = 0; i < N; i++) { rgb[S[i]] += 1; for (long j = i + 1; j < N; j++) { if (S[i] != S[j] && j * 2 - i < N) { if (S[j * 2 - i] != S[i] && S[j * 2 - i] != S[j]) { tmp += 1; } } } } WriteLine(rgb['R'] * rgb['G'] * rgb['B'] - tmp); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 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], ["-", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 7, 8, 196, 0, 7, 10, 198, 39, 199]]
8
229
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static string S; static void INPUT() { N = NextInt(); S = NextString(); } static void OUT() { var r_count = S.Count(__ => __ == 'R'); var g_count = S.Count(__ => __ == 'G'); var b_count = S.Count(__ => __ == 'B'); var omit = 0; for (var i = 0; i < S.Length; i++) { for (var ii = 0; i + ii * 2 < S.Length; ii++) { if (S[i] != S[i + ii] && S[i + ii] != S[i + ii * 2] && S[i] != S[i + ii * 2]) omit++; } } Console.WriteLine((r_count * g_count * b_count) - omit); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; using static Util; class Program { static int N; static string S; static void INPUT() { N = NextInt(); S = NextString(); } static void OUT() { long r_count = S.Count(__ => __ == 'R'); long g_count = S.Count(__ => __ == 'G'); long b_count = S.Count(__ => __ == 'B'); var omit = 0; for (var i = 0; i < S.Length; i++) { for (var ii = 1; i + ii * 2 < S.Length; ii++) { if (S[i] != S[i + ii] && S[i + ii] != S[i + ii * 2] && S[i] != S[i + ii * 2]) omit++; } } Console.WriteLine((r_count * g_count * b_count) - omit); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
575
8
using System; namespace D { class Program { static void Main(string[] args) { var rgb = new int[3]; Int64 count = 0; var len = int.Parse(Console.ReadLine()); var chars = Console.ReadLine().ToCharArray(); /* 全探索アルゴリズム(時間が足りない) for(int i = 0; i < len - 2; i++) { for(int j = i + 1;j<len - 1; j++) { if(chars[j] != chars[i]) { for(int k = j+1;k<len; k++) { if(chars[i] != chars[k] && chars[j] != chars[k] && k - j != j - i) { count++; } } } } }*/ foreach (char c in chars) { if (c == 'R') rgb[0]++; else if (c == 'G') rgb[1]++; else rgb[2]++; } //考えられる組み合わせの総数 Int64 allC = rgb[0] * rgb[1] * rgb[2]; for (int i = 0; i < len; i++) { for (int j = i + 1; j < len; j++) { if (2 * j - i < len) // k-j=j-iの時、k=2j-i,kが範囲外のときは考えない { if (chars[i] != chars[j] && chars[j] != chars[2 * j - i] && chars[i] != chars[2 * j - i]) { allC--; } } } } Console.WriteLine(allC); } } }
using System; namespace D { class Program { static void Main(string[] args) { var rgb = new long[3]; var len = int.Parse(Console.ReadLine()); var chars = Console.ReadLine().ToCharArray(); /* 全探索アルゴリズム(時間が足りない) for(int i = 0; i < len - 2; i++) { for(int j = i + 1;j<len - 1; j++) { if(chars[j] != chars[i]) { for(int k = j+1;k<len; k++) { if(chars[i] != chars[k] && chars[j] != chars[k] && k - j != j - i) { count++; } } } } }*/ foreach (char c in chars) { if (c == 'R') rgb[0]++; else if (c == 'G') rgb[1]++; else rgb[2]++; } //考えられる組み合わせの総数 Int64 allC = rgb[0] * rgb[1] * rgb[2]; for (int i = 0; i < len; i++) { for (int j = i + 1; j < len; j++) { if (2 * j - i < len) // k-j=j-iの時、k=2j-i,kが範囲外のときは考えない { if (chars[i] != chars[j] && chars[j] != chars[2 * j - i] && chars[i] != chars[2 * j - i]) { allC--; } } } } Console.WriteLine(allC); } } }
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 8, 201, 0, 195, 8, 196, 0, 197, 0, 35], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
227
7
/******************************************************************************* * Author: Nirushuu * Date: 2020-04-13 *******************************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.IO; using System.Globalization; using System.Numerics; /******************************************************************************* * IO from Kattio.cs from open.kattis.com/help/csharp */ public class NoMoreTokensException : Exception {} public class Tokenizer { string[] tokens = new string[0]; private int pos; StreamReader reader; public Tokenizer(Stream inStream) { var bs = new BufferedStream(inStream); reader = new StreamReader(bs); } public Tokenizer() : this(Console.OpenStandardInput()) { // Nothing more to do } private string PeekNext() { if (pos < 0) // pos < 0 indicates that there are no more tokens return null; if (pos < tokens.Length) { if (tokens[pos].Length == 0) { ++pos; return PeekNext(); } return tokens[pos]; } string line = reader.ReadLine(); if (line == null) { // There is no more data to read pos = -1; return null; } // Split the line that was read on white space characters tokens = line.Split(null); pos = 0; return PeekNext(); } public bool HasNext() { return (PeekNext() != null); } public string Next() { string next = PeekNext(); if (next == null) throw new NoMoreTokensException(); ++pos; return next; } } public class Scanner : Tokenizer { public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public float NextFloat() { return float.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } public class BufferedStdoutWriter : StreamWriter { public BufferedStdoutWriter() : base(new BufferedStream(Console.OpenStandardOutput())) {} } /******************************************************************************/ /******************************************************************************* * DisjointSet datastructure */ public struct DisjointSet { public int[] parent; public int[] rank; public DisjointSet(int n) { parent = new int[n]; for (int i = 0; i < n; ++i) { parent[i] = i; } rank = new int[n]; } public int Find(int i) { int idx = i; var compress = new List<int>(); while (idx != parent[idx]) { compress.Add(idx); idx = parent[idx]; } foreach (var e in compress) { // path compress parent[e] = idx; } return idx; } public void Union(int a, int b) { int aPar = this.Find(a); int bPar = this.Find(b); if (rank[aPar] > rank[bPar]) { // by rank parent[bPar] = aPar; } else { parent[aPar] = bPar; } if (rank[aPar] == rank[bPar]) { ++rank[bPar]; } } } class MaxHeap { List<int> data; public MaxHeap() { data = new List<int>(); } public void Push(int a) { data.Add(a); int idx = data.Count - 1; int parent = (int)Math.Floor((double)(idx - 1) / 2); while (idx != 0 && (data[idx] > data[parent])) { int tmp = data[parent]; data[parent] = data[idx]; data[idx] = tmp; idx = parent; parent = (int)Math.Floor((double)(idx - 1) / 2); } } public int Pop() { int res = data[0]; data[0] = data[data.Count - 1]; data.RemoveAt(data.Count - 1); int idx = 0; while (true) { int child1 = (2 * idx) + 1; int child2 = (2 * idx) + 2; if (child1 >= data.Count) { // no children break; } else if (child2 >= data.Count) { // one child if (data[idx] < data[child1]) { int tmp = data[idx]; data[idx] = data[child1]; data[child1] = tmp; } break; } else { // two children int maxChild = data[child1] > data[child2] ? child1 : child2; if (data[idx] < data[maxChild]) { int tmp = data[idx]; data[idx] = data[maxChild]; data[maxChild] = tmp; idx = maxChild; continue; } else { // no swap break; } } } return res; } } class Dequeue { public Dictionary<int, int> data = new Dictionary<int, int>(); int firstIdx; public int Count; public Dequeue() { data = new Dictionary<int, int>(); firstIdx = 1; Count = 0; } public void PushFront(int a) { data[firstIdx - 1] = a; ++Count; --firstIdx; } public void PushBack(int a) { data[firstIdx + Count] = a; ++Count; } public int PopFront() { --Count; ++firstIdx; return data[firstIdx - 1]; } public int PopBack() { --Count; return data[firstIdx + Count]; } public int Get(int n) { return data[firstIdx + n]; } } /******************************************************************************/ class MainClass { // Debug functions static void debug<T>(IEnumerable<T> a, string s = "") { Console.WriteLine($"name: {s}"); int i = 0; foreach (var e in a) { Console.WriteLine($"value {i}: {e}"); ++i; } } static void dbg<T>(T a, string s = "") { Console.WriteLine($"name: {s} value: {a}"); } //////////////////// public static void Main() { var sc = new Scanner(); var wr = new BufferedStdoutWriter(); var dot = new NumberFormatInfo(); dot.NumberDecimalSeparator = "."; int n = sc.NextInt(); string s = sc.Next(); var prefixR = new int[n]; var prefixG = new int[n]; var prefixB = new int[n]; for (int i = 0; i < n; ++i) { if (i > 0) { prefixR[i] = prefixR[i - 1]; prefixG[i] = prefixG[i - 1]; prefixB[i] = prefixB[i - 1]; } if (s[i] == 'R') { ++prefixR[i]; } else if (s[i] == 'G') { ++prefixG[i]; } else { ++prefixB[i]; } } // debug(prefixG); int ans = 0; var colors = new char[3] { 'R', 'G', 'B' }; for (int i = 0; i < n; ++i) { for (int j = i + 3; j < n; ++j) { if (s[i] == s[j]) { continue; } char other = ' '; foreach (char c in colors) { if (s[i] != c && s[j] != c) { other = c; } } if (other == 'R') { ans += prefixR[j] - prefixR[i]; } else if (other == 'G') { ans += prefixG[j] - prefixG[i]; } else { ans += prefixB[j] - prefixB[i]; } // wr.WriteLine($"indices {i}{j} ans is {ans}"); if ((j - i) % 2 == 0) { int mid = i + ((j - i) / 2); if (s[mid] == other) { --ans; } } } } wr.Write(ans); wr.Flush(); } }
/******************************************************************************* * Author: Nirushuu * Date: 2020-04-13 *******************************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.IO; using System.Globalization; using System.Numerics; /******************************************************************************* * IO from Kattio.cs from open.kattis.com/help/csharp */ public class NoMoreTokensException : Exception {} public class Tokenizer { string[] tokens = new string[0]; private int pos; StreamReader reader; public Tokenizer(Stream inStream) { var bs = new BufferedStream(inStream); reader = new StreamReader(bs); } public Tokenizer() : this(Console.OpenStandardInput()) { // Nothing more to do } private string PeekNext() { if (pos < 0) // pos < 0 indicates that there are no more tokens return null; if (pos < tokens.Length) { if (tokens[pos].Length == 0) { ++pos; return PeekNext(); } return tokens[pos]; } string line = reader.ReadLine(); if (line == null) { // There is no more data to read pos = -1; return null; } // Split the line that was read on white space characters tokens = line.Split(null); pos = 0; return PeekNext(); } public bool HasNext() { return (PeekNext() != null); } public string Next() { string next = PeekNext(); if (next == null) throw new NoMoreTokensException(); ++pos; return next; } } public class Scanner : Tokenizer { public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public float NextFloat() { return float.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } public class BufferedStdoutWriter : StreamWriter { public BufferedStdoutWriter() : base(new BufferedStream(Console.OpenStandardOutput())) {} } /******************************************************************************/ /******************************************************************************* * DisjointSet datastructure */ public struct DisjointSet { public int[] parent; public int[] rank; public DisjointSet(int n) { parent = new int[n]; for (int i = 0; i < n; ++i) { parent[i] = i; } rank = new int[n]; } public int Find(int i) { int idx = i; var compress = new List<int>(); while (idx != parent[idx]) { compress.Add(idx); idx = parent[idx]; } foreach (var e in compress) { // path compress parent[e] = idx; } return idx; } public void Union(int a, int b) { int aPar = this.Find(a); int bPar = this.Find(b); if (rank[aPar] > rank[bPar]) { // by rank parent[bPar] = aPar; } else { parent[aPar] = bPar; } if (rank[aPar] == rank[bPar]) { ++rank[bPar]; } } } class MaxHeap { List<int> data; public MaxHeap() { data = new List<int>(); } public void Push(int a) { data.Add(a); int idx = data.Count - 1; int parent = (int)Math.Floor((double)(idx - 1) / 2); while (idx != 0 && (data[idx] > data[parent])) { int tmp = data[parent]; data[parent] = data[idx]; data[idx] = tmp; idx = parent; parent = (int)Math.Floor((double)(idx - 1) / 2); } } public int Pop() { int res = data[0]; data[0] = data[data.Count - 1]; data.RemoveAt(data.Count - 1); int idx = 0; while (true) { int child1 = (2 * idx) + 1; int child2 = (2 * idx) + 2; if (child1 >= data.Count) { // no children break; } else if (child2 >= data.Count) { // one child if (data[idx] < data[child1]) { int tmp = data[idx]; data[idx] = data[child1]; data[child1] = tmp; } break; } else { // two children int maxChild = data[child1] > data[child2] ? child1 : child2; if (data[idx] < data[maxChild]) { int tmp = data[idx]; data[idx] = data[maxChild]; data[maxChild] = tmp; idx = maxChild; continue; } else { // no swap break; } } } return res; } } class Dequeue { public Dictionary<int, int> data = new Dictionary<int, int>(); int firstIdx; public int Count; public Dequeue() { data = new Dictionary<int, int>(); firstIdx = 1; Count = 0; } public void PushFront(int a) { data[firstIdx - 1] = a; ++Count; --firstIdx; } public void PushBack(int a) { data[firstIdx + Count] = a; ++Count; } public int PopFront() { --Count; ++firstIdx; return data[firstIdx - 1]; } public int PopBack() { --Count; return data[firstIdx + Count]; } public int Get(int n) { return data[firstIdx + n]; } } /******************************************************************************/ class MainClass { // Debug functions static void debug<T>(IEnumerable<T> a, string s = "") { Console.WriteLine($"name: {s}"); int i = 0; foreach (var e in a) { Console.WriteLine($"value {i}: {e}"); ++i; } } static void dbg<T>(T a, string s = "") { Console.WriteLine($"name: {s} value: {a}"); } //////////////////// public static void Main() { var sc = new Scanner(); var wr = new BufferedStdoutWriter(); var dot = new NumberFormatInfo(); dot.NumberDecimalSeparator = "."; int n = sc.NextInt(); string s = sc.Next(); var prefixR = new int[n]; var prefixG = new int[n]; var prefixB = new int[n]; for (int i = 0; i < n; ++i) { if (i > 0) { prefixR[i] = prefixR[i - 1]; prefixG[i] = prefixG[i - 1]; prefixB[i] = prefixB[i - 1]; } if (s[i] == 'R') { ++prefixR[i]; } else if (s[i] == 'G') { ++prefixG[i]; } else { ++prefixB[i]; } } // debug(prefixG); long ans = 0; var colors = new char[3] { 'R', 'G', 'B' }; for (int i = 0; i < n; ++i) { for (int j = i + 3; j < n; ++j) { if (s[i] == s[j]) { continue; } char other = ' '; foreach (char c in colors) { if (s[i] != c && s[j] != c) { other = c; } } if (other == 'R') { ans += prefixR[j] - prefixR[i]; } else if (other == 'G') { ans += prefixG[j] - prefixG[i]; } else { ans += prefixB[j] - prefixB[i]; } // wr.WriteLine($"indices {i}{j} ans is {ans}"); if ((j - i) % 2 == 0) { int mid = i + ((j - i) / 2); if (s[mid] == other) { --ans; } } } } wr.Write(ans); wr.Flush(); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
1,623
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var S = Console.ReadLine(); var rs = S.Count(c => c == 'R'); var gs = S.Count(c => c == 'G'); var bs = S.Count(c => c == 'B'); long count = rs * gs * bs; for (var i = 0; i < N; i++) { for (var j = 1; j < N; j++) { var ll = i - j; var rr = j + i; if (!(0 <= ll && ll < N && 0 <= rr && rr < N)) continue; if (!(S[ll] != S[i] && S[rr] != S[i] && S[ll] != S[rr])) continue; count--; } } Console.WriteLine(count); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Numerics; using System.Text; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp2 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); var S = Console.ReadLine(); long rs = S.Count(c => c == 'R'); long gs = S.Count(c => c == 'G'); long bs = S.Count(c => c == 'B'); long count = rs * gs * bs; for (var i = 0; i < N; i++) { for (var j = 1; j < N; j++) { var ll = i - j; var rr = j + i; if (!(0 <= ll && ll < N && 0 <= rr && rr < N)) continue; if (!(S[ll] != S[i] && S[rr] != S[i] && S[ll] != S[rr])) continue; count--; } } Console.WriteLine(count); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
257
6
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderCs { class Program { static void Main() { var Num = int.Parse(Console.ReadLine()); var Text = Console.ReadLine().ToArray(); var Patern = new int[Num, 3]; var Result = 0; for (int i = Num - 1; - 1 < i; i--) { if (Text[i] == 'R') Patern[i, 0]++; else if (Text[i] == 'G') Patern[i, 1]++; else Patern[i, 2]++; if (i != Num - 1) { Patern[i, 0] += Patern[i + 1, 0]; Patern[i, 1] += Patern[i + 1, 1]; Patern[i, 2] += Patern[i + 1, 2]; } } for (int i = 0; i + 2 < Num; i++) { for (int j = i + 1; j + 1 < Num; j++) { if (Text[i] != Text[j]) { if (j + j - i < Num) { if (Text[j + j - i] != Text[i] && Text[j + j - i] != Text[j]) Result--; } if (Text[i] != 'R' && Text[j] != 'R') Result += Patern[j + 1, 0]; else if (Text[i] != 'G' && Text[j] != 'G') Result += Patern[j + 1, 1]; else Result += Patern[j + 1, 2]; } } } Console.WriteLine(Result); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderCs { class Program { static void Main() { var Num = int.Parse(Console.ReadLine()); var Text = Console.ReadLine().ToArray(); var Patern = new int[Num, 3]; var Result = 0L; for (int i = Num - 1; - 1 < i; i--) { if (Text[i] == 'R') Patern[i, 0]++; else if (Text[i] == 'G') Patern[i, 1]++; else Patern[i, 2]++; if (i != Num - 1) { Patern[i, 0] += Patern[i + 1, 0]; Patern[i, 1] += Patern[i + 1, 1]; Patern[i, 2] += Patern[i + 1, 2]; } } for (int i = 0; i + 2 < Num; i++) { for (int j = i + 1; j + 1 < Num; j++) { if (Text[i] != Text[j]) { if (j + j - i < Num) { if (Text[j + j - i] != Text[i] && Text[j + j - i] != Text[j]) Result--; } if (Text[i] != 'R' && Text[j] != 'R') Result += Patern[j + 1, 0]; else if (Text[i] != 'G' && Text[j] != 'G') Result += Patern[j + 1, 1]; else Result += Patern[j + 1, 2]; } } } Console.WriteLine(Result); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
377
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var N = int.Parse(Console.ReadLine()); var S = Console.ReadLine(); var r = 0; var g = 0; var b = 0; foreach (var c in S) { switch (c) { case 'R': r++; break; case 'G': g++; break; default: b++; break; } } var answer = r * g * b; foreach (var i in Enumerable.Range(0, N)) { foreach (var j in Enumerable.Range(i + 1, N - i - 1)) { var k = j + j - i; if (k >= S.Length) { continue; } if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) { answer--; } } } Console.WriteLine(answer); } } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; namespace MyProject { class Program { static void Main(string[] args) { #if Local var sw = new Stopwatch(); sw.Start(); Console.SetIn(new StreamReader("input.in")); #endif var solver = new Solver(); solver.Solve(); #if Local Console.WriteLine($"{sw.ElapsedMilliseconds}ms"); #endif } } class Solver { public void Solve() { var N = int.Parse(Console.ReadLine()); var S = Console.ReadLine(); var r = 0L; var g = 0L; var b = 0L; foreach (var c in S) { switch (c) { case 'R': r++; break; case 'G': g++; break; default: b++; break; } } var answer = r * g * b; foreach (var i in Enumerable.Range(0, N)) { foreach (var j in Enumerable.Range(i + 1, N - i - 1)) { var k = j + j - i; if (k >= S.Length) { continue; } if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) { answer--; } } } Console.WriteLine(answer); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
312
6
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()); var s = Console.ReadLine(); var r = 0; var g = 0; var b = 0; for (var i = 0; i < s.Length; i++) { switch (s[i]) { case 'R': r++; break; case 'G': g++; break; case 'B': b++; break; } } long count = r * g * b; for (var i = 0; i < n; i++) { for (var j = i + 1; j < n; j++) { var k = j + j - i; if (k >= n) continue; if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) count--; } } Console.WriteLine(count); } } }
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()); var s = Console.ReadLine(); long r = 0; long g = 0; long b = 0; for (var i = 0; i < s.Length; i++) { switch (s[i]) { case 'R': r++; break; case 'G': g++; break; case 'B': b++; break; } } long count = r * g * b; for (var i = 0; i < n; i++) { for (var j = i + 1; j < n; j++) { var k = j + j - i; if (k >= n) continue; if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) count--; } } Console.WriteLine(count); } } }
[["-", 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
287
8
using System; using System.Collections.Generic; using System.Linq; namespace abc162d { class Program { static void Main(string[] args) { //========================================================================================================================== // 1) input int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); // var rIndexes = s //.Select((p, i) => new { Content = p, Index = i }) //.Where(v => v.Content == 'R') //.Select(v => v.Index + 1); // var gIndexes = s //.Select((p, i) => new { Content = p, Index = i }) //.Where(v => v.Content == 'G') //.Select(v => v.Index + 1); // var bIndexes = s //.Select((p, i) => new { Content = p, Index = i }) //.Where(v => v.Content == 'B') //.Select(v => v.Index + 1); var r = 0; var g = 0; var b = 0; for (int index = 0; index < n; index++) { if (s[index] == 'R') r++; if (s[index] == 'G') g++; if (s[index] == 'B') b++; } //========================================================================================================================== // 2) output int output = 0; //これでは、RGBに対してijkが決まらないため、全検索を行わないといけない //O(N^3) foreach (var r in rIndexes) //{ // foreach (var g in gIndexes) // { // foreach (var b in bIndexes) // { // List<int> holder = new List<int>() { r, g, b }; // var sorted = holder.OrderBy(v => v).ToList(); // if (sorted[1] - sorted[0] != sorted[2] - sorted[1]) // { // output++; // } // } // } //} // O(N^2)となるように考える //コツは、条件式の算出を下記パターンで考える //1)条件1、2を同時に満たす要素を求めるときのO(N) //2)条件1を満たす要素を求めるときのO(N) //3)条件2を満たす要素を求めるときのO(N) //これらを考えたとき、 //1)と2)*3)どちらのオーダーが大きいか比較し、小さい方を採用するようにする //この場合、i,j固定で最後のKを確定するとき、その個数を導出するよう条件を設定する //以下回答 //(1) output = r * g * b; for (int i = 0; i < n; i++) { // i<jより初期値は+1 for (int j = i + 1; j < n; j++) { //満たす個数を見つける場合、条件1であるSi、Sj、Skの比較で実際に要素を比較するしかなくなり、総当たりしかなくなるのでNG //ただしこの条件1の総数は事前にO(N)で算出可能(1)である //また条件2を独立に考えたとき、i,jは決定され、j−i=k−jを満たすkが算出可能なことを考えると、総当たりしてもO(N^2) //さらにijkが決定されているので条件1の確認も可能 //したがって条件1から、条件2のうち条件1を満たす個数を引いていくことでよい // kの算出 int k = j + (j - i); //この時点でkがnを超えてたらスキップでよい if (k >= n) { continue; } //条件1を満たしているか if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) { //条件2を満たさないが条件1を満たすため減算 output--; } } } Console.WriteLine(output); //========================================================================================================================== } } }
using System; using System.Collections.Generic; using System.Linq; namespace abc162d { class Program { static void Main(string[] args) { //========================================================================================================================== // 1) input long n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); // var rIndexes = s //.Select((p, i) => new { Content = p, Index = i }) //.Where(v => v.Content == 'R') //.Select(v => v.Index + 1); // var gIndexes = s //.Select((p, i) => new { Content = p, Index = i }) //.Where(v => v.Content == 'G') //.Select(v => v.Index + 1); // var bIndexes = s //.Select((p, i) => new { Content = p, Index = i }) //.Where(v => v.Content == 'B') //.Select(v => v.Index + 1); long r = 0; long g = 0; long b = 0; for (int index = 0; index < n; index++) { if (s[index] == 'R') r++; if (s[index] == 'G') g++; if (s[index] == 'B') b++; } //========================================================================================================================== // 2) output long output = 0; //これでは、RGBに対してijkが決まらないため、全検索を行わないといけない //O(N^3) foreach (var r in rIndexes) //{ // foreach (var g in gIndexes) // { // foreach (var b in bIndexes) // { // List<int> holder = new List<int>() { r, g, b }; // var sorted = holder.OrderBy(v => v).ToList(); // if (sorted[1] - sorted[0] != sorted[2] - sorted[1]) // { // output++; // } // } // } //} // O(N^2)となるように考える //コツは、条件式の算出を下記パターンで考える //1)条件1、2を同時に満たす要素を求めるときのO(N) //2)条件1を満たす要素を求めるときのO(N) //3)条件2を満たす要素を求めるときのO(N) //これらを考えたとき、 //1)と2)*3)どちらのオーダーが大きいか比較し、小さい方を採用するようにする //この場合、i,j固定で最後のKを確定するとき、その個数を導出するよう条件を設定する //以下回答 //(1) output = r * g * b; for (int i = 0; i < n; i++) { // i<jより初期値は+1 for (int j = i + 1; j < n; j++) { //満たす個数を見つける場合、条件1であるSi、Sj、Skの比較で実際に要素を比較するしかなくなり、総当たりしかなくなるのでNG //ただしこの条件1の総数は事前にO(N)で算出可能(1)である //また条件2を独立に考えたとき、i,jは決定され、j−i=k−jを満たすkが算出可能なことを考えると、総当たりしてもO(N^2) //さらにijkが決定されているので条件1の確認も可能 //したがって条件1から、条件2のうち条件1を満たす個数を引いていくことでよい // kの算出 int k = j + (j - i); //この時点でkがnを超えてたらスキップでよい if (k >= n) { continue; } //条件1を満たしているか if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) { //条件2を満たさないが条件1を満たすため減算 output--; } } } Console.WriteLine(output); //========================================================================================================================== } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217]]
8
295
10
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace a4 { class Program { static void Main(string[] args) { var N = Convert.ToInt32(Console.ReadLine()); var S = Console.ReadLine(); var R = 0; var G = 0; var B = 0; for (var i = 0; i < S.Length; i++) { var c = S[i]; if (c == 'R') R += 1; if (c == 'G') G += 1; if (c == 'B') B += 1; } var res = R * G * B; for (var a = 0; a < S.Length; a++) { for (var s = 1; (a + s * 2) < S.Length; s++) { if (S[a] != S[a + s] && S[a + s] != S[a + s * 2] && S[a] != S[a + s * 2]) { res -= 1; } } } Console.WriteLine(res); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace a4 { class Program { static void Main(string[] args) { var N = Convert.ToInt32(Console.ReadLine()); var S = Console.ReadLine(); var R = 0L; var G = 0L; var B = 0L; for (var i = 0; i < S.Length; i++) { var c = S[i]; if (c == 'R') R += 1; if (c == 'G') G += 1; if (c == 'B') B += 1; } var res = R * G * B; for (var a = 0; a < S.Length; a++) { for (var s = 1; (a + s * 2) < S.Length; s++) { if (S[a] != S[a + s] && S[a + s] != S[a + s * 2] && S[a] != S[a + s * 2]) { res -= 1; } } } Console.WriteLine(res); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
254
6
using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Math; namespace CSharpSpiral { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = #if DEBUG true #else false #endif }; Console.SetOut(sw); new Program().Solve(new ConsoleInput( #if DEBUG new StreamReader("../../../inputData.txt") #else Console.In #endif , ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var S = cin.ReadLine.ToCharArray(); var Rs = ER(0, N).Count(i => S[i] == 'R'); var Bs = ER(0, N).Count(i => S[i] == 'B'); var Gs = ER(0, N).Count(i => S[i] == 'G'); var Res = 0L; Res = Rs * Gs * Bs; for (int i = 0; i < N; i++) { for (int j = 1; i + 2 * j < N; j++) { if (different(S[i], S[i + j], S[i + 2 * j])) Res--; } } Console.WriteLine(Res); } public IEnumerable<int> ER(int start, int count) => Enumerable.Range(start, count); public bool different(char a, char b, char c) => a != b && b != c && c != a; } static class ExtendClass { public static void Swap<T>(this T[] A, int x, int y) { var tmp = A[x]; A[x] = A[y]; A[y] = tmp; } public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X); } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } public bool isEOF { get { return _stream.Peek() == -1; } } } }
using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Math; namespace CSharpSpiral { class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = #if DEBUG true #else false #endif }; Console.SetOut(sw); new Program().Solve(new ConsoleInput( #if DEBUG new StreamReader("../../../inputData.txt") #else Console.In #endif , ' ')); Console.Out.Flush(); } public void Solve(ConsoleInput cin) { var N = cin.ReadInt; var S = cin.ReadLine.ToCharArray(); var Rs = ER(0, N).Count(i => S[i] == 'R'); var Bs = ER(0, N).Count(i => S[i] == 'B'); var Gs = ER(0, N).Count(i => S[i] == 'G'); var Res = 0L; Res = (long)Rs * Gs * Bs; for (int i = 0; i < N; i++) { for (int j = 1; i + 2 * j < N; j++) { if (different(S[i], S[i + j], S[i + 2 * j])) Res--; } } Console.WriteLine(Res); } public IEnumerable<int> ER(int start, int count) => Enumerable.Range(start, count); public bool different(char a, char b, char c) => a != b && b != c && c != a; } static class ExtendClass { public static void Swap<T>(this T[] A, int x, int y) { var tmp = A[x]; A[x] = A[y]; A[y] = tmp; } public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X); } class ConsoleInput { private readonly TextReader _stream; private readonly char _separator = ' '; private readonly Queue<string> inputStream; public ConsoleInput(TextReader stream, char separator = ' ') { this._separator = separator; this._stream = stream; inputStream = new Queue<string>(); } public string Read { get { if (inputStream.Count != 0) return inputStream.Dequeue(); string[] tmp = _stream.ReadLine().Split(_separator); for (int i = 0; i < tmp.Length; ++i) inputStream.Enqueue(tmp[i]); return inputStream.Dequeue(); } } public string ReadLine { get { return _stream.ReadLine(); } } public int ReadInt { get { return int.Parse(Read); } } public long ReadLong { get { return long.Parse(Read); } } public double ReadDouble { get { return double.Parse(Read); } } public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; } public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; } public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; } public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; } public bool isEOF { get { return _stream.Peek() == -1; } } } }
[["+", 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
853
3
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } const char R = 'R'; const char G = 'G'; const char B = 'B'; static object process(TextReader input) { var n = int.Parse(input.ReadLine()); var s = input.ReadLine(); int sum = 0; int r = 0; int g = 0; int b = 0; for (int i = 0; i < n; i++) { var c = s[i]; if (c == R) r++; else if (c == G) g++; else if (c == B) b++; for (int j = 1; j < n - i; j++) { if (i + j + j < n) { if (c != s[i + j] && c != s[i + j + j] && s[i + j] != s[i + j + j]) { sum++; } } } } return (r * g * b) - sum; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; class Program { const string Yes = "Yes"; const string No = "No"; const long Mod = 1000000007; static void Main(string[] args) { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); // MyDebugger.MakeTestCase("../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } const char R = 'R'; const char G = 'G'; const char B = 'B'; static object process(TextReader input) { var n = int.Parse(input.ReadLine()); var s = input.ReadLine(); long sum = 0; long r = 0; long g = 0; long b = 0; for (int i = 0; i < n; i++) { var c = s[i]; if (c == R) r++; else if (c == G) g++; else if (c == B) b++; for (int j = 1; j < n - i; j++) { if (i + j + j < n) { if (c != s[i + j] && c != s[i + j + j] && s[i + j] != s[i + j + j]) { sum++; } } } } return (r * g * b) - sum; } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
323
8
using System; using System.Linq; namespace AtCoder { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int r = s.Count(x => x == 'R'); int g = s.Count(x => x == 'G'); int b = s.Count(x => x == 'B'); int count = 0; for (int i = 0; i < n; i++) { if (s[i] != 'R') continue; for (int j = 0; j < n; j++) { if (s[j] != 'G') continue; int i2, j2; if (i > j) { i2 = i; j2 = j; } else { j2 = i; i2 = j; } int d = i2 - j2; int c1 = j2 - d; int c2 = i2 + d; int c3 = (i2 + j2) / 2; if (c1 >= 0 && s[c1] == 'B') count++; if (c2 < n && s[c2] == 'B') count++; if (d % 2 == 0 && s[c3] == 'B') count++; } } Console.WriteLine(r * g * b - count); } } }
using System; using System.Linq; namespace AtCoder { class Program { static void Main() { int n = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int r = s.Count(x => x == 'R'); int g = s.Count(x => x == 'G'); int b = s.Count(x => x == 'B'); int count = 0; for (int i = 0; i < n; i++) { if (s[i] != 'R') continue; for (int j = 0; j < n; j++) { if (s[j] != 'G') continue; int i2, j2; if (i > j) { i2 = i; j2 = j; } else { j2 = i; i2 = j; } int d = i2 - j2; int c1 = j2 - d; int c2 = i2 + d; int c3 = (i2 + j2) / 2; if (c1 >= 0 && s[c1] == 'B') count++; if (c2 < n && s[c2] == 'B') count++; if (d % 2 == 0 && s[c3] == 'B') count++; } } Console.WriteLine((long)r * g * b - count); } } }
[["+", 0, 16, 31, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 16, 31, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 16, 31, 16, 31, 16, 31, 74, 0, 25]]
8
290
3
using System; using System.Collections.Generic; class Program { static void Main() { int N = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int[] S = new int[N]; var D = new Dictionary<char, int>() { { 'R', 0 }, { 'G', 1 }, { 'B', 2 } }; for (int i = 0; i < N; ++i) S[i] = D[s[i]]; int[,] X = new int[3, N]; int[] nC = new int[] { 0, 0, 0 }; for (int i = N - 1; i >= 0; --i) { for (int j = 0; j < 3; ++j) X[j, i] = nC[j]; ++nC[S[i]]; } int ans = 0; for (int i = 0; i < N - 2; ++i) { for (int j = i + 1; j < N - 1; ++j) { if (S[i] == S[j]) continue; int r = 3 - S[i] - S[j]; ans += X[r, j]; int k = 2 * j - i; if (k < N && S[k] == r) --ans; } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; class Program { static void Main() { int N = int.Parse(Console.ReadLine()); string s = Console.ReadLine(); int[] S = new int[N]; var D = new Dictionary<char, int>() { { 'R', 0 }, { 'G', 1 }, { 'B', 2 } }; for (int i = 0; i < N; ++i) S[i] = D[s[i]]; int[,] X = new int[3, N]; int[] nC = new int[] { 0, 0, 0 }; for (int i = N - 1; i >= 0; --i) { for (int j = 0; j < 3; ++j) X[j, i] = nC[j]; ++nC[S[i]]; } long ans = 0; for (int i = 0; i < N - 2; ++i) { for (int j = i + 1; j < N - 1; ++j) { if (S[i] == S[j]) continue; int r = 3 - S[i] - S[j]; ans += X[r, j]; int k = 2 * j - i; if (k < N && S[k] == r) --ans; } } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
317
2
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC162.D(); } class ABC162 { public static void A() { var N = Read.Int(); Console.WriteLine( N % 10 == 7 || N / 100 == 7 || (N / 10) % 10 == 7 ? "Yes" : "No"); } public static void B() { var N = Read.Int(); long sum = 0; for (int i = 1; i <= N; ++i) { if (i % 3 > 0 && i % 5 > 0) { sum += i; } } Console.WriteLine(sum); } public static void C() { var K = Read.Int(); long sum = 0; for (int a = 1; a <= K; ++a) { for (int b = 1; b <= K; ++b) { for (int c = 1; c <= K; ++c) { sum += Util.GCD(a, Util.GCD(b, c)); } } } Console.WriteLine(sum); } public static void D() { var N = Read.Int(); var S = Read.Str(); var Freq = Util.Frequency(S.ToArray()); var R = Freq.ContainsKey('R') ? Freq['R'] : 0; var G = Freq.ContainsKey('G') ? Freq['G'] : 0; var B = Freq.ContainsKey('B') ? Freq['B'] : 0; long total = R * G * B; if (total == 0) { Console.WriteLine(0); return; } for (int d = 1; d < 2000; ++d) { for (int s = 0; s < 4000; ++s) { var s2 = s + d; var s3 = s + d * 2; if (s3 >= N) { break; } if (S[s] != S[s2] && S[s] != S[s3] && S[s2] != S[s3]) { total--; } } } Console.WriteLine(total); } public static void E() { var N = Read.Int(); var K = Read.Long(); MOD[] counter = new MOD[K + 1]; for (long i = K; i > K / 2; --i) { counter[i] = 1; } for (long i = K / 2; i >= 1; --i) { long biggerC = 0; MOD biggerS = 0; for (int m = 2;; ++m) { var j = i * m; if (j > K) { break; } biggerC++; biggerS += counter[j]; } MOD c = biggerC + 1; counter[i] = c.Power(N) - biggerS; } MOD total = 0; for (int i = 1; i <= K; ++i) { total += i * counter[i]; } Console.WriteLine(total.V); } public static void F() {} } class Util { public static long[] ASum(long[] array) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = res[i] + array[i]; } return res; } public static long GCD(long a, long b) { while (b > 0) { var c = a % b; a = b; b = c; } return a; } public static Dictionary<T, int> Frequency<T>(T[] array) { var dict = new Dictionary<T, int>(); foreach (var a in array) { if (!dict.ContainsKey(a)) { dict.Add(a, 0); } dict[a]++; } return dict; } public static long Inverse(long a, long p) { long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public static long[] Facts(int n, long p) { var facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; ++i) { facts[i] = (i * facts[i - 1]) % p; } return facts; } public static Func<int, int, long> Combin(int n, long P) { var fact = Facts(n, P); var inv = fact.Select(x => Inverse(x, P)).ToArray(); return (N, M) => { if (N < 0 || N < M || M < 0) { return 0; } return (((fact[N] * inv[M]) % P) * inv[N - M]) % P; }; } } struct MOD { public static long P = 1000000007; public readonly long V; public MOD(long a) { this.V = a; } public static implicit operator MOD(long a) { return new MOD(a); } public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); } public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); } public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); } public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); } // public MOD Inverse() { return Util.Inverse(V, P); } public MOD Inverse() { long a = V, p = P; long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } // public MOD Power(long n) { return Util.Power(V, n, P); } public MOD Power(long n) { long a = V, p = P; long res = 1; long mult = a; for (int i = 0; i < 40; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public override string ToString() { return V.ToString(); } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); if (!isDirectional) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { ABC162.D(); } class ABC162 { public static void A() { var N = Read.Int(); Console.WriteLine( N % 10 == 7 || N / 100 == 7 || (N / 10) % 10 == 7 ? "Yes" : "No"); } public static void B() { var N = Read.Int(); long sum = 0; for (int i = 1; i <= N; ++i) { if (i % 3 > 0 && i % 5 > 0) { sum += i; } } Console.WriteLine(sum); } public static void C() { var K = Read.Int(); long sum = 0; for (int a = 1; a <= K; ++a) { for (int b = 1; b <= K; ++b) { for (int c = 1; c <= K; ++c) { sum += Util.GCD(a, Util.GCD(b, c)); } } } Console.WriteLine(sum); } public static void D() { var N = Read.Int(); var S = Read.Str(); var Freq = Util.Frequency(S.ToArray()); var R = Freq.ContainsKey('R') ? Freq['R'] : 0; var G = Freq.ContainsKey('G') ? Freq['G'] : 0; var B = Freq.ContainsKey('B') ? Freq['B'] : 0; long total = (long)R * G * B; if (total == 0) { Console.WriteLine(0); return; } for (int d = 1; d < 2000; ++d) { for (int s = 0; s < 4000; ++s) { var s2 = s + d; var s3 = s + d * 2; if (s3 >= N) { break; } if (S[s] != S[s2] && S[s] != S[s3] && S[s2] != S[s3]) { total--; } } } Console.WriteLine(total); } public static void E() { var N = Read.Int(); var K = Read.Long(); MOD[] counter = new MOD[K + 1]; for (long i = K; i > K / 2; --i) { counter[i] = 1; } for (long i = K / 2; i >= 1; --i) { long biggerC = 0; MOD biggerS = 0; for (int m = 2;; ++m) { var j = i * m; if (j > K) { break; } biggerC++; biggerS += counter[j]; } MOD c = biggerC + 1; counter[i] = c.Power(N) - biggerS; } MOD total = 0; for (int i = 1; i <= K; ++i) { total += i * counter[i]; } Console.WriteLine(total.V); } public static void F() {} } class Util { public static long[] ASum(long[] array) { var res = new long[array.Length + 1]; for (int i = 0; i < array.Length; ++i) { res[i + 1] = res[i] + array[i]; } return res; } public static long GCD(long a, long b) { while (b > 0) { var c = a % b; a = b; b = c; } return a; } public static Dictionary<T, int> Frequency<T>(T[] array) { var dict = new Dictionary<T, int>(); foreach (var a in array) { if (!dict.ContainsKey(a)) { dict.Add(a, 0); } dict[a]++; } return dict; } public static long Inverse(long a, long p) { long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } public static long[] Facts(int n, long p) { var facts = new long[n + 1]; facts[0] = 1; for (int i = 1; i <= n; ++i) { facts[i] = (i * facts[i - 1]) % p; } return facts; } public static Func<int, int, long> Combin(int n, long P) { var fact = Facts(n, P); var inv = fact.Select(x => Inverse(x, P)).ToArray(); return (N, M) => { if (N < 0 || N < M || M < 0) { return 0; } return (((fact[N] * inv[M]) % P) * inv[N - M]) % P; }; } } struct MOD { public static long P = 1000000007; public readonly long V; public MOD(long a) { this.V = a; } public static implicit operator MOD(long a) { return new MOD(a); } public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); } public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); } public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); } public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); } // public MOD Inverse() { return Util.Inverse(V, P); } public MOD Inverse() { long a = V, p = P; long b = p, c = 1, d = 0, e = 0, f = 0; while (b != 0) { e = a / b; f = b; b = a - e * b; a = f; f = d; d = c - e * d; c = f; } c %= p; return c + (c < 0 ? p : 0); } // public MOD Power(long n) { return Util.Power(V, n, P); } public MOD Power(long n) { long a = V, p = P; long res = 1; long mult = a; for (int i = 0; i < 40; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public override string ToString() { return V.ToString(); } } static class Read { static Queue<string> queue = new Queue<string>(); static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } } public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); } public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); } public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); } public static int[] IntN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt32(s)) .ToArray(); } public static long[] LongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToInt64(s)) .ToArray(); } public static string[] StrN() { return Console.ReadLine().Split(' '); } public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); } public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); } public static long[,] LongMatrix(int r, int c) { var mat = new long[r, c]; for (int i = 0; i < r; ++i) { var x = Read.LongN(); for (int j = 0; j < c; ++j) { mat[i, j] = x[j]; } } return mat; } public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M, bool isDirectional = false) { Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new HashSet<int>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1]); if (!isDirectional) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M) { Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>(); for (int i = 0; i <= N; ++i) { dict.Add(i, new Dictionary<int, long>()); } for (int i = 0; i < M; ++i) { var ab = Read.IntN(); dict[ab[0]].Add(ab[1], ab[2]); dict[ab[1]].Add(ab[0], ab[2]); } return dict; } } } }
[["+", 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]]
8
2,556
3
using System; using System.Linq; class F { static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (n % 2 == 0) { var dp = new long[n + 5, 2]; for (int i = 0; i <= n; i++) for (int j = 0; j < 2; j++) dp[i, j] = long.MinValue; dp[1, 1] = a[0]; dp[2, 0] = a[1]; for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) { if (dp[i, j] == long.MinValue) continue; if (i + 1 < n) dp[i + 2, j] = Math.Max(dp[i + 2, j], dp[i, j] + a[i + 1]); if (j > 0 && i + 2 < n) dp[i + 3, j - 1] = Math.Max(dp[i + 3, j - 1], dp[i, j] + a[i + 2]); } Console.WriteLine(Math.Max(dp[n - 1, 0], dp[n, 0])); } else { var dp = new long[n + 5, 3]; for (int i = 0; i <= n; i++) for (int j = 0; j < 3; j++) dp[i, j] = long.MinValue; dp[1, 2] = a[0]; dp[2, 1] = a[1]; dp[3, 0] = a[2]; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) { if (dp[i, j] == long.MinValue) continue; if (i + 1 < n) dp[i + 2, j] = Math.Max(dp[i + 2, j], dp[i, j] + a[i + 1]); if (j > 0 && i + 2 < n) dp[i + 3, j - 1] = Math.Max(dp[i + 3, j - 1], dp[i, j] + a[i + 2]); if (j > 1 && i + 3 < n) dp[i + 4, j - 2] = Math.Max(dp[i + 4, j - 2], dp[i, j] + a[i + 3]); } Console.WriteLine( Math.Max(dp[n - 2, 0], Math.Max(dp[n - 1, 0], dp[n, 0]))); } } }
using System; using System.Linq; class F { static void Main() { var n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (n % 2 == 0) { var dp = new long[n + 5, 2]; for (int i = 0; i <= n; i++) for (int j = 0; j < 2; j++) dp[i, j] = long.MinValue; dp[1, 1] = a[0]; dp[2, 0] = a[1]; for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) { if (dp[i, j] == long.MinValue) continue; if (i + 1 < n) dp[i + 2, j] = Math.Max(dp[i + 2, j], dp[i, j] + a[i + 1]); if (j > 0 && i + 2 < n) dp[i + 3, j - 1] = Math.Max(dp[i + 3, j - 1], dp[i, j] + a[i + 2]); } Console.WriteLine(Math.Max(dp[n - 1, 1], dp[n, 0])); } else { var dp = new long[n + 5, 3]; for (int i = 0; i <= n; i++) for (int j = 0; j < 3; j++) dp[i, j] = long.MinValue; dp[1, 2] = a[0]; dp[2, 1] = a[1]; dp[3, 0] = a[2]; for (int i = 0; i < n; i++) for (int j = 0; j < 3; j++) { if (dp[i, j] == long.MinValue) continue; if (i + 1 < n) dp[i + 2, j] = Math.Max(dp[i + 2, j], dp[i, j] + a[i + 1]); if (j > 0 && i + 2 < n) dp[i + 3, j - 1] = Math.Max(dp[i + 3, j - 1], dp[i, j] + a[i + 2]); if (j > 1 && i + 3 < n) dp[i + 4, j - 2] = Math.Max(dp[i + 4, j - 2], dp[i, j] + a[i + 3]); } Console.WriteLine( Math.Max(dp[n - 2, 2], Math.Max(dp[n - 1, 1], dp[n, 0]))); } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
639
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class F { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { long N = GetLong(); var A = GetLongs(N); long NUM_STATE = (N % 2 == 0) ? 2 : 3; var dp = new long[N + 1, NUM_STATE]; for (long i = 0; i <= N; i++) { for (long j = 0; j < NUM_STATE; j++) dp[i, j] = long.MinValue / 2; } dp[0, 0] = 0; for (long i = 0; i < N; i++) { for (long j = 0; j < NUM_STATE; j++) { if ((i + j) % 2 == 0) chmax(ref dp[i + 1, j], dp[i, j] + A[i]); else chmax(ref dp[i + 1, j], dp[i, j]); if (j < NUM_STATE - 1) chmax(ref dp[i + 1, j + 1], dp[i, j]); } } WriteLine(dp[N, NUM_STATE]); } } 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 decimal GetDecimal() => decimal.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray(); public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray(); public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using static System.Console; using static System.Math; using static MyIO; using static MyUtil; public class F { public static void Main() => (new Solver()).Solve(); } public class Solver { public void Solve() { long N = GetLong(); var A = GetLongs(N); long NUM_STATE = (N % 2 == 0) ? 2 : 3; var dp = new long[N + 1, NUM_STATE]; for (long i = 0; i <= N; i++) { for (long j = 0; j < NUM_STATE; j++) dp[i, j] = long.MinValue / 2; } dp[0, 0] = 0; for (long i = 0; i < N; i++) { for (long j = 0; j < NUM_STATE; j++) { if ((i + j) % 2 == 0) chmax(ref dp[i + 1, j], dp[i, j] + A[i]); else chmax(ref dp[i + 1, j], dp[i, j]); if (j < NUM_STATE - 1) chmax(ref dp[i + 1, j + 1], dp[i, j]); } } WriteLine(dp[N, NUM_STATE - 1]); } } 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 decimal GetDecimal() => decimal.Parse(getArg()); public static string GetString() => getArg(); public static char GetChar() => getArg()[0]; public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray(); public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray(); public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray(); public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray(); public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray(); } public static class MyUtil { public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) < 0) x = y; } public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if (x.CompareTo(y) > 0) x = y; } public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; } }
[["+", 0, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 0, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
770
2
/******************************************************************************* * Author: Nirushuu * Date: 2020-04-16 *******************************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.IO; using System.Globalization; using System.Numerics; /******************************************************************************* * IO from Kattio.cs from open.kattis.com/help/csharp */ public class NoMoreTokensException : Exception {} public class Tokenizer { string[] tokens = new string[0]; private int pos; StreamReader reader; public Tokenizer(Stream inStream) { var bs = new BufferedStream(inStream); reader = new StreamReader(bs); } public Tokenizer() : this(Console.OpenStandardInput()) { // Nothing more to do } private string PeekNext() { if (pos < 0) // pos < 0 indicates that there are no more tokens return null; if (pos < tokens.Length) { if (tokens[pos].Length == 0) { ++pos; return PeekNext(); } return tokens[pos]; } string line = reader.ReadLine(); if (line == null) { // There is no more data to read pos = -1; return null; } // Split the line that was read on white space characters tokens = line.Split(null); pos = 0; return PeekNext(); } public bool HasNext() { return (PeekNext() != null); } public string Next() { string next = PeekNext(); if (next == null) throw new NoMoreTokensException(); ++pos; return next; } } public class Scanner : Tokenizer { public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public float NextFloat() { return float.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } public class BufferedStdoutWriter : StreamWriter { public BufferedStdoutWriter() : base(new BufferedStream(Console.OpenStandardOutput())) {} } /******************************************************************************/ /******************************************************************************* * DisjointSet datastructure */ public struct DisjointSet { public int[] parent; public int[] rank; public DisjointSet(int n) { parent = new int[n]; for (int i = 0; i < n; ++i) { parent[i] = i; } rank = new int[n]; } public int Find(int i) { int idx = i; var compress = new List<int>(); while (idx != parent[idx]) { compress.Add(idx); idx = parent[idx]; } foreach (var e in compress) { // path compress parent[e] = idx; } return idx; } public void Union(int a, int b) { int aPar = this.Find(a); int bPar = this.Find(b); if (rank[aPar] > rank[bPar]) { // by rank parent[bPar] = aPar; } else { parent[aPar] = bPar; } if (rank[aPar] == rank[bPar]) { ++rank[bPar]; } } } class MaxHeap { List<int> data; public MaxHeap() { data = new List<int>(); } public void Push(int a) { data.Add(a); int idx = data.Count - 1; int parent = (int)Math.Floor((double)(idx - 1) / 2); while (idx != 0 && (data[idx] > data[parent])) { int tmp = data[parent]; data[parent] = data[idx]; data[idx] = tmp; idx = parent; parent = (int)Math.Floor((double)(idx - 1) / 2); } } public int Pop() { int res = data[0]; data[0] = data[data.Count - 1]; data.RemoveAt(data.Count - 1); int idx = 0; while (true) { int child1 = (2 * idx) + 1; int child2 = (2 * idx) + 2; if (child1 >= data.Count) { // no children break; } else if (child2 >= data.Count) { // one child if (data[idx] < data[child1]) { int tmp = data[idx]; data[idx] = data[child1]; data[child1] = tmp; } break; } else { // two children int maxChild = data[child1] > data[child2] ? child1 : child2; if (data[idx] < data[maxChild]) { int tmp = data[idx]; data[idx] = data[maxChild]; data[maxChild] = tmp; idx = maxChild; continue; } else { // no swap break; } } } return res; } } class Dequeue { public Dictionary<int, int> data = new Dictionary<int, int>(); int firstIdx; public int Count; public Dequeue() { data = new Dictionary<int, int>(); firstIdx = 1; Count = 0; } public void PushFront(int a) { data[firstIdx - 1] = a; ++Count; --firstIdx; } public void PushBack(int a) { data[firstIdx + Count] = a; ++Count; } public int PopFront() { --Count; ++firstIdx; return data[firstIdx - 1]; } public int PopBack() { --Count; return data[firstIdx + Count]; } public int Get(int n) { return data[firstIdx + n]; } } /******************************************************************************/ class MainClass { // Debug functions static void debug<T>(IEnumerable<T> a, string s = "") { Console.WriteLine($"name: {s}"); int i = 0; foreach (var e in a) { Console.WriteLine($"value {i}: {e}"); ++i; } } static void dbg<T>(T a, string s = "") { Console.WriteLine($"name: {s} value: {a}"); } //////////////////// static int gcd(int a, int b) { while (b != 0) { int t = b; b = a % b; a = t; } return a; } public static void Main() { var sc = new Scanner(); var wr = new BufferedStdoutWriter(); var dot = new NumberFormatInfo(); dot.NumberDecimalSeparator = "."; int n = sc.NextInt(); var ns = new int[n + 1]; for (int i = 1; i <= n; ++i) { ns[i] = sc.NextInt(); } var oddPrefix = new int[n + 1]; oddPrefix[1] = ns[1]; for (int i = 2; i <= n; ++i) { oddPrefix[i] = oddPrefix[i - 1]; if (i % 2 == 1) { oddPrefix[i] += ns[i]; } } // debug(oddPrefix); var dptake = new long[n + 1]; var dpdont = new long[n + 1]; dptake[2] = ns[2]; dpdont[2] = ns[1]; for (int i = 2; i <= n; ++i) { if (i % 2 == 0) { dptake[i] = ns[i] + dpdont[i - 1]; dpdont[i] = oddPrefix[i - 1]; } else { dptake[i] = ns[i] + Math.Max(dptake[i - 2], dpdont[i - 2]); dpdont[i] = Math.Max(dptake[i - 1], dpdont[i - 1]); } } // debug(dptake); // debug(dpdont); wr.Write(Math.Max(dptake[n], dpdont[n])); wr.Flush(); } }
/******************************************************************************* * Author: Nirushuu * Date: 2020-04-16 *******************************************************************************/ using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.IO; using System.Globalization; using System.Numerics; /******************************************************************************* * IO from Kattio.cs from open.kattis.com/help/csharp */ public class NoMoreTokensException : Exception {} public class Tokenizer { string[] tokens = new string[0]; private int pos; StreamReader reader; public Tokenizer(Stream inStream) { var bs = new BufferedStream(inStream); reader = new StreamReader(bs); } public Tokenizer() : this(Console.OpenStandardInput()) { // Nothing more to do } private string PeekNext() { if (pos < 0) // pos < 0 indicates that there are no more tokens return null; if (pos < tokens.Length) { if (tokens[pos].Length == 0) { ++pos; return PeekNext(); } return tokens[pos]; } string line = reader.ReadLine(); if (line == null) { // There is no more data to read pos = -1; return null; } // Split the line that was read on white space characters tokens = line.Split(null); pos = 0; return PeekNext(); } public bool HasNext() { return (PeekNext() != null); } public string Next() { string next = PeekNext(); if (next == null) throw new NoMoreTokensException(); ++pos; return next; } } public class Scanner : Tokenizer { public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public float NextFloat() { return float.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } public class BufferedStdoutWriter : StreamWriter { public BufferedStdoutWriter() : base(new BufferedStream(Console.OpenStandardOutput())) {} } /******************************************************************************/ /******************************************************************************* * DisjointSet datastructure */ public struct DisjointSet { public int[] parent; public int[] rank; public DisjointSet(int n) { parent = new int[n]; for (int i = 0; i < n; ++i) { parent[i] = i; } rank = new int[n]; } public int Find(int i) { int idx = i; var compress = new List<int>(); while (idx != parent[idx]) { compress.Add(idx); idx = parent[idx]; } foreach (var e in compress) { // path compress parent[e] = idx; } return idx; } public void Union(int a, int b) { int aPar = this.Find(a); int bPar = this.Find(b); if (rank[aPar] > rank[bPar]) { // by rank parent[bPar] = aPar; } else { parent[aPar] = bPar; } if (rank[aPar] == rank[bPar]) { ++rank[bPar]; } } } class MaxHeap { List<int> data; public MaxHeap() { data = new List<int>(); } public void Push(int a) { data.Add(a); int idx = data.Count - 1; int parent = (int)Math.Floor((double)(idx - 1) / 2); while (idx != 0 && (data[idx] > data[parent])) { int tmp = data[parent]; data[parent] = data[idx]; data[idx] = tmp; idx = parent; parent = (int)Math.Floor((double)(idx - 1) / 2); } } public int Pop() { int res = data[0]; data[0] = data[data.Count - 1]; data.RemoveAt(data.Count - 1); int idx = 0; while (true) { int child1 = (2 * idx) + 1; int child2 = (2 * idx) + 2; if (child1 >= data.Count) { // no children break; } else if (child2 >= data.Count) { // one child if (data[idx] < data[child1]) { int tmp = data[idx]; data[idx] = data[child1]; data[child1] = tmp; } break; } else { // two children int maxChild = data[child1] > data[child2] ? child1 : child2; if (data[idx] < data[maxChild]) { int tmp = data[idx]; data[idx] = data[maxChild]; data[maxChild] = tmp; idx = maxChild; continue; } else { // no swap break; } } } return res; } } class Dequeue { public Dictionary<int, int> data = new Dictionary<int, int>(); int firstIdx; public int Count; public Dequeue() { data = new Dictionary<int, int>(); firstIdx = 1; Count = 0; } public void PushFront(int a) { data[firstIdx - 1] = a; ++Count; --firstIdx; } public void PushBack(int a) { data[firstIdx + Count] = a; ++Count; } public int PopFront() { --Count; ++firstIdx; return data[firstIdx - 1]; } public int PopBack() { --Count; return data[firstIdx + Count]; } public int Get(int n) { return data[firstIdx + n]; } } /******************************************************************************/ class MainClass { // Debug functions static void debug<T>(IEnumerable<T> a, string s = "") { Console.WriteLine($"name: {s}"); int i = 0; foreach (var e in a) { Console.WriteLine($"value {i}: {e}"); ++i; } } static void dbg<T>(T a, string s = "") { Console.WriteLine($"name: {s} value: {a}"); } //////////////////// static int gcd(int a, int b) { while (b != 0) { int t = b; b = a % b; a = t; } return a; } public static void Main() { var sc = new Scanner(); var wr = new BufferedStdoutWriter(); var dot = new NumberFormatInfo(); dot.NumberDecimalSeparator = "."; int n = sc.NextInt(); var ns = new int[n + 1]; for (int i = 1; i <= n; ++i) { ns[i] = sc.NextInt(); } var oddPrefix = new long[n + 1]; oddPrefix[1] = ns[1]; for (int i = 2; i <= n; ++i) { oddPrefix[i] = oddPrefix[i - 1]; if (i % 2 == 1) { oddPrefix[i] += ns[i]; } } // debug(oddPrefix); var dptake = new long[n + 1]; var dpdont = new long[n + 1]; dptake[2] = ns[2]; dpdont[2] = ns[1]; for (int i = 2; i <= n; ++i) { if (i % 2 == 0) { dptake[i] = ns[i] + dpdont[i - 1]; dpdont[i] = oddPrefix[i - 1]; } else { dptake[i] = ns[i] + Math.Max(dptake[i - 2], dpdont[i - 2]); dpdont[i] = Math.Max(dptake[i - 1], dpdont[i - 1]); } } // debug(dptake); // debug(dpdont); wr.Write(Math.Max(dptake[n], dpdont[n])); wr.Flush(); } }
[["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199]]
8
1,573
2
using System; using System.Collections.Generic; using System.Linq; namespace contest_Csharp { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); List<long> sumeven = new List<long>(), sumodd = new List<long>(); long se = 0, so = 0; sumodd.Add(so); sumeven.Add(se); for (int i = 0; i < N; i++) { if (i % 2 == 0) { se += A[i]; sumeven.Add(se); } else { so += A[i]; sumodd.Add(so); } } List<int> firstlimit = new List<int>(new int[N / 2]), secondlimit = new List<int>(new int[N / 2]); long f = 0; firstlimit[0] = (sumeven[1] > sumodd[1]) ? 0 : -1; // evenをA[i]まで数える for (int i = 1; i < N / 2; i++) { if (sumeven[i + 1] < sumeven[firstlimit[i - 1] + 1] + (sumodd[i + 1] - sumodd[firstlimit[i - 1] + 1])) { firstlimit[i] = firstlimit[i - 1]; } else { firstlimit[i] = i; } } if (N % 2 == 0) { long answer; answer = Math.Max(sumeven[N / 2], sumeven[firstlimit[N / 2 - 1] + 1] + (sumodd[N / 2] - sumodd[firstlimit[N / 2 - 1] + 1])); Console.WriteLine(answer); return; } long ans = long.MinValue; var sumevenI = sumeven.Select(x => sumeven[sumeven.Count() - 1] - x).ToList(); sumevenI.Reverse(); for (int i = 0; i < N / 2 - 1; i++) //後ろi個を確定させる { long a = Math.Max( sumeven[N / 2 - i], sumeven[firstlimit[N / 2 - i - 1] + 1] + (sumodd[N / 2 - i] - sumodd[firstlimit[N / 2 - i - 1] + 1])); ans = Math.Max(ans, a + sumevenI[i]); } ans = Math.Max(ans, sumevenI[N / 2]); Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace contest_Csharp { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); List<long> sumeven = new List<long>(), sumodd = new List<long>(); long se = 0, so = 0; sumodd.Add(so); sumeven.Add(se); for (int i = 0; i < N; i++) { if (i % 2 == 0) { se += A[i]; sumeven.Add(se); } else { so += A[i]; sumodd.Add(so); } } List<int> firstlimit = new List<int>(new int[N / 2]), secondlimit = new List<int>(new int[N / 2]); long f = 0; firstlimit[0] = (sumeven[1] > sumodd[1]) ? 0 : -1; // evenをA[i]まで数える for (int i = 1; i < N / 2; i++) { if (sumeven[i + 1] < sumeven[firstlimit[i - 1] + 1] + (sumodd[i + 1] - sumodd[firstlimit[i - 1] + 1])) { firstlimit[i] = firstlimit[i - 1]; } else { firstlimit[i] = i; } } if (N % 2 == 0) { long answer; answer = Math.Max(sumeven[N / 2], sumeven[firstlimit[N / 2 - 1] + 1] + (sumodd[N / 2] - sumodd[firstlimit[N / 2 - 1] + 1])); Console.WriteLine(answer); return; } long ans = long.MinValue; var sumevenI = sumeven.Select(x => sumeven[sumeven.Count() - 1] - x).ToList(); sumevenI.Reverse(); for (int i = 0; i < N / 2; i++) //後ろi個を確定させる { long a = Math.Max( sumeven[N / 2 - i], sumeven[firstlimit[N / 2 - i - 1] + 1] + (sumodd[N / 2 - i] - sumodd[firstlimit[N / 2 - i - 1] + 1])); ans = Math.Max(ans, a + sumevenI[i]); } ans = Math.Max(ans, sumevenI[N / 2]); Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
567
2
using System; using System.Collections.Generic; namespace abc162 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var sStrList = Console.ReadLine().Split(' '); var sList = new List<long>(); foreach (var sStr in sStrList) { sList.Add(long.Parse(sStr)); } Console.WriteLine(GetMax(sList, sList.Count / 2)); } private static long GetMax(List<long> list, int count) { // Console.WriteLine("List {0}, Count {1}", list.Count, count); if (count == 1) { var max = list[0]; for (var i = 1; i < list.Count; ++i) { if (max < list[i]) { max = list[i]; } } return max; } if (list.Count % 2 == 0) { return GetMaxEven(list); } long left; long center; long right; long center2 = long.MinValue; if (list.Count / 2 + 1 == count) { return GetSkiped(list); } if (list.Count == 5) { left = list[0] + GetMax(list.GetRange(2, 3), 1); center = GetMax(list.GetRange(0, 2), 1) + GetMax(list.GetRange(3, 2), 1); right = GetMax(list.GetRange(0, 3), 1) + list[4]; } else if (count % 2 == 0) { left = GetMax(list.GetRange(0, count - 2), count / 2 - 1) + list[count - 1] + GetMax(list.GetRange(count + 1, count), count / 2); center = GetMax(list.GetRange(0, count - 1), count / 2 - 1) + list[count] + GetMax(list.GetRange(count + 2, count - 1), count / 2); center2 = GetMax(list.GetRange(0, count - 1), count / 2) + list[count] + GetMax(list.GetRange(count + 2, count - 1), count / 2 - 1); right = GetMax(list.GetRange(0, count), count / 2) + list[count + 1] + GetMax(list.GetRange(count + 3, count - 2), count / 2 - 1); } else { left = GetMax(list.GetRange(0, count - 2), count / 2) + list[count - 1] + GetMax(list.GetRange(count + 1, count), count / 2); center = GetMax(list.GetRange(0, count - 1), count / 2) + list[count] + GetMax(list.GetRange(count + 2, count - 1), count / 2); right = GetMax(list.GetRange(0, count), count / 2) + list[count + 1] + GetMax(list.GetRange(count + 3, count - 2), count / 2); } var res = left; if (res < center) { res = center; } if (res < center2) { res = center2; } if (res < right) { res = right; } return res; } private static long GetMaxEven(List<long> list) { // Console.WriteLine(" Even"); var current = GetSkiped(list); var max = current; for (var i = list.Count - 2; i >= 0; i -= 2) { current = current - list[i] + list[i + 1]; if (max < current) { max = current; } } return max; } private static long GetSkiped(List<long> list) { var current = long.MinValue; for (var i = 0; i < list.Count; i += 2) { current += list[i]; } return current; } } }
using System; using System.Collections.Generic; namespace abc162 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var sStrList = Console.ReadLine().Split(' '); var sList = new List<long>(); foreach (var sStr in sStrList) { sList.Add(long.Parse(sStr)); } Console.WriteLine(GetMax(sList, sList.Count / 2)); } private static long GetMax(List<long> list, int count) { // Console.WriteLine("List {0}, Count {1}", list.Count, count); if (count == 1) { var max = list[0]; for (var i = 1; i < list.Count; ++i) { if (max < list[i]) { max = list[i]; } } return max; } if (list.Count % 2 == 0) { return GetMaxEven(list); } long left; long center; long right; long center2 = long.MinValue; if (list.Count / 2 + 1 == count) { return GetSkiped(list); } if (list.Count == 5) { left = list[0] + GetMax(list.GetRange(2, 3), 1); center = GetMax(list.GetRange(0, 2), 1) + GetMax(list.GetRange(3, 2), 1); right = GetMax(list.GetRange(0, 3), 1) + list[4]; } else if (count % 2 == 0) { left = GetMax(list.GetRange(0, count - 2), count / 2 - 1) + list[count - 1] + GetMax(list.GetRange(count + 1, count), count / 2); center = GetMax(list.GetRange(0, count - 1), count / 2 - 1) + list[count] + GetMax(list.GetRange(count + 2, count - 1), count / 2); center2 = GetMax(list.GetRange(0, count - 1), count / 2) + list[count] + GetMax(list.GetRange(count + 2, count - 1), count / 2 - 1); right = GetMax(list.GetRange(0, count), count / 2) + list[count + 1] + GetMax(list.GetRange(count + 3, count - 2), count / 2 - 1); } else { left = GetMax(list.GetRange(0, count - 2), count / 2) + list[count - 1] + GetMax(list.GetRange(count + 1, count), count / 2); center = GetMax(list.GetRange(0, count - 1), count / 2) + list[count] + GetMax(list.GetRange(count + 2, count - 1), count / 2); right = GetMax(list.GetRange(0, count), count / 2) + list[count + 1] + GetMax(list.GetRange(count + 3, count - 2), count / 2); } var res = left; if (res < center) { res = center; } if (res < center2) { res = center2; } if (res < right) { res = right; } return res; } private static long GetMaxEven(List<long> list) { // Console.WriteLine(" Even"); var current = GetSkiped(list); var max = current; for (var i = list.Count - 2; i >= 0; i -= 2) { current = current - list[i] + list[i + 1]; if (max < current) { max = current; } } return max; } private static long GetSkiped(List<long> list) { var current = 0L; for (var i = 0; i < list.Count; i += 2) { current += list[i]; } return current; } } }
[["-", 0, 198, 0, 200, 0, 212, 0, 214, 205, 199], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 0, 131], ["-", 0, 198, 0, 200, 0, 212, 0, 214, 141, 22], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
824
4
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var accumOdd = new long[n + 1]; var accumEven = new long[n + 1]; for (int i = 0; i < n; i++) { if (i % 2 == 0) { accumEven[i + 1] = accumEven[i] + a[i]; accumOdd[i + 1] = accumOdd[i]; } else { accumEven[i + 1] = accumEven[i]; accumOdd[i + 1] = accumOdd[i] + a[i]; } } if (n % 2 == 0) { var res = Max(accumOdd.Last(), accumEven.Last()); var sum = 0; for (int i = accumEven.Length - 3; i >= 0; i -= 2) { sum += a[i + 1]; res = Max(res, accumEven[i] + sum); } Console.WriteLine(res); return; } else { var res = Max(accumOdd.Last(), Max(accumEven.SkipLast(1).Last(), accumEven.Last() - a.First())); var sum = accumEven.SkipLast(1).Last(); var tailSum = 0; var tailMax = 0; for (int i = accumEven.Length - 4; i >= 0; i -= 2) { sum -= a[i]; sum += a[i + 1]; tailSum += a[i + 2]; tailSum -= a[i + 1]; tailMax = Max(tailMax, tailSum); res = Max(res, sum + tailMax); } Console.WriteLine(res); return; } } } class SegmentTree<T> { public int Size { get; private set; } T Identity; T[] Data; Func<T, T, T> Merge; int LeafCount; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, T identity, Func<T, T, T> merge) { Init(size, identity, merge); for (int i = 1; i < Data.Length; i++) Data[i] = identity; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(T[] elems, T identity, Func<T, T, T> merge) { Init(elems.Length, identity, merge); elems.CopyTo(Data, LeafCount); for (int i = elems.Length + LeafCount; i < Data.Length; i++) Data[i] = identity; for (int i = LeafCount - 1; i >= 1; i--) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Init(int size, T identity, Func<T, T, T> merge) { Size = size; Identity = identity; Merge = merge; LeafCount = 1; while (LeafCount < size) LeafCount <<= 1; Data = new T[LeafCount << 1]; } public T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Data[LeafCount + index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] set { Update(index, value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int i, T x) { Data[i += LeafCount] = x; while (0 < (i >>= 1)) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Operate(int i, T x) { Data[i += LeafCount] = Merge(Data[i], x); while (0 < (i >>= 1)) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int l, int r) { T lRes = Identity, rRes = Identity; for (l += LeafCount, r += LeafCount; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) { if ((l & 1) == 1) lRes = Merge(lRes, Data[l]); if ((r & 1) == 0) rRes = Merge(Data[r], rRes); } return Merge(lRes, rRes); } }
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Numerics; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using static System.Math; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; public static class P { public static void Main() { int n = int.Parse(Console.ReadLine()); var a = Console.ReadLine().Split().Select(int.Parse).ToArray(); var accumOdd = new long[n + 1]; var accumEven = new long[n + 1]; for (int i = 0; i < n; i++) { if (i % 2 == 0) { accumEven[i + 1] = accumEven[i] + a[i]; accumOdd[i + 1] = accumOdd[i]; } else { accumEven[i + 1] = accumEven[i]; accumOdd[i + 1] = accumOdd[i] + a[i]; } } if (n % 2 == 0) { var res = Max(accumOdd.Last(), accumEven.Last()); var sum = 0L; for (int i = accumEven.Length - 3; i >= 0; i -= 2) { sum += a[i + 1]; res = Max(res, accumEven[i] + sum); } Console.WriteLine(res); return; } else { var res = Max(accumOdd.Last(), Max(accumEven.SkipLast(1).Last(), accumEven.Last() - a.First())); var sum = accumEven.SkipLast(1).Last(); var tailSum = 0L; var tailMax = 0L; for (int i = accumEven.Length - 4; i >= 0; i -= 2) { sum -= a[i]; sum += a[i + 1]; tailSum += a[i + 2]; tailSum -= a[i + 1]; tailMax = Max(tailMax, tailSum); res = Max(res, sum + tailMax); } Console.WriteLine(res); return; } } } class SegmentTree<T> { public int Size { get; private set; } T Identity; T[] Data; Func<T, T, T> Merge; int LeafCount; [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(int size, T identity, Func<T, T, T> merge) { Init(size, identity, merge); for (int i = 1; i < Data.Length; i++) Data[i] = identity; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public SegmentTree(T[] elems, T identity, Func<T, T, T> merge) { Init(elems.Length, identity, merge); elems.CopyTo(Data, LeafCount); for (int i = elems.Length + LeafCount; i < Data.Length; i++) Data[i] = identity; for (int i = LeafCount - 1; i >= 1; i--) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void Init(int size, T identity, Func<T, T, T> merge) { Size = size; Identity = identity; Merge = merge; LeafCount = 1; while (LeafCount < size) LeafCount <<= 1; Data = new T[LeafCount << 1]; } public T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { return Data[LeafCount + index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] set { Update(index, value); } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Update(int i, T x) { Data[i += LeafCount] = x; while (0 < (i >>= 1)) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Operate(int i, T x) { Data[i += LeafCount] = Merge(Data[i], x); while (0 < (i >>= 1)) Data[i] = Merge(Data[i << 1], Data[(i << 1) | 1]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Query(int l, int r) { T lRes = Identity, rRes = Identity; for (l += LeafCount, r += LeafCount; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) { if ((l & 1) == 1) lRes = Merge(lRes, Data[l]); if ((r & 1) == 0) rRes = Merge(Data[r], rRes); } return Merge(lRes, rRes); } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
1,064
6
using System; using System.CodeDom; using System.Collections.Generic; using System.Configuration; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Xml.Schema; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); } public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); } public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); } public static int PopCount(this int bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); void Multi<T>(out T a) => a = cv<T>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } class Pair : IComparable<Pair> { public Pair(int node, long cost) { Node = node; Cost = cost; } public int Node { get; set; } public long Cost { get; set; } public int CompareTo(Pair p) { return p.Cost > Cost ? 1 : -1; } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } class Comparable : IComparable<Comparable> { public Comparable(int value) { Value = value; } public int Value { get; set; } public int CompareTo(Comparable c) { var a = Math.Abs(Value); var b = Math.Abs(c.Value); return a > b ? 1 : a == b ? 0 : -1; } } class Comparer<T> : IComparer<T> { public int Compare(T t1, T t2) { return 1; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { var a = GetIntArray(); Swap(ref a[0], ref a[1]); Swap(ref a[1], ref a[2]); Console.WriteLine(string.Join(" ", a)); } void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } } }
using System; using System.CodeDom; using System.Collections.Generic; using System.Configuration; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Xml.Schema; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); } public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); } public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); } public static int PopCount(this int bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); void Multi<T>(out T a) => a = cv<T>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } class Pair : IComparable<Pair> { public Pair(int node, long cost) { Node = node; Cost = cost; } public int Node { get; set; } public long Cost { get; set; } public int CompareTo(Pair p) { return p.Cost > Cost ? 1 : -1; } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } class Comparable : IComparable<Comparable> { public Comparable(int value) { Value = value; } public int Value { get; set; } public int CompareTo(Comparable c) { var a = Math.Abs(Value); var b = Math.Abs(c.Value); return a > b ? 1 : a == b ? 0 : -1; } } class Comparer<T> : IComparer<T> { public int Compare(T t1, T t2) { return 1; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { var a = GetIntArray(); Swap(ref a[0], ref a[1]); Swap(ref a[0], ref a[2]); Console.WriteLine(string.Join(" ", a)); } void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; } } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
2,094
2
using System; namespace q1 { class q2 { static void Main() { string[] N = Console.ReadLine().Split(); Console.WriteLine(N[1] + " " + N[0] + " " + N[2]); } } }
using System; namespace q1 { class q2 { static void Main() { string[] N = Console.ReadLine().Split(); Console.WriteLine(N[2] + " " + N[0] + " " + N[1]); } } }
[["-", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 31, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
61
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System; using System.Collections.Generic; using System.Linq; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } class StringComparator2 : IComparer<string> { int IComparer<string>.Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } 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; } static long[] mem; } public class Class1 { // static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, // long>, long>(); static long mod = 1000000007; static long[] factorial = new long[1000001]; static long[] invFactorial = new long[1000001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N + 1; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } class Tree { public HashSet<long> conn = new HashSet<long>(); } static long bin(long a, long x, long n) { long y = a; long res = 1; while (x > 0) { if (x % 2 == 1) { res = res * y % n; } x /= 2; y = y * y % n; } return res; } int cmp(string a, string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } private static long nCm(long n, long m) { if (n < m) return 0; if (m < 0) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } private static long nCm2(long n, long m) { if (n < m) return 0; if (m < 0) return 0; long res = 1; for (long i = n; i > n - m; i--) { res *= i; res %= mod; } return res * invFactorial[m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; if (b <= 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long Lcm(long a, long b) { return a * b % mod * inv(Gcd(a, b)) % mod; } public static long Lcm(long[] a) { List<long> vect = new List<long>(); long lcm = 1; for (int i = 0; i < a.Count(); i++) { var factor = a[i] / GcdVector(vect, a[i]); vect.Add(factor); lcm = lcm * factor % mod; } return lcm; } static long GcdVector(List<long> a, long b) { long ma = 1; for (int i = 0; i < a.Count; i++) ma = ma * a[i] % b; return Gcd(b, ma); } public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static char[][] ReadCharMatrix(long h) { char[][] mtx = new char [h][]; for (int i = 0; i < h; i++) { var s = ReadString(); mtx[i] = s.ToCharArray(); } return mtx; } private static int[][] CreateIntMatrix(long h, long w) { int[][] mtx = new int [h][]; for (int i = 0; i < h; i++) { mtx[i] = new int[w]; } return mtx; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } static void Main(string[] args) { var AA = ReadLongArr(); calcFanctorial(AA[0] + 2); long res = 0; for (long i = AA[1]; i < AA[0] + 2; i++) { res += (AA[0] + 1 - i) * (i) + 1; res = res / mod; } Console.WriteLine(res); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System; using System.Collections.Generic; using System.Linq; namespace ClassLibrary1 { public class ListNode { public int val; public ListNode next; public ListNode(int x) { val = x; } } class StringComparator2 : IComparer<string> { int IComparer<string>.Compare(string a, string b) { int length = Math.Min(a.Length, b.Length); // Console.WriteLine("Comparing with length {0}", length); for (int i = 0; i < length; i++) { if (a[i] < b[i]) { // Console.WriteLine("returning -1"); return -1; } else if (a[i] > b[i]) return 1; } if (a.Length < b.Length) return -1; if (a.Length > b.Length) return 1; // Console.WriteLine("Why are we at the end?"); return 0; } } 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; } static long[] mem; } public class Class1 { // static Dictionary<Tuple<long, long>, long> dic = new Dictionary<Tuple<long, // long>, long>(); static long mod = 1000000007; static long[] factorial = new long[1000001]; static long[] invFactorial = new long[1000001]; private static void calcFanctorial(long N) { factorial[0] = 1; for (int i = 1; i < N + 1; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= mod; } invFactorial[N] = inv(factorial[N]); for (int i = (int)N; i > 0; i--) { invFactorial[i - 1] = invFactorial[i] * i % mod; } } class Tree { public HashSet<long> conn = new HashSet<long>(); } static long bin(long a, long x, long n) { long y = a; long res = 1; while (x > 0) { if (x % 2 == 1) { res = res * y % n; } x /= 2; y = y * y % n; } return res; } int cmp(string a, string b) { for (var i = 0; i < Math.Min(a.Length, b.Length); i++) if (a[i] < b[i]) return -1; else if (a[i] > b[i]) return 1; if (a.Length == b.Length) return 0; if (a.Length > b.Length) return 1; else return -1; } private static long nCm(long n, long m) { if (n < m) return 0; if (m < 0) return 0; return (factorial[n] * invFactorial[m] % mod) * invFactorial[n - m] % mod; } private static long nCm2(long n, long m) { if (n < m) return 0; if (m < 0) return 0; long res = 1; for (long i = n; i > n - m; i--) { res *= i; res %= mod; } return res * invFactorial[m] % mod; } public static long pow(long a, long b, long mod) { a %= mod; if (b <= 0) return 1; var t = pow(a, b / 2, mod); if ((b & 1) == 0) return t * t % mod; return t * t % mod * a % mod; } public static long Lcm(long a, long b) { return a * b % mod * inv(Gcd(a, b)) % mod; } public static long Lcm(long[] a) { List<long> vect = new List<long>(); long lcm = 1; for (int i = 0; i < a.Count(); i++) { var factor = a[i] / GcdVector(vect, a[i]); vect.Add(factor); lcm = lcm * factor % mod; } return lcm; } static long GcdVector(List<long> a, long b) { long ma = 1; for (int i = 0; i < a.Count; i++) ma = ma * a[i] % b; return Gcd(b, ma); } public static long Gcd(long a, long b) { if (a < b) // 引数を入替えて自分を呼び出す return Gcd(b, a); while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } public static long pow(long a, long b) => pow(a, b, mod); public static long inv(long a) => pow(a, mod - 2); private static char[][] ReadCharMatrix(long h) { char[][] mtx = new char [h][]; for (int i = 0; i < h; i++) { var s = ReadString(); mtx[i] = s.ToCharArray(); } return mtx; } private static int[][] CreateIntMatrix(long h, long w) { int[][] mtx = new int [h][]; for (int i = 0; i < h; i++) { mtx[i] = new int[w]; } return mtx; } private static string ReadString() { return Console.ReadLine(); } private static string[] ReadStringArr() { return Console.ReadLine().Split(' '); } private static long ReadLong() { return long.Parse(Console.ReadLine()); } private static long[] ReadLongArr() { string[] s = ReadStringArr(); long[] l = new long[s.Length]; for (int i = 0; i < l.Length; i++) { l[i] = long.Parse(s[i]); } return l; } static void Main(string[] args) { var AA = ReadLongArr(); calcFanctorial(AA[0] + 2); long res = 0; for (long i = AA[1]; i < AA[0] + 2; i++) { res += (AA[0] + 1 - i) * (i) + 1; res %= mod; } Console.WriteLine(res); } } }
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 132]]
8
1,886
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_162_Lucky7 { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 string N = Console.ReadLine(); List<string> list = new List<string>(); for (int i = 1; i < N.Length + 1; i++) { list.Add(N.Substring(i, 1)); } if (list.Contains("7")) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { class A_162_Lucky7 { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 string N = Console.ReadLine(); List<string> list = new List<string>(); for (int i = 0; i < N.Length; i++) { list.Add(N.Substring(i, 1)); } if (list.Contains("7")) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.Out.Flush(); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
178
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var s = Console.ReadLine(); if (s.Contains("7")) Console.WriteLine("YES"); else Console.WriteLine("NO"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var s = Console.ReadLine(); if (s.Contains("7")) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
85
4
using System; using System.Collections.Generic; using System.Linq; public class Test { public static void Main() { var num = int.Parse(Console.ReadLine()); Console.Write(num); } static string LuckyNumber(int n) { while (n > 0) { var digit = n % 10; if (digit == 7) return "Yes"; n = n / 10; } return "No"; } }
using System; using System.Collections.Generic; using System.Linq; public class Test { public static void Main() { var num = int.Parse(Console.ReadLine()); Console.Write(LuckyNumber(num)); } static string LuckyNumber(int n) { while (n > 0) { var digit = n % 10; if (digit == 7) return "Yes"; n = n / 10; } return "No"; } }
[["+", 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, 25]]
8
95
3
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public static void Main(string[] args) { new A().test(); } } public class A { public void test() { // スペース区切りの整数の入力 var input = CommonRead.ReadStr(); // 文字列チェックする if (input.IndexOf("7") > 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } static class CommonRead { public static string ReadStr() { return Console.ReadLine(); } public static string[] ReadStrA() { return ReadStr().Split(' '); } public static List<string> ReadStrL() { return ReadStrA().ToList(); } public static int ReadInt() { return Convert.ToInt32(ReadStr()); } public static int[] ReadIntA() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray(); } public static List<int> ReadIntL() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToList(); } public static long ReadLong() { return Convert.ToInt64(ReadStr()); } public static long[] ReadLongA() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray(); } public static List<long> ReadLongL() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToList(); } public static decimal ReadDecimal() { return Convert.ToDecimal(ReadStr()); } public static decimal[] ReadDecimalA() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray(); } public static List<decimal> ReadDecimalL() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList(); } public static double ReadDouble() { return Convert.ToDouble(ReadStr()); } public static double[] ReadDoubleA() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray(); } public static List<double> ReadDoubleL() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToList(); } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; public class Program { public static void Main(string[] args) { new A().test(); } } public class A { public void test() { // スペース区切りの整数の入力 var input = CommonRead.ReadStr(); // 文字列チェックする if (input.IndexOf("7") > -1) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } static class CommonRead { public static string ReadStr() { return Console.ReadLine(); } public static string[] ReadStrA() { return ReadStr().Split(' '); } public static List<string> ReadStrL() { return ReadStrA().ToList(); } public static int ReadInt() { return Convert.ToInt32(ReadStr()); } public static int[] ReadIntA() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray(); } public static List<int> ReadIntL() { return ReadStrA().Select(s => Convert.ToInt32(s)).ToList(); } public static long ReadLong() { return Convert.ToInt64(ReadStr()); } public static long[] ReadLongA() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray(); } public static List<long> ReadLongL() { return ReadStrA().Select(s => Convert.ToInt64(s)).ToList(); } public static decimal ReadDecimal() { return Convert.ToDecimal(ReadStr()); } public static decimal[] ReadDecimalA() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray(); } public static List<decimal> ReadDecimalL() { return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList(); } public static double ReadDouble() { return Convert.ToDouble(ReadStr()); } public static double[] ReadDoubleA() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray(); } public static List<double> ReadDoubleL() { return ReadStrA().Select(s => Convert.ToDouble(s)).ToList(); } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 33], ["+", 8, 196, 0, 57, 15, 16, 12, 241, 0, 203]]
8
491
3
using System; using System.Linq; using System.Text; using System.Collections; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { var n = ReadLine(); var f = false; for (int i = 0; i < n.Length; i++) { if (n[i].Equals('7')) f = true; else f = false; } if (f) Console.WriteLine("Yes"); else Console.WriteLine("No"); } public static int nCm(int n, int m) { if (n == 0) return 0; if (m == 0) return 1; return n * nCm(n - 1, m - 1) / m; } public static string ReadLine() { return Console.ReadLine(); } public static int ReadLineInt() { return int.Parse(ReadLine()); } public static string[] ReadLineStringSplit(char s = ' ') { return ReadLine().Split(s).ToArray(); } public static int[] ReadLineIntSplit(char s = ' ') { return ReadLine().Split(s).Select(x => int.Parse(x)).ToArray(); } public static long[] ReadLineLongSplit(char s = ' ') { return ReadLine().Split(s).Select(x => long.Parse(x)).ToArray(); } } }
using System; using System.Linq; using System.Text; using System.Collections; using System.Collections.Generic; namespace AtCoder { class Program { static void Main(string[] args) { var n = ReadLine(); var f = false; for (int i = 0; i < n.Length; i++) { if (n[i].Equals('7')) { f = true; break; } } if (f) Console.WriteLine("Yes"); else Console.WriteLine("No"); } public static int nCm(int n, int m) { if (n == 0) return 0; if (m == 0) return 1; return n * nCm(n - 1, m - 1) / m; } public static string ReadLine() { return Console.ReadLine(); } public static int ReadLineInt() { return int.Parse(ReadLine()); } public static string[] ReadLineStringSplit(char s = ' ') { return ReadLine().Split(s).ToArray(); } public static int[] ReadLineIntSplit(char s = ' ') { return ReadLine().Split(s).Select(x => int.Parse(x)).ToArray(); } public static long[] ReadLineLongSplit(char s = ' ') { return ReadLine().Split(s).Select(x => long.Parse(x)).ToArray(); } } }
[["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 45], ["-", 8, 196, 0, 7, 8, 196, 0, 57, 0, 95], ["-", 8, 196, 0, 57, 75, 1, 0, 11, 31, 22], ["-", 0, 57, 75, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 57, 75, 1, 0, 11, 12, 211, 0, 147], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 64, 196, 0, 46]]
8
314
7
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(); for (int i = 0; i < n.Length; i++) { if (n[i] == '7') { WriteRead("Yes"); break; } } WriteRead("No"); } 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); } } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double ToDouble(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(); for (int i = 0; i < n.Length; i++) { if (n[i] == '7') { WriteRead("Yes"); return; } } WriteRead("No"); } 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); } } } public static class Extentions { public static int ToInt(this object obj) { return int.Parse(obj.ToString()); } public static decimal ToDecimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double ToDouble(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(); } }
[["-", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38]]
8
312
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; class program { static public int mod = 1000000007; static void Main() { var n = rint(); long ans = n * (n + 1) / 2; int n3 = n / 3, n5 = n / 5, n15 = n / 15; ans -= 3 * n3 * (n3 + 1) / 2; ans -= 5 * n5 * (n5 + 1) / 2; ans += 15 * n15 * (n15 + 1) / 2; Write(ans); } static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static 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] = double.Parse(read_str_array[countup_i]); } return return_double_array; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.IO; using static System.Console; using static System.Math; class program { static public int mod = 1000000007; static void Main() { var n = rlong(); long ans = n * (n + 1) / 2; long n3 = n / 3, n5 = n / 5, n15 = n / 15; ans -= 3 * n3 * (n3 + 1) / 2; ans -= 5 * n5 * (n5 + 1) / 2; ans += 15 * n15 * (n15 + 1) / 2; Write(ans); } static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; } static string rstr() { return ReadLine(); } static int rint() { return int.Parse(ReadLine()); } static long rlong() { return long.Parse(ReadLine()); } static string[] stra() { return ReadLine().Split(' '); } static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); } static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; } static 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] = double.Parse(read_str_array[countup_i]); } return return_double_array; } static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } } static long LCM(long a, long b) { return a * b / GCD(a, b); } static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } } static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); } }
[["-", 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
802
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace atcoder { public class Program { public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long answer = 0; for (int i = 0; i < N; i++) { if (i % 15 == 0) continue; if (i % 5 == 0) continue; if (i % 3 == 0) continue; answer += i; } Console.WriteLine(answer); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace atcoder { public class Program { public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long answer = 0; for (int i = 0; i <= N; i++) { if (i % 15 == 0) continue; if (i % 5 == 0) continue; if (i % 3 == 0) continue; answer += i; } Console.WriteLine(answer); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
124
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC162B { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long count = 0; for (long i = 0; i < N; i++) { if (i % 3 != 0 & i % 5 != 0) { count += i; } } Console.WriteLine(count); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC162B { class Program { static void Main(string[] args) { long N = long.Parse(Console.ReadLine()); long count = 0; for (long i = 1; i < N + 1; i++) { if (i % 3 != 0 & i % 5 != 0) { count += i; } } Console.WriteLine(count); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
108
4
using System; namespace abc162B { class MainClass { public static void Main(string[] args) { float A = float.Parse(Console.ReadLine()); float ans = 0; for (float i = 1; i <= A; i++) { if (i % 3 != 0 && i % 5 != 0) ans = ans + i; } Console.WriteLine(ans); } } }
using System; namespace abc162B { class MainClass { public static void Main(string[] args) { long A = long.Parse(Console.ReadLine()); long ans = 0; for (long i = 1; i <= A; i++) { if (i % 3 != 0 && i % 5 != 0) ans = ans + i; } 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, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
8
85
8
using System; using System.Linq; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int res = 0; for (int i = 1; i <= n; i++) { if (i % 3 != 0 && i % 5 != 0) res += i; } Console.WriteLine(res); } }
using System; using System.Linq; class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); long res = 0; for (int i = 1; i <= n; i++) { if (i % 3 != 0 && i % 5 != 0) res += i; } Console.WriteLine(res); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
83
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_20190707_1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long answer = 0; for (int i = 0; i < N; i++) { if (i % 3 != 0 && i % 5 != 0) { answer += i; } } Console.WriteLine(answer); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_20190707_1 { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long answer = 0; for (int i = 1; i <= N; i++) { if (i % 3 != 0 && i % 5 != 0) { answer += i; } } Console.WriteLine(answer); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
108
4
using System; namespace Sample { class Sample { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); int output = 0; for (int i = 1; i <= N; i++) { if ((i % 3 != 0) && (i % 5 != 0)) { output = output + i; } } Console.WriteLine(output); } } }
using System; namespace Sample { class Sample { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long output = 0; for (int i = 1; i <= N; i++) { if ((i % 3 != 0) && (i % 5 != 0)) { output = output + i; } } Console.WriteLine(output); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
90
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var n = ReadLineLongInt(); var re = 0; for (int i = 1; i <= n; i++) { if (i % 3 == 0 || i % 5 == 0) continue; re += i; } Console.WriteLine(re); ReadLine(); } //最大公約数 static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { var n = ReadLineLongInt(); long re = 0; for (int i = 1; i <= n; i++) { if (i % 3 == 0 || i % 5 == 0) continue; re += i; } Console.WriteLine(re); ReadLine(); } //最大公約数 static int gcd(int a, int b) { if (a > b) { return gcd(b, a); } while (b != 0) { var remainder = a % b; a = b; b = remainder; } return a; } //最小公倍数 static int lcm(int a, int b) => a * b / gcd(a, b); /// <summary> /// コンビネーション /// </summary> static int nCm(int n, int m) { if (m == 0) return 1; if (n == 0) return 0; return n * nCm(n - 1, m - 1) / m; } public static string ReadLine() => Console.ReadLine(); public static int ReadLineInt() => int.Parse(Console.ReadLine()); public static long ReadLineLongInt() => long.Parse(Console.ReadLine()); public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray(); public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray(); public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray(); static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
625
2
using System; class FizzBuzzSum { static void Main(string[] args) { var input = ulong.Parse(Console.ReadLine()); ulong sum = 0; for (ulong i = 0; i < input; i++) { if (!(i % 3 == 0 || i % 5 == 0)) { sum += i; } } Console.WriteLine(sum); } }
using System; class FizzBuzzSum { static void Main(string[] args) { var input = ulong.Parse(Console.ReadLine()); ulong sum = 0; for (ulong i = 1; i <= input; i++) { if (!(i % 3 == 0 || i % 5 == 0)) { sum += i; } } Console.WriteLine(sum); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
83
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 競プロCS { class ABC162B { static void Main() { int n = int.Parse(Console.ReadLine()); long total = 0; for (int i = 1; i < n; i++) { if (!((i % 3 == 0) || (i % 5 == 0))) { total += i; } } Console.WriteLine(total); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 競プロCS { class ABC162B { static void Main() { int n = int.Parse(Console.ReadLine()); long total = 0; for (int i = 1; i < n + 1; i++) { if (!((i % 3 == 0) || (i % 5 == 0))) { total += i; } } Console.WriteLine(total); } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
105
2
using System; namespace AtCoder { class Program { static void Main(string[] args) { var input = Convert.ToInt32(Console.ReadLine()); var sum = 0; for (int i = 0; i <= input; i++) { if (i % 15 != 0 && i % 5 != 0 && i % 3 != 0) { sum += i; } } Console.WriteLine(sum); Console.Read(); } } }
using System; namespace AtCoder { class Program { static void Main(string[] args) { var input = Convert.ToUInt64(Console.ReadLine()); UInt64 sum = 0; for (UInt64 i = 0; i <= input; i++) { if (i % 15 != 0 && i % 5 != 0 && i % 3 != 0) { sum += i; } } Console.WriteLine(sum); Console.Read(); } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 22], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 22]]
8
96
6
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var N = LnInt(); var n = 1; var result = 0; for (int i = 0; i < N; i++) { if (n % 5 == 0 && n % 3 == 0) { } else if (n % 5 == 0) { } else if (n % 3 == 0) { } else { result += n; } n++; } Console.WriteLine(result); } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
using System; using System.Collections.Generic; using System.Numerics; using System.Linq; using static System.Math; class MainClass { public static void Main(string[] args) { var N = LnInt(); var n = 1L; var result = 0L; for (int i = 0; i < N; i++) { if (n % 5L == 0 && n % 3L == 0) { } else if (n % 5L == 0) { } else if (n % 3L == 0) { } else { result += n; } n++; } Console.WriteLine(result); } public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; } public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); } public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split( new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; } public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["-", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["-", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 0, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["-", 75, 57, 75, 57, 15, 16, 31, 16, 12, 203], ["+", 75, 57, 75, 57, 15, 16, 31, 16, 12, 203]]
8
309
12
using System; namespace Sample { class Program { static void Main(string[] args) { // N int N = int.Parse(Console.ReadLine()); int i = 1; int ans = 0; while (i < N) { if (i % 3 == 0 && i % 5 == 0) { // FizzBuzz i++; continue; } if (i % 3 == 0) { // Fizz i++; continue; } if (i % 5 == 0) { // Buzz i++; continue; } ans += i; i++; } Console.WriteLine(ans); } } }
using System; namespace Sample { class Program { static void Main(string[] args) { // N int N = int.Parse(Console.ReadLine()); int i = 1; long ans = 0; while (i < N + 1) { if (i % 3 == 0 && i % 5 == 0) { // FizzBuzz i++; continue; } if (i % 3 == 0) { // Fizz i++; continue; } if (i % 5 == 0) { // Buzz i++; continue; } ans += i; i++; } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 12, 203]]
8
123
4
using System; class Program { static void Main() { int n = int.Parse(Console.ReadLine()); int result = 0; for (int i = 1; i <= n; i++) { if (i % 3 == 0 || i % 5 == 0) { continue; } result += i; } Console.WriteLine(result.ToString()); } }
using System; class Program { static void Main() { double n = double.Parse(Console.ReadLine()); double result = 0; for (double i = 1; i <= n; i++) { if (i % 3 == 0 || i % 5 == 0) { continue; } result += i; } Console.WriteLine(result.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, 199], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
8
82
8
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var solver = new Solver(); solver.Calc(); } } public class Solver { public void Calc() { var N = int.Parse(Console.ReadLine()); var sum = 0; foreach (var i in Enumerable.Range(1, N)) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } Console.WriteLine(sum); } } }
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var solver = new Solver(); solver.Calc(); } } public class Solver { public void Calc() { var N = int.Parse(Console.ReadLine()); long sum = 0; foreach (var i in Enumerable.Range(1, N)) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } Console.WriteLine(sum); } } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
115
2
using System; namespace B { class Program { // 初項a, 公差d, 項数nの等差数列の和 public static long sumN(int a, int d, int n) { return n * (2 * a + (n - 1) * d) / 2; } static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long ans = sumN(1, 1, N) - sumN(3, 3, N / 3) - sumN(5, 5, N / 5) + sumN(15, 15, N / 15); Console.WriteLine(ans); } } }
using System; namespace B { class Program { // 初項a, 公差d, 項数nの等差数列の和 public static long sumN(int a, int d, int n) { return (long)n * (2 * a + (n - 1) * d) / 2; } static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long ans = sumN(1, 1, N) - sumN(3, 3, N / 3) - sumN(5, 5, N / 5) + sumN(15, 15, N / 15); Console.WriteLine(ans); } } }
[["+", 0, 37, 0, 16, 31, 16, 31, 74, 0, 24], ["+", 0, 37, 0, 16, 31, 16, 31, 74, 39, 199], ["+", 0, 37, 0, 16, 31, 16, 31, 74, 0, 25]]
8
124
3
using System; namespace B { class Program { static void Main(string[] args) { string line = Console.ReadLine(); int N = int.Parse(line); int sum = 0; for (int i = 1; i <= N; i++) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } Console.WriteLine(sum); } } }
using System; namespace B { class Program { static void Main(string[] args) { string line = Console.ReadLine(); long N = long.Parse(line); long sum = 0; for (int i = 1; i <= N; i++) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } Console.WriteLine(sum); } } }
[["-", 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
89
6
using System; class Program { static void Main() { var N = long.Parse(Console.ReadLine()); int S = 0; for (int i = 0; i <= N; i++) S += i; for (int i = 1; i <= N / 3; i++) S -= i * 3; for (int i = 1; i <= N / 5; i++) S -= i * 5; for (int i = 0; i <= N / 15; i++) S += i * 15; Console.WriteLine(S); } }
using System; class Program { static void Main() { var N = long.Parse(Console.ReadLine()); long S = 0; for (long i = 0; i <= N; i++) S += i; for (int i = 1; i <= N / 3; i++) S -= i * 3; for (int i = 1; i <= N / 5; i++) S -= i * 5; for (int i = 0; i <= N / 15; i++) S += i * 15; Console.WriteLine(S); } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
8
124
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { public static void Main() { int input = int.Parse(Console.ReadLine()); long ans = 0; for (int i = 0; i < input; i++) { if (i % 3 != 0 && i % 5 != 0) { ans += i; } } Console.WriteLine(ans); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { public static void Main() { int input = int.Parse(Console.ReadLine()); long ans = 0; for (int i = 0; i <= input; i++) { if (i % 3 != 0 && i % 5 != 0) { ans += i; } } Console.WriteLine(ans); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
94
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace q2 { class Program { static void Main(string[] args) { var N = Convert.ToInt32(Console.ReadLine()); long r = 0; for (var i = 1; i < N; i++) { if (i % 5 != 0 && i % 3 != 0) r += i; } Console.WriteLine(r); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace q2 { class Program { static void Main(string[] args) { var N = Convert.ToInt32(Console.ReadLine()); long r = 0; for (var i = 1; i <= N; i++) { if (i % 5 != 0 && i % 3 != 0) r += i; } Console.WriteLine(r); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
106
2
using System; namespace LevelB { class Program { static void Main(string[] args) { var x = int.Parse(Console.ReadLine()); long buf = 0; for (int i = 0; i < x; i++) { if (!Program.Judge(i)) { buf += i; } } Console.WriteLine(buf.ToString()); } private static bool Judge(int x) { if (x % 5 == 0 || x % 3 == 0) return true; else return false; } } }
using System; namespace LevelB { class Program { static void Main(string[] args) { var x = int.Parse(Console.ReadLine()); long buf = 0; for (int i = 0; i < x + 1; i++) { if (!Program.Judge(i)) { buf += i; } } Console.WriteLine(buf.ToString()); } private static bool Judge(int x) { if (x % 5 == 0 || x % 3 == 0) return true; else return false; } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
115
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; // using static Util; class Program { static int S; static void INPUT() { S = NextInt(); } static void OUT() { var a = 0L; for (var n = 0; n < S; n++) { if (n % 3 != 0 && n % 5 != 0) { a += n; } } Console.WriteLine(a); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using static Input; // using static Util; class Program { static int S; static void INPUT() { S = NextInt(); } static void OUT() { var a = 0L; for (var n = 1; n <= S; n++) { if (n % 3 != 0 && n % 5 != 0) { a += n; } } Console.WriteLine(a); } static void Main(string[] args) { #if DEBUG // TESTINPUT(); INPUT(); #else INPUT(); #endif OUT(); } static void TESTINPUT() {} } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } } class Util {}
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
455
4
using System; namespace Test { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); long sum = 0; for (int i = 1; i < n; i++) { if (i % 3 == 0 && i % 5 == 0) continue; else if (i % 3 == 0) continue; else if (i % 5 == 0) continue; else sum += i; } Console.WriteLine(sum); } } }
using System; namespace Test { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); long sum = 0; for (int i = 1; i <= n; i++) { if (i % 3 == 0 && i % 5 == 0) continue; else if (i % 3 == 0) continue; else if (i % 5 == 0) continue; else sum += i; } Console.WriteLine(sum); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
107
2
using System; namespace Sumple1 { class MainClass { static void Main() { Scanner cin = new Scanner(); long n = cin.NextLong(); long sum = 0; for (long i = 0; i < n; i++) { if ((i % 3) == 0 & (i % 5) == 0) { // FizzBuzz } else if ((i % 3) == 0) { // Fizz } else if ((i % 5) == 0) { // Buzz } else { sum += i; } } Console.WriteLine(sum); } } 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; namespace Sumple1 { class MainClass { static void Main() { Scanner cin = new Scanner(); long n = cin.NextLong(); long sum = 0; for (long i = 1; i <= n; i++) { if ((i % 3) == 0 & (i % 5) == 0) { // FizzBuzz } else if ((i % 3) == 0) { // Fizz } else if ((i % 5) == 0) { // Buzz } else { sum += i; } } Console.WriteLine(sum); } } 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, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
469
4
using System; using System.Linq; namespace ConsoleApp12 { class Program { static void Main(string[] args) { double N = double.Parse(Console.ReadLine()); decimal Sc = 0; if (N < 15) { for (int i = 1; i <= N; i++) { if (i % 3 == 0 || i % 5 == 0) { continue; } Sc += i; } Console.WriteLine(Sc); return; } for (int i = 1; i < N; i++) { if (i % 3 == 0 && i % 5 == 0 && i == N) { break; } if (i % 3 == 0 || i % 5 == 0) { continue; } Sc += i; } Console.WriteLine(Sc); } } }
using System; using System.Linq; namespace ConsoleApp12 { class Program { static void Main(string[] args) { double N = double.Parse(Console.ReadLine()); decimal Sc = 0; if (N < 15) { for (int i = 1; i <= N; i++) { if (i % 3 == 0 || i % 5 == 0) { continue; } Sc += i; } Console.WriteLine(Sc); return; } for (int i = 1; i <= N; i++) { if (i % 3 == 0 && i % 5 == 0 && i == N) { break; } if (i % 3 == 0 || i % 5 == 0) { continue; } Sc += i; } Console.WriteLine(Sc); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
168
2
using System; namespace AtCoder { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int count = 0; for (int i = 1; i <= n; i++) { if (i % 3 == 0 && i % 5 == 0) { // Console.WriteLine("FizzBuzz"); } else if (i % 5 == 0) { // Console.WriteLine("Buzz"); } else if (i % 3 == 0) { // Console.WriteLine("Fizz"); } else { // Console.WriteLine(i); count += i; } } Console.WriteLine(count); } } }
using System; namespace AtCoder { class Program { static void Main(string[] args) { long n = int.Parse(Console.ReadLine()); long count = 0; for (long i = 1; i <= n; i++) { if (i % 3 == 0 && i % 5 == 0) { // Console.WriteLine("FizzBuzz"); } else if (i % 5 == 0) { // Console.WriteLine("Buzz"); } else if (i % 3 == 0) { // Console.WriteLine("Fizz"); } else { // Console.WriteLine(i); count += i; } } Console.WriteLine(count); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 7, 10, 198, 39, 199]]
8
113
6
using System; namespace B_FizzBuzz_Sum { class Program { static void Main(string[] args) { int ans = 0; int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { if (i % 3 == 0 || i % 5 == 0) { } else { ans += i; } } Console.WriteLine(ans); } } }
using System; namespace B_FizzBuzz_Sum { class Program { static void Main(string[] args) { long ans = 0; int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) { if (i % 3 == 0 || i % 5 == 0) { } else { ans += i; } } Console.WriteLine(ans); } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
87
2
using System; using System.Collections.Generic; using System.Text; namespace AtCoderCs { class Class1 { static void Main() { var K = long.Parse(Console.ReadLine()); var Result = 0L; for (; 0 < K; K--) { if (K % 3 != 0 || K % 5 != 0) Result += K; } Console.WriteLine(Result); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoderCs { class Program { static void Main() { var K = long.Parse(Console.ReadLine()); var Result = 0L; for (; 0 < K; K--) { if (K % 3 != 0 && K % 5 != 0) Result += K; } Console.WriteLine(Result); } } }
[["-", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["+", 36, 36, 0, 208, 0, 231, 141, 232, 141, 22], ["-", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["+", 0, 208, 0, 209, 8, 201, 0, 235, 141, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
86
6
using System; namespace B { class Program { static void Main(string[] args) { var num = int.Parse(Console.ReadLine()); Int64 sum = 0; for (int i = 0; i < num; i++) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } Console.WriteLine(sum); } } }
using System; namespace B { class Program { static void Main(string[] args) { var num = int.Parse(Console.ReadLine()); Int64 sum = 0; for (int i = 1; i < num + 1; i++) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } Console.WriteLine(sum); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
84
4
namespace Test { using System; using System.Collections.Generic; using System.Linq; using System.Text; public class Test { public static void Main(string[] args) { var t = new Test(); var input = t.ReadInputOneLine(); long sum = 0; for (var i = 0; i < input; i++) { if (i % 3 != 0) { if (i % 5 != 0) { if (i % 15 != 0) { sum += i; } } } } Console.WriteLine(sum); } public int ReadInputOneLine() { return int.Parse(Console.ReadLine()); } public string[] ReadInput() { return Console.ReadLine().Split(' '); } public List<int> ParseIntList(string[] x) { var convertedList = new List<int>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(int.Parse(x[i])); } return convertedList; } public List<double> ParseDoubleList(string[] x) { var convertedList = new List<double>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(double.Parse(x[i])); } return convertedList; } public List<long> ParseLongList(string[] x) { var convertedList = new List<long>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(long.Parse(x[i])); } return convertedList; } public int CountContainWords(string source, string word) { var count = 0; var loopCount = source.Length - (word.Length - 1); for (var i = 0; i < loopCount; i++) { if (source.Substring(i, word.Length) == word) { count++; } } return count; } } }
namespace Test { using System; using System.Collections.Generic; using System.Linq; using System.Text; public class Test { public static void Main(string[] args) { var t = new Test(); var input = t.ReadInputOneLine(); long sum = 0; for (var i = 1; i <= input; i++) { if (i % 3 != 0) { if (i % 5 != 0) { if (i % 15 != 0) { sum += i; } } } } Console.WriteLine(sum); } public int ReadInputOneLine() { return int.Parse(Console.ReadLine()); } public string[] ReadInput() { return Console.ReadLine().Split(' '); } public List<int> ParseIntList(string[] x) { var convertedList = new List<int>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(int.Parse(x[i])); } return convertedList; } public List<double> ParseDoubleList(string[] x) { var convertedList = new List<double>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(double.Parse(x[i])); } return convertedList; } public List<long> ParseLongList(string[] x) { var convertedList = new List<long>(x.Length); for (var i = 0; i < x.Length; i++) { convertedList.Add(long.Parse(x[i])); } return convertedList; } public int CountContainWords(string source, string word) { var count = 0; var loopCount = source.Length - (word.Length - 1); for (var i = 0; i < loopCount; i++) { if (source.Substring(i, word.Length) == word) { count++; } } return count; } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
425
4
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var n = Int32.Parse(Console.ReadLine()); var ret = 0; for (var i = 1; i <= n; ++i) { if (i % 3 != 0 && i % 5 != 0) { ret += i; } } Console.WriteLine(ret); } }
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { var n = Int32.Parse(Console.ReadLine()); long ret = 0; for (var i = 1; i <= n; ++i) { if (i % 3 != 0 && i % 5 != 0) { ret += i; } } Console.WriteLine(ret); } }
[["-", 8, 196, 0, 197, 0, 198, 39, 216, 0, 217], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
90
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_solve { class Program { public const ulong mod = 1000000007; static void Main(string[] args) { var n = ulong.Parse(Console.ReadLine()); var x = 0; ulong ans = 0; for (ulong i = 0; i < n; i++) { if (i % 3 == 0 || i % 5 == 0) x++; else ans += i; } Console.WriteLine(ans); } static public long Input() { return long.Parse(Console.ReadLine()); } static public string[] Input2() { return Console.ReadLine().Split(); } static public long[] Input3() { string[] data = Console.ReadLine().Split(); long[] res = new long[data.LongLength]; for (long i = 0; i < data.LongLength; i++) { res[i] = long.Parse(data[i]); } return res; } public static long Choose(long n, long a) { long x = 1; long y = 1; for (long i = 0; i < a; i++) { x *= n - i; y *= i + 1; } return x / y; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder_solve { class Program { public const ulong mod = 1000000007; static void Main(string[] args) { var n = ulong.Parse(Console.ReadLine()); var x = 0; ulong ans = 0; for (ulong i = 1; i <= n; i++) { if (i % 3 == 0 || i % 5 == 0) x++; else ans += i; } Console.WriteLine(ans); } static public long Input() { return long.Parse(Console.ReadLine()); } static public string[] Input2() { return Console.ReadLine().Split(); } static public long[] Input3() { string[] data = Console.ReadLine().Split(); long[] res = new long[data.LongLength]; for (long i = 0; i < data.LongLength; i++) { res[i] = long.Parse(data[i]); } return res; } public static long Choose(long n, long a) { long x = 1; long y = 1; for (long i = 0; i < a; i++) { x *= n - i; y *= i + 1; } return x / y; } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
293
4
using System; class MainClass { public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); // long sum = (1 + N) * N / 2; // int a = N / 3; // long b = 3 * (1 + a) * a / 2; // int c = N / 5; // long d = 5 * (1 + c) * c / 2; // int e = N / 15; // long f = 15 * (1 + e) * e / 2; // sum = sum - b - d + f; long sum = 0; for (int i = 1; i <= N; i++) { if (i % 3 != 0) { if (i % 5 != 0) { sum += i; } } } Console.WriteLine(); } }
using System; class MainClass { public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); // long sum = (1 + N) * N / 2; // int a = N / 3; // long b = 3 * (1 + a) * a / 2; // int c = N / 5; // long d = 5 * (1 + c) * c / 2; // int e = N / 15; // long f = 15 * (1 + e) * e / 2; // sum = sum - b - d + f; long sum = 0; for (int i = 1; i <= N; i++) { if (i % 3 != 0) { if (i % 5 != 0) { sum += i; } } } Console.WriteLine(sum); } }
[["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
92
1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder1 { class Program { static void Main(string[] args) { int num = int.Parse(Console.ReadLine()); long sum = 0; for (int i = 0; i < num; i++) { if (Check(i)) { sum += i; } } Console.WriteLine(sum); } static bool Check(int num) { if (num % 3 == 0) { return false; } else if (num % 5 == 0) { return false; } else if (num % 15 == 0) { return false; } else { return true; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder1 { class Program { static void Main(string[] args) { int num = int.Parse(Console.ReadLine()); long sum = 0; for (int i = 1; i <= num; i++) { if (Check(i)) { sum += i; } } Console.WriteLine(sum); } static bool Check(int num) { if (num % 3 == 0) { return false; } else if (num % 5 == 0) { return false; } else if (num % 15 == 0) { return false; } else { return true; } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
157
4
using System; class p { static void Main() { int N = int.Parse(Console.ReadLine()); long sum = 0; for (int i = 0; i < N; i++) { if (i % 3 == 0 || i % 5 == 0) { continue; } sum += i; } Console.WriteLine(sum); } }
using System; class p { static void Main() { int N = int.Parse(Console.ReadLine()); long sum = 0; for (int i = 1; i <= N; i++) { if (i % 3 == 0 || i % 5 == 0) { continue; } sum += i; } Console.WriteLine(sum); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
78
4
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Beginner162 { public class ABC162B { public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long sum = 0; for (int i = 0; i < N; i++) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } Console.WriteLine(sum); } } }
using System; using System.Linq; using System.Collections.Generic; namespace AtCoder.Beginner162 { public class ABC162B { public static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); long sum = 0; for (int i = 1; i <= N; i++) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } Console.WriteLine(sum); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
100
4
using System; class ProgramB { static void Main(string[] args) { //入力 int n = int.Parse(Console.ReadLine()); long sum = 0; // RかBかでそれぞれリストを作る for (int i = 1; i <= n; i++) { if (i % 3 != 0 || i % 5 != 0) sum += i; } Console.WriteLine(sum); } }
using System; class ProgramB { static void Main(string[] args) { //入力 int n = int.Parse(Console.ReadLine()); long sum = 0; // RかBかでそれぞれリストを作る for (int i = 1; i <= n; i++) { if (i % 3 != 0 && i % 5 != 0) sum += i; } Console.WriteLine(sum); } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98]]
8
80
2
using System; using System.Collections.Generic; using System.Linq; namespace abc162 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var input = Enumerable.Range(1, n).ToArray(); int ans = 0; foreach (var item in input) { if (item % 3 != 0 && item % 5 != 0 && item % 15 != 0) { ans += item; } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace abc162 { class Program { static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var input = Enumerable.Range(1, n).ToArray(); long ans = 0; foreach (var item in input) { if (item % 3 != 0 && item % 5 != 0 && item % 15 != 0) { ans += item; } } Console.WriteLine(ans); /* var k = int.Parse(Console.ReadLine()); var a = Enumerable.Range(1,k).ToArray(); var b = Enumerable.Range(1, k).ToArray(); var c = Enumerable.Range(1, k).ToArray(); if() */ } } }
[["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
111
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC162 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); long o = 0; for (int i = 0; i < N; i++) { if (i % 3 == 0 || i % 5 == 0) continue; o += i; } Console.WriteLine(o); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC162 { class Program { static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); long o = 0; for (int i = 0; i <= N; i++) { if (i % 3 == 0 || i % 5 == 0) continue; o += i; } Console.WriteLine(o); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
108
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderB { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); long answer = 0; for (long i = 0; i < n; i++) { if (i % 3 != 0 && i % 5 != 0) { answer += i; } } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class AtCoderB { static void Main() { var sc = new Scanner(); long n = sc.NextLong(); long answer = 0; for (long i = 1; i <= n; i++) { if (i % 3 != 0 && i % 5 != 0) { answer += i; } } Console.WriteLine(answer); } class Scanner { private string[] _line; private int _index; private const char Separator = ' '; public Scanner() { _line = new string[0]; _index = 0; } public string Next() { while (_index >= _line.Length) { _line = Console.ReadLine().Split(Separator); _index = 0; } return _line[_index++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public double NextDouble() => double.Parse(Next()); public decimal NextDecimal() => decimal.Parse(Next()); public char NextChar() => Next()[0]; public char[] NextCharArray() => Next().ToCharArray(); public string[] Array() { _line = Console.ReadLine().Split(Separator); _index = _line.Length; return _line; } public int[] IntArray() => Array().Select(int.Parse).ToArray(); public long[] LongArray() => Array().Select(long.Parse).ToArray(); public double[] DoubleArray() => Array().Select(double.Parse).ToArray(); public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray(); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
391
4
using System; namespace AtCoder.Problems { public class ProblemB { public static void Main(string[] args) { var s = new SolveB(); s.Solve(); } public class Scanner { private string[] _s; private int _i; private readonly char[] _separators = 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(_separators, StringSplitOptions.RemoveEmptyEntries); if (_s.Length == 0) return Next(); _i = 0; return _s[_i++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public ulong NextULong() => ulong.Parse(Next()); public double NextDouble() => double.Parse(Next()); public int[] GetIntArray(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[] GetLongArray(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[] GetDoubleArray(int n, double add = 0) { double[] array = new double[n]; for (int i = 0; i < n; i++) { array[i] = NextDouble() + add; } return array; } } } public class SolveB { public void Solve() { var cin = new ProblemB.Scanner(); var n = cin.NextInt(); var result = GetAnswer(n); Console.WriteLine(result); } public long GetAnswer(int n) { long sum = 0; for (var i = 0; i < n; i++) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } return sum; } } }
using System; namespace AtCoder.Problems { public class ProblemB { public static void Main(string[] args) { var s = new SolveB(); s.Solve(); } public class Scanner { private string[] _s; private int _i; private readonly char[] _separators = 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(_separators, StringSplitOptions.RemoveEmptyEntries); if (_s.Length == 0) return Next(); _i = 0; return _s[_i++]; } public int NextInt() => int.Parse(Next()); public long NextLong() => long.Parse(Next()); public ulong NextULong() => ulong.Parse(Next()); public double NextDouble() => double.Parse(Next()); public int[] GetIntArray(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[] GetLongArray(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[] GetDoubleArray(int n, double add = 0) { double[] array = new double[n]; for (int i = 0; i < n; i++) { array[i] = NextDouble() + add; } return array; } } } public class SolveB { public void Solve() { var cin = new ProblemB.Scanner(); var n = cin.NextInt(); var result = GetAnswer(n); Console.WriteLine(result); } public long GetAnswer(int n) { long sum = 0; for (var i = 1; i <= n; i++) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } return sum; } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
503
4
using System; namespace CSharp { class Program { static void Main() { var N = long.Parse(Console.ReadLine()); var result = 0L; for (int i = 1; i < N; i++) { if (i % 3 > 0 && i % 5 > 0) { result += i; } } Console.WriteLine(result); } } }
using System; namespace CSharp { class Program { static void Main() { var N = long.Parse(Console.ReadLine()); var result = 0L; for (int i = 1; i <= N; i++) { if (i % 3 > 0 && i % 5 > 0) { result += i; } } Console.WriteLine(result); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
80
2
using System; using System.Linq; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); Console.WriteLine(Enumerable.Range(0, N) .Select(i => (long)i) .Where(i => i % 3 != 0 && i % 5 != 0) .Sum()); } }
using System; using System.Linq; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); Console.WriteLine(Enumerable.Range(1, N) .Select(i => (long)i) .Where(i => i % 3 != 0 && i % 5 != 0) .Sum()); } }
[["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203]]
8
82
2
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO.Compression; using System.Linq; using System.Text; namespace Atcoder { class Program { private const long COMDIV = 1000000007; static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); LinkedList<int> nums = new LinkedList<int>(); for (int i = 1; i <= N; i++) { if (i % 3 == 0 || i % 5 == 0) { continue; } nums.AddLast(i); } Console.WriteLine(nums.Sum()); } } }
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.IO.Compression; using System.Linq; using System.Text; namespace Atcoder { class Program { private const long COMDIV = 1000000007; static void Main(string[] args) { var N = int.Parse(Console.ReadLine()); LinkedList<long> nums = new LinkedList<long>(); for (int i = 1; i <= N; i++) { if (i % 3 == 0 || i % 5 == 0) { continue; } nums.AddLast(i); } Console.WriteLine(nums.Sum()); } } }
[["-", 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
143
4
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var N = sc.ReadInt(); var X = sc.ReadInt() - 1; var Y = sc.ReadInt() - 1; var dij = new Dijkstra(N); dij.Add(X, Y); for (int i = 0; i < N - 1; i++) { dij.Add(i, i + 1); } var ans = new int[N]; for (int i = 0; i < N; i++) { var dp = dij.Calc(i); for (int j = i + 1; j < N; j++) { ans[dp[j]]++; } } for (int i = 1; i < N - 1; i++) { Console.WriteLine(ans[i]); } Console.Out.Flush(); } class Dijkstra { public int V { get; set; } public int E { get; set; } public List<Edge>[] G { get; set; } public bool Directed { get; set; } public Dijkstra(int n, bool directed = false) { this.V = n; this.Directed = directed; this.G = new List<Edge>[V]; for (int i = 0; i < V; i++) { this.G[i] = new List<Edge>(); } } public void Add(int a, int b, long cost = 1) { this.G[a].Add(new Edge(b, cost)); if (!this.Directed) this.G[b].Add(new Edge(a, cost)); this.E++; } public long GetMinCost(int start, int goal) { var cost = new long[V]; for (int i = 0; i < V; i++) cost[i] = long.MaxValue; cost[start] = 0; var capacity = Math.Max(1, E); var q = new PriorityQueue<P>(capacity, false); q.Enqueue(new P(start, 0)); while (q.Count > 0) { var p = q.Dequeue(); if (p.Cost != cost[p.A]) continue; foreach (var e in this.G[p.A]) { if (cost[e.To] > p.Cost + e.Cost) { cost[e.To] = p.Cost + e.Cost; q.Enqueue(new P(e.To, cost[e.To])); } } } return cost[goal] == long.MaxValue ? -1 : cost[goal]; } public long[] Calc(int start) { var cost = new long[V]; for (int i = 0; i < V; i++) cost[i] = long.MaxValue; cost[start] = 0; var capacity = Math.Max(1, E); var q = new PriorityQueue<P>(capacity, false); q.Enqueue(new P(start, 0)); while (q.Count > 0) { var p = q.Dequeue(); if (p.Cost != cost[p.A]) continue; foreach (var e in this.G[p.A]) { if (cost[e.To] > p.Cost + e.Cost) { cost[e.To] = p.Cost + e.Cost; q.Enqueue(new P(e.To, cost[e.To])); } } } return cost; } public struct Edge { public int To; public long Cost; public Edge(int to, long cost) { this.To = to; this.Cost = cost; } } public struct P : IComparable<P> { public int A; public long Cost; public P(int a, long cost) { this.A = a; this.Cost = cost; } public int CompareTo(P other) { return this.Cost.CompareTo(other.Cost); } } } class PriorityQueue<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; private IComparer<T> Cmp; public PriorityQueue(int capacity, bool greater = true, IComparer<T> cmp = null) { this.Cmp = cmp; if (cmp == null) { this.Cmp = Comparer<T>.Default; } this.Array = new T[capacity]; this.Greater = greater; } public void Enqueue(T item) { this.Array[this.Count] = item; this.Count += 1; this.UpHeap(); } public T Dequeue() { this.Swap(0, this.Count - 1); this.Count -= 1; this.DownHeap(); return this.Array[this.Count]; } public T Peek() { return this.Array[0]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (this.Compare(this.Array[n], this.Array[parent]) > 0) { this.Swap(n, parent); n = parent; } else { break; } } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0) { child += 1; } if (this.Compare(this.Array[parent], this.Array[child]) < 0) { this.Swap(parent, child); parent = child; } else { break; } } } private int Compare(T a, T b) { var c = this.Cmp.Compare(a, b); if (!this.Greater) { c = -c; } return c; } private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var N = sc.ReadInt(); var X = sc.ReadInt() - 1; var Y = sc.ReadInt() - 1; var dij = new Dijkstra(N); dij.Add(X, Y); for (int i = 0; i < N - 1; i++) { dij.Add(i, i + 1); } var ans = new int[N]; for (int i = 0; i < N; i++) { var dp = dij.Calc(i); for (int j = i + 1; j < N; j++) { ans[dp[j]]++; } } for (int i = 1; i < N; i++) { Console.WriteLine(ans[i]); } Console.Out.Flush(); } class Dijkstra { public int V { get; set; } public int E { get; set; } public List<Edge>[] G { get; set; } public bool Directed { get; set; } public Dijkstra(int n, bool directed = false) { this.V = n; this.Directed = directed; this.G = new List<Edge>[V]; for (int i = 0; i < V; i++) { this.G[i] = new List<Edge>(); } } public void Add(int a, int b, long cost = 1) { this.G[a].Add(new Edge(b, cost)); if (!this.Directed) this.G[b].Add(new Edge(a, cost)); this.E++; } public long GetMinCost(int start, int goal) { var cost = new long[V]; for (int i = 0; i < V; i++) cost[i] = long.MaxValue; cost[start] = 0; var capacity = Math.Max(1, E); var q = new PriorityQueue<P>(capacity, false); q.Enqueue(new P(start, 0)); while (q.Count > 0) { var p = q.Dequeue(); if (p.Cost != cost[p.A]) continue; foreach (var e in this.G[p.A]) { if (cost[e.To] > p.Cost + e.Cost) { cost[e.To] = p.Cost + e.Cost; q.Enqueue(new P(e.To, cost[e.To])); } } } return cost[goal] == long.MaxValue ? -1 : cost[goal]; } public long[] Calc(int start) { var cost = new long[V]; for (int i = 0; i < V; i++) cost[i] = long.MaxValue; cost[start] = 0; var capacity = Math.Max(1, E); var q = new PriorityQueue<P>(capacity, false); q.Enqueue(new P(start, 0)); while (q.Count > 0) { var p = q.Dequeue(); if (p.Cost != cost[p.A]) continue; foreach (var e in this.G[p.A]) { if (cost[e.To] > p.Cost + e.Cost) { cost[e.To] = p.Cost + e.Cost; q.Enqueue(new P(e.To, cost[e.To])); } } } return cost; } public struct Edge { public int To; public long Cost; public Edge(int to, long cost) { this.To = to; this.Cost = cost; } } public struct P : IComparable<P> { public int A; public long Cost; public P(int a, long cost) { this.A = a; this.Cost = cost; } public int CompareTo(P other) { return this.Cost.CompareTo(other.Cost); } } } class PriorityQueue<T> { public readonly T[] Array; public readonly bool Greater; public int Count { get; private set; } = 0; private IComparer<T> Cmp; public PriorityQueue(int capacity, bool greater = true, IComparer<T> cmp = null) { this.Cmp = cmp; if (cmp == null) { this.Cmp = Comparer<T>.Default; } this.Array = new T[capacity]; this.Greater = greater; } public void Enqueue(T item) { this.Array[this.Count] = item; this.Count += 1; this.UpHeap(); } public T Dequeue() { this.Swap(0, this.Count - 1); this.Count -= 1; this.DownHeap(); return this.Array[this.Count]; } public T Peek() { return this.Array[0]; } private void UpHeap() { var n = this.Count - 1; while (n != 0) { var parent = (n - 1) / 2; if (this.Compare(this.Array[n], this.Array[parent]) > 0) { this.Swap(n, parent); n = parent; } else { break; } } } private void DownHeap() { var parent = 0; while (true) { var child = 2 * parent + 1; if (child > this.Count - 1) break; if (child < this.Count - 1 && this.Compare(this.Array[child], this.Array[child + 1]) < 0) { child += 1; } if (this.Compare(this.Array[parent], this.Array[child]) < 0) { this.Swap(parent, child); parent = child; } else { break; } } } private int Compare(T a, T b) { var c = this.Cmp.Compare(a, b); if (!this.Greater) { c = -c; } return c; } private void Swap(int a, int b) { var tmp = this.Array[a]; this.Array[a] = this.Array[b]; this.Array[b] = tmp; } } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
2,369
2
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using System.Threading; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string s1 = S.Substring(0, (S.Length - 1) / 2); string s2 = S.Substring((S.Length + 3) / 2); if (s1 == s2) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } } //文字列の入力 // string s = Console.ReadLine(); //整数の入力 // long n = long.Parse(Console.ReadLine()); //文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); //整数配列の入力 // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(); // Console.ReadKey();
using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text.RegularExpressions; using System.Threading; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string S = Console.ReadLine(); string s1 = S.Substring(0, (S.Length - 1) / 2); string s2 = S.Substring((S.Length + 3 - 1) / 2); if (s1 == s2) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } } //文字列の入力 // string s = Console.ReadLine(); //整数の入力 // long n = long.Parse(Console.ReadLine()); //文字列配列の入力 // string[] inputStrArray = Console.ReadLine().Split(' '); //整数配列の入力 // long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => // long.Parse(i)).ToArray(); // Console.WriteLine(); // Console.ReadKey();
[["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203]]
8
149
2
using System; namespace ConsoleApp21 { class Program { static void Main(string[] args) { long x = int.Parse(Console.ReadLine()); int u = 0; while (x > 500) { x -= 500; u += 1000; } while (x > 5) { x -= 5; u += 5; } Console.WriteLine(u); } } }
using System; namespace ConsoleApp21 { class Program { static void Main(string[] args) { long x = int.Parse(Console.ReadLine()); int u = 0; while (x >= 500) { x -= 500; u += 1000; } while (x >= 5) { x -= 5; u += 5; } Console.WriteLine(u); } } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20]]
8
80
4
using System; namespace abc160_b { class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); int coinCount500 = x / 500; int sum = 0; int x5 = 0; for (int i = 1; i <= coinCount500; i++) { sum += 1000; x5 = x % 500; } int coinCount5 = x5 / 5; for (int j = 1; j <= coinCount5; j++) { sum += 5; } Console.WriteLine(sum); } } }
using System; namespace abc160_b { class Program { static void Main(string[] args) { int x = int.Parse(Console.ReadLine()); int coinCount500 = x / 500; int sum = 0; int x5 = x; for (int i = 1; i <= coinCount500; i++) { sum += 1000; x5 = x5 % 500; } int coinCount5 = x5 / 5; for (int j = 1; j <= coinCount5; j++) { sum += 5; } Console.WriteLine(sum); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 22], ["-", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 16, 31, 22]]
8
113
4
using System; namespace AtCoder2020Ned { class Program { static void Main(string[] args) { var money = int.Parse(Console.ReadLine()); var fiveHundredHappiness = money / 500 * 1000; money %= 1000; var fiveHappiness = money / 5 * 5; Console.WriteLine(fiveHundredHappiness + fiveHappiness); Console.Read(); } } }
using System; namespace AtCoder2020Ned { class Program { static void Main(string[] args) { var money = int.Parse(Console.ReadLine()); var fiveHundredHappiness = money / 500 * 1000; money %= 500; var fiveHappiness = money / 5 * 5; Console.WriteLine(fiveHundredHappiness + fiveHappiness); Console.Read(); } } }
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203]]
8
73
2