dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { public class Node { public int key ; public Node left , right ; } ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . left = temp . right = null ; return temp ; } static int ans ; static void countReqNodes ( Node root , int minNodeVal ) { if ( root == null ) return ; if ( root . key <= minNodeVal ) { minNodeVal = root . key ; ans ++ ; } countReqNodes ( root . left , minNodeVal ) ; countReqNodes ( root . right , minNodeVal ) ; } public static void Main ( String [ ] args ) { Node root = newNode ( 8 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 6 ) ; root . left . right = newNode ( 7 ) ; root . right . left = newNode ( 3 ) ; root . right . right = newNode ( 9 ) ; int minNodeVal = int . MaxValue ; ans = 0 ; countReqNodes ( root , minNodeVal ) ; Console . Write ( ans ) ; } }

Accumulator variables: ans
Class/struct names: GFG, Node
C# program:
using System ; using System . Text ; class GFG { static bool isPalindrome ( String str ) { int i = 0 , j = str . Length - 1 ; while ( i < j ) { if ( str [ i ] != str [ j ] ) return false ; i ++ ; j -- ; } return true ; } static void formPalindrome ( String a , String b , int n ) { char [ ] aa = new char [ n + 2 ] ; char [ ] bb = new char [ n + 2 ] ; for ( int i = 0 ; i < n + 2 ; i ++ ) { aa [ i ] = ' ▁ ' ; bb [ i ] = ' ▁ ' ; } for ( int i = 1 ; i <= n ; i ++ ) { aa [ i ] = a [ i - 1 ] ; bb [ i ] = b [ i - 1 ] ; } bool ok = false ; for ( int i = 0 ; i <= n + 1 ; i ++ ) { StringBuilder la = new StringBuilder ( ) ; StringBuilder ra = new StringBuilder ( ) ; StringBuilder lb = new StringBuilder ( ) ; StringBuilder rb = new StringBuilder ( ) ; for ( int j = 1 ; j <= i - 1 ; j ++ ) { la . Append ( ( aa [ j ] == ' ▁ ' ) ? ' ▁ ' : aa [ j ] ) ; lb . Append ( ( bb [ j ] == ' ▁ ' ) ? ' ▁ ' : bb [ j ] ) ; } for ( int j = i ; j <= n + 1 ; j ++ ) { ra . Append ( ( aa [ j ] == ' ▁ ' ) ? ' ▁ ' : aa [ j ] ) ; rb . Append ( ( bb [ j ] == ' ▁ ' ) ? ' ▁ ' : bb [ j ] ) ; } if ( isPalindrome ( la . ToString ( ) + rb . ToString ( ) ) || isPalindrome ( lb . ToString ( ) + ra . ToString ( ) ) ) { ok = true ; break ; } } if ( ! ok ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } public static void Main ( String [ ] args ) { String A = " bdea " ; String B = " abbb " ; int N = 4 ; formPalindrome ( A , B , N ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: ok
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int minElements ( int [ ] A , int [ ] B , int N , int M ) { Dictionary < int , int > map = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < A . Length ; i ++ ) { map . Add ( A [ i ] , i ) ; } List < int > subseq = new List < int > ( ) ; int l = 0 , r = - 1 ; for ( int i = 0 ; i < M ; i ++ ) { if ( map . ContainsKey ( B [ i ] ) ) { int e = map [ B [ i ] ] ; while ( l <= r ) { int m = l + ( r - l ) / 2 ; if ( subseq [ m ] < e ) l = m + 1 ; else r = m - 1 ; } if ( r + 1 < subseq . Count ) { subseq [ r + 1 ] = e ; } else { subseq . Add ( e ) ; } l = 0 ; r = subseq . Count - 1 ; } } return N - subseq . Count ; } public static void Main ( String [ ] args ) { int [ ] A = { 1 , 2 , 3 , 4 , 5 } ; int [ ] B = { 2 , 5 , 6 , 4 , 9 , 12 } ; int M = A . Length ; int N = B . Length ; Console . WriteLine ( minElements ( A , B , M , N ) ) ; } }

Index/key variables: i, m
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static bool sfpa ( int V , int src , int [ , ] Edges , int M ) { List < pair > [ ] g = new List < pair > [ V ] ; for ( int i = 0 ; i < V ; i ++ ) { g [ i ] = new List < pair > ( ) ; } for ( int i = 0 ; i < M ; i ++ ) { int u = Edges [ i , 0 ] ; int v = Edges [ i , 1 ] ; int w = Edges [ i , 2 ] ; g [ u ] . Add ( new pair ( v , w ) ) ; } int [ ] dist = new int [ V ] ; for ( int i = 0 ; i < V ; i ++ ) dist [ i ] = int . MaxValue ; bool [ ] inQueue = new bool [ V ] ; int [ ] cnt = new int [ V ] ; dist [ src ] = 0 ; Queue < int > q = new Queue < int > ( ) ; q . Enqueue ( src ) ; inQueue [ src ] = true ; while ( q . Count != 0 ) { int u = q . Peek ( ) ; q . Dequeue ( ) ; inQueue [ u ] = false ; foreach ( pair x in g [ u ] ) { int v = x . first ; int cost = x . second ; if ( dist [ v ] > dist [ u ] + cost ) { dist [ v ] = dist [ u ] + cost ; if ( ! inQueue [ v ] ) { q . Enqueue ( v ) ; inQueue [ v ] = true ; cnt [ v ] ++ ; if ( cnt [ v ] >= V ) return true ; } } } } return false ; } public static void Main ( String [ ] args ) { int N = 4 ; int src = 0 ; int M = 4 ; int [ , ] Edges = { { 0 , 1 , 1 } , { 1 , 2 , - 1 } , { 2 , 3 , - 1 } , { 3 , 0 , - 1 } } ; if ( sfpa ( N , src , Edges , M ) == true ) Console . Write ( " Yes " + " STRNEWLINE " ) ; else Console . Write ( " No " + " STRNEWLINE " ) ; } }

Index/key variables: V, i, src, u, v
Accumulator variables: i
Iterator variables: i, x
Class/struct names: GFG, pair
C# program:
using System ; class GFG { static readonly int INF = 99999 ; static int floyd_warshall ( int [ , ] graph , int V ) { int [ , ] dist = new int [ V , V ] ; int i , j , k ; for ( i = 0 ; i < V ; i ++ ) { for ( j = 0 ; j < V ; j ++ ) { dist [ i , j ] = graph [ i , j ] ; } } for ( k = 0 ; k < V ; k ++ ) { for ( i = 0 ; i < V ; i ++ ) { for ( j = 0 ; j < V ; j ++ ) { if ( dist [ i , k ] + dist [ k , j ] < dist [ i , j ] ) { dist [ i , j ] = dist [ i , k ] + dist [ k , j ] ; } } } } int sum = 0 ; for ( i = 0 ; i < V ; i ++ ) { for ( j = i + 1 ; j < V ; j ++ ) { sum += dist [ i , j ] ; } } return sum ; } static int sumOfshortestPath ( int N , int E , int [ , ] edges ) { int [ , ] g = new int [ N , N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { g [ i , j ] = INF ; } } for ( int i = 0 ; i < E ; i ++ ) { int u = edges [ i , 0 ] ; int v = edges [ i , 1 ] ; int w = edges [ i , 2 ] ; g [ u , v ] = w ; g [ v , u ] = w ; } return floyd_warshall ( g , N ) ; } public static void Main ( String [ ] args ) { int N = 4 ; int E = 3 ; int [ , ] Edges = { { 0 , 1 , 1 } , { 1 , 2 , 2 } , { 2 , 3 , 3 } } ; Console . Write ( sumOfshortestPath ( N , E , Edges ) ) ; } }

Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static void print_kth_string ( string s , int K ) { int N = s . Length ; int i ; for ( i = 0 ; i < N ; i ++ ) { if ( s [ i ] == ' ▁ ' ) K -- ; if ( K == 1 ) break ; } while ( i ++ < N - 1 && s [ i ] != ' ▁ ' ) Console . Write ( s [ i ] ) ; } public static void Main ( ) { string s = "10 ▁ 20 ▁ 30 ▁ 40" ; int K = 4 ; print_kth_string ( s , K ) ; } }

