buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 1; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long N = inputArray[0]; var X = retreiveStringArray()[0]; //扱いやすいように1の桁から並べる var Xrev = X.Reverse().ToArray(); var popCount = Xrev.Where(x => x == '1').Count(); // popCount の+-1を格納 var popS = new long[2]; popS[0] = popCount + 1; popS[1] = popCount - 1 <= 0 ? 0 : popCount - 1; // N...2のN乗 2...pop+- それぞれの余り var TwoMods = new long[N, 2]; TwoMods[0, 0] = 1 % popS[0]; TwoMods[0, 1] = 1 % popS[1]; for (int p = 0; p < 2; p++) { for (int i = 1; i < N; i++) { TwoMods[i, p] = (TwoMods[i - 1, p] * 2) % popS[p]; } } // Xをpop+-1で割ったあまり var Fx = new long[2]; for (int p = 0; p < 2; p++) { for (int i = 0; i < N; i++) { var c = Xrev[i]; if (c == '1') { Fx[p] += TwoMods[i, p]; Fx[p] %= popS[p]; } } } // i番目をひっくり返す 降順になる for (var i = N - 1; i >= 0; i--) { var c = Xrev[i]; long first = 0; if (c == '1') { // 1つしかない1を反転させると、操作0回になる if (popCount == 1) { Console.WriteLine(0); continue; } var p = 1; first = Fx[p] - TwoMods[i, p]; if (first < 0) { first += popS[p]; } } else { var p = 0; first = Fx[p] + TwoMods[i, p]; first %= popS[p]; } var ans = 1 + function(first); Console.WriteLine(ans); } } /// <summary> /// 問題文のfunctionを実装した関数 /// </summary> /// <param name="n"></param> /// <returns></returns> private static long function(long n) { var count = 0; while (n > 0) { // 1が何個あるか求める var OneCount = 0; for (int i = 0; i < 32; i++) { if ((n >> i & 1) == 1) { OneCount++; } } if (OneCount == 0) { Console.WriteLine("異常発生"); return -1; //この経路はnの条件的に通らないはず } // nを割ってあまりを求める n %= OneCount; count++; } return count; } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } /// <summary> /// 2組みずつの入力データ(数値)からTuppleListを作成する /// </summary> /// <param name="N"></param> /// <returns></returns> private static List<Tuple<long, long>> createLongTuppleList(long N) { var inpList = new List<Tuple<long, long>>(); for (int i = 0; i < N; i++) { var inp = retreiveLongArray(); var item1 = inp[0]; var item2 = inp[1]; inpList.Add(new Tuple<long, long>(item1, item2)); } return inpList; } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder2 { class Program { static void Main(string[] args) { var inputArray = retreiveLongArray(); var inputCount = 1; // 不正な入力は処理しない if (inputArray.Length != inputCount) { Console.WriteLine("invalid input"); return; } long N = inputArray[0]; var X = retreiveStringArray()[0]; //扱いやすいように1の桁から並べる var Xrev = X.Reverse().ToArray(); var popCount = Xrev.Where(x => x == '1').Count(); // popCount の+-1を格納 var popS = new long[2]; popS[0] = popCount + 1; popS[1] = popCount - 1 <= 0 ? 1 : popCount - 1; // N...2のN乗 2...pop+- それぞれの余り var TwoMods = new long[N, 2]; TwoMods[0, 0] = 1 % popS[0]; TwoMods[0, 1] = 1 % popS[1]; for (int p = 0; p < 2; p++) { for (int i = 1; i < N; i++) { TwoMods[i, p] = (TwoMods[i - 1, p] * 2) % popS[p]; } } // Xをpop+-1で割ったあまり var Fx = new long[2]; for (int p = 0; p < 2; p++) { for (int i = 0; i < N; i++) { var c = Xrev[i]; if (c == '1') { Fx[p] += TwoMods[i, p]; Fx[p] %= popS[p]; } } } // i番目をひっくり返す 降順になる for (var i = N - 1; i >= 0; i--) { var c = Xrev[i]; long first = 0; if (c == '1') { // 1つしかない1を反転させると、操作0回になる if (popCount == 1) { Console.WriteLine(0); continue; } var p = 1; first = Fx[p] - TwoMods[i, p]; if (first < 0) { first += popS[p]; } } else { var p = 0; first = Fx[p] + TwoMods[i, p]; first %= popS[p]; } var ans = 1 + function(first); Console.WriteLine(ans); } } /// <summary> /// 問題文のfunctionを実装した関数 /// </summary> /// <param name="n"></param> /// <returns></returns> private static long function(long n) { var count = 0; while (n > 0) { // 1が何個あるか求める var OneCount = 0; for (int i = 0; i < 32; i++) { if ((n >> i & 1) == 1) { OneCount++; } } if (OneCount == 0) { Console.WriteLine("異常発生"); return -1; //この経路はnの条件的に通らないはず } // nを割ってあまりを求める n %= OneCount; count++; } return count; } /// <summary> /// スペースで区切られた文字列配列の入力を受け取る /// </summary> /// <returns></returns> private static string[] retreiveStringArray() { var inputArray = Console.ReadLine().Split(' '); return inputArray; } /// <summary> /// スペースで区切られた整数配列の入力を受け取る /// </summary> /// <returns></returns> private static long[] retreiveLongArray() { var inputArray = Console.ReadLine().Split(' '); var longArray = inputArray.Select(s => long.Parse(s)); return longArray.ToArray(); } /// <summary> /// 2組みずつの入力データ(数値)からTuppleListを作成する /// </summary> /// <param name="N"></param> /// <returns></returns> private static List<Tuple<long, long>> createLongTuppleList(long N) { var inpList = new List<Tuple<long, long>>(); for (int i = 0; i < N; i++) { var inp = retreiveLongArray(); var item1 = inp[0]; var item2 = inp[1]; inpList.Add(new Tuple<long, long>(item1, item2)); } return inpList; } } }
[["-", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203]]
8
778
2
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var X = sc.ReadStr().Reverse().ToArray(); var popcount = X.Count(c => c == '1'); var pc = new int[2]; pc[0] = popcount + 1; pc[1] = popcount - 1; var pow = new long[N, 2]; var now = new long[2]; now[0] = 1; now[1] = 1; var sum = new long[N + 1, 2]; for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { pow[i, j] = now[j]; sum[i + 1, j] = sum[i, j]; if (X[i] == '1') sum[i + 1, j] += pow[i, j]; sum[i + 1, j] %= pc[j] == 0 ? 1 : pc[j]; now[j] *= 2; now[j] %= pc[j] == 0 ? 1 : pc[j]; } } for (int i = N - 1; i >= 0; i--) { if (X[i] == '1' && popcount == 1) { Console.WriteLine(0); return; } var nj = X[i] - '0'; var next = sum[N, nj]; if (nj == 0) next += pow[i, nj]; else { next -= pow[i, nj]; if (next < 0) next += pc[nj]; } next %= pc[nj]; var ans = 1; while (next > 0) { ans++; next %= PopulationCount(next); } Console.WriteLine(ans); } } static int PopulationCount(long x) { var count = 0; for (; x > 0; x &= x - 1) count++; return count; } static Scanner sc = new Scanner(); } class Scanner { string[] S = new string[0]; int Index = 0; char[] Separators = new char[] { ' ' }; public string Next() { if (this.Index < this.S.Length) return this.S[this.Index++]; var line = ""; while (line == "") line = Console.ReadLine(); this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries); if (this.S.Length == 0) return this.Next(); this.Index = 0; return this.S[this.Index++]; } public string ReadStr() { return this.Next(); } public char ReadChar() { return this.Next()[0]; } public int ReadInt() { return int.Parse(this.Next()); } public uint ReadUInt() { return uint.Parse(this.Next()); } public long ReadLong() { return long.Parse(this.Next()); } public double ReadDouble() { return double.Parse(this.Next()); } public Tuple<int, int> ReadTup(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add); } public Tuple<long, long> ReadTupLong(int add = 0) { return Tuple.Create(this.ReadLong() + add, this.ReadLong() + add); } public Tuple<int, int, int> ReadTup3(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public Tuple<int, int, int, int> ReadTup4(int add = 0) { return Tuple.Create(this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add, this.ReadInt() + add); } public int[] ReadIntArray(int n) { var array = new int[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadInt(); } return array; } public long[] ReadLongArray(int n) { var array = new long[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadLong(); } return array; } public double[] ReadDoubleArray(int n) { var array = new double[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadDouble(); } return array; } public char[] ReadCharArray(int n) { var array = new char[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadChar(); } return array; } public string[] ReadStrArray(int n) { var array = new string[n]; for (int i = 0; i < array.Length; i++) { array[i] = this.ReadStr(); } return array; } public Tuple<long, long>[] ReadTupLongArray(int n, int add = 0) { var array = new Tuple<long, long>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTupLong(add); } return array; } public Tuple<int, int>[] ReadTupArray(int n, int add = 0) { var array = new Tuple<int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup(add); } return array; } public Tuple<int, int, int>[] ReadTup3Array(int n, int add = 0) { var array = new Tuple<int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup3(add); } return array; } public Tuple<int, int, int, int>[] ReadTup4Array(int n, int add = 0) { var array = new Tuple<int, int, int, int>[n]; for (int i = 0; i < n; i++) { array[i] = this.ReadTup4(add); } return array; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; class Program { static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } static void Solve() { var N = sc.ReadInt(); var X = sc.ReadStr().Reverse().ToArray(); // var N = (int)2e5; // var X = new string('1', N).Reverse().ToArray(); var popcount = X.Count(c => c == '1'); var pc = new int[2]; pc[0] = popcount + 1; pc[1] = popcount - 1; var pow = new long[N, 2]; var now = new long[2]; now[0] = 1; now[1] = 1; var sum = new long[N + 1, 2]; for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { pow[i, j] = now[j]; sum[i + 1, j] = sum[i, j]; if (X[i] == '1') sum[i + 1, j] += pow[i, j]; sum[i + 1, j] %= pc[j] == 0 ? 2 : pc[j]; now[j] *= 2; now[j] %= pc[j] == 0 ? 2 : pc[j]; } } for (int i = N - 1; i >= 0; i--) { if (X[i] == '1' && popcount == 1) { Console.WriteLine(0); continue; } var nj = X[i] - '0'; var next = sum[N, nj]; if (nj == 0) next += pow[i, nj]; else { next -= pow[i, nj]; if (next < 0) next += pc[nj]; } next %= pc[nj]; var ans = 1; while (next > 0) { ans++; next %= PopulationCount(next); } Console.WriteLine(ans); } } static int PopulationCount(long x) { var count = 0; for (; x > 0; x &= x - 1) count++; return count; } 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, 1, 0, 11, 12, 41, 64, 203], ["+", 8, 196, 0, 1, 0, 11, 12, 41, 64, 203], ["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117]]
8
1,483
6
using System; using System.Collections.Generic; using System.Linq; public static class Bits { 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); } } public class Solution { public static int PopCount(string str) { return str.Count(c => c == '1'); } public static int CalcF(int n) { var count = 1; while (n > 0) { n %= n.PopCount(); count++; } return count; } public static void Main() { var N = int.Parse(Console.ReadLine()); var X = Console.ReadLine(); var pop = PopCount(X); var modA = pop + 1; var modB = pop - 1; if (modA == 0) { modA = 1; } if (modB == 0) { modB = 1; } int NA = 0; int NB = 0; foreach (var c in X) { NA *= 2; NB *= 2; if (c == '1') { NA++; NB++; } NA %= modA; NB %= modB; } var basisA = new int[N]; var basisB = new int[N]; int tA = 1; int tB = 1; for (int i = N - 1; i >= 0; i--) { basisA[i] = tA; basisB[i] = tB; tA = (tA * 2) % modA; tB = (tB * 2) % modB; } var answers = new int[N]; for (int i = 0; i < N; i++) { var sign = X[i] == '0' ? 1 : -1; var p = pop + sign; if (p == 0) { answers[i] = 0; } else if (p == modA) { answers[i] = CalcF(NA + basisA[i] * sign % p); } else if (p == modB) { answers[i] = CalcF(NB + basisB[i] * sign % p); } } Console.WriteLine(string.Join(Environment.NewLine, answers)); } }
using System; using System.Collections.Generic; using System.Linq; public static class Bits { 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); } } public class Solution { public static int PopCount(string str) { return str.Count(c => c == '1'); } public static int CalcF(int n) { var count = 1; while (n > 0) { n %= n.PopCount(); count++; } return count; } public static void Main() { var N = int.Parse(Console.ReadLine()); var X = Console.ReadLine(); var pop = PopCount(X); var modA = pop + 1; var modB = pop - 1; if (modA == 0) { modA = 1; } if (modB == 0) { modB = 1; } int NA = 0; int NB = 0; foreach (var c in X) { NA *= 2; NB *= 2; if (c == '1') { NA++; NB++; } NA %= modA; NB %= modB; } var basisA = new int[N]; var basisB = new int[N]; int tA = 1; int tB = 1; for (int i = N - 1; i >= 0; i--) { basisA[i] = tA; basisB[i] = tB; tA = (tA * 2) % modA; tB = (tB * 2) % modB; } var answers = new int[N]; for (int i = 0; i < N; i++) { var sign = X[i] == '0' ? 1 : -1; var p = pop + sign; if (p == 0) { answers[i] = 0; } else if (p == modA) { answers[i] = CalcF((NA + basisA[i] * sign) % p); } else if (p == modB) { answers[i] = CalcF((NB + basisB[i] * sign + p) % p); } } Console.WriteLine(string.Join(Environment.NewLine, answers)); } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 213, 3, 4, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 22]]
8
521
6
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string X = Console.ReadLine(); int ct = 0; int[] A = new int[N]; for (var i = 0; i < X.Length; i++) { int s = int.Parse(X.Substring(i, 1)); if (s == 1) { A[i] = 1; ct++; } } int[,] B = new int[N, 4]; int t = 1; int a = 0; for (var j = N - 1; j >= 0; j--) { if (A[j] == 1) { a = (a + t) % (ct + 1); } B[j, 0] = a; t = (t * 2) % (ct + 1); } t = 1; a = 0; for (var j = N - 1; j >= 0; j--) { if (ct > 1) { if (A[j] == 1) { a = (a + t) % (ct - 1); } B[j, 1] = a; t = (t * 2) % (ct - 1); } else { B[j, 1] = 0; } } t = 1; for (var j = N - 1; j >= 0; j--) { B[j, 2] = t; t = (t * 2) % (ct + 1); } t = 1; for (var j = N - 1; j >= 0; j--) { if (ct > 1) { B[j, 3] = t; t = (t * 2) % (ct - 1); } else { B[j, 3] = 0; } } int[] C = new int[100002]; for (var i = 1; i <= 100001; i++) { int at = i; int c = 1; int ca = 0; while (true) { if (at / c % 2 == 1) { ca++; } c *= 2; if (c > at) { break; } } int d = at % ca; C[at] = C[d] + 1; } // for(var i=0;i<N;i++){ // Console.Error.WriteLine(B[i,0]+" "+B[i,1]+" "+B[i,2]+" "+B[i,3]); //} // for(var i=0;i<100;i++){ // Console.Error.WriteLine(C[i]); // } for (var i = 0; i < N; i++) { if (A[i] == 0) { int a3 = B[0, 0] + B[i, 2]; // Console.WriteLine(a3); Console.WriteLine(C[a3 % (ct + 1)] + 1); } else { if (ct == 1) { Console.WriteLine(1); } else { int a3 = (B[0, 1] - B[i, 3] + (ct - 1)) % (ct - 1); // Console.WriteLine(a3); Console.WriteLine(C[a3 % (ct - 1)] + 1); } } } } }
using System; using System.Collections.Generic; class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string X = Console.ReadLine(); int ct = 0; int[] A = new int[N]; for (var i = 0; i < X.Length; i++) { int s = int.Parse(X.Substring(i, 1)); if (s == 1) { A[i] = 1; ct++; } } int[,] B = new int[N, 4]; int t = 1; int a = 0; for (var j = N - 1; j >= 0; j--) { if (A[j] == 1) { a = (a + t) % (ct + 1); } B[j, 0] = a; t = (t * 2) % (ct + 1); } t = 1; a = 0; for (var j = N - 1; j >= 0; j--) { if (ct > 1) { if (A[j] == 1) { a = (a + t) % (ct - 1); } B[j, 1] = a; t = (t * 2) % (ct - 1); } else { B[j, 1] = 0; } } t = 1; for (var j = N - 1; j >= 0; j--) { B[j, 2] = t; t = (t * 2) % (ct + 1); } t = 1; for (var j = N - 1; j >= 0; j--) { if (ct > 1) { B[j, 3] = t; t = (t * 2) % (ct - 1); } else { B[j, 3] = 0; } } int[] C = new int[200002]; for (var i = 1; i <= 200001; i++) { int at = i; int c = 1; int ca = 0; while (true) { if (at / c % 2 == 1) { ca++; } c *= 2; if (c > at) { break; } } int d = at % ca; C[at] = C[d] + 1; } for (var i = 0; i < N; i++) { if (A[i] == 0) { int a3 = B[0, 0] + B[i, 2]; Console.WriteLine(C[a3 % (ct + 1)] + 1); } else { if (ct == 1) { Console.WriteLine(0); } else { int a3 = (B[0, 1] - B[i, 3] + (ct - 1)) % (ct - 1); Console.WriteLine(C[a3 % (ct - 1)] + 1); } } } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 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
647
6
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; using static System.Math; using static System.Array; using static AtCoder.Sc_out; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var th = new Thread(Run, 1 << 26); th.Start(); th.Join(); // Run(); Console.Out.Flush(); } static void Run() { int Testcase = Cin.Int; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { int N = Cin.Int; var K = new int[N]; var L = new long[N]; var R = new long[N]; var pl = new List<List<int>>(); var mn = new List<List<int>>(); var ok = new Priority_Queue<int>( (x, y) => { return Sig((L[y] - R[y]) - (L[x] - R[x])); }); for (var i = 0; i < N; i++) { pl.Add(new List<int>()); mn.Add(new List<int>()); } int num = -1; var same = new Queue<long>(); for (var i = 0; i < N; i++) { Cin.Input(out K[i], out L[i], out R[i]); if (L[i] > R[i]) pl[K[i] - 1].Add(i); else if (L[i] < R[i]) { if (K[i] == N) { same.Enqueue(L[i]); } else mn[K[i]].Add(i); } else { same.Enqueue(L[i]); } if (L[i] > R[i]) num++; } int s = same.Count(); var ans = new long[N]; Initialize(ref ans, -1); //左側 for (var i = N - 1; i >= 0; i--) { foreach (var idx in pl[i]) ok.Enqueue(idx); if (i > num) continue; if (!ok.Any()) { ans[i] = -1; continue; } ans[i] = L[ok.Dequeue()]; } for (var i = 0; i < num; i++) { if (ans[i] == -1) { ans[i] = R[ok.Dequeue()]; } } // if (ok.Any()) { OutL("ERROR1");Environment.Exit(-1); } ok = new Priority_Queue<int>( (x, y) => { return Sig((R[y] - L[y]) - (R[x] - L[x])); }); //同じやつ for (var i = num + 1; i < num + 1 + s; i++) ans[i] = same.Dequeue(); //右側 for (var i = 0; i < N; i++) { foreach (var idx in mn[i]) { ok.Enqueue(idx); } if (i <= num + s) continue; if (!ok.Any()) { ans[i] = -1; continue; } ans[i] = R[ok.Dequeue()]; } for (var i = num + 1 + s; i < N; i++) { if (ans[i] == -1) { ans[i] = L[ok.Dequeue()]; } } if (ok.Any()) { OutL("ERROR2"); Environment.Exit(-1); } OutL(ans.Sum()); } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class Cin { public static string[] ReadSplit => Console.ReadLine().Split(); public static int[] ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } } static class Sc_out { public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Numerics; using System.Threading; using System.Runtime.CompilerServices; using System.Diagnostics; using static System.Math; using static System.Array; using static AtCoder.Sc_out; using static AtCoder.Tool; using static AtCoder.ModInt; namespace AtCoder { class AC { const int MOD = 1000000007; // const int MOD = 998244353; const int INF = int.MaxValue / 2; const long SINF = long.MaxValue / 2; const double EPS = 1e-8; static readonly int[] dI = { 0, 1, 0, -1, 1, -1, -1, 1 }; static readonly int[] dJ = { 1, 0, -1, 0, 1, 1, -1, -1 }; // static List<List<int>> G = new List<List<int>>(); // static List<List<Edge>> G = new List<List<Edge>>(); // static List<Edge> E = new List<Edge>(); static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var th = new Thread(Run, 1 << 26); th.Start(); th.Join(); // Run(); Console.Out.Flush(); } static void Run() { int Testcase = Cin.Int; for (var _ = 0; _ < Testcase; _++) Solve(); } static void Solve() { int N = Cin.Int; var K = new int[N]; var L = new long[N]; var R = new long[N]; var pl = new List<List<int>>(); var mn = new List<List<int>>(); var ok = new Priority_Queue<int>( (x, y) => { return Sig((L[y] - R[y]) - (L[x] - R[x])); }); for (var i = 0; i < N; i++) { pl.Add(new List<int>()); mn.Add(new List<int>()); } int num = -1; var same = new Queue<long>(); for (var i = 0; i < N; i++) { Cin.Input(out K[i], out L[i], out R[i]); if (L[i] > R[i]) pl[K[i] - 1].Add(i); else if (L[i] < R[i]) { if (K[i] == N) { same.Enqueue(L[i]); } else mn[K[i]].Add(i); } else { same.Enqueue(L[i]); } if (L[i] > R[i]) num++; } int s = same.Count(); var ans = new long[N]; Initialize(ref ans, -1); //左側 for (var i = N - 1; i >= 0; i--) { foreach (var idx in pl[i]) ok.Enqueue(idx); if (i > num) continue; if (!ok.Any()) { ans[i] = -1; continue; } ans[i] = L[ok.Dequeue()]; } for (var i = 0; i <= num; i++) { if (ans[i] == -1) { ans[i] = R[ok.Dequeue()]; } } // if (ok.Any()) { OutL("ERROR1");Environment.Exit(-1); } ok = new Priority_Queue<int>( (x, y) => { return Sig((R[y] - L[y]) - (R[x] - L[x])); }); //同じやつ for (var i = num + 1; i < num + 1 + s; i++) ans[i] = same.Dequeue(); //右側 for (var i = 0; i < N; i++) { foreach (var idx in mn[i]) { ok.Enqueue(idx); } if (i <= num + s) continue; if (!ok.Any()) { ans[i] = -1; continue; } ans[i] = R[ok.Dequeue()]; } for (var i = num + 1 + s; i < N; i++) { if (ans[i] == -1) { ans[i] = L[ok.Dequeue()]; } } if (ok.Any()) { OutL("ERROR2"); Environment.Exit(-1); } OutL(ans.Sum()); } public struct Edge { public int from; public int to; public long dist; public Edge(int t, long c) { from = -1; to = t; dist = c; } public Edge(int f, int t, long c) { from = f; to = t; dist = c; } } } public class Priority_Queue<T> { private List<T> Q; private readonly Comparison<T> Func_Compare; public Priority_Queue(Comparison<T> comp) { Func_Compare = comp; Q = new List<T>(); } private void PushHeap(List<T> list, T item) { int n = list.Count(); list.Add(item); while (n != 0) { int pIndex = (n - 1) / 2; if (Func_Compare(list[n], list[pIndex]) < 0) { Swap(Q, n, pIndex); } else { break; } n = pIndex; } } private void PopHeap(List<T> list) { int n = list.Count() - 1; list[0] = list[n]; list.RemoveAt(n); int cur = 0; int comp; while (2 * cur + 1 <= n - 1) { int c1 = 2 * cur + 1; int c2 = 2 * (cur + 1); if (c1 == n - 1) { comp = c1; } else { comp = Func_Compare(list[c1], list[c2]) < 0 ? c1 : c2; } if (Func_Compare(list[cur], list[comp]) > 0) { Swap(Q, cur, comp); } else { break; } cur = comp; } } private void Swap(List<T> list, int a, int b) { T keep = list[a]; list[a] = list[b]; list[b] = keep; } public void Enqueue(T value) { PushHeap(Q, value); } public T Dequeue() { T ret = Q[0]; PopHeap(Q); return ret; } public T Peek() { return Q[0]; } public int Count() { return Q.Count(); } public bool Any() { return Q.Any(); } } struct ModInt { public long value; private const int MOD = 1000000007; // private const int MOD = 998244353; public ModInt(long value) { this.value = value; } public static implicit operator ModInt(long a) { var ret = a % MOD; return new ModInt(ret < 0 ? (ret + MOD) : ret); } public static ModInt operator +(ModInt a, ModInt b) => (a.value + b.value); public static ModInt operator -(ModInt a, ModInt b) => (a.value - b.value); public static ModInt operator *(ModInt a, ModInt b) => (a.value * b.value); public static ModInt operator /(ModInt a, ModInt b) => a * Modpow(b, MOD - 2); public static ModInt operator <<(ModInt a, int n) => (a.value << n); public static ModInt operator>>(ModInt a, int n) => (a.value >> n); public static ModInt operator ++(ModInt a) => a.value + 1; public static ModInt operator --(ModInt a) => a.value - 1; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Modpow(ModInt a, long n) { var k = a; ModInt ret = 1; while (n > 0) { if ((n & 1) != 0) ret *= k; k *= k; n >>= 1; } return ret; } private static readonly List<long> Factorials = new List<long>() { 1 }; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(long n) { for (var i = Factorials.Count(); i <= n; i++) { Factorials.Add((Factorials[i - 1] * i) % MOD); } return Factorials[(int)n]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt nCr(long n, long r) { return n < r ? 0 : Fac(n) / (Fac(r) * Fac(n - r)); } public static explicit operator int(ModInt a) => (int)a.value; } static class Cin { public static string[] ReadSplit => Console.ReadLine().Split(); public static int[] ReadSplitInt => ConvertAll(Console.ReadLine().Split(), int.Parse); public static long[] ReadSplitLong => ConvertAll(Console.ReadLine().Split(), long.Parse); public static double[] ReadSplit_Double => ConvertAll(Console.ReadLine().Split(), double.Parse); public static string Str => Console.ReadLine(); public static int Int => int.Parse(Console.ReadLine()); public static long Long => long.Parse(Console.ReadLine()); public static double Double => double.Parse(Console.ReadLine()); public static T Conv<T>(string input) { if (typeof(T).Equals(typeof(ModInt))) { return (T)(dynamic)(long.Parse(input)); } return (T)Convert.ChangeType(input, typeof(T)); } public static void Input<T>(out T a) => a = Conv<T>(Console.ReadLine()); public static void Input<T, U>(out T a, out U b) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); } public static void Input<T, U, V>(out T a, out U b, out V c) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); } public static void Input<T, U, V, W>(out T a, out U b, out V c, out W d) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); } public static void Input<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var q = ReadSplit; a = Conv<T>(q[0]); b = Conv<U>(q[1]); c = Conv<V>(q[2]); d = Conv<W>(q[3]); e = Conv<X>(q[4]); } } static class Sc_out { public static void OutL(object s) => Console.WriteLine(s); public static void Out_Sep<T>(IEnumerable<T> s) => Console.WriteLine(string.Join(" ", s)); public static void Out_Sep<T>(IEnumerable<T> s, string sep) => Console.WriteLine(string.Join($"{sep}", s)); public static void Out_Sep(params object[] s) => Console.WriteLine(string.Join(" ", s)); public static void Out_One(object s) => Console.Write($"{s} "); public static void Out_One(object s, string sep) => Console.Write($"{s}{sep}"); public static void Endl() => Console.WriteLine(); } public static class Tool { static public void Initialize<T>(ref T[] array, T initialvalue) { array = ConvertAll(array, x => initialvalue); } static public void Swap<T>(ref T a, ref T b) { T keep = a; a = b; b = keep; } static public void Display<T>(T[,] array2d, int n, int m) { for (var i = 0; i < n; i++) { for (var j = 0; j < m; j++) { Console.Write($"{array2d[i, j]} "); } Console.WriteLine(); } } static public long Gcd(long a, long b) { if (a == 0 || b == 0) return Max(a, b); return a % b == 0 ? b : Gcd(b, a % b); } static public long LPow(int a, int b) => (long)Pow(a, b); static public bool Bit(long x, int dig) => ((1L << dig) & x) != 0; static public int Sig(long a) => a == 0 ? 0 : (int)(a / Abs(a)); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
2,915
2
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using static System.Math; using pair = Pair<long, long>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); int T = int.Parse(ReadLine()); for (int i = 0; i < T; i++) { // Write($"Case #{i + 1}: "); new Program().solve(); } Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { int N = cin.nextint; var K = new int[N]; var L = new long[N]; var R = new long[N]; var A = new List<pair>(); var B = new List<pair>(); long sum = 0; for (int i = 0; i < N; i++) { K[i] = cin.nextint; L[i] = cin.nextint; R[i] = cin.nextint; sum += R[i]; if (L[i] - R[i] > 0) { A.Add(new pair(K[i], L[i] - R[i])); } else if (L[i] - R[i] < 0) { B.Add(new pair(-K[i], R[i] - L[i])); } } var P = new PriorityQueue<long>(-1); A.Sort(); foreach (var v in A) { long k = v.f; //先頭がk個より少ない if (P.Count < k) { P.Enqueue(v.s); sum += v.s; } else if (P.Count == k) { if (P.Peek < v.s) { var d = P.Dequeue(); sum -= d; P.Enqueue(v.s); sum += d; } } else { throw new IndexOutOfRangeException(); } } var Q = new PriorityQueue<long>(-1); B.Sort(); foreach (var v in B) { long k = N + v.f; // WriteLine($"k={k}"); if (k == 0) { sum -= v.s; } else if (Q.Count < k) { Q.Enqueue(v.s); } else if (Q.Count == k) { if (Q.Peek < v.s) { var d = Q.Dequeue(); sum -= d; Q.Enqueue(v.s); } else { sum -= v.s; } } else { throw new IndexOutOfRangeException(); } } WriteLine(sum); } } class PriorityQueue<T> where T : IComparable<T> { List<T> heap; readonly int cmp; public PriorityQueue(int cmp = 1) { heap = new List<T>(); this.cmp = cmp; } public void Enqueue(T x) { heap.Add(x); int i = Count++; while (i > 0) { int p = (i - 1) >> 1; if (x.CompareTo(heap[p]) * cmp <= 0) break; heap[i] = heap[p]; i = p; } heap[i] = x; } public T Dequeue() { T ret = heap[0]; T x = heap[--Count]; int i = 0; while ((i << 1) + 1 < Count) { int a = (i << 1) + 1; int b = (i << 1) + 2; if (b < Count && heap[a].CompareTo(heap[b]) * cmp < 0) a = b; if (x.CompareTo(heap[a]) * cmp >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(Count); return ret; } public int Count { get; private set; } public bool Any => Count > 0; public T Peek => heap[0]; } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => Array.ConvertAll(scan, double.Parse); public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
using System; using System.Collections.Generic; using System.Linq; using System.IO; using SB = System.Text.StringBuilder; // using System.Text.RegularExpressions; // using System.Globalization; // using System.Diagnostics; using static System.Console; using static System.Math; using pair = Pair<long, long>; class Program { static void Main() { SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); int T = int.Parse(ReadLine()); for (int i = 0; i < T; i++) { // Write($"Case #{i + 1}: "); new Program().solve(); } Out.Flush(); } readonly Scanner cin = new Scanner(); readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑ readonly int mod = 1000000007; readonly int dom = 998244353; bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; } bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; } void solve() { int N = cin.nextint; var K = new int[N]; var L = new long[N]; var R = new long[N]; var A = new List<pair>(); var B = new List<pair>(); long sum = 0; for (int i = 0; i < N; i++) { K[i] = cin.nextint; L[i] = cin.nextint; R[i] = cin.nextint; sum += R[i]; if (L[i] - R[i] > 0) { A.Add(new pair(K[i], L[i] - R[i])); } else if (L[i] - R[i] < 0) { B.Add(new pair(-K[i], R[i] - L[i])); } } var P = new PriorityQueue<long>(-1); A.Sort(); foreach (var v in A) { long k = v.f; //先頭がk個より少ない if (P.Count < k) { P.Enqueue(v.s); sum += v.s; } else if (P.Count == k) { if (P.Peek < v.s) { var d = P.Dequeue(); sum -= d; P.Enqueue(v.s); sum += v.s; } } else { throw new IndexOutOfRangeException(); } } var Q = new PriorityQueue<long>(-1); B.Sort(); foreach (var v in B) { long k = N + v.f; // WriteLine($"k={k}"); if (k == 0) { sum -= v.s; } else if (Q.Count < k) { Q.Enqueue(v.s); } else if (Q.Count == k) { if (Q.Peek < v.s) { var d = Q.Dequeue(); sum -= d; Q.Enqueue(v.s); } else { sum -= v.s; } } else { throw new IndexOutOfRangeException(); } } WriteLine(sum); } } class PriorityQueue<T> where T : IComparable<T> { List<T> heap; readonly int cmp; public PriorityQueue(int cmp = 1) { heap = new List<T>(); this.cmp = cmp; } public void Enqueue(T x) { heap.Add(x); int i = Count++; while (i > 0) { int p = (i - 1) >> 1; if (x.CompareTo(heap[p]) * cmp <= 0) break; heap[i] = heap[p]; i = p; } heap[i] = x; } public T Dequeue() { T ret = heap[0]; T x = heap[--Count]; int i = 0; while ((i << 1) + 1 < Count) { int a = (i << 1) + 1; int b = (i << 1) + 2; if (b < Count && heap[a].CompareTo(heap[b]) * cmp < 0) a = b; if (x.CompareTo(heap[a]) * cmp >= 0) break; heap[i] = heap[a]; i = a; } heap[i] = x; heap.RemoveAt(Count); return ret; } public int Count { get; private set; } public bool Any => Count > 0; public T Peek => heap[0]; } static class Ex { public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values)); public static string concat<T>(this IEnumerable<T> values) => string.Concat(values); public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); } public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) < 0) low = mid + 1; else high = mid; } return low; } public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T> { int low = 0, high = arr.Count; int mid; while (low < high) { mid = ((high - low) >> 1) + low; if (arr[mid].CompareTo(val) <= 0) low = mid + 1; else high = mid; } return low; } } class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U> { public T f; public U s; public Pair(T f, U s) { this.f = f; this.s = s; } public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s); public override string ToString() => $"{f} {s}"; } class Scanner { string[] s; int i; readonly char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string[] scan => ReadLine().Split(); public int[] scanint => Array.ConvertAll(scan, int.Parse); public long[] scanlong => Array.ConvertAll(scan, long.Parse); public double[] scandouble => Array.ConvertAll(scan, double.Parse); public string next { get { if (i < s.Length) return s[i++]; string st = ReadLine(); while (st == "") st = ReadLine(); s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return next; } } public int nextint => int.Parse(next); public long nextlong => long.Parse(next); public double nextdouble => double.Parse(next); }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 205, 22], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 0, 131], ["+", 64, 196, 0, 1, 0, 11, 12, 214, 141, 22]]
8
1,621
4
using System; using System.Linq; using System.Collections.Generic; namespace Contest { class Program { static void Main(string[] args) { // ABC031.D(); Aising2020.E(); } class Aising2020 { public static void A() { var L = Read.Int(); var R = Read.Int(); var D = Read.Int(); Console.WriteLine(R / D - (L - 1) / D); } public static void B() { var N = Read.Int(); var A = Read.IntN(); Console.WriteLine( A.Select((x, i) => x % 2 == 1 && i % 2 == 0 ? 1 : 0).Sum()); } public static void C() { var N = Read.Int(); int[] count = new int[2000000]; for (int x = 1; x <= 100; ++x) { for (int y = 1; y <= 100; ++y) { for (int z = 1; z <= 100; ++z) { var v = x * x + y * y + z * z + x * y + y * z + x * z; count[v]++; } } } Console.WriteLine( String.Join(Environment.NewLine, count.Skip(1).Take(N))); } public static void D() { var N = Read.Int(); var X = Read.Str(); var value = new int[N]; var ans = Enumerable.Range(0, N).Select(i => -1).ToArray(); int bit = 0; for (int i = 0; i < N; ++i) { bit += X[i] == '1' ? 1 : 0; } var p1 = bit + 1; var p2 = Math.Max(1, bit - 1); int a1 = 0, a2 = 0; for (int i = 0; i < N; ++i) { a1 = (a1 * 2 + (X[i] == '1' ? 1 : 0)) % p1; a2 = (a2 * 2 + (X[i] == '1' ? 1 : 0)) % p2; } var pow1 = 1; var pow2 = 1; for (int i = N - 1; i >= 0; --i) { if (X[i] == '1') { if (bit == 1) { ans[i] = 0; } else { var v = (a2 + p2 - (pow2 % p2)) % p2; int count = 1; while (v > 0) { var b = BitwiseOperation.Count1((ulong)v); v = v % b; count++; } ans[i] = count; } } else { var v = (a1 + pow1) % p1; int count = 1; while (v > 0) { var b = BitwiseOperation.Count1((ulong)v); v = v % b; count++; } ans[i] = count; } pow1 = (pow1 * 2) % p1; pow2 = (pow2 * 2) % p2; } Console.WriteLine(String.Join(Environment.NewLine, ans)); } public static void E() { var T = Read.Int(); var ans = new List<long>(); for (int t = 0; t < T; ++t) { var N = Read.Int(); var KLR = Enumerable.Range(0, N).Select(i => Read.LongN()).ToArray(); // var list = new List<Tuple<bool, int, long>>(); var listA = new List<Tuple<int, long>>(); var listB = new List<Tuple<int, long>>(); long sum = 0; foreach (var klr in KLR) { sum += Math.Min(klr[1], klr[2]); var D = klr[1] - klr[2]; // if (D != 0) //{ // list.Add(new Tuple<bool, int, long>(D > 0, (int)klr[0] - 1, // Math.Abs(D))); //} if (D > 0) { listA.Add(new Tuple<int, long>((int)klr[0] - 1, Math.Abs(D))); } else { listB.Add(new Tuple<int, long>(N - 1 - (int)klr[0], Math.Abs(D))); } } listA = listA.OrderBy(x => -x.Item2).ToList(); listB = listB.OrderBy(x => -x.Item2).ToList(); sum += E_Max(listA, N); sum += E_Max(listB, N); // int min = 0; // int max = listA.Count + 1; // while(min < max - 1) //{ // var mid = (min + max) / 2; // if (E_OK(listA, mid)) // { // min = mid; // } // else // { // max = mid; // } //} // for(int i = 0; i < min; ++i) //{ // sum += listA[i].Item2; //} // min = 0; // max = listB.Count + 1; // while (min < max - 1) //{ // var mid = (min + max) / 2; // if (E_OK(listB, mid)) // { // min = mid; // } // else // { // max = mid; // } //} // for (int i = 0; i < min; ++i) //{ // sum += listB[i].Item2; //} ans.Add(sum); } Console.WriteLine(String.Join(Environment.NewLine, ans)); } static long E_Max(List<Tuple<int, long>> list, int N) { long sum = 0; var bit = new Util.BIT(N + 10); for (int i = 1; i <= N; ++i) { bit.Add(i, 1); } for (int i = 0; i < list.Count; ++i) { var idx = list[i].Item1 + 1; if (bit.Sum(idx) == 0) { continue; } int min = 1; int max = idx + 1; var bidx = bit.Sum(idx); while (min + 1 < max) { var mid = (min + max) / 2; if (bit.Sum(mid) == bidx) { max = mid; } else { min = mid; } } sum += list[i].Item2; // Console.WriteLine(min); bit.Add(min + 1, -1); } return sum; } public static void F() {} } class Util { public static T[,] Gen<T>(int r, int c, T v) { var matrix = new T[r, c]; for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) { matrix[i, j] = v; } } return matrix; } 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[,] ASum(long[,] matrix) { var N = matrix.GetLength(0); var M = matrix.GetLength(1); var res = new long[N + 1, M + 1]; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { res[i + 1, j + 1] = res[i, j + 1] + res[i + 1, j] - res[i, j] + matrix[i, j]; } } return res; } // public static Dictionary<T, long> Frequency<T>(T[] array) //{ // var dict = new Dictionary<T, long>(); // foreach (var a in array) // { // if (!dict.ContainsKey(a)) { dict.Add(a, 0); } // dict[a]++; // } // return dict; //} public static MyDict<T, long> Frequency2<T>(T[] array) { var dict = new MyDict<T, long>(); foreach (var a in array) { dict[a]++; } return dict; } public static long Power(long a, long n, long p) { long res = 1; long mult = a; for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } 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; }; } public class BIT { int N; long[] array; public BIT(int m) { for (int n = 1;; n *= 2) { if (n >= m) { N = n; array = new long[N + 1]; break; } } } public void Add(int idx, int v) { for (int x = idx; x <= N; x += x & -x) { array[x] += v; } } public long Sum(int idx) { long ret = 0; for (int x = idx; x > 0; x -= x & -x) { ret += array[x]; } return ret; } } public class BST<T> where T : IComparable { public class Node { public T V; public Node L, R; public int Count; public Node(T v) { V = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.L) + Count(t.R) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.R = Merge(l.R, r); return Update(l); } else { r.L = Merge(l, r.L); return Update(r); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.L)) { var s = Split(t.L, k); t.L = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.R, k - Count(t.L) - 1); t.R = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.V.CompareTo(v); if (cmp > 0) t = t.L; else if (cmp < 0) t = t.R; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.R) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.L; currentIdx -= (Count(t == null ? null : t.R) + 1); } else { t = t.R; currentIdx += (Count(t == null ? null : t.L) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.R) - 1; while (t != null) { var cmp = t.V.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.L; idx -= (Count(t == null ? null : t.R) + 1); } else if (cmp <= 0) { t = t.R; idx += (Count(t == null ? null : t.L) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.R) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.V.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.L; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.R) + 1); } else if (cmp < 0) { t = t.R; idx += (Count(t == null ? null : t.L) + 1); if (t == null) return idx; } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.L, ret); ret.Add(t.V); Enumerate(t.R, ret); } } public class Set<T> where T : IComparable { protected BST<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return BST<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new BST<T>.Node(v); else { if (BST<T>.Find(_root, v) != null) return; _root = BST<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = BST<T>.Remove(_root, v); } public bool Contains(T v) { return BST<T>.Contains(_root, v); } public T ElementAt(int k) { var node = BST<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.V; } public int Count(T v) { return BST<T>.UpperBound(_root, v) - BST<T>.LowerBound(_root, v); } public int LowerBound(T v) { return BST<T>.LowerBound(_root, v); } public int UpperBound(T v) { return BST<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(BST<T>.LowerBound(_root, v), BST<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(BST<T>.Enumerate(_root)); } } public class MyDict<T1, T2> : Dictionary<T1, T2> { public new T2 this[T1 key] { get { if (!base.ContainsKey(key)) { base.Add(key, default(T2)); } return base[key]; } set { base[key] = value; } } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private bool _isAsc = true; private T[] _heap; private int _sz = 0; public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } public PriorityQueue(int maxSize, bool isAsc = true) { _heap = new T[maxSize]; _isAsc = isAsc; } private int Compare(T x, T y) { if (_comparer != null) { return _comparer.Compare(x, y); } return _isAsc ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { var i = _sz++; while (i > 0) { var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) { break; } _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { 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 _sz; } 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 class MyTuple<T1, T2> : IComparable where T1 : IComparable<T1> { public readonly T1 Item1; public readonly T2 Item2; public MyTuple(T1 item1, T2 item2) { Item1 = item1; Item2 = item2; } public int CompareTo(object obj) { return Item1.CompareTo(((MyTuple<T1, T2>)obj).Item1); } } public static long[] Dijkstra(Dictionary<int, Dictionary<int, long>> adj, int N, int M, int start) { long INF = 1000000000000000000; var dist = Enumerable.Range(0, N + 1).Select(i => INF).ToArray(); var queue = new PriorityQueue<MyTuple<long, int>>(N + M + 100); dist[start] = 0; queue.Push(new MyTuple<long, int>(0, start)); while (queue.Count() > 0) { var kvp = queue.Pop(); var d = kvp.Item1; var v = kvp.Item2; if (dist[v] < d) { continue; } foreach (var kvp2 in adj[v]) { var newV = kvp2.Key; var newD = dist[v] + kvp2.Value; if (newD < dist[newV]) { dist[newV] = newD; queue.Push(new MyTuple<long, int>(newD, newV)); } } } return dist; } } class Graph { public static HashSet<int> ConnectedComponent(Dictionary<int, HashSet<int>> adj, int idx) { HashSet<int> comp = new HashSet<int>(); comp.Add(idx); List<int> target = new List<int>(); target.Add(idx); while (target.Count > 0) { List<int> next = new List<int>(); foreach (var p in target) { foreach (var f in adj[p]) { if (!comp.Contains(f)) { next.Add(f); comp.Add(f); } } } target = next; } return comp; } public static int[] CalcDistance_OnTree(Dictionary<int, HashSet<int>> adj, int N, int start) { var dist = Enumerable.Range(0, N + 1).Select(i => -1).ToArray(); dist[start] = 0; Queue<int> queue = new Queue<int>(); queue.Enqueue(start); while (queue.Count > 0) { var v = queue.Dequeue(); foreach (var w in adj[v]) { if (dist[w] < 0) { dist[w] = dist[v] + 1; queue.Enqueue(w); } } } return dist; } public static long[] CalcDistance_OnTree( Dictionary<int, Dictionary<int, long>> adj, int N, int start) { var dist = Enumerable.Range(0, N + 1).Select(i => -1L).ToArray(); dist[start] = 0; Queue<int> queue = new Queue<int>(); queue.Enqueue(start); while (queue.Count > 0) { var v = queue.Dequeue(); foreach (var t in adj[v]) { var w = t.Key; var c = t.Value; if (dist[w] < 0) { dist[w] = dist[v] + c; queue.Enqueue(w); } } } return dist; } } struct MOD { public static long P = 1000000007; public readonly long V; public MOD(long a) { this.V = a % P; } 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() { 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) { long a = V, p = P; long res = 1; long mult = a; for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public override string ToString() { return V.ToString(); } } class BitwiseOperation { public static int Count1(UInt64 x) { UInt64 y = (x & 0x5555555555555555) + ((x >> 1) & 0x5555555555555555); y = (y & 0x3333333333333333) + ((y >> 2) & 0x3333333333333333); y = (y & 0x0f0f0f0f0f0f0f0f) + ((y >> 4) & 0x0f0f0f0f0f0f0f0f); y = (y & 0x00ff00ff00ff00ff) + ((y >> 8) & 0x00ff00ff00ff00ff); y = (y & 0x0000ffff0000ffff) + ((y >> 16) & 0x0000ffff0000ffff); return (int)((y & 0x00000000ffffffff) + ((y >> 32) & 0x00000000ffffffff)); } public static int MSB(UInt64 x) { if (x == 0) { return -1; } x |= (x >> 1); x |= (x >> 2); x |= (x >> 4); x |= (x >> 8); x |= (x >> 16); x |= (x >> 32); return Count1(x) - 1; } } 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 ulong[] ULongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToUInt64(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(); if (!dict[ab[0]].Contains(ab[1])) { dict[ab[0]].Add(ab[1]); } if (!isDirectional && !dict[ab[1]].Contains(ab[0])) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M, bool isDirectional = false) { 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]); if (!isDirectional) { 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) { // ABC031.D(); Aising2020.E(); } class Aising2020 { public static void A() { var L = Read.Int(); var R = Read.Int(); var D = Read.Int(); Console.WriteLine(R / D - (L - 1) / D); } public static void B() { var N = Read.Int(); var A = Read.IntN(); Console.WriteLine( A.Select((x, i) => x % 2 == 1 && i % 2 == 0 ? 1 : 0).Sum()); } public static void C() { var N = Read.Int(); int[] count = new int[2000000]; for (int x = 1; x <= 100; ++x) { for (int y = 1; y <= 100; ++y) { for (int z = 1; z <= 100; ++z) { var v = x * x + y * y + z * z + x * y + y * z + x * z; count[v]++; } } } Console.WriteLine( String.Join(Environment.NewLine, count.Skip(1).Take(N))); } public static void D() { var N = Read.Int(); var X = Read.Str(); var value = new int[N]; var ans = Enumerable.Range(0, N).Select(i => -1).ToArray(); int bit = 0; for (int i = 0; i < N; ++i) { bit += X[i] == '1' ? 1 : 0; } var p1 = bit + 1; var p2 = Math.Max(1, bit - 1); int a1 = 0, a2 = 0; for (int i = 0; i < N; ++i) { a1 = (a1 * 2 + (X[i] == '1' ? 1 : 0)) % p1; a2 = (a2 * 2 + (X[i] == '1' ? 1 : 0)) % p2; } var pow1 = 1; var pow2 = 1; for (int i = N - 1; i >= 0; --i) { if (X[i] == '1') { if (bit == 1) { ans[i] = 0; } else { var v = (a2 + p2 - (pow2 % p2)) % p2; int count = 1; while (v > 0) { var b = BitwiseOperation.Count1((ulong)v); v = v % b; count++; } ans[i] = count; } } else { var v = (a1 + pow1) % p1; int count = 1; while (v > 0) { var b = BitwiseOperation.Count1((ulong)v); v = v % b; count++; } ans[i] = count; } pow1 = (pow1 * 2) % p1; pow2 = (pow2 * 2) % p2; } Console.WriteLine(String.Join(Environment.NewLine, ans)); } public static void E() { var T = Read.Int(); var ans = new List<long>(); for (int t = 0; t < T; ++t) { var N = Read.Int(); var KLR = Enumerable.Range(0, N).Select(i => Read.LongN()).ToArray(); // var list = new List<Tuple<bool, int, long>>(); var listA = new List<Tuple<int, long>>(); var listB = new List<Tuple<int, long>>(); long sum = 0; foreach (var klr in KLR) { sum += Math.Min(klr[1], klr[2]); var D = klr[1] - klr[2]; // if (D != 0) //{ // list.Add(new Tuple<bool, int, long>(D > 0, (int)klr[0] - 1, // Math.Abs(D))); //} if (D > 0) { listA.Add(new Tuple<int, long>((int)klr[0] - 1, Math.Abs(D))); } else { listB.Add(new Tuple<int, long>(N - 1 - (int)klr[0], Math.Abs(D))); } } listA = listA.OrderBy(x => -x.Item2).ToList(); listB = listB.OrderBy(x => -x.Item2).ToList(); sum += E_Max(listA, N); sum += E_Max(listB, N); // int min = 0; // int max = listA.Count + 1; // while(min < max - 1) //{ // var mid = (min + max) / 2; // if (E_OK(listA, mid)) // { // min = mid; // } // else // { // max = mid; // } //} // for(int i = 0; i < min; ++i) //{ // sum += listA[i].Item2; //} // min = 0; // max = listB.Count + 1; // while (min < max - 1) //{ // var mid = (min + max) / 2; // if (E_OK(listB, mid)) // { // min = mid; // } // else // { // max = mid; // } //} // for (int i = 0; i < min; ++i) //{ // sum += listB[i].Item2; //} ans.Add(sum); } Console.WriteLine(String.Join(Environment.NewLine, ans)); } static long E_Max(List<Tuple<int, long>> list, int N) { long sum = 0; var bit = new Util.BIT(N + 10); for (int i = 1; i <= N; ++i) { bit.Add(i, 1); } for (int i = 0; i < list.Count; ++i) { var idx = list[i].Item1 + 1; if (bit.Sum(idx) == 0) { continue; } int min = 0; int max = idx; var bidx = bit.Sum(idx); while (min + 1 < max) { var mid = (min + max) / 2; if (bit.Sum(mid) == bidx) { max = mid; } else { min = mid; } } sum += list[i].Item2; // Console.WriteLine(min); bit.Add(min + 1, -1); } return sum; } public static void F() {} } class Util { public static T[,] Gen<T>(int r, int c, T v) { var matrix = new T[r, c]; for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) { matrix[i, j] = v; } } return matrix; } 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[,] ASum(long[,] matrix) { var N = matrix.GetLength(0); var M = matrix.GetLength(1); var res = new long[N + 1, M + 1]; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) { res[i + 1, j + 1] = res[i, j + 1] + res[i + 1, j] - res[i, j] + matrix[i, j]; } } return res; } // public static Dictionary<T, long> Frequency<T>(T[] array) //{ // var dict = new Dictionary<T, long>(); // foreach (var a in array) // { // if (!dict.ContainsKey(a)) { dict.Add(a, 0); } // dict[a]++; // } // return dict; //} public static MyDict<T, long> Frequency2<T>(T[] array) { var dict = new MyDict<T, long>(); foreach (var a in array) { dict[a]++; } return dict; } public static long Power(long a, long n, long p) { long res = 1; long mult = a; for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } 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; }; } public class BIT { int N; long[] array; public BIT(int m) { for (int n = 1;; n *= 2) { if (n >= m) { N = n; array = new long[N + 1]; break; } } } public void Add(int idx, int v) { for (int x = idx; x <= N; x += x & -x) { array[x] += v; } } public long Sum(int idx) { long ret = 0; for (int x = idx; x > 0; x -= x & -x) { ret += array[x]; } return ret; } } public class BST<T> where T : IComparable { public class Node { public T V; public Node L, R; public int Count; public Node(T v) { V = v; Count = 1; } } static Random _rnd = new Random(); public static int Count(Node t) { return t == null ? 0 : t.Count; } static Node Update(Node t) { t.Count = Count(t.L) + Count(t.R) + 1; return t; } public static Node Merge(Node l, Node r) { if (l == null || r == null) return l == null ? r : l; if ((double)Count(l) / (double)(Count(l) + Count(r)) > _rnd.NextDouble()) { l.R = Merge(l.R, r); return Update(l); } else { r.L = Merge(l, r.L); return Update(r); } } public static Tuple<Node, Node> Split(Node t, int k) { if (t == null) return new Tuple<Node, Node>(null, null); if (k <= Count(t.L)) { var s = Split(t.L, k); t.L = s.Item2; return new Tuple<Node, Node>(s.Item1, Update(t)); } else { var s = Split(t.R, k - Count(t.L) - 1); t.R = s.Item1; return new Tuple<Node, Node>(Update(t), s.Item2); } } public static Node Remove(Node t, T v) { if (Find(t, v) == null) return t; return RemoveAt(t, LowerBound(t, v)); } public static Node RemoveAt(Node t, int k) { var s = Split(t, k); var s2 = Split(s.Item2, 1); return Merge(s.Item1, s2.Item2); } public static bool Contains(Node t, T v) { return Find(t, v) != null; } public static Node Find(Node t, T v) { while (t != null) { var cmp = t.V.CompareTo(v); if (cmp > 0) t = t.L; else if (cmp < 0) t = t.R; else break; } return t; } public static Node FindByIndex(Node t, int idx) { if (t == null) return null; var currentIdx = Count(t) - Count(t.R) - 1; while (t != null) { if (currentIdx == idx) return t; if (currentIdx > idx) { t = t.L; currentIdx -= (Count(t == null ? null : t.R) + 1); } else { t = t.R; currentIdx += (Count(t == null ? null : t.L) + 1); } } return null; } public static int UpperBound(Node t, T v) { var torg = t; if (t == null) return -1; var ret = Int32.MaxValue; var idx = Count(t) - Count(t.R) - 1; while (t != null) { var cmp = t.V.CompareTo(v); if (cmp > 0) { ret = Math.Min(ret, idx); t = t.L; idx -= (Count(t == null ? null : t.R) + 1); } else if (cmp <= 0) { t = t.R; idx += (Count(t == null ? null : t.L) + 1); } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static int LowerBound(Node t, T v) { var torg = t; if (t == null) return -1; var idx = Count(t) - Count(t.R) - 1; var ret = Int32.MaxValue; while (t != null) { var cmp = t.V.CompareTo(v); if (cmp >= 0) { if (cmp == 0) ret = Math.Min(ret, idx); t = t.L; if (t == null) ret = Math.Min(ret, idx); idx -= t == null ? 0 : (Count(t.R) + 1); } else if (cmp < 0) { t = t.R; idx += (Count(t == null ? null : t.L) + 1); if (t == null) return idx; } } return ret == Int32.MaxValue ? Count(torg) : ret; } public static Node Insert(Node t, T v) { var ub = LowerBound(t, v); return InsertByIdx(t, ub, v); } static Node InsertByIdx(Node t, int k, T v) { var s = Split(t, k); return Merge(Merge(s.Item1, new Node(v)), s.Item2); } public static IEnumerable<T> Enumerate(Node t) { var ret = new List<T>(); Enumerate(t, ret); return ret; } static void Enumerate(Node t, List<T> ret) { if (t == null) return; Enumerate(t.L, ret); ret.Add(t.V); Enumerate(t.R, ret); } } public class Set<T> where T : IComparable { protected BST<T>.Node _root; public T this[int idx] { get { return ElementAt(idx); } } public int Count() { return BST<T>.Count(_root); } public virtual void Insert(T v) { if (_root == null) _root = new BST<T>.Node(v); else { if (BST<T>.Find(_root, v) != null) return; _root = BST<T>.Insert(_root, v); } } public void Clear() { _root = null; } public void Remove(T v) { _root = BST<T>.Remove(_root, v); } public bool Contains(T v) { return BST<T>.Contains(_root, v); } public T ElementAt(int k) { var node = BST<T>.FindByIndex(_root, k); if (node == null) throw new IndexOutOfRangeException(); return node.V; } public int Count(T v) { return BST<T>.UpperBound(_root, v) - BST<T>.LowerBound(_root, v); } public int LowerBound(T v) { return BST<T>.LowerBound(_root, v); } public int UpperBound(T v) { return BST<T>.UpperBound(_root, v); } public Tuple<int, int> EqualRange(T v) { if (!Contains(v)) return new Tuple<int, int>(-1, -1); return new Tuple<int, int>(BST<T>.LowerBound(_root, v), BST<T>.UpperBound(_root, v) - 1); } public List<T> ToList() { return new List<T>(BST<T>.Enumerate(_root)); } } public class MyDict<T1, T2> : Dictionary<T1, T2> { public new T2 this[T1 key] { get { if (!base.ContainsKey(key)) { base.Add(key, default(T2)); } return base[key]; } set { base[key] = value; } } } public class PriorityQueue<T> where T : IComparable { private IComparer<T> _comparer = null; private bool _isAsc = true; private T[] _heap; private int _sz = 0; public PriorityQueue(int maxSize, IComparer<T> comparer) { _heap = new T[maxSize]; _comparer = comparer; } public PriorityQueue(int maxSize, bool isAsc = true) { _heap = new T[maxSize]; _isAsc = isAsc; } private int Compare(T x, T y) { if (_comparer != null) { return _comparer.Compare(x, y); } return _isAsc ? x.CompareTo(y) : y.CompareTo(x); } public void Push(T x) { var i = _sz++; while (i > 0) { var p = (i - 1) / 2; if (Compare(_heap[p], x) <= 0) { break; } _heap[i] = _heap[p]; i = p; } _heap[i] = x; } public T Pop() { T ret = _heap[0]; T x = _heap[--_sz]; int i = 0; while (i * 2 + 1 < _sz) { 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 _sz; } 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 class MyTuple<T1, T2> : IComparable where T1 : IComparable<T1> { public readonly T1 Item1; public readonly T2 Item2; public MyTuple(T1 item1, T2 item2) { Item1 = item1; Item2 = item2; } public int CompareTo(object obj) { return Item1.CompareTo(((MyTuple<T1, T2>)obj).Item1); } } public static long[] Dijkstra(Dictionary<int, Dictionary<int, long>> adj, int N, int M, int start) { long INF = 1000000000000000000; var dist = Enumerable.Range(0, N + 1).Select(i => INF).ToArray(); var queue = new PriorityQueue<MyTuple<long, int>>(N + M + 100); dist[start] = 0; queue.Push(new MyTuple<long, int>(0, start)); while (queue.Count() > 0) { var kvp = queue.Pop(); var d = kvp.Item1; var v = kvp.Item2; if (dist[v] < d) { continue; } foreach (var kvp2 in adj[v]) { var newV = kvp2.Key; var newD = dist[v] + kvp2.Value; if (newD < dist[newV]) { dist[newV] = newD; queue.Push(new MyTuple<long, int>(newD, newV)); } } } return dist; } } class Graph { public static HashSet<int> ConnectedComponent(Dictionary<int, HashSet<int>> adj, int idx) { HashSet<int> comp = new HashSet<int>(); comp.Add(idx); List<int> target = new List<int>(); target.Add(idx); while (target.Count > 0) { List<int> next = new List<int>(); foreach (var p in target) { foreach (var f in adj[p]) { if (!comp.Contains(f)) { next.Add(f); comp.Add(f); } } } target = next; } return comp; } public static int[] CalcDistance_OnTree(Dictionary<int, HashSet<int>> adj, int N, int start) { var dist = Enumerable.Range(0, N + 1).Select(i => -1).ToArray(); dist[start] = 0; Queue<int> queue = new Queue<int>(); queue.Enqueue(start); while (queue.Count > 0) { var v = queue.Dequeue(); foreach (var w in adj[v]) { if (dist[w] < 0) { dist[w] = dist[v] + 1; queue.Enqueue(w); } } } return dist; } public static long[] CalcDistance_OnTree( Dictionary<int, Dictionary<int, long>> adj, int N, int start) { var dist = Enumerable.Range(0, N + 1).Select(i => -1L).ToArray(); dist[start] = 0; Queue<int> queue = new Queue<int>(); queue.Enqueue(start); while (queue.Count > 0) { var v = queue.Dequeue(); foreach (var t in adj[v]) { var w = t.Key; var c = t.Value; if (dist[w] < 0) { dist[w] = dist[v] + c; queue.Enqueue(w); } } } return dist; } } struct MOD { public static long P = 1000000007; public readonly long V; public MOD(long a) { this.V = a % P; } 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() { 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) { long a = V, p = P; long res = 1; long mult = a; for (int i = 0; i < 63; ++i) { if ((n & ((long)1 << i)) > 0) { res = (res * mult) % p; } mult = (mult * mult) % p; } return res; } public override string ToString() { return V.ToString(); } } class BitwiseOperation { public static int Count1(UInt64 x) { UInt64 y = (x & 0x5555555555555555) + ((x >> 1) & 0x5555555555555555); y = (y & 0x3333333333333333) + ((y >> 2) & 0x3333333333333333); y = (y & 0x0f0f0f0f0f0f0f0f) + ((y >> 4) & 0x0f0f0f0f0f0f0f0f); y = (y & 0x00ff00ff00ff00ff) + ((y >> 8) & 0x00ff00ff00ff00ff); y = (y & 0x0000ffff0000ffff) + ((y >> 16) & 0x0000ffff0000ffff); return (int)((y & 0x00000000ffffffff) + ((y >> 32) & 0x00000000ffffffff)); } public static int MSB(UInt64 x) { if (x == 0) { return -1; } x |= (x >> 1); x |= (x >> 2); x |= (x >> 4); x |= (x >> 8); x |= (x >> 16); x |= (x >> 32); return Count1(x) - 1; } } 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 ulong[] ULongN() { return Console.ReadLine() .Split(' ') .Select(s => Convert.ToUInt64(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(); if (!dict[ab[0]].Contains(ab[1])) { dict[ab[0]].Add(ab[1]); } if (!isDirectional && !dict[ab[1]].Contains(ab[0])) { dict[ab[1]].Add(ab[0]); } } return dict; } public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M, bool isDirectional = false) { 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]); if (!isDirectional) { dict[ab[1]].Add(ab[0], ab[2]); } } return dict; } } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
6,596
4
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(ReadLine()); if (n % 1000 == 0) { WriteLine(n / 1000); } else { WriteLine(n - n % 1000); } } }
using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static void Main(string[] args) { int n = int.Parse(ReadLine()); if (n % 1000 == 0) { WriteLine(0); } else { WriteLine(1000 - n % 1000); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 31, 203]]
8
77
6
using System; class A { static void Main() { var a = int.Parse(Console.ReadLine()); while (a >= 1000) a -= 1000; Console.WriteLine(a == 1000 ? 1000 - a : 0); } }
using System; class A { static void Main() { var a = int.Parse(Console.ReadLine()); while (a >= 1000) a -= 1000; Console.WriteLine(a == 0 ? 0 : 1000 - a); } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 64, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 0, 102], ["-", 0, 213, 3, 4, 0, 28, 0, 41, 75, 203]]
8
53
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A { class Program { static void Main(string[] args) { string line = Console.ReadLine(); // tstring[] strs = line.Split(' '); int N = int.Parse(line); Console.WriteLine(1000 - (N % 1000)); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A { class Program { static void Main(string[] args) { string line = Console.ReadLine(); // tstring[] strs = line.Split(' '); int N = int.Parse(line); Console.WriteLine((1000 - (N % 1000)) % 1000); } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 109], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
79
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 n = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); var result = n % 1000; if (result == 0) { result = n; } Console.WriteLine(1000 - result); } } }
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 n = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); var result = n % 1000; if (result == 0) { result = 1000; } Console.WriteLine(1000 - result); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 203]]
8
94
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var p = Console.ReadLine().ToInt(); Console.WriteLine(p + p * p * p * p * p); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var p = Console.ReadLine().ToInt(); Console.WriteLine(p + p * p + p * p * p); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
[["-", 0, 16, 12, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
275
2
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(" "); var N = int.Parse(input[0]); var M = int.Parse(input[1]); var K = int.Parse(input[2]); var A = new List<int>(); var line = Console.ReadLine().Split(" "); for (int i = 0; i < N; i++) { A.Add(int.Parse(line[i])); }; var B = new List<int>(); var line2 = Console.ReadLine().Split(" "); for (int i = 0; i < M; i++) { B.Add(int.Parse(line2[i])); }; var count = 0; long sum = 0; var left = -1; for (; left < N - 1;) { left++; sum += A[left]; if (sum > K) { sum -= A[left]; left--; break; } count++; } var right = -1; var countMax = count; for (; right < M - 1; right++) { right++; sum += B[right]; while (sum > K) { if (left < 0) { break; } sum -= A[left]; left--; count--; } if (sum > K) { break; } count++; countMax = Math.Max(countMax, count); } Console.WriteLine(countMax); } }
using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(" "); var N = int.Parse(input[0]); var M = int.Parse(input[1]); var K = int.Parse(input[2]); var A = new List<int>(); var line = Console.ReadLine().Split(" "); for (int i = 0; i < N; i++) { A.Add(int.Parse(line[i])); }; var B = new List<int>(); var line2 = Console.ReadLine().Split(" "); for (int i = 0; i < M; i++) { B.Add(int.Parse(line2[i])); }; var count = 0; long sum = 0; var left = -1; for (; left < N - 1;) { left++; sum += A[left]; if (sum > K) { sum -= A[left]; left--; break; } count++; } var right = -1; var countMax = count; for (; right < M - 1;) { right++; sum += B[right]; while (sum > K) { if (left < 0) { break; } sum -= A[left]; left--; count--; } if (sum > K) { break; } count++; countMax = Math.Max(countMax, count); } Console.WriteLine(countMax); } }
[["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 22], ["-", 0, 195, 8, 196, 0, 7, 26, 223, 0, 29]]
8
371
2
using System; class C { static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); static void Main() { int[] n = Read(), a = Read(), b = Read(), c = new int[n[0] + 1], d = new int[n[1] + 1]; int s = 0, j = n[1]; for (int i = 1; i <= n[0]; i++) c[i] = c[i - 1] + a[i - 1]; for (int i = 1; i <= n[1]; i++) d[i] = d[i - 1] + b[i - 1]; for (int i = 0; i <= n[0]; i++) { if (c[i] > n[2]) break; while (d[j] > n[2] - c[i]) j--; s = Math.Max(s, i + j); } Console.WriteLine(s); } }
using System; class C { static long[] Read() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); static void Main() { long[] n = Read(), a = Read(), b = Read(), c = new long[n[0] + 1], d = new long[n[1] + 1]; long s = 0, j = n[1]; for (int i = 1; i <= n[0]; i++) c[i] = c[i - 1] + a[i - 1]; for (int i = 1; i <= n[1]; i++) d[i] = d[i - 1] + b[i - 1]; for (int i = 0; i <= n[0]; i++) { if (c[i] > n[2]) break; while (d[j] > n[2] - c[i]) j--; s = Math.Max(s, i + j); } Console.WriteLine(s); } }
[["-", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["+", 0, 235, 8, 201, 0, 195, 39, 224, 39, 199], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["+", 0, 213, 3, 4, 0, 28, 0, 214, 205, 199], ["-", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["+", 8, 196, 0, 197, 0, 198, 39, 224, 39, 199], ["-", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["+", 0, 200, 0, 212, 0, 227, 39, 224, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
245
12
using System; using System.Linq; namespace AtCoder.Abcdef { public class QuestionC { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // Input int array int[] inputArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); (int n, int m, long k) = (inputArray[0], inputArray[1], inputArray[2]); var a = (Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray()); var b = (Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray()); long t = b.Sum(); var j = b.Length; var ans = 0; for (int i = 0; i < a.Length + 1; i++) { while (j > 0 && t > k) { j--; t -= b[j]; } if (t > k) break; ans = Math.Max(ans, i + j); if (i == a.Length) break; t += a[i]; } Console.WriteLine(ans); Console.Out.Flush(); } } }
using System; using System.Linq; namespace AtCoder.Abcdef { public class QuestionC { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // Input int array int[] inputArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); (int n, int m, long k) = (inputArray[0], inputArray[1], inputArray[2]); var a = (Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray()); var b = (Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray()); long t = b.Sum(); var j = b.Length; var ans = 0; for (int i = 0; i < a.Length + 1; i++) { while (j > 0 && t > k) { j--; t -= b[j]; } if (t > k) break; ans = Math.Max(ans, i + j); if (i == a.Length) break; t += a[i]; } Console.WriteLine(ans); Console.Out.Flush(); } } }
[["-", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199], ["+", 0, 28, 0, 218, 8, 213, 63, 214, 205, 199]]
8
307
4
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; namespace C_ABC172 { class MainClass { static long[] s, a, b; public static void Main(string[] args) { s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse); a = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse); b = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse); long n = s[0]; long m = s[1]; long k = s[2]; var sa = new List<long>(); var sb = new List<long>(); sa.Add(0); long atmp = 0; long btmp = 0; bool aover = false; bool bover = false; for (long i = 0; i < Max(m, n); i++) { if (!aover && !bover) { atmp += a[i]; if (atmp <= k) { sa.Add(atmp); if (i == n - 1) aover = true; } else { aover = true; } btmp += b[i]; if (btmp <= k) { sb.Add(btmp); if (i == m - 1) bover = true; } else { bover = true; } } else if (!aover) { atmp += a[i]; if (atmp <= k) { sa.Add(atmp); if (i == n - 1) aover = true; } else { aover = true; } } else if (!bover) { btmp += b[i]; if (btmp <= k) { sb.Add(btmp); if (i == m - 1) bover = true; } else { bover = true; } } else { break; } } long ans = 0; var sbb = sb.ToArray(); for (int i = 0; i < sa.Count; i++) { var t = LowerBound(sbb, (k - sa[i])); // WriteLine("t: {0} i: {1}", t, i); if (t < sb.Count && sbb[t] == k - sa[i]) { // WriteLine("here"); t++; } else if (t == sb.Count) { // WriteLine("here2"); t--; } ans = Max(ans, t + (i)); } WriteLine(ans); } public static int LowerBound<T>(T[] a, T v) { return LowerBound(a, v, Comparer<T>.Default); } public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp) { var l = 0; var r = a.Length - 1; while (l <= r) { var mid = l + (r - l) / 2; var res = cmp.Compare(a[mid], v); if (res == -1) l = mid + 1; else r = mid - 1; } return l; } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using static System.Math; namespace C_ABC172 { class MainClass { static long[] s, a, b; public static void Main(string[] args) { s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse); a = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse); b = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse); long n = s[0]; long m = s[1]; long k = s[2]; var sa = new List<long>(); var sb = new List<long>(); sa.Add(0); long atmp = 0; long btmp = 0; bool aover = false; bool bover = false; for (long i = 0; i < Max(m, n); i++) { if (!aover && !bover) { atmp += a[i]; if (atmp <= k) { sa.Add(atmp); if (i == n - 1) aover = true; } else { aover = true; } btmp += b[i]; if (btmp <= k) { sb.Add(btmp); if (i == m - 1) bover = true; } else { bover = true; } } else if (!aover) { atmp += a[i]; if (atmp <= k) { sa.Add(atmp); if (i == n - 1) aover = true; } else { aover = true; } } else if (!bover) { btmp += b[i]; if (btmp <= k) { sb.Add(btmp); if (i == m - 1) bover = true; } else { bover = true; } } else { break; } } long ans = 0; var sbb = sb.ToArray(); for (int i = 0; i < sa.Count; i++) { var t = LowerBound(sbb, (k - sa[i])); // WriteLine("t: {0} i: {1}", t, i); if (t < sb.Count && sbb[t] == k - sa[i]) { // WriteLine("here"); t++; } else if (t == sb.Count) { // WriteLine("here2"); // t--; } ans = Max(ans, t + (i)); } WriteLine(ans); } public static int LowerBound<T>(T[] a, T v) { return LowerBound(a, v, Comparer<T>.Default); } public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp) { var l = 0; var r = a.Length - 1; while (l <= r) { var mid = l + (r - l) / 2; var res = cmp.Compare(a[mid], v); if (res == -1) l = mid + 1; else r = mid - 1; } return l; } } }
[["-", 75, 57, 64, 196, 0, 1, 0, 223, 0, 22], ["-", 75, 57, 64, 196, 0, 1, 0, 223, 0, 68], ["-", 0, 57, 75, 57, 64, 196, 0, 1, 0, 35]]
8
654
3
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc172 { 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_abc172C2(); Console.Out.Flush(); } // https://atcoder.jp/contests/abc172/submissions/14749792 public static void solve_abc172C2() { long[] nmk = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long n = nmk[0]; long m = nmk[1]; k = nmk[2]; long[] a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long[] b = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long aSum = 0; for (int i = 0; i < n; i++) { aSum += a[i]; } long bSum = 0; long j = 0; long ans = 0; for (long i = n - 1; i >= 0; i--) { if (i < n) { aSum -= a[i]; } if (aSum <= k) { while (j < m && aSum + bSum + b[j] <= k) { bSum += b[j]; j++; } ans = Math.Max(ans, i + j); } } Console.WriteLine(ans); } /* Increment in the parameters doesn't work in recursive calls Example: getTotal(cnt++); Should be gettotal(cnt + 1); */ public static long getTotal(long sum, long cnt, long idx1, long idx2) { if (idx1 < a.Length) { if (sum + a[idx1] < k) { total = Math.Max(total, getTotal(sum + a[idx1], cnt + 1, idx1 + 1, idx2)); } } if (idx2 < b.Length) { if (sum + b[idx2] < k) { total = Math.Max(total, getTotal(sum + b[idx2], cnt + 1, idx1, idx2 + 1)); } } return cnt; } public static long[] a; public static long[] b; public static long k; public static long total = 0; public static void solve_abc172C() { long[] nmk = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long n = nmk[0]; long m = nmk[1]; k = nmk[2]; a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); b = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); Console.WriteLine(getTotal(0, 0, 0, 0)); /*long min = 0; long cnt = 0; long i = 0; long j = 0; while (i < n || j < m) { if (i >= n && j < m) { if (min + b[j] <= k) { min += b[j]; cnt++; } j++; } else if (j >= m && i < n) { if (min + a[i] <= k) { min += a[i]; cnt++; } i++; } else { if (min + Math.Min(a[i], b[j]) <= k) { min += Math.Min(a[i], b[j]); cnt++; } else { break; } if (a[i] < b[j]) { i++; } else { j++; } } } Console.WriteLine(cnt); */ } public static void solve_abc172B() { string s = Console.ReadLine(); string t = Console.ReadLine(); int cnt = 0; for (int i = 0; i < s.Length; i++) { if (s[i] != t[i]) { cnt++; } } Console.WriteLine(cnt); } public static void solve_abc172A() { int a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(a + Math.Pow(a, 2) + Math.Pow(a, 3)); } } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc172 { 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_abc172C2(); Console.Out.Flush(); } // https://atcoder.jp/contests/abc172/submissions/14749792 public static void solve_abc172C2() { long[] nmk = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long n = nmk[0]; long m = nmk[1]; k = nmk[2]; long[] a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long[] b = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long aSum = 0; for (int i = 0; i < n; i++) { aSum += a[i]; } long bSum = 0; long j = 0; long ans = 0; for (long i = n; i >= 0; i--) { if (i < n) { aSum -= a[i]; } if (aSum <= k) { while (j < m && aSum + bSum + b[j] <= k) { bSum += b[j]; j++; } ans = Math.Max(ans, i + j); } } Console.WriteLine(ans); } /* Increment in the parameters doesn't work in recursive calls Example: getTotal(cnt++); Should be gettotal(cnt + 1); */ public static long getTotal(long sum, long cnt, long idx1, long idx2) { if (idx1 < a.Length) { if (sum + a[idx1] < k) { total = Math.Max(total, getTotal(sum + a[idx1], cnt + 1, idx1 + 1, idx2)); } } if (idx2 < b.Length) { if (sum + b[idx2] < k) { total = Math.Max(total, getTotal(sum + b[idx2], cnt + 1, idx1, idx2 + 1)); } } return cnt; } public static long[] a; public static long[] b; public static long k; public static long total = 0; public static void solve_abc172C() { long[] nmk = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); long n = nmk[0]; long m = nmk[1]; k = nmk[2]; a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); b = Array.ConvertAll(Console.ReadLine().Split(), long.Parse); Console.WriteLine(getTotal(0, 0, 0, 0)); /*long min = 0; long cnt = 0; long i = 0; long j = 0; while (i < n || j < m) { if (i >= n && j < m) { if (min + b[j] <= k) { min += b[j]; cnt++; } j++; } else if (j >= m && i < n) { if (min + a[i] <= k) { min += a[i]; cnt++; } i++; } else { if (min + Math.Min(a[i], b[j]) <= k) { min += Math.Min(a[i], b[j]); cnt++; } else { break; } if (a[i] < b[j]) { i++; } else { j++; } } } Console.WriteLine(cnt); */ } public static void solve_abc172B() { string s = Console.ReadLine(); string t = Console.ReadLine(); int cnt = 0; for (int i = 0; i < s.Length; i++) { if (s[i] != t[i]) { cnt++; } } Console.WriteLine(cnt); } public static void solve_abc172A() { int a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(a + Math.Pow(a, 2) + Math.Pow(a, 3)); } } }
[["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
731
2
// // ABC172C // URL : https://atcoder.jp/contests/abc172/tasks/abc172_c // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.IO.Pipes; namespace AtCoder.ABC172C { class Solver { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; public static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } public void Solve() { var inputArray = Console.ReadLine() .Split(' ') .Select(_inputStr => long.Parse(_inputStr)) .ToArray(); long N = inputArray[0]; long M = inputArray[1]; long K = inputArray[2]; var An = Console.ReadLine() .Split(' ') .Select(_inputStr => long.Parse(_inputStr)) .ToArray(); var Bm = Console.ReadLine() .Split(' ') .Select(_inputStr => long.Parse(_inputStr)) .ToArray(); long ans = 0; var ATime = AggregateSumList(An.ToList()); var BTime = AggregateSumList(Bm.ToList()); int bReadNumBest = BTime.Count - 1; //まずAからaReadNum冊連続で取る。 for (int aReadNum = 0; aReadNum < ATime.Count; aReadNum++) { // Aから取っただけでK分超えた場合、この回数より上を調べる意味はない // Bからはもちろん取れない(bReadNumBest = 0)。 if (ATime[aReadNum] >= K) { break; } else { // AかaReadNumi冊選んだとする。BかbReadNumj冊選ぶ for (int bReadNum = bReadNumBest; bReadNum >= 0; bReadNum--) { // bReadNum冊取ったとして、K分未満なら、 if (ATime[aReadNum] + BTime[bReadNum] <= K) { //それが「AかaReadNum冊取ったときに取れる、Bからの冊数の最大値」 //次回のloopで決まるbestは、Atimeが増加するため必ず今回のloopのbestは以下となる bReadNumBest = bReadNum; break; } } } ans = Math.Max(ans, aReadNum + bReadNumBest); } Console.WriteLine(ans); } //--------------------------------------------------------------------------------- #region MyLib /// <summary> /// リストから、重複したものを除外したリストを新規に作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="src"></param> /// <param name="dst"></param> public static void getDistinctList<T>(List<T> src, out List<T> dst) { var iter = src.Distinct(); dst = new List<T>(); foreach (var item in iter) { dst.Add(item); } } /// <summary> /// グラフ系 /// </summary> public class Node { public Node(long val) { this.Value = val; this.Children = new List<Node>(); } public Node(long val, List<Node> children) { this.Value = val; this.Children = children; } public long Value { get; set; } public List<Node> Children { get; set; } } /// <summary> /// Clamping /// </summary> /// <typeparam name="T">比較型</typeparam> /// <param name="x">clampしたい値</param> /// <param name="min">最小値</param> /// <param name="max">最大値</param> /// <returns>clamp済みの値</returns> public static T Clamp<T>(T x, T min, T max) where T : IComparable<T> { if (x.CompareTo(min) < 0) { return min; } else if (x.CompareTo(max) > 0) { return max; } else return x; // return Math.Max(Math.Min(x, max), min); } /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } #endregion MyLib } }
// // ABC172C // URL : https://atcoder.jp/contests/abc172/tasks/abc172_c // using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.IO.Pipes; namespace AtCoder.ABC172C { class Solver { public static readonly long MOD_CONST = 1000000007; //(long)Math.Pow(10, 9) + 7; public static void Main(string[] args) { //出力高速化 var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var solver = new Solver(); solver.Solve(); Console.Out.Flush(); } public void Solve() { var inputArray = Console.ReadLine() .Split(' ') .Select(_inputStr => long.Parse(_inputStr)) .ToArray(); long N = inputArray[0]; long M = inputArray[1]; long K = inputArray[2]; var An = Console.ReadLine() .Split(' ') .Select(_inputStr => long.Parse(_inputStr)) .ToArray(); var Bm = Console.ReadLine() .Split(' ') .Select(_inputStr => long.Parse(_inputStr)) .ToArray(); long ans = 0; var ATime = AggregateSumList(An.ToList()); var BTime = AggregateSumList(Bm.ToList()); int bReadNumBest = BTime.Count - 1; //まずAからaReadNum冊連続で取る。 for (int aReadNum = 0; aReadNum < ATime.Count; aReadNum++) { // Aから取っただけでK分超えた場合、この回数より上を調べる意味はない // Bからはもちろん取れない(bReadNumBest = 0)。 if (ATime[aReadNum] > K) { break; } else { // AかaReadNumi冊選んだとする。BかbReadNumj冊選ぶ for (int bReadNum = bReadNumBest; bReadNum >= 0; bReadNum--) { // bReadNum冊取ったとして、K分未満なら、 if (ATime[aReadNum] + BTime[bReadNum] <= K) { //それが「AかaReadNum冊取ったときに取れる、Bからの冊数の最大値」 //次回のloopで決まるbestは、Atimeが増加するため必ず今回のloopのbestは以下となる bReadNumBest = bReadNum; break; } } } ans = Math.Max(ans, aReadNum + bReadNumBest); } Console.WriteLine(ans); } //--------------------------------------------------------------------------------- #region MyLib /// <summary> /// リストから、重複したものを除外したリストを新規に作成する /// </summary> /// <typeparam name="T"></typeparam> /// <param name="src"></param> /// <param name="dst"></param> public static void getDistinctList<T>(List<T> src, out List<T> dst) { var iter = src.Distinct(); dst = new List<T>(); foreach (var item in iter) { dst.Add(item); } } /// <summary> /// グラフ系 /// </summary> public class Node { public Node(long val) { this.Value = val; this.Children = new List<Node>(); } public Node(long val, List<Node> children) { this.Value = val; this.Children = children; } public long Value { get; set; } public List<Node> Children { get; set; } } /// <summary> /// Clamping /// </summary> /// <typeparam name="T">比較型</typeparam> /// <param name="x">clampしたい値</param> /// <param name="min">最小値</param> /// <param name="max">最大値</param> /// <returns>clamp済みの値</returns> public static T Clamp<T>(T x, T min, T max) where T : IComparable<T> { if (x.CompareTo(min) < 0) { return min; } else if (x.CompareTo(max) > 0) { return max; } else return x; // return Math.Max(Math.Min(x, max), min); } /// <summary> /// 指定された底log_baseでの, 対数を計算 /// </summary> /// <param name="x"></param> /// <param name="log_base">指定の底</param> /// <returns></returns> public static double LogBase(double x, double log_base) { // log_b(N) = log_a(N) / log_a(B)より return Math.Log(x) / Math.Log(log_base); } /// <summary> /// 初項a, 公差d, 項数nの数列の和 /// </summary> /// <param name="n">求めたいところ</param> /// <returns>初項からxまで足した値</returns> static long SumSeries(long a, long d, long n) { return (2 * a + (n - 1) * d) * n / 2; } /// <summary> /// 累積和の配列を計算する /// Sum[ a[0], a[i] )がs[i+1]に入っている /// s[0] : 0 //一切和を取らない場合 /// s[1] : ls[0] //a[0] + s[0] = a[0] /// s[2] : ls[1] + s[1] //a[1] + a[0] /// ... /// s[N] : ls[N-1] + s[N-1] //a[N-1] + ... + a[0] /// s[N+1]: ls[N] + s[N] //a[N] + ... + a[0] /// /// 例: [1, 7)の和(a[1] + ... + a[6]) /// s[1] = a[0] //[0, 1) /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7) /// よってs[7] - s[1]); /// </summary> /// <param name="ls">計算したい配列</param> /// <returns>累積和配列</returns> static List<long> AggregateSumList(List<long> a) { var s = new List<long>(a.Count + 1); if (a.Count == 0) { return s; } s.Add(0); // s[0] = 0 for (int i = 0; i < a.Count; ++i) { s.Add(a[i] + s[i]); } return s; } /// <summary> /// 与えられた数が素数かどうかを計算する /// </summary> /// <param name="num">対象数</param> /// <returns>true:素数, false:素数ではない(合成数)</returns> public static bool isPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = Math.Sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } /// <summary> /// 順列mPnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Permutation(long m, long n) { long ret = 1; for (var i = 0; i < n; ++i) { ret *= m - i; } return ret; } /// <summary> /// 組み合わせmCnを計算する /// </summary> /// <param name="m"></param> /// <param name="n"></param> /// <returns></returns> public static long Combination(long m, long n) { if (m == n || n == 0) { return 1; } long ans = 1; for (var i = 1; i <= n; ++i) { ans = ans * (m - i + 1) / i; } return ans; } static long Gcd(long m, long n) { if (n == 0) return m; return Gcd(n, m % n); } static long Lcm(long m, long n) { var gcd = Gcd(m, n); // return (m * n) / gcd; return m / gcd * n; //桁あふれ対策 } #endregion MyLib } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 47]]
8
1,054
2
using System; using System.Collections.Generic; using System.Linq; namespace Contest { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = input[0]; var m = input[1]; var k = input[2]; input = Console.ReadLine().Split().Select(int.Parse).ToArray(); long[] a = new long[input.Length]; a[0] = input[0]; var ans = a[0] <= k ? 1 : 0; int[] maxBooks = { 1, 1 }; for (int i = 1; i < input.Length; i++) { a[i] = a[i - 1] + input[i]; if (a[i] < k) { ans = i + 1; maxBooks[0] = i + 1; } } input = Console.ReadLine().Split().Select(int.Parse).ToArray(); long[] b = new long[input.Length]; b[0] = input[0]; ans = b[0] <= k ? Math.Max(ans, 1) : ans; for (int i = 1; i < input.Length; i++) { b[i] = b[i - 1] + input[i]; if (b[i] < k) { ans = Math.Max(ans, i + 1); maxBooks[1] = i + 1; } } for (int i = 0; i < maxBooks[0]; i++) { for (int j = maxBooks[1] - 1; j >= 0; j--) { if (a[i] + b[j] > k) continue; else { ans = Math.Max(ans, i + j + 2); maxBooks[1] = j + 1; break; } } } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace Contest { class Program { static void Main(string[] args) { var input = Console.ReadLine().Split().Select(int.Parse).ToArray(); var n = input[0]; var m = input[1]; var k = input[2]; input = Console.ReadLine().Split().Select(int.Parse).ToArray(); long[] a = new long[input.Length]; a[0] = input[0]; var ans = a[0] <= k ? 1 : 0; int[] maxBooks = { 1, 1 }; for (int i = 1; i < input.Length; i++) { a[i] = a[i - 1] + input[i]; if (a[i] <= k) { ans = i + 1; maxBooks[0] = i + 1; } } input = Console.ReadLine().Split().Select(int.Parse).ToArray(); long[] b = new long[input.Length]; b[0] = input[0]; ans = b[0] <= k ? Math.Max(ans, 1) : ans; for (int i = 1; i < input.Length; i++) { b[i] = b[i - 1] + input[i]; if (b[i] <= k) { ans = Math.Max(ans, i + 1); maxBooks[1] = i + 1; } } for (int i = 0; i < maxBooks[0]; i++) { for (int j = maxBooks[1] - 1; j >= 0; j--) { if (a[i] + b[j] > k) continue; else { ans = Math.Max(ans, i + j + 2); maxBooks[1] = j + 1; break; } } } Console.WriteLine(ans); } } }
[["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19]]
8
440
4
using System; using System.Linq; namespace ConsoleApp3 { internal class Program { private static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); Console.WriteLine(Enumerable.Range(1, n).Sum(x => x * GetAllOfSum(n / x))); } private static long GetAllOfSum(int n) { return n * (n + 1) / 2; } } }
using System; using System.Linq; namespace ConsoleApp3 { internal class Program { private static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); Console.WriteLine( Enumerable.Range(1, n).Sum(x => x * GetAllOfSum((long)n / x))); } private static decimal GetAllOfSum(decimal n) { return n * (n + 1) / 2; } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 24], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 39, 199], ["+", 3, 4, 0, 28, 0, 16, 31, 74, 0, 25], ["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199], ["+", 8, 201, 0, 195, 54, 55, 0, 220, 39, 199]]
8
92
7
using System; namespace ABC172Test { class Program { static void Main() { int N = int.Parse(Console.ReadLine().Trim()); long result = 0; result = abc172_f2(N); Console.WriteLine(result); } static int abc172_f2(int k) { int sum = 0; for (int i = 1; i <= k; i++) { int max = k / i; for (int j = 1; j <= max; j++) { sum += i * j; } } return sum; } } }
using System; namespace ABC172Test { class Program { static void Main() { int N = int.Parse(Console.ReadLine().Trim()); long result = 0; result = abc172_f2(N); Console.WriteLine(result); } static long abc172_f2(int k) { long sum = 0; for (int i = 1; i <= k; i++) { int max = k / i; for (int j = 1; j <= max; j++) { sum += i * j; } } return sum; } } }
[["-", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["+", 8, 201, 0, 235, 8, 201, 0, 195, 39, 199], ["-", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199], ["+", 0, 195, 8, 196, 0, 197, 0, 198, 39, 199]]
8
117
4
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; const double eps = 1e-11; static void Main() { Sc sc = new Sc(); var s = sc.Ia; Cb r = new Cb(s[1] << 1); var c = new int[] { 1, -1 }; Mint ans = r.P1(s[1], s[0]), d = ans; for (int i = 1; i <= s[0]; i++) { d += r.P1(s[1] - i, s[0] - i) * (Mint)r.C1(s[0], i) * c[i & 1]; } Console.WriteLine("{0}", ans * d); } } public class Cb { private const int mod = (int)1e9 + 7; public long[] r; public Cb(int n) { r = new long[n]; r[0] = 1; for (int i = 1; i < n; i++) { r[i] = (r[i - 1] * i) % mod; } } public long C1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; } public long C2(long n, long k) { long l = 1; n %= mod; for (int i = 1; i <= k; i++) { l = (l * (n - i + 1)) % mod; l = (l * Mi(i)) % mod; } return l; } public long P1(long n, long k) { return n >= k ? (r[n] * Mi(r[n - k])) % mod : 0; } public long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; (a, b) = (b, a); u -= t * v; (u, v) = (v, u); } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public struct Mint { const int mod = (int)1e9 + 7; private long d; public Mint(long d) { this.d = d; } public static implicit operator Mint(long d) { return new Mint(d % mod); } public static explicit operator long(Mint d) { return d.d; } public override string ToString() { return d.ToString(); } public static Mint operator +(Mint a, long b) { a.d = (mod + a.d + b) % mod; return a; } public static Mint operator +(Mint a, Mint b) { a.d = (a.d + b.d) % mod; return a; } public static Mint operator -(Mint a, long b) { a.d = (mod + a.d - b) % mod; return a; } public static Mint operator -(Mint a, Mint b) { a.d = (mod + a.d - b.d) % mod; return a; } public static Mint operator *(Mint a, long b) { a.d = (a.d * b) % mod; return a; } public static Mint operator *(Mint a, Mint b) { a.d = (a.d * b.d) % mod; return a; } public static Mint operator /(Mint a, long b) { a.d = (a.d * Mi(b)) % mod; return a; } public static Mint operator /(Mint a, Mint b) { a.d = (a.d * Mi(b.d)) % mod; return a; } private static long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; (a, b) = (b, a); u -= t * v; (u, v) = (v, u); } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse); } public int[] Ia3(int a) { return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse); } public long[] La3(int a) { return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
using System; using System.Collections.Generic; using System.Collections; using System.Collections.Specialized; using System.Linq; using System.Text; using System.IO; using System.Reflection; using static System.Math; using System.Numerics; static class Program { const int mod = (int)1e9 + 7; const double eps = 1e-11; static void Main() { Sc sc = new Sc(); var s = sc.Ia; Cb r = new Cb(s[1] << 1); var c = new int[] { 1, -1 }; Mint ans = r.P1(s[1], s[0]), d = ans; for (int i = 1; i <= s[0]; i++) { d += r.P1(s[1] - i, s[0] - i) * (Mint)r.C1(s[0], i) * c[i & 1]; } Console.WriteLine("{0}", ans * d); } } public class Cb { private const int mod = (int)1e9 + 7; public long[] r; public Cb(int n) { r = new long[n]; r[0] = 1; for (int i = 1; i < n; i++) { r[i] = (r[i - 1] * i) % mod; } } public long C1(long n, long k) { return (r[n] * Mi(r[k] * r[n - k])) % mod; } public long C2(long n, long k) { long l = 1; n %= mod; for (int i = 1; i <= k; i++) { l = (l * (n - i + 1)) % mod; l = (l * Mi(i)) % mod; } return l; } public long P1(long n, long k) { return n >= k ? (r[n] * Mi(r[n - k])) % mod : 0; } public long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; (a, b) = (b, a); u -= t * v; (u, v) = (v, u); } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public struct Mint { const int mod = (int)1e9 + 7; private long d; public Mint(long d) { this.d = d; } public static implicit operator Mint(long d) { return new Mint(d % mod); } public static explicit operator long(Mint d) { return d.d; } public override string ToString() { return d.ToString(); } public static Mint operator +(Mint a, long b) { a.d = (mod + a.d + b) % mod; return a; } public static Mint operator +(Mint a, Mint b) { a.d = (mod + a.d + b.d) % mod; return a; } public static Mint operator -(Mint a, long b) { a.d = (mod + a.d - b) % mod; return a; } public static Mint operator -(Mint a, Mint b) { a.d = (mod + a.d - b.d) % mod; return a; } public static Mint operator *(Mint a, long b) { a.d = (a.d * b) % mod; return a; } public static Mint operator *(Mint a, Mint b) { a.d = (a.d * b.d) % mod; return a; } public static Mint operator /(Mint a, long b) { a.d = (a.d * Mi(b)) % mod; return a; } public static Mint operator /(Mint a, Mint b) { a.d = (a.d * Mi(b.d)) % mod; return a; } private static long Mi(long a) { a = (a + mod) % mod; long b = mod, u = 1, v = 0; while (b > 0) { long t = a / b; a -= t * b; (a, b) = (b, a); u -= t * v; (u, v) = (v, u); } u %= mod; if (u < 0) { u += mod; } return u % mod; } } public class Sc { public int I { get { return int.Parse(Console.ReadLine()); } } public long L { get { return long.Parse(Console.ReadLine()); } } public double D { get { return double.Parse(Console.ReadLine()); } } public string S { get { return Console.ReadLine(); } } public int[] Ia { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } } public long[] La { get { return Array.ConvertAll(Console.ReadLine().Split(), long.Parse); } } public double[] Da { get { return Array.ConvertAll(Console.ReadLine().Split(), double.Parse); } } public string[] Sa { get { return Console.ReadLine().Split(); } } public object[] Oa { get { return Console.ReadLine().Split(); } } public int[] Ia2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), int.Parse); } } public int[] Ia3(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), int.Parse); } public int[] Ia3(int a) { return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(), int.Parse); } public long[] La2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), long.Parse); } } public long[] La3(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), long.Parse); } public long[] La3(int a) { return Array.ConvertAll((Console.ReadLine() + " " + a.ToString()).Split(), long.Parse); } public double[] Da2 { get { return Array.ConvertAll(("0 " + Console.ReadLine() + " 0").Split(), double.Parse); } } public double[] Da3(string a, string b) { return Array.ConvertAll((a + Console.ReadLine() + b).Split(), double.Parse); } public T[] Arr<T>(int n, Func<T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(); } return a; } public T[] Arr<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i); } return a; } public T[] Arr<T>(int n, Func<string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(Console.ReadLine().Split()); } return a; } public T[] Arr<T>(int n, Func<int, string[], T> f) { var a = new T[n]; for (int i = 0; i < n; i++) { a[i] = f(i, Console.ReadLine().Split()); } return a; } }
[["+", 12, 16, 31, 23, 0, 16, 31, 16, 31, 22], ["+", 12, 16, 31, 23, 0, 16, 31, 16, 17, 72]]
8
1,807
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; public class Hello { public static void Main() { // Your code here! // var n = int.Parse(Console.ReadLine()); // string str = Console.ReadLine(); string str = Console.ReadLine(); string ans = ""; // var t = Console.ReadLine(); if (str.Equals(str.ToUpper())) { ans = "a"; } else { ans = "A"; } Console.WriteLine(ans); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; public class Hello { public static void Main() { // Your code here! // var n = int.Parse(Console.ReadLine()); // string str = Console.ReadLine(); string str = Console.ReadLine(); string ans = ""; // var t = Console.ReadLine(); if (str.Equals(str.ToUpper())) { ans = "A"; } else { ans = "a"; } Console.WriteLine(ans); } }
[["-", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 64, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["-", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222], ["+", 75, 196, 0, 1, 0, 11, 12, 5, 0, 222]]
8
94
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace AtCoder.Abc { /// <summary> /// https://atcoder.jp/contests/abc172/tasks/abc172_b /// </summary> class A_171_αlphabet { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 string a = Console.ReadLine(); if (Regex.IsMatch("A-Z", "A-Z")) { a = "A"; } else { a = "a"; } string result = a; Console.WriteLine(result); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace AtCoder.Abc { /// <summary> /// https://atcoder.jp/contests/abc172/tasks/abc172_b /// </summary> class A_171_αlphabet { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 string a = Console.ReadLine(); if (Regex.IsMatch(a, "[A-Z]")) { a = "A"; } else { a = "a"; } string result = a; Console.WriteLine(result); Console.Out.Flush(); } } }
[["-", 15, 213, 3, 4, 0, 28, 0, 5, 0, 62], ["-", 15, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 57, 15, 213, 3, 4, 0, 28, 0, 22], ["+", 15, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
150
6
using System; using System.Linq; namespace fightx { class Program { static void Main(string[] args) { /* int[] NK = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); int[] PN = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); Array.Sort(PN); int ans = 0; for (int a = 0; a < NK[1]; a++) ans += PN[a]; Console.WriteLine(ans);*/ /* string N = "a"; char c = N[0]; */ string N = Console.ReadLine(); char c = N[0]; if (Char.IsLower(c)) { Console.WriteLine("a"); } else { Console.WriteLine("Ak"); } } } }
using System; using System.Linq; namespace fightx { class Program { static void Main(string[] args) { /* int[] NK = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); int[] PN = Console.ReadLine().Split(" ").Select(int.Parse).ToArray(); Array.Sort(PN); int ans = 0; for (int a = 0; a < NK[1]; a++) ans += PN[a]; Console.WriteLine(ans);*/ /* string N = "a"; char c = N[0]; */ string N = Console.ReadLine(); char c = N[0]; if (Char.IsLower(c)) { Console.WriteLine("a"); } else { Console.WriteLine("A"); } } } }
[["-", 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; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var a = Console.ReadLine()[0]; Console.WriteLine(char.IsLower(a) ? 'A' : 'a'); } }
using System; using System.Linq; using System.Collections.Generic; using E = System.Linq.Enumerable; public class Program { public static void Main() { var a = Console.ReadLine()[0]; Console.WriteLine(char.IsLower(a) ? 'a' : 'A'); } }
[["-", 3, 4, 0, 28, 0, 41, 64, 252, 0, 253], ["+", 3, 4, 0, 28, 0, 41, 64, 252, 0, 253], ["-", 3, 4, 0, 28, 0, 41, 75, 252, 0, 253], ["+", 3, 4, 0, 28, 0, 41, 75, 252, 0, 253]]
8
69
4
using System; using System.Collections.Generic; class Program { static void Main() { string S = Console.ReadLine(); if (S == "A" || S == "B" || S == "C" || S == "D" || S == "E" || S == "F" || S == "G" || S == "H" || S == "I" || S == "J" || S == "K" || S == "L" || S == "M" || S == "N" || S == "O" || S == "P" || S == "Q" || S == "R" || S == "S" || S == "T" || S == "U" || S == "V" || S == "W" || S == "X" || S == "Y" || S == "C") { Console.WriteLine("A"); } else { Console.WriteLine("a"); } } }
using System; using System.Collections.Generic; class Program { static void Main() { string S = Console.ReadLine(); if (S == "A" || S == "B" || S == "C" || S == "D" || S == "E" || S == "F" || S == "G" || S == "H" || S == "I" || S == "J" || S == "K" || S == "L" || S == "M" || S == "N" || S == "O" || S == "P" || S == "Q" || S == "R" || S == "S" || S == "T" || S == "U" || S == "V" || S == "W" || S == "X" || S == "Y" || S == "Z") { Console.WriteLine("A"); } else { Console.WriteLine("a"); } } }
[["-", 0, 57, 15, 16, 12, 16, 12, 5, 0, 222], ["+", 0, 57, 15, 16, 12, 16, 12, 5, 0, 222]]
8
211
2
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.IO; namespace AtCoder.A { public class Program { public static void Main(string[] args) { var s = r(); if (Char.IsUpper(s[0])) { P("A"); return; } P("B"); } private static StreamReader sr; public static int[] Ecr() { if (sr == null) { sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8")); } return sr.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Er() { if (sr == null) { sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8")); } return sr.ReadLine(); } public static string r() { return Console.ReadLine(); } public static int[] cr() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static int cri() { return int.Parse(Console.ReadLine()); } public static void P(string str) { Console.WriteLine(str); } public static void P(int num) { P(num.ToString()); } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.IO; namespace AtCoder.A { public class Program { public static void Main(string[] args) { var s = r(); if (Char.IsUpper(s[0])) { P("A"); return; } P("a"); } private static StreamReader sr; public static int[] Ecr() { if (sr == null) { sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8")); } return sr.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Er() { if (sr == null) { sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8")); } return sr.ReadLine(); } public static string r() { return Console.ReadLine(); } public static int[] cr() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static int cri() { return int.Parse(Console.ReadLine()); } public static void P(string str) { Console.WriteLine(str); } public static void P(int num) { P(num.ToString()); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
294
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc141/tasks/abc141_a public class QuestionA { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 string s = Console.ReadLine(); var reg = new Regex("[a-zA-Z]"); string result = "A"; if (reg.IsMatch(s)) { result = "a"; } Console.WriteLine(result); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc141/tasks/abc141_a public class QuestionA { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 文字列の入力 string s = Console.ReadLine(); var reg = new Regex("[a-z]"); string result = "A"; if (reg.IsMatch(s)) { result = "a"; } Console.WriteLine(result); Console.Out.Flush(); } } }
[["-", 0, 230, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 230, 3, 4, 0, 28, 0, 5, 0, 222]]
8
147
2
using System; using System.Linq; namespace ProblemA { class Program { static void Main() { string ch = Console.ReadLine(); if (ch[0] > 'A' && ch[0] < 'Z') { Console.WriteLine("A"); } else { Console.WriteLine("a"); } } public static int GetInt() => int.Parse(Console.ReadLine()); public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static double GetDouble() => double.Parse(Console.ReadLine()); public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray(); public static long GetLong() => long.Parse(Console.ReadLine()); public static long[] GetLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray(); } }
using System; using System.Linq; namespace ProblemA { class Program { static void Main() { string ch = Console.ReadLine(); if (ch[0] >= 'A' && ch[0] <= 'Z') { Console.WriteLine("A"); } else { Console.WriteLine("a"); } } public static int GetInt() => int.Parse(Console.ReadLine()); public static int[] GetIntArray() => Console.ReadLine().Split().Select(int.Parse).ToArray(); public static double GetDouble() => double.Parse(Console.ReadLine()); public static double[] GetDoubleArray() => Console.ReadLine().Split().Select(double.Parse).ToArray(); public static long GetLong() => long.Parse(Console.ReadLine()); public static long[] GetLongArray() => Console.ReadLine().Split().Select(long.Parse).ToArray(); } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
8
219
4
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; static void Main(string[] args) { var a = Read().ToCharArray(); if (Char.IsUpper(a[0])) { WriteRead("A"); } else { WriteRead("B"); } } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; static void Main(string[] args) { var a = Read().ToCharArray(); if (Char.IsUpper(a[0])) { WriteRead("A"); } else { WriteRead("a"); } } public static string Read() { return Console.ReadLine(); } public static string[] ReadSplit() { return Console.ReadLine().Split(' '); } public static void WriteRead(object str) { Console.WriteLine(str); Read(); } public static void Write(object str) { Console.WriteLine(str); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
418
2
using System; using System.Linq; namespace workspace { class Program { static void Main() { var tmp = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); var N = tmp[0]; var K = tmp[1]; var price = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); price.Sort(); var sum = 0; for (int i = 0; i < K; i++) { sum = sum + price[i]; } Console.WriteLine(price); } } }
using System; using System.Linq; namespace workspace { class Program { static void Main() { var tmp = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); var N = tmp[0]; var K = tmp[1]; var price = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); price.Sort(); var sum = 0; for (int i = 0; i < K; i++) { sum = sum + price[i]; } Console.WriteLine(sum); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
146
2
using System; using System.Linq; public class Program { public static void Main() { int[] numbers = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int[] prices = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); Console.WriteLine(prices.OrderBy(a => a).Take(3).Sum()); } }
using System; using System.Linq; public class Program { public static void Main() { int[] numbers = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int[] prices = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); Console.WriteLine(prices.OrderBy(a => a).Take(numbers[1]).Sum()); } }
[["-", 63, 214, 205, 213, 3, 4, 0, 28, 0, 203], ["+", 205, 213, 3, 4, 0, 28, 0, 204, 205, 22], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 70], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 3, 4, 0, 28, 0, 204, 206, 207, 0, 73]]
8
112
5
using System; using System.Linq; class name { static void Main() { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < b.Length - 1; i++) { // 下から上に順番に比較します for (int j = b.Length - 1; j > i; j--) { // 上の方が大きいときは互いに入れ替えます if (b[j] < b[j - 1]) { int t = b[j]; b[j] = b[j - 1]; b[j - 1] = t; } } } int s = 0; for (int d = 0; d < a[1]; d++) { s += a[d]; } Console.WriteLine(s); } }
using System; using System.Linq; class name { static void Main() { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < b.Length - 1; i++) { // 下から上に順番に比較します for (int j = b.Length - 1; j > i; j--) { // 上の方が大きいときは互いに入れ替えます if (b[j] < b[j - 1]) { int t = b[j]; b[j] = b[j - 1]; b[j - 1] = t; } } } int s = 0; for (int d = 0; d < a[1]; d++) { s += b[d]; } Console.WriteLine(s); } }
[["-", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22], ["+", 8, 196, 0, 1, 0, 11, 12, 204, 205, 22]]
8
196
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC173D { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] Ainput = Console.ReadLine().Split(' '); long[] A = new long[N]; for (int i = 0; i < N; i++) { A[i] = long.Parse(Ainput[i]); } Array.Sort(A); Array.Reverse(A); // Console.WriteLine(string.Join("",A)); int count = 2; long ans = A[0]; long max = 0; if ((N - 1) % 2 == 0) { max = N - 2; ans += A[N - 2]; } else { max = N - 1; } while (count <= max) { if (count % 2 == 0) { ans += A[count / 2]; } else { ans += A[(count - 1) / 2]; } count += 1; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ABC173D { class Program { static void Main(string[] args) { int N = int.Parse(Console.ReadLine()); string[] Ainput = Console.ReadLine().Split(' '); long[] A = new long[N]; for (int i = 0; i < N; i++) { A[i] = long.Parse(Ainput[i]); } Array.Sort(A); Array.Reverse(A); // Console.WriteLine(string.Join("",A)); int count = 2; long ans = A[0]; long max = 0; if ((N - 1) % 2 == 0) { max = N - 2; ans += A[(N - 1) / 2]; } else { max = N - 1; } while (count <= max) { if (count % 2 == 0) { ans += A[count / 2]; } else { ans += A[(count - 1) / 2]; } count += 1; } Console.WriteLine(ans); } } }
[["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 24], ["+", 0, 28, 0, 16, 31, 23, 0, 16, 12, 203], ["+", 206, 207, 0, 28, 0, 16, 31, 23, 0, 25], ["+", 12, 204, 206, 207, 0, 28, 0, 16, 17, 85]]
8
245
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var a = Input().Select(t => long.Parse(t)).ToArray(); var na = new long[n]; Array.Sort(a); Array.Reverse(a); long wa = 0; var list = new LinkedList<long>(); int j = 0; bool turn = false; LinkedListNode<long> ptr = null; for (int i = 0; i < n; i++) { LinkedListNode<long> t = null; if (j < n && !turn) { if (list.Count == 0) { list.AddFirst(a[i]); t = list.First; ptr = t; } else { t = list.AddAfter(ptr, a[i]); } j += 2; } else { if (!turn) { turn = true; j -= 1; if (n % 2 == 1) j -= 2; list.AddBefore(list.Last, new LinkedListNode<long>(a[i])); t = list.Last.Previous; ptr = t; } else { list.AddBefore(ptr.Previous, new LinkedListNode<long>(a[i])); ptr = ptr.Previous.Previous; t = ptr; } } if (list.Count > 1) { if (t == list.First) { wa += Math.Min(t.Next.Value, list.Last.Value); } else wa += Math.Min(t.Previous.Value, t.Next == null ? list.First.Value : t.Next.Value); } } /* if(n%2==0) { int j = 0; bool turn = false; for(int i = 0; i < n; i++) { if(j < n && !turn) { na[j] = a[i]; j+=2; } else { if(!turn) { turn = true; j--; } na[j] = a[i]; j-=2; } } } else { int j = 0; bool turn = false; for(int i = 0; i < n; i++) { if(j < n && !turn) { na[j] = a[i]; j+=2; } else { if(!turn) { turn = true; j-=3; } na[j] = a[i]; j-=2; } } } Console.WriteLine(string.Join(",", na)); for(int i = 1; i < n; i++) { wa += NearMax(i, na); } */ Console.WriteLine(wa); } static long NearMax(int k, long[] m) { return (long)Math.Max(m[(k + 1) % m.Length], m[(k + (m.Length - 1)) % m.Length]); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; public class MainClass { public const long Giri = 1000000007; public const long DpInf = 99999999999999; public static void Main(string[] args) { var n = Console.ReadLine().ToInt(); var a = Input().Select(t => long.Parse(t)).ToArray(); var na = new long[n]; Array.Sort(a); Array.Reverse(a); long wa = 0; var list = new LinkedList<long>(); int j = 0; bool turn = false; LinkedListNode<long> ptr = null; for (int i = 0; i < n; i++) { LinkedListNode<long> t = null; if (j < n && !turn) { if (list.Count == 0) { list.AddFirst(a[i]); t = list.First; ptr = t; } else { t = list.AddAfter(ptr, a[i]); ptr = t; } j += 2; } else { if (!turn) { turn = true; j -= 1; if (n % 2 == 1) j -= 2; list.AddBefore(list.Last, new LinkedListNode<long>(a[i])); t = list.Last.Previous; ptr = t; } else { list.AddBefore(ptr.Previous, new LinkedListNode<long>(a[i])); ptr = ptr.Previous.Previous; t = ptr; } } if (list.Count > 1) { if (t == list.First) { wa += Math.Min(t.Next.Value, list.Last.Value); } else wa += Math.Min(t.Previous.Value, t.Next == null ? list.First.Value : t.Next.Value); } // Console.WriteLine(string.Join(",", list.Select(o=>o).ToArray() )); } /* if(n%2==0) { int j = 0; bool turn = false; for(int i = 0; i < n; i++) { if(j < n && !turn) { na[j] = a[i]; j+=2; } else { if(!turn) { turn = true; j--; } na[j] = a[i]; j-=2; } } } else { int j = 0; bool turn = false; for(int i = 0; i < n; i++) { if(j < n && !turn) { na[j] = a[i]; j+=2; } else { if(!turn) { turn = true; j-=3; } na[j] = a[i]; j-=2; } } } */ /* for(int i = 1; i < n; i++) { wa += NearMax(i, na); } */ // Console.WriteLine(string.Join(",", list.Select(o=>o).ToArray() )); Console.WriteLine(wa); } static long NearMax(int k, long[] m) { return (long)Math.Max(m[(k + 1) % m.Length], m[(k + (m.Length - 1)) % m.Length]); } static long GCD(long a, long b) { var v = new[] { a, b }; while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; } return v[0]; } public static string[] Input() { return Console.ReadLine().Split(); } } public static class Smarter { public static int ToInt(this string str) { return int.Parse(str); } public static long ToLong(this string str) { return long.Parse(str); } public static int[] ToInt(this string[] str, int offset = 0) { var r = new int[str.Length]; for (int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset; return r; } }
[["+", 0, 57, 75, 196, 0, 1, 0, 11, 31, 22], ["+", 75, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 57, 75, 196, 0, 1, 0, 11, 12, 22], ["+", 64, 196, 0, 57, 75, 196, 0, 1, 0, 35]]
8
662
4
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const char White = '.'; const char Black = '#'; const long Mod = 1000000007; static void Main(string[] args) { checked { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // TestCaseMaker.MakeTestCase1("../TextFile2.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } } static object process(TextReader input) { var n = int.Parse(input.ReadLine()); var aa = ToIntArray(input.ReadLine(), n); Array.Sort(aa, (x, y) => y - x); var queue = new PriorityQueue<Item>(n); long sum = 0; queue.Push(new Item(aa[0], aa[0])); for (int i = 1; i < n; i++) { var x = aa[i]; var q = queue.Pop(); sum += q.happy; queue.Push(new Item(q.l, x)); queue.Push(new Item(x, q.r)); } return sum; } public class Item : IComparable { public int l; public int r; public int happy; public Item(int l, int r) { this.l = l; this.r = r; this.happy = Math.Min(l, r); } public int CompareTo(object obj) { var o = obj as Item; return this.happy.CompareTo(o.happy); } } //コピペ 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 int[] ToIntArray(string strs, int n) { var ret = new int[n]; if (n == 0) return ret; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } }
using System; using System.Diagnostics; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { const string Yes = "Yes"; const string No = "No"; const char White = '.'; const char Black = '#'; const long Mod = 1000000007; static void Main(string[] args) { checked { #if DEBUG MyDebugger.Test(process, "../TextFile1.txt"); // TestCaseMaker.MakeTestCase1("../TextFile2.txt"); // MyDebugger.Test(process, "../TextFile2.txt"); #else object ret = process(new StreamReader(Console.OpenStandardInput())); Console.WriteLine(ret); #endif } } static object process(TextReader input) { var n = int.Parse(input.ReadLine()); var aa = ToIntArray(input.ReadLine(), n); Array.Sort(aa, (x, y) => y - x); var queue = new PriorityQueue<Item>(n); long sum = 0; queue.Push(new Item(aa[0], aa[0])); for (int i = 1; i < n; i++) { var x = aa[i]; var q = queue.Pop(); sum += q.happy; queue.Push(new Item(q.l, x)); queue.Push(new Item(x, q.r)); } return sum; } public class Item : IComparable { public int l; public int r; public int happy; public Item(int l, int r) { this.l = l; this.r = r; this.happy = Math.Min(l, r); } public int CompareTo(object obj) { var o = obj as Item; return o.happy.CompareTo(this.happy); } } //コピペ 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 int[] ToIntArray(string strs, int n) { var ret = new int[n]; if (n == 0) return ret; var spl = strs.Split(' '); for (int i = 0; i < n; i++) ret[i] = int.Parse(spl[i]); return ret; } }
[["-", 0, 213, 63, 214, 205, 214, 205, 273, 0, 274], ["+", 0, 37, 0, 213, 63, 214, 205, 214, 205, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 3, 4, 0, 28, 0, 214, 205, 273, 0, 274]]
8
1,009
4
using System; class Program { const int TYPE_NUM = 26; static void Main(string[] args) { int i, j; int d = int.Parse(Console.ReadLine()); int[] c = new int[TYPE_NUM + 1]; int[,] s = new int[d + 1, TYPE_NUM + 1]; string[] strInput = Console.ReadLine().Split(' '); for (i = 1; i <= TYPE_NUM; i++) { c[i] = int.Parse(strInput[i - 1]); } for (i = 1; i <= d; i++) { strInput = Console.ReadLine().Split(' '); for (j = 1; j < TYPE_NUM; j++) { s[i, j] = int.Parse(strInput[j - 1]); } } int[] t = new int[d + 1]; for (i = 1; i <= d; i++) { t[i] = int.Parse(Console.ReadLine()); } int result = 0; int[] last = new int[TYPE_NUM + 1]; int resultDiff; for (i = 1; i <= d; i++) { result += s[i, t[i]]; last[t[i]] = i; resultDiff = 0; for (j = 1; j <= TYPE_NUM; j++) { resultDiff += c[j] * (i - last[j]); } result -= resultDiff; Console.WriteLine(result); } return; } }
using System; class Program { const int TYPE_NUM = 26; static void Main(string[] args) { int i, j; int d = int.Parse(Console.ReadLine()); int[] c = new int[TYPE_NUM + 1]; int[,] s = new int[d + 1, TYPE_NUM + 1]; string[] strInput = Console.ReadLine().Split(' '); for (i = 1; i <= TYPE_NUM; i++) { c[i] = int.Parse(strInput[i - 1]); } for (i = 1; i <= d; i++) { strInput = Console.ReadLine().Split(' '); for (j = 1; j <= TYPE_NUM; j++) { s[i, j] = int.Parse(strInput[j - 1]); } } int[] t = new int[d + 1]; for (i = 1; i <= d; i++) { t[i] = int.Parse(Console.ReadLine()); } int result = 0; int[] last = new int[TYPE_NUM + 1]; int resultDiff; for (i = 1; i <= d; i++) { result += s[i, t[i]]; last[t[i]] = i; resultDiff = 0; for (j = 1; j <= TYPE_NUM; j++) { resultDiff += c[j] * (i - last[j]); } result -= resultDiff; Console.WriteLine(result); } return; } }
[["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
338
2
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { int a = int.Parse(ReadLine()); a = a * a + a * a * a + a; WriteLine("{0},a"); } } }
using System; using System.Collections.Generic; using System.Linq; using static System.Console; using System.Text; using System.Threading.Tasks; namespace Atcoder { class Program { static void Main(string[] args) { int a = int.Parse(ReadLine()); a = a * a + a * a * a + a; WriteLine("{0}", a); } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 21], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
85
4
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder.Abc171 { public class ModularCombinationFixedK { int k; long mod; long[] combination; public ModularCombinationFixedK(int maxN, int k, long mod) { combination = new long[maxN + 1]; this.k = k; this.mod = mod; combination[k] = 1; for (int i = k; i < maxN; i++) combination[i + 1] = combination[i] * (i + 1) % mod * Inverse(i - k + 1) % mod; } public ModularCombinationFixedK(int n, long mod) : this(n, n, mod) {} public long Get(int n) { return combination[n]; } long Inverse(long a) { long i = mod, v = 0, d = 1; while (a > 0) { long t = i / a, x = a; a = i % x; i = x; x = d; d = v - t * x; v = x; } v %= mod; if (v < 0) v = (v + mod) % mod; return v; } } class F { static readonly long mod = 1000000007; public static void Main() { var k = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); int n = k + s.Length; var comb = new ModularCombinationFixedK(n - 1, s.Length - 1, mod); long ans = 0; var pow26 = new long[k + 1]; pow26[0] = 1; for (int i = 1; i <= k; i++) pow26[i] = (pow26[i - 1] * 26) % mod; long pow25 = 1; for (int i = 0; i <= k; i++) { ans += (comb.Get(s.Length - 1 + i) * pow25) % mod * pow26[k - i] % mod; pow25 = pow25 * 25 % mod; } Console.WriteLine(ans); } } }
using System; using System.Collections.Generic; using System.Linq; namespace AtCoder.Abc171 { public class ModularCombinationFixedK { int k; long mod; long[] combination; public ModularCombinationFixedK(int maxN, int k, long mod) { combination = new long[maxN + 1]; this.k = k; this.mod = mod; combination[k] = 1; for (int i = k; i < maxN; i++) combination[i + 1] = combination[i] * (i + 1) % mod * Inverse(i - k + 1) % mod; } public ModularCombinationFixedK(int n, long mod) : this(n, n, mod) {} public long Get(int n) { return combination[n]; } long Inverse(long a) { long i = mod, v = 0, d = 1; while (a > 0) { long t = i / a, x = a; a = i % x; i = x; x = d; d = v - t * x; v = x; } v %= mod; if (v < 0) v = (v + mod) % mod; return v; } } class F { static readonly long mod = 1000000007; public static void Main() { var k = int.Parse(Console.ReadLine()); var s = Console.ReadLine(); int n = k + s.Length; var comb = new ModularCombinationFixedK(n - 1, s.Length - 1, mod); long ans = 0; var pow26 = new long[k + 1]; pow26[0] = 1; for (int i = 1; i <= k; i++) pow26[i] = (pow26[i - 1] * 26) % mod; long pow25 = 1; for (int i = 0; i <= k; i++) { ans = (ans + (comb.Get(s.Length - 1 + i) * pow25) % mod * pow26[k - i]) % mod; pow25 = pow25 * 25 % mod; } Console.WriteLine(ans); } } }
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
8
440
6
using System; using System.Collections.Generic; using System.Linq; using System.IO; using System.Threading; 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 { public Scanner sc; public void Solve() { int K; string S; sc.Make(out K, out S); ModInt.Build(200100); ModInt res = 0; for (int i = 0; i <= K; i++) { res += ModInt.Comb(S.Length - 1 + K - i, K - i) * ModInt.Pow(25, K - i) * ModInt.Pow(26, i); } Console.WriteLine(res); // Console.WriteLine(ModInt.Pow(25, K) * ModInt.Comb(S.Length + K, K)); } } public struct ModInt { public const long MOD = (int)1e9 + 7; // public const long MOD = 998244353; public long Value { get; set; } public ModInt(long n = 0) { Value = n; } private static ModInt[] fac; // i! private static ModInt[] inv; // 1/i private static ModInt[] facinv; // 1/(i!) public override string ToString() => Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt l, ModInt r) { l.Value += r.Value; if (l.Value >= MOD) l.Value -= MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt l, ModInt r) { l.Value -= r.Value; if (l.Value < 0) l.Value += MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt l) => l.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public static ModInt Pow(ModInt m, long n) { if (n == 0) return 1; if (n % 2 == 0) return Pow(m * m, n >> 1); else return Pow(m * m, n >> 1) * m; } public static void Build(int n) { fac = new ModInt[n + 1]; facinv = new ModInt[n + 1]; inv = new ModInt[n + 1]; inv[1] = 1; fac[0] = fac[1] = 1; facinv[0] = facinv[1] = 1; for (var i = 2; i <= n; i++) { fac[i] = fac[i - 1] * i; inv[i] = MOD - inv[MOD % i] * (MOD / i); facinv[i] = facinv[i - 1] * inv[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(ModInt n) => fac[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Inv(ModInt n) => inv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt FacInv(ModInt n) => facinv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Comb(ModInt n, ModInt r) { if (n < r) return 0; if (n == r) return 1; var calc = fac[n]; calc = calc * facinv[r]; calc = calc * facinv[n - r]; return calc; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var sol = new Solver() { sc = new Scanner() }; // var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join(); sol.Solve(); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { 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) < 0) { 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[] 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; } 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 IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } 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 void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); } // 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.Threading; 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 { public Scanner sc; public void Solve() { int K; string S; sc.Make(out K, out S); ModInt.Build(2001001); ModInt res = 0; for (int i = 0; i <= K; i++) { res += ModInt.Comb(S.Length - 1 + K - i, K - i) * ModInt.Pow(25, K - i) * ModInt.Pow(26, i); } Console.WriteLine(res); // Console.WriteLine(ModInt.Pow(25, K) * ModInt.Comb(S.Length + K, K)); } } public struct ModInt { public const long MOD = (int)1e9 + 7; // public const long MOD = 998244353; public long Value { get; set; } public ModInt(long n = 0) { Value = n; } private static ModInt[] fac; // i! private static ModInt[] inv; // 1/i private static ModInt[] facinv; // 1/(i!) public override string ToString() => Value.ToString(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator +(ModInt l, ModInt r) { l.Value += r.Value; if (l.Value >= MOD) l.Value -= MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator -(ModInt l, ModInt r) { l.Value -= r.Value; if (l.Value < 0) l.Value += MOD; return l; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator *(ModInt l, ModInt r) => new ModInt(l.Value * r.Value % MOD); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt operator /(ModInt l, ModInt r) => l * Pow(r, MOD - 2); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator long(ModInt l) => l.Value; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator ModInt(long n) { n %= MOD; if (n < 0) n += MOD; return new ModInt(n); } public static ModInt Pow(ModInt m, long n) { if (n == 0) return 1; if (n % 2 == 0) return Pow(m * m, n >> 1); else return Pow(m * m, n >> 1) * m; } public static void Build(int n) { fac = new ModInt[n + 1]; facinv = new ModInt[n + 1]; inv = new ModInt[n + 1]; inv[1] = 1; fac[0] = fac[1] = 1; facinv[0] = facinv[1] = 1; for (var i = 2; i <= n; i++) { fac[i] = fac[i - 1] * i; inv[i] = MOD - inv[MOD % i] * (MOD / i); facinv[i] = facinv[i - 1] * inv[i]; } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Fac(ModInt n) => fac[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Inv(ModInt n) => inv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt FacInv(ModInt n) => facinv[n]; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static ModInt Comb(ModInt n, ModInt r) { if (n < r) return 0; if (n == r) return 1; var calc = fac[n]; calc = calc * facinv[r]; calc = calc * facinv[n - r]; return calc; } } #region Template public static class Template { static void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var sol = new Solver() { sc = new Scanner() }; // var th = new Thread(sol.Solve, 1 << 26);th.Start();th.Join(); sol.Solve(); Console.Out.Flush(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) > 0) { 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) < 0) { 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[] 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; } 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 IEnumerable<T> Shuffle<T>(this IEnumerable<T> A) => A.OrderBy(v => Guid.NewGuid()); public static int CompareTo<T>(this T[] A, T[] B, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; for (var i = 0; i < Min(A.Length, B.Length); i++) { int c = cmp(A[i], B[i]); if (c > 0) return 1; else if (c < 0) return -1; } if (A.Length == B.Length) return 0; if (A.Length > B.Length) return 1; else return -1; } public static int MaxElement<T>(this IList<T> A, Comparison<T> cmp = null) { cmp = cmp ?? Comparer<T>.Default.Compare; T max = A[0]; int rt = 0; for (int i = 1; i < A.Count; i++) if (cmp(max, A[i]) < 0) { max = A[i]; rt = i; } return rt; } public static T PopBack<T>(this List<T> A) { var v = A[A.Count - 1]; A.RemoveAt(A.Count - 1); return v; } 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 void Make<T1, T2, T3, T4, T5, T6, T7>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6, out T7 v7) { Make(out v1, out v2, out v3, out v4, out v5, out v6); v7 = Next<T7>(); } // 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, 1, 0, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 203]]
8
2,583
2
using System; class A { static void Main() => Console.WriteLine(360 / Gcd(180, int.Parse(Console.ReadLine()))); static int Gcd(int a, int b) { for (int r; (r = a % b) > 0; a = b, b = r) ; return b; } }
using System; class A { static void Main() => Console.WriteLine(360 / Gcd(360, int.Parse(Console.ReadLine()))); static int Gcd(int a, int b) { for (int r; (r = a % b) > 0; a = b, b = r) ; return b; } }
[["-", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203], ["+", 0, 16, 12, 213, 3, 4, 0, 28, 0, 203]]
8
75
2
using System; namespace takahashikun { class Program { static void Main(string[] args) { string inX = Console.ReadLine(); int X = int.Parse(inX); int K = 1; while (!(K * X >= 360 && K * X % 360 == 0)) K++; Console.WriteLine(X); } } }
using System; namespace takahashikun { class Program { static void Main(string[] args) { string inX = Console.ReadLine(); int X = int.Parse(inX); int K = 1; while (!(K * X >= 360 && K * X % 360 == 0)) K++; Console.WriteLine(K); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
75
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); } public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); } public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); } public static int BuildBitCount(this int bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); void Multi<T>(out T a) => a = cv<T>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { int A; int B; int C; int D; Multi(out A, out B, out C, out D); long mod = 998244353; long[][] F = CreateJaggedArray(C + 1, D + 1, 0L); F[A][B] = 1; for (int x = B; x < D; x++) { F[A][x + 1] = F[A][x] * A % mod; } for (int y = A; y < C; y++) { F[y + 1][B] = F[y][B] * B % mod; for (int x = B; x < D; x++) { F[y + 1][x + 1] = (F[y + 1][x] * (y + 1) + F[y][x + 1] * (x + 1) - y * x * F[y][x] + mod) % mod; } } Console.WriteLine(F[C][D]); } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; namespace AtCoder { public static class Ex { public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.OrdinalIgnoreCase); return s.ToList(); } public static void yesno(this bool b) { Console.WriteLine(b ? "yes" : "no"); } public static void YesNo(this bool b) { Console.WriteLine(b ? "Yes" : "No"); } public static void YESNO(this bool b) { Console.WriteLine(b ? "YES" : "NO"); } public static int BuildBitCount(this int bits) { bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555); bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333); bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f); bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff); return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff); } } partial class AtCoder { public string GetStr() { return Console.ReadLine().Trim(); } public char GetChar() { return Console.ReadLine().Trim()[0]; } public int GetInt() { return int.Parse(Console.ReadLine().Trim()); } public long GetLong() { return long.Parse(Console.ReadLine().Trim()); } public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); } public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); } public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); } public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); } public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); } public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); } public T[][] CreateJaggedArray<T>(int H, int W, T value) { return Enumerable.Repeat(0, H) .Select(s => Enumerable.Repeat(value, W).ToArray()) .ToArray(); } public int[][] GetIntJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetIntArray().ToArray()) .ToArray(); } public long[][] GetLongJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetLongArray().ToArray()) .ToArray(); } public char[][] GetCharJaggedArray(int N) { return Enumerable.Repeat(0, N) .Select(s => GetStr().ToCharArray()) .ToArray(); } public double[][] GetDoubleJaggedArray(int N) { return Enumerable.Repeat(0, N).Select(s => GetDoubleArray()).ToArray(); } Dictionary<int, List<int>> GetUnweightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<int>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<int>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; dic[a].Add(b); if (isDirected == false) dic[b].Add(a); } return dic; } Dictionary<int, List<Edge>> GetWeightedAdjacencyList(int N, int M, bool isDirected, bool isNode_0indexed) { var dic = new Dictionary<int, List<Edge>>(); foreach (var e in Enumerable.Range(0, N)) { dic.Add(e, new List<Edge>()); } for (int i = 0; i < M; i++) { var input = GetIntArray(); var a = isNode_0indexed ? input[0] : input[0] - 1; var b = isNode_0indexed ? input[1] : input[1] - 1; var c = input[2]; dic[a].Add(new Edge(b, c)); if (isDirected == false) dic[b].Add(new Edge(a, c)); } return dic; } bool eq<T, U>() => typeof(T).Equals(typeof(U)); T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T)); T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); void Multi<T>(out T a) => a = cv<T>(GetStr()); void Multi<T, U>(out T a, out U b) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); } void Multi<T, U, V>(out T a, out U b, out V c) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } } class Edge { public Edge(int to, long length) { To = to; Length = length; } public int To { get; set; } public long Length { get; set; } } partial class Program { static void Main() { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); new AtCoder().Solve(); Console.Out.Flush(); Console.Read(); } } public partial class AtCoder { public void Solve() { int A; int B; int C; int D; Multi(out A, out B, out C, out D); long mod = 998244353; long[][] F = CreateJaggedArray(C + 1, D + 1, 0L); F[A][B] = 1; for (int x = B; x < D; x++) { F[A][x + 1] = F[A][x] * A % mod; } for (int y = A; y < C; y++) { F[y + 1][B] = F[y][B] * B % mod; for (int x = B; x < D; x++) { F[y + 1][x + 1] = (F[y + 1][x] * (y + 1) % mod + F[y][x + 1] * (x + 1) % mod - y * x * F[y][x] % mod + mod) % mod; } } Console.WriteLine(F[C][D]); } } }
[["+", 0, 16, 31, 16, 31, 16, 31, 16, 17, 109], ["+", 0, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 17, 109], ["+", 0, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 17, 109], ["+", 31, 23, 0, 16, 31, 16, 12, 16, 12, 22]]
8
2,044
6
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using static System.Math; using static Program.IO.Scanner; using Number = System.Int64; using System.Numerics; #region IO namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } static public class Scanner { public static StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); public static int ri => sc.Integer(); public static long rl => sc.Long(); public static string rs => sc.Scan(); public static double rd => sc.Double(); } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); var t = new System.Threading.Thread(solver.Solve, 50000000); t.Start(); t.Join(); //*/ // solver.Solve(); Console.Out.Flush(); } } #endregion namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var s = rs + '0'; var k = ri; k = 1000000; var a = new List<int>(); var cnt = 0; foreach (var x in s) { if (x == '0') { a.Add(cnt); cnt = 0; } else cnt++; } var sum = a.Sum(); k = Min(k, sum); Debug.WriteLine(a.AsJoinedString()); var dp = Enumerate(k + 5, x => new ModInt[k + 5]); dp[0][0] = 1; foreach (var x in a) { // Debug.WriteLine("------"); var next = Enumerate(k + 5, y => new ModInt[k + 5]); for (int i = k; i >= 0; i--) for (int j = k; j >= 0; j--) if (dp[i][j].num != 0) { // Debug.WriteLine($"{i} {j} {dp[i][j]}"); next[i][j] += dp[i][j]; //ここを累積和でまとめる for (int ni = i + 1; ni <= k; ni++) next[ni][j] += dp[i][j]; for (int nj = j + 1; nj <= i && nj <= k && nj - j <= x; nj++) next[i][nj] += dp[i][j]; } dp = next; } ModInt ans = 0; for (int i = 0; i <= k; i++) ans += dp[i][i]; Console.WriteLine(ans); } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static T[][] Enumerate<T>(int n, int m, Func<int, int, T> f) { return Enumerate(n, x => Enumerate(m, y => f(x, y))); } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { public const long Mod = (int)998244353; public long num; public ModInt(long n) { num = n; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { return new ModInt(l.num + r.num < Mod ? l.num + r.num : l.num + r.num - Mod); } public static ModInt operator -(ModInt l, ModInt r) { return new ModInt(l.num + Mod - r.num < Mod ? l.num + Mod - r.num : l.num - r.num); } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static ModInt operator /(ModInt l, ModInt r) { return l * Inverse(r); } public static implicit operator ModInt(long n) { return n.mod(); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } public static partial class ModIntEx { public static ModInt mod(this long v) { v %= ModInt.Mod; if (v < 0) v += ModInt.Mod; return new ModInt(v); } public static ModInt mod(this int v) { var u = v % ModInt.Mod; if (u < 0) u += ModInt.Mod; return new ModInt(u); } public static ModInt m(this long v) { return new ModInt(v); } public static ModInt m(this int v) { return new ModInt(v); } } #endregion
using System; using System.Linq; using System.Collections.Generic; using Debug = System.Diagnostics.Trace; using SB = System.Text.StringBuilder; using static System.Math; using static Program.IO.Scanner; using Number = System.Int64; using System.Numerics; #region IO namespace Program.IO { using System.IO; using System.Text; using System.Globalization; public class Printer : StreamWriter { public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } } public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) {} } static public class Scanner { public static StreamScanner sc = new StreamScanner(Console.OpenStandardInput()); public static int ri => sc.Integer(); public static long rl => sc.Long(); public static string rs => sc.Scan(); public static double rd => sc.Double(); } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } public readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) return 0; if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char() { byte b = 0; do b = read(); while ((b < 33 || 126 < b) && !isEof); return (char)b; } public string Scan() { var sb = new StringBuilder(); for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } public string ScanLine() { var sb = new StringBuilder(); for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b); return sb.ToString(); } public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); } public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); } public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); } } } #endregion #region main static class Ex { static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); } static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") { return string.Join(st, ie); } static public void Main() { Console.SetOut(new Program.IO.Printer( Console.OpenStandardOutput()) { AutoFlush = false }); var solver = new Program.Solver(); var t = new System.Threading.Thread(solver.Solve, 50000000); t.Start(); t.Join(); //*/ // solver.Solve(); Console.Out.Flush(); } } #endregion namespace Program { public class Solver { Random rnd = new Random(0); public void Solve() { var s = rs + '0'; var k = ri; var a = new List<int>(); var cnt = 0; foreach (var x in s) { if (x == '0') { a.Add(cnt); cnt = 0; } else cnt++; } var sum = a.Sum(); k = Min(k, sum); Debug.WriteLine(a.AsJoinedString()); var dp = Enumerate(k + 5, x => new ModInt[k + 5]); dp[0][0] = 1; foreach (var x in a) { // Debug.WriteLine("------"); var next = Enumerate(k + 5, y => new ModInt[k + 5]); for (int i = k; i >= 0; i--) for (int j = k; j >= 0; j--) if (dp[i][j].num != 0) { // Debug.WriteLine($"{i} {j} {dp[i][j]}"); next[i][j] += dp[i][j]; //ここを累積和でまとめる for (int ni = i + 1; ni <= k; ni++) next[ni][j] += dp[i][j]; for (int nj = j + 1; nj <= i && nj <= k && nj - j <= x; nj++) next[i][nj] += dp[i][j]; } dp = next; } ModInt ans = 0; for (int i = 0; i <= k; i++) ans += dp[i][i]; Console.WriteLine(ans); } const long INF = 1L << 60; static int[] dx = { -1, 0, 1, 0 }; static int[] dy = { 0, 1, 0, -1 }; static T[] Enumerate<T>(int n, Func<int, T> f) { var a = new T[n]; for (int i = 0; i < a.Length; ++i) a[i] = f(i); return a; } static T[][] Enumerate<T>(int n, int m, Func<int, int, T> f) { return Enumerate(n, x => Enumerate(m, y => f(x, y))); } static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; } } } #region ModInt /// <summary> /// [0,<see cref="Mod"/>) までの値を取るような数 /// </summary> public struct ModInt { public const long Mod = (int)998244353; public long num; public ModInt(long n) { num = n; } public override string ToString() { return num.ToString(); } public static ModInt operator +(ModInt l, ModInt r) { return new ModInt(l.num + r.num < Mod ? l.num + r.num : l.num + r.num - Mod); } public static ModInt operator -(ModInt l, ModInt r) { return new ModInt(l.num + Mod - r.num < Mod ? l.num + Mod - r.num : l.num - r.num); } public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); } public static ModInt operator /(ModInt l, ModInt r) { return l * Inverse(r); } public static implicit operator ModInt(long n) { return n.mod(); } public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); } public static ModInt Pow(long v, long k) { long ret = 1; for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod) if ((k & 1) == 1) ret = ret * v % Mod; return new ModInt(ret); } public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); } } public static partial class ModIntEx { public static ModInt mod(this long v) { v %= ModInt.Mod; if (v < 0) v += ModInt.Mod; return new ModInt(v); } public static ModInt mod(this int v) { var u = v % ModInt.Mod; if (u < 0) u += ModInt.Mod; return new ModInt(u); } public static ModInt m(this long v) { return new ModInt(v); } public static ModInt m(this int v) { return new ModInt(v); } } #endregion
[["-", 0, 195, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 0, 195, 8, 196, 0, 1, 0, 11, 12, 203], ["-", 8, 201, 0, 195, 8, 196, 0, 1, 0, 35]]
8
1,684
4
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 x = Console.ReadLine().Split().Select(int.Parse).ToArray(); var ans = 0; for (int i = 0; i < 4; i++) { if (x[i] == 0) ans = i + 1; } Console.WriteLine(ans); } static public long Input() { return long.Parse(Console.ReadLine()); } static public string[] Input2() { return Console.ReadLine().Split(); } /*static public void DFS(int h, int w, bool[][] _visited) { if (w < 0 || h < 0 || h > _visited.Length - 1 || w > _visited[h].Length-1 || map[h][w]=='x') return; if (_visited[h][w]) return; //Console.WriteLine(h + " " + w+" "+ _visited[h].Length + " " + _visited.Length); _visited[h][w] = true; DFS(h + 1, w,_visited); DFS(h - 1, w,_visited); DFS(h, w + 1,_visited); DFS(h, w - 1,_visited); }*/ } }
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 x = Console.ReadLine().Split().Select(int.Parse).ToArray(); var ans = 0; for (int i = 0; i < 5; i++) { if (x[i] == 0) ans = i + 1; } Console.WriteLine(ans); } static public long Input() { return long.Parse(Console.ReadLine()); } static public string[] Input2() { return Console.ReadLine().Split(); } /*static public void DFS(int h, int w, bool[][] _visited) { if (w < 0 || h < 0 || h > _visited.Length - 1 || w > _visited[h].Length-1 || map[h][w]=='x') return; if (_visited[h][w]) return; //Console.WriteLine(h + " " + w+" "+ _visited[h].Length + " " + _visited.Length); _visited[h][w] = true; DFS(h + 1, w,_visited); DFS(h - 1, w,_visited); DFS(h, w + 1,_visited); DFS(h, w - 1,_visited); }*/ } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203]]
8
162
2
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var x = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < 5; i++) { if (x[i] == 0) { Console.WriteLine(i); break; } } } } }
using System; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { var x = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < 5; i++) { if (x[i] == 0) { Console.WriteLine(i + 1); break; } } } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
87
2
using System; namespace q1 { class q2 { static void Main() { string[] x = Console.ReadLine().Split(); int[] kazu = new int[5]; for (int gokai = 0; gokai < 5; gokai++) { kazu[gokai] = int.Parse(x[gokai]); } for (int y = 0; y < 5; y++) { if (kazu[y] == 0) { Console.WriteLine(y); } else { } } } } }
using System; namespace q1 { class q2 { static void Main() { string[] x = Console.ReadLine().Split(); int[] kazu = new int[5]; for (int gokai = 0; gokai < 5; gokai++) { kazu[gokai] = int.Parse(x[gokai]); } for (int y = 0; y < 5; y++) { if (kazu[y] == 0) { Console.WriteLine(y + 1); } else { } } } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
112
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc170/tasks/abc170_a class A_FiveVariables_170 { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int result = 0; for (int i = 0; i < inputLongArray.Length; i++) { if (inputLongArray[i] == 0) { result = i; } } Console.WriteLine(result); Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc170/tasks/abc170_a class A_FiveVariables_170 { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int result = 0; for (int i = 0; i < inputLongArray.Length; i++) { if (inputLongArray[i] == 0) { result = i + 1; } } Console.WriteLine(result); Console.Out.Flush(); } } }
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
165
2
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int i = 1; foreach (string str in input) { if (str == "0") { Console.WriteLine(i); break; } } } }
using System; class Program { static void Main(string[] args) { // スペース区切りの整数の入力 string[] input = Console.ReadLine().Split(' '); int i = 1; foreach (string str in input) { if (str == "0") { Console.WriteLine(i); break; } i++; } } }
[["+", 0, 210, 8, 196, 0, 1, 0, 223, 0, 22], ["+", 0, 210, 8, 196, 0, 1, 0, 223, 0, 29], ["+", 8, 196, 0, 210, 8, 196, 0, 1, 0, 35]]
8
70
3
using System; namespace AtCoder { public class Program { static void Main(string[] args) { int target = 0; string[] input = Console.ReadLine().Split(' '); int[] nums = new int[5]; for (int i = 0; i < 5; i++) { nums[i] = int.Parse(input[i]); } for (int i = 0; i < 5; i++) { if (nums[i] == 0) { target = i; } } Console.WriteLine(target); } } }
using System; namespace AtCoder { public class Program { static void Main(string[] args) { int target = 0; string[] input = Console.ReadLine().Split(' '); int[] nums = new int[5]; for (int i = 0; i < 5; i++) { nums[i] = int.Parse(input[i]); } for (int i = 0; i < 5; i++) { if (nums[i] == 0) { target = i + 1; } } Console.WriteLine(target); } } }
[["+", 64, 196, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
126
2
using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var a = ReadLine().Split(" "); for (int i = 0; i < a.Length; i++) { if (a[i] == "0") { WriteLine(i); return; } } return; } }
using System.Linq; using static System.Console; class Program { static void Main(string[] args) { var a = ReadLine().Split(" "); for (int i = 0; i < a.Length; i++) { if (a[i] == "0") { WriteLine(i + 1); return; } } return; } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
80
2
using System; using System.Linq; class A { static void Main() { Console.WriteLine(Console.ReadLine().Split().ToList().IndexOf("0")); } }
using System; using System.Linq; class A { static void Main() { Console.WriteLine(Console.ReadLine().Split().ToList().IndexOf("0") + 1); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
45
2
using System; using System.Globalization; using System.IO; using System.Text; public class Program { public static void Main(string[] args) { var stdin = Console.OpenStandardInput(); var ss = new StreamScanner(stdin); var p = new Program(); p.solve(ss); stdin.Close(); } private void solve(StreamScanner ss) { var x = ss.IntArray(5); var i = 1; while (i <= 5) { if (x[i] == 0) break; ++i; } Console.WriteLine(i); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char { get { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } } public string Scan { get { var sb = new StringBuilder(); for (var b = Char; b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } } public long Long { get { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } } public int Int => (int)Long; public int[] IntArray(int n) { var arr = new int[n]; for (var i = 0; i < n; ++i) { arr[i] = Int; } return arr; } public double Double => double.Parse(Scan, CultureInfo.InvariantCulture); }
using System; using System.Globalization; using System.IO; using System.Text; public class Program { public static void Main(string[] args) { var stdin = Console.OpenStandardInput(); var ss = new StreamScanner(stdin); var p = new Program(); p.solve(ss); stdin.Close(); } private void solve(StreamScanner ss) { var x = ss.IntArray(5); var i = 0; while (i < 5) { if (x[i] == 0) break; ++i; } Console.WriteLine(++i); } } public class StreamScanner { public StreamScanner(Stream stream) { str = stream; } private readonly Stream str; private readonly byte[] buf = new byte[1024]; private int len, ptr; public bool isEof = false; public bool IsEndOfStream { get { return isEof; } } private byte read() { if (isEof) throw new EndOfStreamException(); if (ptr >= len) { ptr = 0; if ((len = str.Read(buf, 0, 1024)) <= 0) { isEof = true; return 0; } } return buf[ptr++]; } public char Char { get { byte b = 0; do b = read(); while (b < 33 || 126 < b); return (char)b; } } public string Scan { get { var sb = new StringBuilder(); for (var b = Char; b >= 33 && b <= 126; b = (char)read()) sb.Append(b); return sb.ToString(); } } public long Long { get { long ret = 0; byte b = 0; var ng = false; do b = read(); while (b != '-' && (b < '0' || '9' < b)); if (b == '-') { ng = true; b = read(); } for (; true; b = read()) { if (b < '0' || '9' < b) return ng ? -ret : ret; else ret = ret * 10 + b - '0'; } } } public int Int => (int)Long; public int[] IntArray(int n) { var arr = new int[n]; for (var i = 0; i < n; ++i) { arr[i] = Int; } return arr; } public double Double => double.Parse(Scan, CultureInfo.InvariantCulture); }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 18], ["+", 0, 213, 3, 4, 0, 28, 0, 241, 0, 29]]
8
531
5
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class { static void Main(string[] args) { var x = RL<int>(); for (var i = 0; i < x.Length; i++) { if (x[i] == 0) { Console.Write(i); return; } } } static T[] RL<T>() where T : IComparable { if (typeof(T) == typeof(int)) { return (T[])(object)Console.ReadLine() .Trim() .Split() .Select(int.Parse) .ToArray(); } if (typeof(T) == typeof(long)) { return (T[])(object)Console.ReadLine() .Trim() .Split() .Select(long.Parse) .ToArray(); } if (typeof(T) == typeof(double)) { return (T[])(object)Console.ReadLine() .Trim() .Split() .Select(double.Parse) .ToArray(); } if (typeof(T) == typeof(decimal)) { return (T[])(object)Console.ReadLine() .Trim() .Split() .Select(decimal.Parse) .ToArray(); } return (T[])(object)Console.ReadLine().Trim().Split().ToArray(); } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApp1 { public class Class { static void Main(string[] args) { var x = RL<int>(); for (var i = 0; i < x.Length; i++) { if (x[i] == 0) { Console.Write(i + 1); return; } } } static T[] RL<T>() where T : IComparable { if (typeof(T) == typeof(int)) { return (T[])(object)Console.ReadLine() .Trim() .Split() .Select(int.Parse) .ToArray(); } if (typeof(T) == typeof(long)) { return (T[])(object)Console.ReadLine() .Trim() .Split() .Select(long.Parse) .ToArray(); } if (typeof(T) == typeof(double)) { return (T[])(object)Console.ReadLine() .Trim() .Split() .Select(double.Parse) .ToArray(); } if (typeof(T) == typeof(decimal)) { return (T[])(object)Console.ReadLine() .Trim() .Split() .Select(decimal.Parse) .ToArray(); } return (T[])(object)Console.ReadLine().Trim().Split().ToArray(); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
318
2
using System; namespace aziz { class Program { static void Main(string[] args) { String[] X = Console.ReadLine().Split(' '); int X1 = int.Parse(X[0]); int X2 = int.Parse(X[1]); int X3 = int.Parse(X[2]); int X4 = int.Parse(X[3]); int X5 = int.Parse(X[4]); for (int i = 0; i < X.Length; i++) { if (X[i] == "0") { Console.WriteLine(i); } } } } }
using System; namespace aziz { class Program { static void Main(string[] args) { String[] X = Console.ReadLine().Split(' '); int X1 = int.Parse(X[0]); int X2 = int.Parse(X[1]); int X3 = int.Parse(X[2]); int X4 = int.Parse(X[3]); int X5 = int.Parse(X[4]); for (int i = 0; i < X.Length; i++) { if (X[i] == "0") { Console.WriteLine(i + 1); } } } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
143
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc141/tasks/abc141_a public class QuestionA { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); string[] inputStrArray = Console.ReadLine().Split(' '); for (int i = 0; i < 4; i++) { if (inputStrArray[i] == "0") { Console.WriteLine((i + 1).ToString()); break; } } Console.Out.Flush(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoder.Abc { // https://atcoder.jp/contests/abc141/tasks/abc141_a public class QuestionA { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); string[] inputStrArray = Console.ReadLine().Split(' '); for (int i = 0; i <= 4; i++) { if (inputStrArray[i] == "0") { Console.WriteLine((i + 1).ToString()); break; } } Console.Out.Flush(); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
152
2
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { decimal[] a = Console.ReadLine().Split(" ").Select(x => decimal.Parse(x)).ToArray(); decimal res = 0; for (int i = 1; i <= a.Length; i++) { if (a[i] != i) { res = i; } } Console.WriteLine(res); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace ConsoleApp1 { class Program { static void Main(string[] args) { decimal[] a = Console.ReadLine().Split(" ").Select(x => decimal.Parse(x)).ToArray(); decimal res = 0; for (int i = 1; i < a.Length + 1; i++) { if (a[i - 1] != i) { res = i; } } Console.WriteLine(res); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
118
6
using System; namespace AtCoder { public static class AtCoder { public static void Main() { var input = Console.ReadLine().Split(' '); for (int i = 0; i < 5; i++) { if (input[0] == "0") { Console.WriteLine(i + 1); return; } } return; } } }
using System; namespace AtCoder { public static class AtCoder { public static void Main() { var input = Console.ReadLine().Split(' '); for (int i = 0; i < 5; i++) { if (input[i] == "0") { Console.WriteLine(i + 1); return; } } return; } } }
[["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 203], ["+", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22]]
8
79
2
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.IO; namespace AtCoder.XXX.A { public class Program { public static void Main(string[] args) { var datas = cr(); var cnt = 0; foreach (var data in datas) { if (data == 0) { P(cnt); return; } cnt++; } } private static StreamReader sr; public static int[] Ecr() { if (sr == null) { sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8")); } return sr.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Er() { if (sr == null) { sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8")); } return sr.ReadLine(); } public static string r() { return Console.ReadLine(); } public static int[] cr() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static int cri() { return int.Parse(Console.ReadLine()); } public static void P(string str) { Console.WriteLine(str); } public static void P(int num) { P(num.ToString()); } } }
using System; using System.Text; using System.Collections.Generic; using System.Linq; using System.IO; namespace AtCoder.XXX.A { public class Program { public static void Main(string[] args) { var datas = cr(); var cnt = 0; foreach (var data in datas) { if (data == 0) { P(cnt + 1); return; } cnt++; } } private static StreamReader sr; public static int[] Ecr() { if (sr == null) { sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8")); } return sr.ReadLine().Split().Select(int.Parse).ToArray(); } public static string Er() { if (sr == null) { sr = new StreamReader("input.txt", Encoding.GetEncoding("UTF-8")); } return sr.ReadLine(); } public static string r() { return Console.ReadLine(); } public static int[] cr() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); } public static int cri() { return int.Parse(Console.ReadLine()); } public static void P(string str) { Console.WriteLine(str); } public static void P(int num) { P(num.ToString()); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
298
2
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace B { 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 XY = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var X = XY[0]; var Y = XY[1]; var answer = false; for (var i = 1; i <= 100; i++) { var turu = i; var kame = X - i; if (2 * turu + 4 * kame == Y) answer = true; } Console.WriteLine(answer ? "Yes" : "No"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace B { 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 XY = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); var X = XY[0]; var Y = XY[1]; var answer = false; for (var i = 0; i <= X; i++) { var turu = i; var kame = X - i; if (2 * turu + 4 * kame == Y) answer = true; } Console.WriteLine(answer ? "Yes" : "No"); } } }
[["-", 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, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
201
4
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 xy = Console.ReadLine().Split().Select(int.Parse).ToArray(); var maxleg = 4 * xy[0]; var ans = ""; for (int i = 0; i <= xy[0]; i++) { if (xy[1] > maxleg) { ans = "No"; break; } else { if (maxleg - 2 * i == xy[1]) { ans = "Yes"; break; } } } Console.WriteLine(ans); } static public long Input() { return long.Parse(Console.ReadLine()); } static public string[] Input2() { return Console.ReadLine().Split(); } /*static public void DFS(int h, int w, bool[][] _visited) { if (w < 0 || h < 0 || h > _visited.Length - 1 || w > _visited[h].Length-1 || map[h][w]=='x') return; if (_visited[h][w]) return; //Console.WriteLine(h + " " + w+" "+ _visited[h].Length + " " + _visited.Length); _visited[h][w] = true; DFS(h + 1, w,_visited); DFS(h - 1, w,_visited); DFS(h, w + 1,_visited); DFS(h, w - 1,_visited); }*/ } }
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 xy = Console.ReadLine().Split().Select(int.Parse).ToArray(); var maxleg = 4 * xy[0]; var ans = "No"; for (int i = 0; i <= xy[0]; i++) { if (xy[1] > maxleg) { ans = "No"; break; } else { if (maxleg - 2 * i == xy[1]) { ans = "Yes"; break; } } // Console.WriteLine(maxleg - 2 * i); } Console.WriteLine(ans); } static public long Input() { return long.Parse(Console.ReadLine()); } static public string[] Input2() { return Console.ReadLine().Split(); } /*static public void DFS(int h, int w, bool[][] _visited) { if (w < 0 || h < 0 || h > _visited.Length - 1 || w > _visited[h].Length-1 || map[h][w]=='x') return; if (_visited[h][w]) return; //Console.WriteLine(h + " " + w+" "+ _visited[h].Length + " " + _visited.Length); _visited[h][w] = true; DFS(h + 1, w,_visited); DFS(h - 1, w,_visited); DFS(h, w + 1,_visited); DFS(h, w - 1,_visited); }*/ } }
[["+", 0, 198, 0, 200, 0, 212, 0, 5, 0, 222]]
8
206
1
using System; class IDONTKNOWCSHARP { public static void Main() { string[] values = Console.ReadLine().Split( new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); int num = int.Parse(values[0]); int leg = int.Parse(values[1]); int count = 0; while (num > count) { if (4 * count + 2 * (num - count) == leg) { Console.WriteLine("Yes"); return; } count++; } Console.WriteLine("No"); } }
using System; class IDONTKNOWCSHARP { public static void Main() { string[] values = Console.ReadLine().Split( new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); int num = int.Parse(values[0]); int leg = int.Parse(values[1]); int count = 0; while (num >= count) { if (4 * count + 2 * (num - count) == leg) { Console.WriteLine("Yes"); return; } count++; } Console.WriteLine("No"); } }
[["-", 0, 195, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 52, 15, 16, 17, 20]]
8
123
2
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(" "); var X = int.Parse(input[0]); var Y = int.Parse(input[1]); var result = "No"; for (int i = 1; i <= X; i++) { var turu = i; var kame = X - i; if ((turu * 2 + kame * 4) == Y) { result = "Yes"; break; } } Console.WriteLine(result); } }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = Console.ReadLine().Split(" "); var X = int.Parse(input[0]); var Y = int.Parse(input[1]); var result = "No"; for (int i = 0; i <= X; i++) { var turu = i; var kame = X - i; if ((turu * 2 + kame * 4) == Y) { result = "Yes"; break; } } Console.WriteLine(result); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
138
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { int[] vals = Console.ReadLine().Split(' ').Select(tmp => int.Parse(tmp)).ToArray(); int flag = 0; for (int i = 0; i < vals[0]; i++) { if (2 * i + 4 * (vals[0] - i) == vals[1]) { flag = 1; } } if (flag == 1) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { int[] vals = Console.ReadLine().Split(' ').Select(tmp => int.Parse(tmp)).ToArray(); int flag = 0; for (int i = 0; i < vals[0] + 1; i++) { if (2 * i + 4 * (vals[0] - i) == vals[1]) { flag = 1; } } if (flag == 1) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
161
2
using System; using System.Diagnostics; using System.Linq; namespace ConsoleApp1 { class Program { static void print(string s) { Console.WriteLine(s); } static string scan() { return Console.ReadLine(); } static void Main(string[] args) { int x, y; string[] lineArray = scan().Split(" "); x = int.Parse(lineArray[0]); y = int.Parse(lineArray[1]); int i = 0; for (i = 0; i < x; i++) { if (i * 2 + (x - i) * 4 == y) { i = 999; } } if (i >= 999) print("Yes"); else print("No"); } } }
using System; using System.Diagnostics; using System.Linq; namespace ConsoleApp1 { class Program { static void print(string s) { Console.WriteLine(s); } static string scan() { return Console.ReadLine(); } static void Main(string[] args) { int x, y; string[] lineArray = scan().Split(" "); x = int.Parse(lineArray[0]); y = int.Parse(lineArray[1]); int i = 0; for (i = 0; i <= x; i++) { if (i * 2 + (x - i) * 4 == y) { i = 999; } } if (i >= 999) print("Yes"); else print("No"); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
170
2
using System; namespace q1 { class q2 { static void Main() { string[] x = Console.ReadLine().Split(); int a = int.Parse(x[0]); int b = int.Parse(x[1]); if (a * 2 <= b && b <= a * 4) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; namespace q1 { class q2 { static void Main() { string[] x = Console.ReadLine().Split(); int a = int.Parse(x[0]); int b = int.Parse(x[1]); if (a * 2 <= b && b <= a * 4 && b % 2 == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
96
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderExamCS { class Program { static void Main(string[] args) { string tmp = Console.ReadLine(); string[] tmpSplit = tmp.Split(); int[] tmpInt = new int[2]; for (int i = 0; i < tmpSplit.Length; i++) { tmpInt[i] = int.Parse(tmpSplit[i]); } if (tmpInt[1] % 2 != 0 || tmpInt[0] > 50 || tmpInt[0] * 2 > tmpInt[1] || tmpInt[0] * 4 < tmpInt[1]) { Console.WriteLine("No"); } else { bool flag = false; for (int i = 0; i < tmpInt[0]; i++) { if ((tmpInt[0] - i) * 2 + i * 4 == tmpInt[1]) { flag = true; } } if (flag) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AtCoderExamCS { class Program { static void Main(string[] args) { string tmp = Console.ReadLine(); string[] tmpSplit = tmp.Split(); int[] tmpInt = new int[2]; for (int i = 0; i < tmpSplit.Length; i++) { tmpInt[i] = int.Parse(tmpSplit[i]); } if (tmpInt[1] % 2 != 0 || tmpInt[0] > 50 || tmpInt[0] * 2 > tmpInt[1] || tmpInt[0] * 4 < tmpInt[1]) { Console.WriteLine("No"); } else { bool flag = false; for (int i = 0; i <= tmpInt[0]; i++) { if ((tmpInt[0] - i) * 2 + i * 4 == tmpInt[1]) { flag = true; } } if (flag) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } } }
[["-", 0, 57, 75, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 75, 196, 0, 7, 15, 16, 17, 19]]
8
245
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] vs = (Console.ReadLine().Split(' ')); int X = Convert.ToInt32(vs[0]); int Y = Convert.ToInt32(vs[1]); bool a = false; for (int i = 0; i < X; i++) { if (2 * (i) + 4 * (X - i) == Y) { a = true; } } if (a == true) { Console.WriteLine("Yes"); } else Console.WriteLine("No"); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { string[] vs = (Console.ReadLine().Split(' ')); int X = Convert.ToInt32(vs[0]); int Y = Convert.ToInt32(vs[1]); bool a = false; for (int i = 0; i <= X; i++) { if (2 * (i) + 4 * (X - i) == Y) { a = true; } } if (a == true) { Console.WriteLine("Yes"); } else Console.WriteLine("No"); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
160
2
using System; using System.Collections.Generic; namespace test { class MainClass { public static void Main(string[] args) { string[] lines = Console.ReadLine().Split(' '); int x = int.Parse(lines[0]); int y = int.Parse(lines[1]); for (int i = 0; i < x + 1; i++) { if (i * 2 + (x - i) * 4 == y) { // Console.WriteLine(i); Console.WriteLine("YES"); return; } } Console.WriteLine("NO"); return; } } }
using System; using System.Collections.Generic; namespace test { class MainClass { public static void Main(string[] args) { string[] lines = Console.ReadLine().Split(' '); int x = int.Parse(lines[0]); int y = int.Parse(lines[1]); for (int i = 0; i < x + 1; i++) { if (i * 2 + (x - i) * 4 == y) { // Console.WriteLine(i); Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); return; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
133
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] strs = line.Split(' '); int X = int.Parse(strs[0]); int Y = int.Parse(strs[1]); if (Y >= X * 2 && Y <= X * 4) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace B { class Program { static void Main(string[] args) { string line = Console.ReadLine(); string[] strs = line.Split(' '); int X = int.Parse(strs[0]); int Y = int.Parse(strs[1]); if (Y >= X * 2 && Y <= X * 4 && Y % 2 == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
132
6
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace AtCoder { public class ABC { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(args); Console.Out.Flush(); } const int mod = 1000000007; // 10^9+7 static int Mod(long x, int m) { return (int)((x % m + m) % m); } static long Mod(long x, long m) { return (x % m + m) % m; } static public void Solve(string[] args) { // string s = Console.ReadLine(); // int n = int.Parse(Console.ReadLine()); // long x = long.Parse(Console.ReadLine()); // int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); // long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray(); int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); int x = vs[0]; int y = vs[1]; int a = y - (x * 2); if (a % 2 == 0 && a / 2 <= x) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; namespace AtCoder { public class ABC { static public void Main(string[] args) { Console.SetOut( new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); Solve(args); Console.Out.Flush(); } const int mod = 1000000007; // 10^9+7 static int Mod(long x, int m) { return (int)((x % m + m) % m); } static long Mod(long x, long m) { return (x % m + m) % m; } static public void Solve(string[] args) { // string s = Console.ReadLine(); // int n = int.Parse(Console.ReadLine()); // long x = long.Parse(Console.ReadLine()); // int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); // long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray(); int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray(); int x = vs[0]; int y = vs[1]; int a = y - (x * 2); if (a >= 0 && a % 2 == 0 && a / 2 <= x) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["+", 0, 57, 15, 16, 31, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 16, 31, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 98], ["+", 15, 16, 31, 16, 12, 16, 31, 16, 31, 22]]
8
244
4
using System; class Program { static bool _trigger; static void Main() { var line = Console.ReadLine(); var _line = line.Split(" "); int x = int.Parse(_line[0]); int y = int.Parse(_line[1]); for (int i = 0; i < x; i++) { if (i * 2 + (x - i) * 4 == y) { _trigger = true; } } string message = _trigger ? "Yes" : "No"; Console.WriteLine(message); } }
using System; class Program { static bool _trigger; static void Main() { var line = Console.ReadLine(); var _line = line.Split(" "); int x = int.Parse(_line[0]); int y = int.Parse(_line[1]); for (int i = 0; i < x + 1; i++) { if (i * 2 + (x - i) * 4 == y) { _trigger = true; } } string message = _trigger ? "Yes" : "No"; Console.WriteLine(message); } }
[["+", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
123
2
using System; class Program { static void Main() { String[] inline = Console.ReadLine().Split(' '); long x = long.Parse(inline[0]); long y = long.Parse(inline[1]); String ans = "No"; if (x % 2 == 0 && x * 4 >= y && x * 2 <= y) { ans = "Yes"; } Console.WriteLine(ans); } }
using System; class Program { static void Main() { String[] inline = Console.ReadLine().Split(' '); long x = long.Parse(inline[0]); long y = long.Parse(inline[1]); String ans = "No"; if (y % 2 == 0 && x * 4 >= y && x * 2 <= y) { ans = "Yes"; } Console.WriteLine(ans); } }
[["-", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 31, 22]]
8
100
2
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main() { string[] inputs = Console.ReadLine().Split(" "); int legsSum = int.Parse(inputs[1]); int animals = int.Parse(inputs[0]); bool possible = false; for (int i = 0; i <= animals; i++) { for (int j = 0; j <= animals; j++) { if (i * 4 + j * 2 == legsSum) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace AtCoder { class Program { static void Main() { string[] inputs = Console.ReadLine().Split(" "); int legsSum = int.Parse(inputs[1]); int animals = int.Parse(inputs[0]); bool possible = false; for (int i = 0; i <= animals; i++) { for (int j = 0; j <= animals; j++) { if (i * 4 + j * 2 == legsSum && i + j == animals) { Console.WriteLine("Yes"); return; } } } Console.WriteLine("No"); } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 72], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 60], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
150
6
using System; namespace B { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(" "); int X = int.Parse(input[0]); int Y = int.Parse(input[1]); string ans = "No"; for (int k = 1; k < 100; k++) { for (int t = 1; t < 100; t++) if (k + t == X && 2 * k + 4 * t == Y) { ans = "Yes"; break; } } Console.WriteLine(ans); } } }
using System; namespace B { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(" "); int X = int.Parse(input[0]); int Y = int.Parse(input[1]); string ans = "No"; for (int k = 0; k <= 100; k++) { for (int t = 0; t <= 100; t++) if (k + t == X && 2 * k + 4 * t == Y) { ans = "Yes"; break; } } Console.WriteLine(ans); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
138
8
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { //入力を保持する var input = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray(); //鶴のカウントとして控えておく var c = input[0]; var legs = input[1]; //亀は0匹スタートとする int t = 0; for (var n = 0; n < input[0]; n++) { if (4 * t + 2 * c == legs) { Console.WriteLine("Yes"); return; } c -= 1; t += 1; } Console.WriteLine("No"); } }
using System; using System.Collections.Generic; using System.Linq; public class Hello { public static void Main() { //入力を保持する var input = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray(); //鶴のカウントとして控えておく var c = input[0]; var legs = input[1]; //亀は0匹スタートとする int t = 0; for (var n = 0; n <= input[0]; n++) { if (4 * t + 2 * c == legs) { Console.WriteLine("Yes"); return; } c -= 1; t += 1; } Console.WriteLine("No"); } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
142
2
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.IO.Compression; using System.Linq; using System.Numerics; using System.Text; using Console = System.Console; namespace Atcoder { class Program { private const long COMDIV = 1000000007; static void Main(string[] args) { var XY = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i < XY[0]; i++) { var twoLeg = i; var fourLeg = XY[0] - i; if (twoLeg * 2 + fourLeg * 4 == XY[1]) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.IO.Compression; using System.Linq; using System.Numerics; using System.Text; using Console = System.Console; namespace Atcoder { class Program { private const long COMDIV = 1000000007; static void Main(string[] args) { var XY = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int i = 0; i <= XY[0]; i++) { var twoLeg = i; var fourLeg = XY[0] - i; if (twoLeg * 2 + fourLeg * 4 == XY[1]) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
8
177
2
using System.Collections.Generic; using static System.Console; class Program { static void Main(string[] args) { var a = ReadLine().Split(" "); var x = int.Parse(a[0]); var y = int.Parse(a[1]); for (int i = 0; i <= x; i++) { var legs = 0; legs = 4 * i + 2 * (x - i); if (legs == y) { WriteLine("YES"); return; } } WriteLine("NO"); } }
using System.Collections.Generic; using static System.Console; class Program { static void Main(string[] args) { var a = ReadLine().Split(" "); var x = int.Parse(a[0]); var y = int.Parse(a[1]); for (int i = 0; i <= x; i++) { var legs = 0; legs = 4 * i + 2 * (x - i); if (legs == y) { WriteLine("Yes"); return; } } WriteLine("No"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
127
4
using System; class Program { static void Main(string[] args) { string[] In = Console.ReadLine().Split(' '); int x = int.Parse(In[0]); int y = int.Parse(In[1]); bool flag = false; for (int i = 0; i <= 25; i++) // 4本 { int j = x - i; // 2本 int sum = 4 * i + 2 * j; if (sum == y) { flag = true; break; } } if (flag) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
using System; class Program { static void Main(string[] args) { string[] In = Console.ReadLine().Split(' '); int x = int.Parse(In[0]); int y = int.Parse(In[1]); bool flag = false; for (int i = 0; i <= 25; i++) // 4本 { int j = x - i; // 2本 int sum = 4 * i + 2 * j; if (sum == y && j >= 0) { flag = true; break; } } if (flag) Console.WriteLine("Yes"); else Console.WriteLine("No"); } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
140
4
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var x = int.Parse(line[0]); var y = int.Parse(line[1]); Console.WriteLine(getAns(x, y)); } static string getAns(int x, int y) { for (int c = 0; c <= 100; c++) { var t = x - c; if (c * 2 + t * 4 == y) { return "Yes"; } } return "No"; } }
using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var x = int.Parse(line[0]); var y = int.Parse(line[1]); Console.WriteLine(getAns(x, y)); } static string getAns(int x, int y) { for (int c = 0; c <= x; c++) { var t = x - c; if (c * 2 + t * 4 == y) { return "Yes"; } } return "No"; } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 12, 22]]
8
135
2
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); int[] tempArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int x = tempArray[0]; int y = tempArray[1]; int t = (y - 2 * x) / 2; int c = x - t; if (t > 0 && c > 0 && t + c == x && 4 * t + 2 * c == y) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.Out.Flush(); } } }
using System; using System.Linq; namespace AtCoder { class Program { static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); int[] tempArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray(); int x = tempArray[0]; int y = tempArray[1]; int t = (y - 2 * x) / 2; int c = x - t; if (t >= 0 && c >= 0 && t + c == x && 4 * t + 2 * c == y) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } Console.Out.Flush(); } } }
[["-", 15, 16, 31, 16, 31, 16, 31, 16, 17, 47], ["+", 15, 16, 31, 16, 31, 16, 31, 16, 17, 20], ["-", 15, 16, 31, 16, 31, 16, 12, 16, 17, 47], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 20]]
8
183
4
using System; using System.ComponentModel; using System.Security.Cryptography.X509Certificates; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] line = Console.ReadLine().Split(' '); int goukei = int.Parse(line[0]); int ashigoukei = int.Parse(line[1]); //全部鶴だった場合の足の数y int y = (4 * goukei); //想定との足差 int x = y - ashigoukei; //カメの匹数 int kame = x / 2; //鶴の匹数 int turu = (ashigoukei - kame * 2) / 4; if (turu * 4 + kame * 2 == ashigoukei && turu + kame == goukei && x >= 0 && y >= 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
using System; using System.ComponentModel; using System.Security.Cryptography.X509Certificates; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] line = Console.ReadLine().Split(' '); int goukei = int.Parse(line[0]); int ashigoukei = int.Parse(line[1]); //全部鶴だった場合の足の数y int y = (4 * goukei); //想定との足差 int x = y - ashigoukei; //カメの匹数 int kame = x / 2; //鶴の匹数 int turu = (ashigoukei - kame * 2) / 4; if (turu * 4 + kame * 2 == ashigoukei && turu + kame == goukei && turu >= 0 && kame >= 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } }
[["-", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 16, 31, 16, 12, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
8
169
4
using System; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var sp = Console.ReadLine().Split(' '); var x = int.Parse(sp[0]); var y = int.Parse(sp[1]); if (y % 2 != 0 || y / 2 < x || y / 4 > x) { Console.WriteLine("No"); } else { Console.WriteLine("Yes"); } Console.Out.Flush(); } } }
using System; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); var sp = Console.ReadLine().Split(' '); var x = int.Parse(sp[0]); var y = int.Parse(sp[1]); if (y % 2 != 0 || y / 2 < x || (y + 3) / 4 > x) { Console.WriteLine("No"); } else { Console.WriteLine("Yes"); } Console.Out.Flush(); } } }
[["+", 15, 16, 12, 16, 31, 16, 31, 23, 0, 24], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 12, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 15, 16, 12, 16, 31, 16, 31, 23, 0, 25]]
8
147
4
using System; using System.Linq; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); var count = inputLongArray[0]; var legs = inputLongArray[1]; string result = judge(count, legs); Console.WriteLine(result); Console.Out.Flush(); } public static string judge(long count, long legs) { if ((4 * count - legs) % 2 != 0) return "No"; var result = (4 * count - legs) / 2; if (result < 0 || result > 100) return "No"; return "Yes"; } } }
using System; using System.Linq; namespace AtCoder.Abc { class QuestionB { public static void Main(string[] args) { var sw = new System.IO.StreamWriter( Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); // 整数配列の入力 var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray(); var count = inputLongArray[0]; var legs = inputLongArray[1]; string result = judge(count, legs); Console.WriteLine(result); Console.Out.Flush(); } public static string judge(long count, long legs) { if ((4 * count - legs) % 2 != 0) return "No"; var result = (4 * count - legs) / 2; if (result < 0 || result > count) return "No"; return "Yes"; } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 22]]
8
198
2
using System; namespace atcoder { class Atcoder170 { static void Main(string[] args) { string[] input = Console.ReadLine().Split(" "); int a = Int32.Parse(input[0]); int b = Int32.Parse(input[1]); if (b % 2 == 1) { Console.WriteLine("No"); return; } if (a == (b * 2) || a == (b * 4)) { Console.WriteLine("Yes"); return; } for (int cc = a - 1, d = 1; cc > 0; cc--, d++) { if ((cc * 2 + d * 4) == b) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
using System; namespace atcoder { class Atcoder170 { static void Main(string[] args) { string[] input = Console.ReadLine().Split(" "); int a = Int32.Parse(input[0]); int b = Int32.Parse(input[1]); if (b % 2 == 1) { Console.WriteLine("No"); return; } if (b == (a * 2) || b == (a * 4)) { Console.WriteLine("Yes"); return; } for (int cc = a - 1, d = 1; cc > 0; cc--, d++) { if ((cc * 2 + d * 4) == b) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 31, 22], ["-", 15, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["+", 15, 16, 31, 16, 12, 23, 0, 16, 31, 22], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22], ["-", 15, 16, 12, 16, 12, 23, 0, 16, 31, 22], ["+", 15, 16, 12, 16, 12, 23, 0, 16, 31, 22]]
8
179
8
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int h = int.Parse(input[0]); int f = int.Parse(input[1]); if (h * 2 > f || h * 4 < f) { Console.WriteLine("No"); } else { Console.WriteLine("Yes"); } } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int h = int.Parse(input[0]); int f = int.Parse(input[1]); if (h * 2 > f || h * 4 < f || f % 2 != 0) { Console.WriteLine("No"); } else { Console.WriteLine("Yes"); } } }
[["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 106], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 109], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 79], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
99
6
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = INP(); int num = TOI(input[0]); int sousuu = TOI(input[1]); if (sousuu % 2 == 1) { CWL("NO"); return; } if (sousuu > num * 4) { CWL("NO"); return; } if (sousuu < num * 2) { CWL("NO"); return; } CWL("YES"); } public static List<int> PrimeFactors(int n) { var tmpList = new List<int>(); int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; tmpList.Add(i); } else { i++; } } if (tmp != 1) tmpList.Add(tmp); return tmpList; } static string[] INP() { return Console.ReadLine().Split(' '); } static void CWL(string value) { Console.WriteLine(value); } static void CWL(int value) { Console.WriteLine(value); } static void CWL(long value) { Console.WriteLine(value); } static void CWL(float value) { Console.WriteLine(value); } static void CWL(double value) { Console.WriteLine(value); } static int TOI(string str) { return int.Parse(str); } static long TOL(string str) { return long.Parse(str); } static float TOF(string str) { return float.Parse(str); } static double TOD(string str) { return double.Parse(str); } /*static void Main (string[] args) { var input = INP(); var input2 = INP(); var input3 = INP(); CWL("dummy"); }*/ }
using System; using System.Collections.Generic; using System.Linq; class Program { static void Main(string[] args) { var input = INP(); int num = TOI(input[0]); int sousuu = TOI(input[1]); if (sousuu % 2 == 1) { CWL("No"); return; } if (sousuu > num * 4) { CWL("No"); return; } if (sousuu < num * 2) { CWL("No"); return; } CWL("Yes"); } public static List<int> PrimeFactors(int n) { var tmpList = new List<int>(); int i = 2; int tmp = n; while (i * i <= n) { if (tmp % i == 0) { tmp /= i; tmpList.Add(i); } else { i++; } } if (tmp != 1) tmpList.Add(tmp); return tmpList; } static string[] INP() { return Console.ReadLine().Split(' '); } static void CWL(string value) { Console.WriteLine(value); } static void CWL(int value) { Console.WriteLine(value); } static void CWL(long value) { Console.WriteLine(value); } static void CWL(float value) { Console.WriteLine(value); } static void CWL(double value) { Console.WriteLine(value); } static int TOI(string str) { return int.Parse(str); } static long TOL(string str) { return long.Parse(str); } static float TOF(string str) { return float.Parse(str); } static double TOD(string str) { return double.Parse(str); } /*static void Main (string[] args) { var input = INP(); var input2 = INP(); var input3 = INP(); CWL("dummy"); }*/ }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
382
8
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc170 { 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_abc170B(); Console.Out.Flush(); } public static void solve_abc170B() { int[] xy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int x = xy[0]; int y = xy[1]; double a = (double)(y - (2 * x)) / 2; double b = x - a; if (y % 2 != 0) { Console.WriteLine("No"); } else if (a >= 0 && b >= 0 && a + b == x) { Console.WriteLine("Yes"); } else { Console.WriteLine("NO"); } } public static void solve_abc170A() { int[] x = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); for (int i = 0; i < x.Length; i++) { if (x[i] == 0) { Console.WriteLine(i + 1); break; } } } } }
using System; using System.IO; using System.Linq; using System.Collections.Generic; using System.Text; using System.Numerics; namespace abc170 { 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_abc170B(); Console.Out.Flush(); } public static void solve_abc170B() { int[] xy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); int x = xy[0]; int y = xy[1]; double a = (double)(y - (2 * x)) / 2; double b = x - a; if (y % 2 != 0) { Console.WriteLine("No"); } else if (a >= 0 && b >= 0 && a + b == x) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } public static void solve_abc170A() { int[] x = Array.ConvertAll(Console.ReadLine().Split(), int.Parse); for (int i = 0; i < x.Length; i++) { if (x[i] == 0) { Console.WriteLine(i + 1); break; } } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
311
2
using System; class p { static void Main() { string[] ipt = Console.ReadLine().Split(' '); int X = int.Parse(ipt[0]); int Y = int.Parse(ipt[1]); bool result = false; for (int i = 0; i < X; i++) { if (((i * 4) + ((X - i) * 2)) == Y) { result = true; break; } } Console.WriteLine(result ? "Yes" : "No"); } }
using System; class p { static void Main() { string[] ipt = Console.ReadLine().Split(' '); int X = int.Parse(ipt[0]); int Y = int.Parse(ipt[1]); bool result = false; for (int i = 0; i <= X; i++) { if (((i * 4) + ((X - i) * 2)) == Y) { result = true; break; } } Console.WriteLine(result ? "Yes" : "No"); } }
[["-", 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; using System.Collections.Generic; using System.IO; using System.Linq; public class Contestant { public static void Main(string[] args) { checked { var /*XY*/ (X, Y) = (Int(), Int()); for (int i = 0; i <= X; i++) { var legs = i * 2 + (X - 1) * 4; if (legs == Y) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } private static string NextInput = ""; private static int Int() => int.Parse(Str()); private static long Long() => long.Parse(Str()); private static float Float() => float.Parse(Str()); private static double Double() => double.Parse(Str()); private static string Str() { var s = NextInput; if (s == "") s = Console.ReadLine(); var idx = s.IndexOf(' '); if (idx >= 0) { NextInput = s.Substring(idx + 1); return s.Substring(0, idx); } NextInput = ""; return s; } }
using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; public class Contestant { public static void Main(string[] args) { checked { var /*XY*/ (X, Y) = (Int(), Int()); for (int i = 0; i <= X; i++) { var legs = i * 2 + (X - i) * 4; if (legs == Y) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } } private static string NextInput = ""; private static int Int() => int.Parse(Str()); private static long Long() => long.Parse(Str()); private static float Float() => float.Parse(Str()); private static double Double() => double.Parse(Str()); private static string Str() { var s = NextInput; if (s == "") s = Console.ReadLine(); var idx = s.IndexOf(' '); if (idx >= 0) { NextInput = s.Substring(idx + 1); return s.Substring(0, idx); } NextInput = ""; return s; } }
[["-", 0, 16, 12, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 12, 22]]
8
271
2
using System; using System.Collections.Generic; using System.Linq; public class GFG { public static void Main() { var input = Console.ReadLine().Split(' '); var tot = int.Parse(input[0]); var legs = int.Parse(input[1]); for (int i = 1; i <= 100; i++) { for (int j = 1; j <= 100; j++) { if ((i * 2 + j * 4) == legs) { if (i + j == tot) { Console.Write("Yes"); return; } } } } Console.Write("No"); } }
using System; using System.Collections.Generic; using System.Linq; public class GFG { public static void Main() { var input = Console.ReadLine().Split(' '); var tot = int.Parse(input[0]); var legs = int.Parse(input[1]); for (int i = 0; i <= 100; i++) { for (int j = 0; j <= 100; j++) { if ((i * 2 + j * 4) == legs) { if (i + j == tot) { Console.Write("Yes"); return; } } } } Console.Write("No"); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
148
4
using System; using System.Linq; class Program { static void Main(string[] args) { int[] xy = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int x = xy[0]; int y = xy[1]; for (int i = 1; i <= x; i++) { if (2 * i + 4 * (x - i) == y) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } }
using System; using System.Linq; class Program { static void Main(string[] args) { int[] xy = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); int x = xy[0]; int y = xy[1]; for (int i = 0; i <= x; i++) { if (2 * i + 4 * (x - i) == y) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
127
2
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; static void Main(string[] args) { var r = ReadSplit(); var x = r[0].Int(); var y = r[1].Int(); if (x * 4 < y) { WriteRead("No"); return; } if (((y - 2 * x) / 2) < 0) { WriteRead("No"); } if ((y - 2 * x) % 2 == 0) { WriteRead("Yes"); } else { 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); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
using System; using System.Collections.Generic; using System.Windows; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Atcoder { public class Program { private static long mod = 1000000007; static void Main(string[] args) { var r = ReadSplit(); var x = r[0].Int(); var y = r[1].Int(); if (x * 4 < y) { WriteRead("No"); return; } if (((y - 2 * x) / 2) < 0) { WriteRead("No"); return; } if ((y - 2 * x) % 2 == 0) { WriteRead("Yes"); } else { 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); } private static bool ChangeMin<T>(ref T a, T b) where T : IComparable { if (a.CompareTo(b) > 0) { a = b; return true; } return false; } private static bool ChangekMax<T>(ref T a, T b) where T : IComparable { if (b.CompareTo(a) > 0) { a = b; return true; } return false; } } } public static class Extentions { public static int Int(this object obj) { return int.Parse(obj.ToString()); } public static long Long(this object obj) { return long.Parse(obj.ToString()); } public static decimal Decimal(this object obj) { return decimal.Parse(obj.ToString()); } public static double Double(this object obj) { return double.Parse(obj.ToString()); } public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct { T2 value; if (d.TryGetValue(key, out value)) { return value; } return new T2(); } }
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
8
484
2
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int x = int.Parse(input[0]); int y = int.Parse(input[1]); for (int i = 0; i <= x; i++) { int j = x - i; if (i * 2 + j * 4 == y) { Console.WriteLine("YES"); return; } } Console.WriteLine("NO"); } }
using System; class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int x = int.Parse(input[0]); int y = int.Parse(input[1]); for (int i = 0; i <= x; i++) { int j = x - i; if (i * 2 + j * 4 == y) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
119
4
using System; class Class3 { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int X = int.Parse(input[0]); int Y = int.Parse(input[1]); string result = "Yes"; if ((4 * X - Y) < 0 || ((4 * X - Y) % 2) > 1) { result = "No"; } if ((-2 * X + Y) < 0 || ((-2 * X + Y) % 2) > 1) { result = "No"; } Console.WriteLine(result); } }
using System; class Class3 { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int X = int.Parse(input[0]); int Y = int.Parse(input[1]); string result = "Yes"; if ((4 * X - Y) < 0 || ((4 * X - Y) % 2) >= 1) { result = "No"; } if ((-2 * X + Y) < 0 || ((-2 * X + Y) % 2) >= 1) { result = "No"; } Console.WriteLine(result); } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20]]
8
146
4
using System; class Program { static void Main(string[] args) { string[] strInput = Console.ReadLine().Split(' '); ; int x = int.Parse(strInput[0]); int y = int.Parse(strInput[1]); int tsuru, kame; if (y % 2 != 0) { Console.WriteLine("NO"); return; } kame = y / 2 - x; tsuru = 2 * x - y / 2; if (kame < 0 || tsuru < 0) { Console.WriteLine("NO"); return; } if (kame + tsuru == x) { if (2 * tsuru + 4 * kame == y) { Console.WriteLine("YES"); return; } } Console.WriteLine("NO"); return; } }
using System; class Program { static void Main(string[] args) { string[] strInput = Console.ReadLine().Split(' '); ; int x = int.Parse(strInput[0]); int y = int.Parse(strInput[1]); int tsuru, kame; if (y % 2 != 0) { Console.WriteLine("No"); return; } kame = y / 2 - x; tsuru = 2 * x - y / 2; if (kame < 0 || tsuru < 0) { Console.WriteLine("No"); return; } if (kame + tsuru == x) { if (2 * tsuru + 4 * kame == y) { Console.WriteLine("Yes"); return; } } Console.WriteLine("No"); return; } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
176
8
using System; namespace ABC170B { class Program { static void Main(string[] args) { var t = Console.ReadLine().Trim().Split(' '); int X = int.Parse(t[0]); int Y = int.Parse(t[1]); bool f = false; for (int i = 0; i < 101; i++) { if (i * 2 + (X - i) * 4 == Y) { f = true; break; } } if (f) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
using System; namespace ABC170B { class Program { static void Main(string[] args) { var t = Console.ReadLine().Trim().Split(' '); int X = int.Parse(t[0]); int Y = int.Parse(t[1]); bool f = false; for (int i = 0; i < 101; i++) { if (i * 2 + (X - i) * 4 == Y && X - i >= 0) { f = true; break; } } if (f) Console.WriteLine("Yes"); else Console.WriteLine("No"); } } }
[["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 98], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 57, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 20], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 12, 203]]
8
136
6
using System; namespace ForAtcoder { class Program { static void Main(string[] args) { var arg = Console.ReadLine().Split(" "); var x = long.Parse(arg[0]); var y = long.Parse(arg[1]); for (var i = 1; i <= 100; i++) { for (var j = 1; j <= 100; j++) { if (i + j == x && 2 * i + 4 * j == y) { Console.WriteLine("Yes"); goto END; } if (i == 100 && j == 100) Console.WriteLine("No"); } } END:; } } }
using System; namespace ForAtcoder { class Program { static void Main(string[] args) { var arg = Console.ReadLine().Split(" "); var x = long.Parse(arg[0]); var y = long.Parse(arg[1]); for (var i = 0; i <= 100; i++) { for (var j = 0; j <= 100; j++) { if (i + j == x && 2 * i + 4 * j == y) { Console.WriteLine("Yes"); goto END; } if (i == 100 && j == 100) Console.WriteLine("No"); } } END:; } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
150
4
using System; using System.Collections.Generic; using System.Linq; namespace PaizaTest { class Program { static void Main(string[] args) { var xy = Console.ReadLine().Split().Select(int.Parse).ToList(); var headCount = xy[0]; var footCount = xy[1]; // 亀の数を増やしながら数える var result = "No"; for (int i = 0; i < headCount; i++) { var turtleNum = i; var craneNum = headCount - i; if (turtleNum * 4 + craneNum * 2 == footCount) { result = "Yes"; } } Console.WriteLine(result); } } }
using System; using System.Collections.Generic; using System.Linq; namespace PaizaTest { class Program { static void Main(string[] args) { var xy = Console.ReadLine().Split().Select(int.Parse).ToList(); var headCount = xy[0]; var footCount = xy[1]; // 亀の数を増やしながら数える var result = "No"; for (int i = 0; i <= headCount; i++) { var turtleNum = i; var craneNum = headCount - i; if (turtleNum * 4 + craneNum * 2 == footCount) { result = "Yes"; break; } } Console.WriteLine(result); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
8
137
4