Index/key variables: i
Accumulator variables: K, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void minPeaks ( List < int > list ) { int n = list . Count ; List < int > result = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int min = int . MaxValue ; int index = - 1 ; int size = list . Count ; for ( int j = 0 ; j < size ; j ++ ) { if ( j == 0 && j + 1 < size ) { if ( list [ j ] > list [ j + 1 ] && min > list [ j ] ) { min = list [ j ] ; index = j ; } } else if ( j == size - 1 && j - 1 >= 0 ) { if ( list [ j ] > list [ j - 1 ] && min > list [ j ] ) { min = list [ j ] ; index = j ; } } else if ( size == 1 ) { min = list [ j ] ; index = j ; } else if ( list [ j ] > list [ j - 1 ] && list [ j ] > list [ j + 1 ] && min > list [ j ] ) { min = list [ j ] ; index = j ; } } list . RemoveAt ( index ) ; result . Add ( min ) ; } for ( int i = 0 ; i < result . Count ; i ++ ) Console . Write ( result [ i ] + " , ▁ " ) ; } public static void Main ( String [ ] args ) { List < int > arr = new List < int > { 1 , 9 , 7 , 8 , 2 , 6 } ; minPeaks ( arr ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int binarySearch ( int [ ] arr , int N , int X ) { int start = 0 ; int end = N ; while ( start <= end ) { int mid = start + ( end - start ) / 2 ; if ( X == arr [ mid ] ) { return mid ; } else if ( X < arr [ mid ] ) { start = mid + 1 ; } else { end = mid - 1 ; } } return - 1 ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 4 , 3 , 2 , 1 } ; int N = arr . Length ; int X = 5 ; Console . WriteLine ( binarySearch ( arr , N , X ) ) ; } }

Index/key variables: mid
Class/struct names: GFG
C# program:
using System ; class GFG { static bool check_both_present ( int [ ] arr , int N , int a , int b ) { bool f1 = false , f2 = false ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == a ) { f1 = true ; } if ( arr [ i ] == b ) { f2 = true ; } } if ( f1 && f2 ) { return true ; } else { return false ; } } static void print_array ( int [ ] ans , int N ) { for ( int i = 0 ; i < N ; i ++ ) { Console . Write ( ans [ i ] + " ▁ " ) ; } } static void build_AP ( int N , int a , int b ) { int [ ] arr = new int [ N ] ; int [ ] ans = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) ans [ i ] = int . MaxValue ; if ( a > b ) { a += ( b - ( b = a ) ) ; } int diff = b - a ; for ( int start = 1 ; start <= a ; start ++ ) { for ( int d = 1 ; d <= diff ; d ++ ) { arr [ 0 ] = start ; for ( int i = 1 ; i < N ; i ++ ) { arr [ i ] = arr [ i - 1 ] + d ; } if ( check_both_present ( arr , N , a , b ) && arr [ N - 1 ] < ans [ N - 1 ] ) { for ( int i = 0 ; i < N ; i ++ ) { ans [ i ] = arr [ i ] ; } } } } print_array ( ans , N ) ; } static public void Main ( ) { int N = 5 , A = 20 , B = 50 ; build_AP ( N , A , B ) ; } }

Index/key variables: N, i
Accumulator variables: a, d, i, start
Iterator variables: d, i, start
Boolean variables: f1, f2
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static String isPrefixOfWord ( String sentence , String Word ) { String [ ] a = sentence . Split ( ' ▁ ' ) ; List < String > v = new List < String > ( ) ; foreach ( String e in a ) v . Add ( e ) ; for ( int i = 0 ; i < v . Count ; i ++ ) { for ( int j = 0 ; j < v [ i ] . Length ; j ++ ) { if ( v [ i ] [ j ] != Word [ j ] ) break ; else if ( j == Word . Length - 1 ) return v [ i ] ; } } return " - 1" ; } public static void Main ( String [ ] args ) { String s = " Welcome ▁ to ▁ Geeksforgeeks " ; String word = " Gee " ; Console . WriteLine ( isPrefixOfWord ( s , word ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: e, i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections ; public struct Pair { public int idx ; public string psf ; public int jmps ; public Pair ( int idx , String psf , int jmps ) { this . idx = idx ; this . psf = psf ; this . jmps = jmps ; } } class GFG { public static int [ ] minJumps ( int [ ] arr ) { int [ ] dp = new int [ arr . Length ] ; int n = dp . Length ; for ( int i = 0 ; i < n ; i ++ ) dp [ i ] = int . MaxValue ; dp [ n - 1 ] = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { int steps = arr [ i ] ; int min = int . MaxValue ; for ( int j = 1 ; j <= steps && i + j < n ; j ++ ) { if ( dp [ i + j ] != int . MaxValue && dp [ i + j ] < min ) { min = dp [ i + j ] ; } } if ( min != int . MaxValue ) dp [ i ] = min + 1 ; } return dp ; } public static void possiblePath ( int [ ] arr , int [ ] dp ) { Queue queue = new Queue ( ) ; queue . Enqueue ( new Pair ( 0 , "0" , dp [ 0 ] ) ) ; while ( queue . Count > 0 ) { Pair tmp = ( Pair ) queue . Dequeue ( ) ; if ( tmp . jmps == 0 ) { Console . WriteLine ( tmp . psf ) ; continue ; } for ( int step = 1 ; step <= arr [ tmp . idx ] ; step ++ ) { if ( tmp . idx + step < arr . Length && tmp . jmps - 1 == dp [ tmp . idx + step ] ) { queue . Enqueue ( new Pair ( tmp . idx + step , tmp . psf + " ▁ - > ▁ " + ( tmp . idx + step ) , tmp . jmps - 1 ) ) ; } } } } public static void Solution ( int [ ] arr ) { int [ ] dp = minJumps ( arr ) ; possiblePath ( arr , dp ) ; } static public void Main ( ) { int [ ] arr = { 3 , 3 , 0 , 2 , 1 , 2 , 4 , 2 , 0 , 0 } ; int size = arr . Length ; Solution ( arr ) ; } }

Index/key variables: i
Accumulator variables: i, j, step
Iterator variables: i, j, step
Class/struct names: GFG, Pair
C# program:
using System ; class GFG { static void EvenLIS ( int [ ] arr ) { int n = arr . Length ; int [ ] lis = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) lis [ i ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( Math . Abs ( arr [ i ] ) > Math . Abs ( arr [ j ] ) && Math . Abs ( arr [ i ] ) % 2 == 0 && Math . Abs ( arr [ j ] ) % 2 == 0 && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; } } int maxlen = 0 ; for ( int i = 0 ; i < n ; i ++ ) maxlen = Math . Max ( maxlen , lis [ i ] ) ; Console . WriteLine ( maxlen ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 11 , - 22 , 43 , - 54 , 66 , 5 } ; int N = arr . Length ; EvenLIS ( arr ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int res = 0 ; public class Node { public int data ; public Node left ; public Node right ; public Node ( int val ) { data = val ; left = right = null ; } } ; static int Sum ( Node root ) { if ( root == null ) { return 0 ; } int leftSubSum = Sum ( root . left ) ; int rightSubSum = Sum ( root . right ) ; if ( root . left != null && root . right != null && leftSubSum == rightSubSum ) res += 1 ; return root . data + leftSubSum + rightSubSum ; } public static void Main ( String [ ] args ) { Node root = new Node ( 9 ) ; root . left = new Node ( 2 ) ; root . left . left = new Node ( - 1 ) ; root . left . right = new Node ( 3 ) ; root . right = new Node ( 4 ) ; root . right . right = new Node ( 0 ) ; res = 0 ; Sum ( root ) ; Console . Write ( res ) ; } }

Accumulator variables: res
Class/struct names: GFG, Node
C# program:
using System ; using System . Collections . Generic ; class GFG { class Node { public int data ; public Node left ; public Node right ; public Node ( int val ) { data = val ; left = right = null ; } } ; static void PrintAlternate ( Node root ) { Queue < Node > Q = new Queue < Node > ( ) ; Q . Enqueue ( root ) ; while ( Q . Count != 0 ) { int N = Q . Count ; for ( int i = 0 ; i < N ; i ++ ) { Node temp = Q . Peek ( ) ; Q . Dequeue ( ) ; if ( i % 2 == 0 ) { Console . Write ( temp . data + " ▁ " ) ; } if ( temp . left != null ) { Q . Enqueue ( temp . left ) ; } if ( temp . right != null ) { Q . Enqueue ( temp . right ) ; } } Console . WriteLine ( ) ; } } public static void Main ( String [ ] args ) { Node root ; root = new Node ( 71 ) ; root . left = new Node ( 88 ) ; root . right = new Node ( 99 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; root . left . left . left = new Node ( 8 ) ; root . left . left . right = new Node ( 9 ) ; root . left . right . left = new Node ( 10 ) ; root . left . right . right = new Node ( 11 ) ; root . right . left . right = new Node ( 13 ) ; root . right . right . left = new Node ( 14 ) ; PrintAlternate ( root ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Node
C# program:
using System ; using System . Collections ; class GFG { static int [ ] countingSubarray ( int [ ] arr , int n ) { int [ ] a = new int [ n ] ; int [ ] nsml = new int [ n ] ; Array . Fill ( nsml , - 1 ) ; int [ ] nsmr = new int [ n ] ; Array . Fill ( nsmr , n ) ; Stack st = new Stack ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { while ( st . Count > 0 && arr [ ( int ) st . Peek ( ) ] >= arr [ i ] ) st . Pop ( ) ; nsmr [ i ] = ( st . Count > 0 ) ? ( int ) st . Peek ( ) : n ; st . Push ( i ) ; } while ( st . Count > 0 ) st . Pop ( ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( st . Count > 0 && arr [ ( int ) st . Peek ( ) ] >= arr [ i ] ) st . Pop ( ) ; nsml [ i ] = ( st . Count > 0 ) ? ( int ) st . Peek ( ) : - 1 ; st . Push ( i ) ; } for ( int i = 0 ; i < n ; i ++ ) { nsml [ i ] ++ ; nsmr [ i ] -- ; int r = nsmr [ i ] - i + 1 ; int l = i - nsml [ i ] + 1 ; a [ i ] = r * l ; } return a ; } static void Main ( ) { int N = 5 ; int [ ] arr = { 3 , 2 , 4 , 1 , 5 } ; int [ ] a = countingSubarray ( arr , N ) ; Console . Write ( " [ " ) ; int n = a . Length - 1 ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( a [ i ] + " , ▁ " ) ; Console . Write ( a [ n ] + " ] " ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static String reorderString ( char [ ] A , char [ ] B ) { int size_a = A . Length ; int size_b = B . Length ; int [ ] freq = new int [ 300 ] ; for ( int i = 0 ; i < size_b ; i ++ ) freq [ B [ i ] ] ++ ; for ( int i = 0 ; i < size_a ; i ++ ) freq [ A [ i ] ] -- ; for ( int j = ' a ' ; j <= ' z ' ; j ++ ) { if ( freq [ j ] < 0 ) return " - 1" ; } String answer = " " ; for ( int j = ' a ' ; j < A [ 0 ] ; j ++ ) while ( freq [ j ] > 0 ) { answer += j ; freq [ j ] -- ; } int first = A [ 0 ] ; for ( int j = 0 ; j < size_a ; j ++ ) { if ( A [ j ] > A [ 0 ] ) break ; if ( A [ j ] < A [ 0 ] ) { answer += String . Join ( " " , A ) ; A = new char [ A . Length ] ; break ; } } while ( freq [ first ] > 0 ) { answer += String . Join ( " " , ( char ) first ) ; -- freq [ first ] ; } answer += String . Join ( " " , A ) ; for ( int j = ' a ' ; j <= ' z ' ; j ++ ) while ( freq [ j ] -- > 0 ) answer += ( ( char ) j ) ; return answer ; } public static void Main ( String [ ] args ) { String A = " aa " ; String B = " ababab " ; Console . Write ( reorderString ( A . ToCharArray ( ) , B . ToCharArray ( ) ) ) ; } }

Index/key variables: first, i, j
Accumulator variables: answer, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Linq ; using System . Collections . Generic ; class GFG { static int func ( int n ) { int count = 0 ; if ( n == 2 n == 1 ) return 1 ; if ( n % 2 == 0 ) count = 1 + func ( n / 2 ) ; if ( n % 2 != 0 ) count = 1 + func ( n * 3 + 1 ) ; return count ; } static void findKthElement ( int l , int r , int k ) { List < int > arr = new List < int > ( ) ; for ( int i = l ; i <= r ; i ++ ) arr . Add ( i ) ; Dictionary < int , int > result = new Dictionary < int , int > ( ) ; foreach ( int i in arr ) { result . Add ( i , func ( i ) ) ; } var myList = result . ToList ( ) ; myList . Sort ( ( pair1 , pair2 ) => pair1 . Value . CompareTo ( pair2 . Value ) ) ; Console . WriteLine ( myList [ 1 ] . Key ) ; } public static void Main ( String [ ] args ) { int l = 12 ; int r = 15 ; int k = 2 ; findKthElement ( l , r , k ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static void checkHex ( String s ) { int n = s . Length ; for ( int i = 0 ; i < n ; i ++ ) { char ch = s [ i ] ; if ( ( ch < '0' ch > '9' ) && ( ch < ' A ' ch > ' F ' ) ) { Console . WriteLine ( " No " ) ; return ; } } Console . WriteLine ( " Yes " ) ; } public static void Main ( String [ ] args ) { String s = " BF57C " ; checkHex ( s ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int lenghtOfLongestAP ( int [ ] A , int n ) { Dictionary < int , Dictionary < int , int > > dp = new Dictionary < int , Dictionary < int , int > > ( ) ; int res = 2 ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = i + 1 ; j < n ; ++ j ) { int d = A [ j ] - A [ i ] ; if ( dp . ContainsKey ( d ) ) { if ( dp [ d ] . ContainsKey ( i ) ) { dp [ d ] [ j ] = dp [ d ] [ i ] + 1 ; } else { dp [ d ] [ j ] = 2 ; } } else { dp [ d ] = new Dictionary < int , int > ( ) ; dp [ d ] [ j ] = 2 ; } res = Math . Max ( res , dp [ d ] [ j ] ) ; } } return res ; } public static void Main ( string [ ] args ) { int [ ] arr = { 20 , 1 , 15 , 3 , 10 , 5 , 8 } ; int N = arr . Length ; Console . Write ( lenghtOfLongestAP ( arr , N ) ) ; } }

Index/key variables: d, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Linq ; class GFG { static readonly int N = 100005 ; static void SieveOfEratosthenes ( bool [ ] prime , int p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } static int LISPrime ( int [ ] arr , int n ) { int [ ] lisp = new int [ n ] ; bool [ ] prime = new bool [ N + 1 ] ; for ( int i = 0 ; i < prime . Length ; i ++ ) prime [ i ] = true ; SieveOfEratosthenes ( prime , N ) ; lisp [ 0 ] = prime [ arr [ 0 ] ] ? 1 : 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( ! prime [ arr [ i ] ] ) { lisp [ i ] = 0 ; continue ; } lisp [ i ] = 1 ; for ( int j = 0 ; j < i ; j ++ ) { if ( prime [ arr [ j ] ] && arr [ i ] > arr [ j ] && lisp [ i ] < lisp [ j ] + 1 ) { lisp [ i ] = lisp [ j ] + 1 ; } } } return lisp . Max ( ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 5 , 3 , 2 , 5 , 1 , 7 } ; int M = arr . Length ; Console . Write ( LISPrime ( arr , M ) ) ; } }

Index/key variables: i, j, n, p
Accumulator variables: i, j, p
Iterator variables: i, j, p
Class/struct names: GFG
C# program:
using System ; class GFG { static void checkSumOfNatural ( int n ) { int i = 1 ; bool flag = false ; while ( i * ( i + 1 ) < n * 2 ) { int X = i * ( i + 1 ) ; int t = n * 2 - X ; int k = ( int ) Math . Sqrt ( t ) ; if ( k * ( k + 1 ) == t ) { flag = true ; break ; } i += 1 ; } if ( flag ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } public static void Main ( String [ ] args ) { int n = 25 ; checkSumOfNatural ( n ) ; } }

Accumulator variables: i
Boolean variables: flag
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static long binomialCoeff ( int n , int k ) { long res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static long catalan ( int n ) { long c = binomialCoeff ( 2 * n , n ) ; return c / ( n + 1 ) ; } static long findWays ( int n ) { if ( ( n & 1 ) == 1 ) return 0 ; return catalan ( n / 2 ) ; } static void countNonNPeriodic ( int N ) { Console . Write ( findWays ( 2 * N ) - findWays ( N ) ) ; } public static void Main ( string [ ] args ) { int N = 4 ; countNonNPeriodic ( N ) ; } }

Accumulator variables: res
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void checkSameDiag ( int [ , ] li , int x , int y , int m , int n ) { int I = 0 , J = 0 ; int P = 0 , Q = 0 ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( li [ i , j ] == x ) { I = i ; J = j ; } if ( li [ i , j ] == y ) { P = i ; Q = j ; } } } if ( P - Q == I - J P + Q == I + J ) { Console . WriteLine ( " YES " ) ; } else Console . WriteLine ( " NO " ) ; } public static void Main ( String [ ] args ) { int m = 6 ; int n = 5 ; int [ , ] li = { { 32 , 94 , 99 , 26 , 82 } , { 51 , 69 , 52 , 63 , 17 } , { 90 , 36 , 88 , 55 , 33 } , { 93 , 42 , 73 , 39 , 28 } , { 81 , 31 , 83 , 53 , 10 } , { 12 , 29 , 85 , 80 , 87 } } ; int x = 42 ; int y = 80 ; checkSameDiag ( li , x , y , m , n ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int isValid ( int n , int m , int k ) { int step2 = n - m ; int cnt = ( step2 * ( step2 + 1 ) ) / 2 ; if ( cnt - m == k ) return 0 ; if ( cnt - m > k ) return 1 ; return - 1 ; } static void countOfOperations ( int n , int k ) { int start = 0 , end = n ; bool ok = true ; while ( start <= end ) { int mid = ( start + end ) / 2 ; int temp = isValid ( n , mid , k ) ; if ( temp == 0 ) { ok = false ; Console . Write ( mid ) ; break ; } else if ( temp == 1 ) { start = mid + 1 ; } else { end = mid - 1 ; } } if ( ok ) Console . Write ( " - 1" ) ; } public static void Main ( String [ ] args ) { int N = 5 , K = 4 ; countOfOperations ( N , K ) ; } }

Boolean variables: ok
Class/struct names: GFG