dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { public class Node { public int data ; public Node next ; } ; static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . next = null ; return node ; } static int alivesol ( int Num ) { if ( Num == 1 ) return 1 ; Node last = newNode ( 1 ) ; last . next = last ; for ( int i = 2 ; i <= Num ; i ++ ) { Node tem = newNode ( i ) ; tem . next = last . next ; last . next = tem ; last = tem ; } Node curr = last . next ; Node tem1 = new Node ( ) ; while ( curr . next != curr ) { tem1 = curr ; curr = curr . next ; tem1 . next = curr . next ; tem1 = tem1 . next ; curr = tem1 ; } int res = tem1 . data ; return res ; } public static void Main ( String [ ] args ) { int N = 100 ; Console . WriteLine ( alivesol ( N ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Node
C# program:
using System ; class Node { public Node left = null ; public Node right = null ; public int data ; public Node ( int data ) { this . data = data ; } } public class GFG { static int findDepth ( Node root ) { if ( root == null ) return 0 ; int left = findDepth ( root . left ) ; int right = findDepth ( root . right ) ; return 1 + Math . Max ( left , right ) ; } static Node DFS ( Node root , int curr , int depth ) { if ( root == null ) return null ; if ( curr == depth ) return root ; Node left = DFS ( root . left , curr + 1 , depth ) ; Node right = DFS ( root . right , curr + 1 , depth ) ; if ( left != null && right != null ) return root ; return ( left != null ) ? left : right ; } static Node lcaOfDeepestLeaves ( Node root ) { if ( root == null ) return null ; int depth = findDepth ( root ) - 1 ; return DFS ( root , 0 , depth ) ; } public static void Main ( String [ ] args ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; 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 . right . left . left = new Node ( 8 ) ; root . right . left . right = new Node ( 9 ) ; Console . WriteLine ( lcaOfDeepestLeaves ( root ) . data ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; class GFG { static int filter ( int x , int y , int z ) { if ( x != - 1 && y != - 1 ) { return z ; } return x == - 1 ? y : x ; } static int samePathUtil ( int [ , ] mtrx , int vrtx , int v1 , int v2 , int i ) { int ans = - 1 ; if ( i == v1 i == v2 ) return i ; for ( int j = 0 ; j < vrtx ; j ++ ) { if ( mtrx [ i , j ] == 1 ) { ans = filter ( ans , samePathUtil ( mtrx , vrtx , v1 , v2 , j ) , i ) ; } } return ans ; } static bool isVertexAtSamePath ( int [ , ] mtrx , int vrtx , int v1 , int v2 , int i ) { int lca = samePathUtil ( mtrx , vrtx , v1 - 1 , v2 - 1 , i ) ; if ( lca == v1 - 1 lca == v2 - 1 ) return true ; return false ; } public static void Main ( String [ ] args ) { int vrtx = 7 ; int [ , ] mtrx = { { 0 , 1 , 1 , 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 1 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 1 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 1 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 0 , 0 , 0 } } ; int v1 = 1 , v2 = 5 ; if ( isVertexAtSamePath ( mtrx , vrtx , v1 , v2 , 0 ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }

Accumulator variables: j
Iterator variables: j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static readonly int MAX = 1000 ; static readonly int log = 10 ; static int [ ] level = new int [ MAX ] ; static int [ , ] lca = new int [ MAX , log ] ; static int [ , ] dist = new int [ MAX , log ] ; static List < List < int [ ] > > graph = new List < List < int [ ] > > ( ) ; static void addEdge ( int u , int v , int cost ) { graph [ u ] . Add ( new int [ ] { v , cost } ) ; graph [ v ] . Add ( new int [ ] { u , cost } ) ; } static void dfs ( int node , int parent , int h , int cost ) { lca [ node , 0 ] = parent ; level [ node ] = h ; if ( parent != - 1 ) { dist [ node , 0 ] = cost ; } for ( int i = 1 ; i < log ; i ++ ) { if ( lca [ node , i - 1 ] != - 1 ) { lca [ node , i ] = lca [ lca [ node , i - 1 ] , i - 1 ] ; dist [ node , i ] = dist [ node , i - 1 ] + dist [ lca [ node , i - 1 ] , i - 1 ] ; } } foreach ( int [ ] i in graph [ node ] ) { if ( i [ 0 ] == parent ) continue ; dfs ( i [ 0 ] , node , h + 1 , i [ 1 ] ) ; } } static void findDistance ( int u , int v ) { int ans = 0 ; if ( level [ u ] > level [ v ] ) { int temp = u ; u = v ; v = temp ; } for ( int i = log - 1 ; i >= 0 ; i -- ) { if ( lca [ v , i ] != - 1 && level [ lca [ v , i ] ] >= level [ u ] ) { ans += dist [ v , i ] ; v = lca [ v , i ] ; } } if ( v == u ) { Console . WriteLine ( ans ) ; } else { for ( int i = log - 1 ; i >= 0 ; i -- ) { if ( lca [ v , i ] != lca [ u , i ] ) { ans += dist [ u , i ] + dist [ v , i ] ; v = lca [ v , i ] ; u = lca [ u , i ] ; } } ans += dist [ u , 0 ] + dist [ v , 0 ] ; Console . WriteLine ( ans ) ; } } public static void Main ( String [ ] args ) { int n = 5 ; for ( int i = 0 ; i < MAX ; i ++ ) { graph . Add ( new List < int [ ] > ( ) ) ; } addEdge ( 1 , 2 , 2 ) ; addEdge ( 1 , 3 , 3 ) ; addEdge ( 2 , 4 , 5 ) ; addEdge ( 2 , 5 , 7 ) ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 0 ; j < log ; j ++ ) { lca [ i , j ] = - 1 ; dist [ i , j ] = 0 ; } } dfs ( 1 , - 1 , 0 , 0 ) ; findDistance ( 1 , 3 ) ; findDistance ( 2 , 3 ) ; findDistance ( 3 , 5 ) ; } }

Index/key variables: MAX, node, u, v
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static readonly int MAX = 1000 ; static int [ ] weight = new int [ MAX ] ; static int [ ] level = new int [ MAX ] ; static int [ ] par = new int [ MAX ] ; static bool [ ] prime = new bool [ MAX + 1 ] ; static List < int > [ ] graph = new List < int > [ MAX ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i < prime . Length ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= MAX ; i += p ) prime [ i ] = false ; } } } static void dfs ( int node , int parent , int h ) { par [ node ] = parent ; level [ node ] = h ; foreach ( int child in graph [ node ] ) { if ( child == parent ) continue ; dfs ( child , node , h + 1 ) ; } } static int findPrimeOnPath ( int u , int v ) { int count = 0 ; if ( level [ u ] > level [ v ] ) { int temp = v ; v = u ; u = temp ; } int d = level [ v ] - level [ u ] ; while ( d -- > 0 ) { if ( prime [ weight [ v ] ] ) count ++ ; v = par [ v ] ; } if ( v == u ) { if ( prime [ weight [ v ] ] ) count ++ ; return count ; } while ( v != u ) { if ( prime [ weight [ v ] ] ) count ++ ; if ( prime [ weight [ u ] ] ) count ++ ; u = par [ u ] ; v = par [ v ] ; } if ( prime [ weight [ v ] ] ) count ++ ; return count ; } public static void Main ( String [ ] args ) { for ( int i = 0 ; i < graph . Length ; i ++ ) graph [ i ] = new List < int > ( ) ; SieveOfEratosthenes ( ) ; weight [ 1 ] = 5 ; weight [ 2 ] = 10 ; weight [ 3 ] = 11 ; weight [ 4 ] = 8 ; weight [ 5 ] = 6 ; graph [ 1 ] . Add ( 2 ) ; graph [ 2 ] . Add ( 3 ) ; graph [ 2 ] . Add ( 4 ) ; graph [ 1 ] . Add ( 5 ) ; dfs ( 1 , - 1 , 0 ) ; int u = 3 , v = 5 ; Console . Write ( findPrimeOnPath ( u , v ) ) ; } }

Index/key variables: MAX, i, node, p, u, v
Accumulator variables: count, d, i, p
Iterator variables: child, i, p
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { static int T = 1 ; static void dfs ( int node , int parent , List < int > [ ] g , int [ ] level , int [ ] t_in , int [ ] t_out ) { if ( parent == - 1 ) { level [ node ] = 1 ; } else { level [ node ] = level [ parent ] + 1 ; } t_in [ node ] = T ; foreach ( int i in g [ node ] ) { if ( i != parent ) { T ++ ; dfs ( i , node , g , level , t_in , t_out ) ; } } T ++ ; t_out [ node ] = T ; } static int findLCA ( int n , List < int > [ ] g , List < int > v ) { int [ ] level = new int [ n + 1 ] ; int [ ] t_in = new int [ n + 1 ] ; int [ ] t_out = new int [ n + 1 ] ; dfs ( 1 , - 1 , g , level , t_in , t_out ) ; int mint = int . MaxValue , maxt = int . MinValue ; int minv = - 1 , maxv = - 1 ; for ( int i = 0 ; i < v . Count ; i ++ ) { if ( t_in [ v [ i ] ] < mint ) { mint = t_in [ v [ i ] ] ; minv = v [ i ] ; } if ( t_out [ v [ i ] ] > maxt ) { maxt = t_out [ v [ i ] ] ; maxv = v [ i ] ; } } if ( minv == maxv ) { return minv ; } int lev = Math . Min ( level [ minv ] , level [ maxv ] ) ; int node = 0 , l = int . MinValue ; for ( int i = 1 ; i <= n ; i ++ ) { if ( level [ i ] > lev ) continue ; if ( t_in [ i ] <= mint && t_out [ i ] >= maxt && level [ i ] > l ) { node = i ; l = level [ i ] ; } } return node ; } public static void Main ( String [ ] args ) { int n = 10 ; List < int > [ ] g = new List < int > [ n + 1 ] ; for ( int i = 0 ; i < g . Length ; i ++ ) g [ i ] = new List < int > ( ) ; g [ 1 ] . Add ( 2 ) ; g [ 2 ] . Add ( 1 ) ; g [ 1 ] . Add ( 3 ) ; g [ 3 ] . Add ( 1 ) ; g [ 1 ] . Add ( 4 ) ; g [ 4 ] . Add ( 1 ) ; g [ 2 ] . Add ( 5 ) ; g [ 5 ] . Add ( 2 ) ; g [ 2 ] . Add ( 6 ) ; g [ 6 ] . Add ( 2 ) ; g [ 3 ] . Add ( 7 ) ; g [ 7 ] . Add ( 3 ) ; g [ 4 ] . Add ( 10 ) ; g [ 10 ] . Add ( 4 ) ; g [ 8 ] . Add ( 7 ) ; g [ 7 ] . Add ( 8 ) ; g [ 9 ] . Add ( 7 ) ; g [ 7 ] . Add ( 9 ) ; List < int > v = new List < int > ( ) ; v . Add ( 7 ) ; v . Add ( 3 ) ; v . Add ( 8 ) ; Console . Write ( findLCA ( n , g , v ) + " STRNEWLINE " ) ; } }

Index/key variables: i, maxv, minv, node, parent
Accumulator variables: T, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int MAX_SIZE = 100005 , MAX_CHAR = 26 ; static int [ , ] nodecharsCount = new int [ MAX_SIZE , MAX_CHAR ] ; static List < int > [ ] tree = new List < int > [ MAX_SIZE ] ; static bool canFormPalindrome ( int [ ] charArray ) { int oddCount = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( charArray [ i ] % 2 == 1 ) oddCount ++ ; } if ( oddCount >= 2 ) return false ; else return true ; } static int LCA ( int currentNode , int x , int y ) { if ( currentNode == x ) return x ; if ( currentNode == y ) return y ; int xLca , yLca ; xLca = yLca = - 1 ; int gotLca = - 1 ; for ( int l = 0 ; l < tree [ currentNode ] . Count ; l ++ ) { int nextNode = tree [ currentNode ] [ l ] ; int out_ = LCA ( nextNode , x , y ) ; if ( out_ == x ) xLca = out_ ; if ( out_ == y ) yLca = out_ ; if ( xLca != - 1 && yLca != - 1 ) return currentNode ; if ( out_ != - 1 ) gotLca = out_ ; } return gotLca ; } static void buildTree ( int i ) { for ( int l = 0 ; l < tree [ i ] . Count ; l ++ ) { int nextNode = tree [ i ] [ l ] ; for ( int j = 0 ; j < MAX_CHAR ; j ++ ) { nodecharsCount [ nextNode , j ] += nodecharsCount [ i , j ] ; } buildTree ( nextNode ) ; } } static bool canFormPalindromicPath ( int x , int y ) { int lcaNode ; if ( x == y ) lcaNode = x ; else lcaNode = LCA ( 1 , x , y ) ; int [ ] charactersCountFromXtoY = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { charactersCountFromXtoY [ i ] = nodecharsCount [ x , i ] + nodecharsCount [ y , i ] - 2 * nodecharsCount [ lcaNode , i ] ; } if ( canFormPalindrome ( charactersCountFromXtoY ) ) return true ; return false ; } static void updateNodecharsCount ( String str , int v ) { for ( int i = 0 ; i < str . Length ; i ++ ) nodecharsCount [ v , str [ i ] - ' a ' ] ++ ; } static void performQueries ( int [ , ] queries , int q ) { int i = 0 ; while ( i < q ) { int x = queries [ i , 0 ] ; int y = queries [ i , 1 ] ; if ( canFormPalindromicPath ( x , y ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; i ++ ; } } public static void Main ( String [ ] args ) { for ( int i = 0 ; i < MAX_SIZE ; i ++ ) { for ( int j = 0 ; j < MAX_CHAR ; j ++ ) { nodecharsCount [ i , j ] = 0 ; } } for ( int i = 0 ; i < MAX_SIZE ; i ++ ) { tree [ i ] = new List < int > ( ) ; } tree [ 1 ] . Add ( 2 ) ; updateNodecharsCount ( " bbc " , 2 ) ; tree [ 1 ] . Add ( 3 ) ; updateNodecharsCount ( " ac " , 3 ) ; buildTree ( 1 ) ; int [ , ] queries = { { 1 , 2 } , { 2 , 3 } , { 3 , 1 } , { 3 , 3 } } ; int q = queries . GetLength ( 0 ) ; performQueries ( queries , q ) ; } }

Index/key variables: MAX_CHAR, MAX_SIZE, currentNode, i, l
Accumulator variables: i, j, l, oddCount
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; using System . Collections ; class GFG { class Node { public Node left ; public Node right ; public int data ; } ; static Node newNode ( int key ) { Node node = new Node ( ) ; node . left = node . right = null ; node . data = key ; return node ; } static ArrayList path ; static bool FindPath ( Node root , int key ) { if ( root == null ) return false ; path . Add ( root . data ) ; if ( root . data == key ) return true ; if ( FindPath ( root . left , key ) || FindPath ( root . right , key ) ) return true ; path . Remove ( ( int ) path [ path . Count - 1 ] ) ; return false ; } static int minMaxNodeInPath ( Node root , int a , int b ) { path = new ArrayList ( ) ; bool flag = true ; ArrayList Path2 = new ArrayList ( ) ; ArrayList Path1 = new ArrayList ( ) ; int min1 = Int32 . MaxValue ; int max1 = Int32 . MinValue ; int min2 = Int32 . MaxValue ; int max2 = Int32 . MinValue ; int i = 0 ; int j = 0 ; flag = FindPath ( root , a ) ; Path1 = path ; path = new ArrayList ( ) ; flag &= FindPath ( root , b ) ; Path2 = path ; if ( flag ) { for ( i = 0 ; i < Path1 . Count && i < Path2 . Count ; i ++ ) if ( ( int ) Path1 [ i ] != ( int ) Path2 [ i ] ) break ; i -- ; j = i ; for ( ; i < Path1 . Count ; i ++ ) { if ( min1 > ( int ) Path1 [ i ] ) min1 = ( int ) Path1 [ i ] ; if ( max1 < ( int ) Path1 [ i ] ) max1 = ( int ) Path1 [ i ] ; } for ( ; j < Path2 . Count ; j ++ ) { if ( min2 > ( int ) Path2 [ j ] ) min2 = ( int ) Path2 [ j ] ; if ( max2 < ( int ) Path2 [ j ] ) max2 = ( int ) Path2 [ j ] ; } Console . Write ( " Min ▁ = ▁ " + Math . Min ( min1 , min2 ) + " STRNEWLINE " ) ; Console . Write ( " Max ▁ = ▁ " + Math . Max ( max1 , max2 ) + " STRNEWLINE " ) ; } else Console . Write ( " Max = - 1 " ) ; return 0 ; } public static void Main ( string [ ] arg ) { Node root = newNode ( 20 ) ; root . left = newNode ( 8 ) ; root . right = newNode ( 22 ) ; root . left . left = newNode ( 5 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 4 ) ; root . right . right = newNode ( 25 ) ; root . left . right . left = newNode ( 10 ) ; root . left . right . right = newNode ( 14 ) ; int a = 5 ; int b = 14 ; minMaxNodeInPath ( root , a , b ) ; } }

Index/key variables: i, j
Accumulator variables: flag, i, j
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG, Node
C# program:
using System ; using System . Collections . Generic ; class GFG { public class Node { public int data ; public Node left ; public Node right ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return node ; } static Boolean getPath ( Node root , List < int > arr , int x ) { if ( root == null ) return false ; arr . Add ( root . data ) ; if ( root . data == x ) return true ; if ( getPath ( root . left , arr , x ) || getPath ( root . right , arr , x ) ) return true ; arr . RemoveAt ( arr . Count - 1 ) ; return false ; } static int sumOddNodes ( Node root , int n1 , int n2 ) { List < int > path1 = new List < int > ( ) ; List < int > path2 = new List < int > ( ) ; getPath ( root , path1 , n1 ) ; getPath ( root , path2 , n2 ) ; int intersection = - 1 ; int i = 0 , j = 0 ; while ( i < path1 . Count < path2 . Count ) { if ( i == j && path1 [ i ] == path2 [ j ] ) { i ++ ; j ++ ; } else { intersection = j - 1 ; break ; } } int sum = 0 ; for ( i = path1 . Count - 1 ; i > intersection ; i -- ) if ( path1 [ i ] % 2 != 0 ) sum += path1 [ i ] ; for ( i = intersection ; i < path2 . Count ; i ++ ) if ( path2 [ i ] % 2 != 0 ) sum += path2 [ i ] ; return sum ; } public static void Main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right . right = newNode ( 6 ) ; int node1 = 5 ; int node2 = 6 ; Console . Write ( sumOddNodes ( root , node1 , node2 ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i
Class/struct names: GFG, Node
C# program:
using System ; class GFG { static int MAX = 1000 ; static int findLCA ( int n1 , int n2 , int [ ] parent ) { Boolean [ ] visited = new Boolean [ MAX ] ; visited [ n1 ] = true ; while ( parent [ n1 ] != - 1 ) { visited [ n1 ] = true ; n1 = parent [ n1 ] ; } visited [ n1 ] = true ; while ( ! visited [ n2 ] ) n2 = parent [ n2 ] ; return n2 ; } static void insertAdj ( int [ ] parent , int i , int j ) { parent [ i ] = j ; } public static void Main ( String [ ] args ) { int [ ] parent = new int [ MAX ] ; parent [ 20 ] = - 1 ; insertAdj ( parent , 8 , 20 ) ; insertAdj ( parent , 22 , 20 ) ; insertAdj ( parent , 4 , 8 ) ; insertAdj ( parent , 12 , 8 ) ; insertAdj ( parent , 10 , 12 ) ; insertAdj ( parent , 14 , 12 ) ; Console . WriteLine ( findLCA ( 10 , 14 , parent ) ) ; } }

Index/key variables: MAX, i, n1, n2
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static readonly int MAXN = 100001 ; static List < int > [ ] tree = new List < int > [ MAXN ] ; static int [ , ] path = new int [ 3 , MAXN ] ; static bool flag ; static void dfs ( int cur , int prev , int pathNumber , int ptr , int node ) { for ( int i = 0 ; i < tree [ cur ] . Count ; i ++ ) { if ( tree [ cur ] [ i ] != prev && ! flag ) { path [ pathNumber , ptr ] = tree [ cur ] [ i ] ; if ( tree [ cur ] [ i ] == node ) { flag = true ; path [ pathNumber , ptr + 1 ] = - 1 ; return ; } dfs ( tree [ cur ] [ i ] , cur , pathNumber , ptr + 1 , node ) ; } } } static int LCA ( int a , int b ) { if ( a == b ) return a ; path [ 1 , 0 ] = path [ 2 , 0 ] = 1 ; flag = false ; dfs ( 1 , 0 , 1 , 1 , a ) ; flag = false ; dfs ( 1 , 0 , 2 , 1 , b ) ; int i = 0 ; while ( i < MAXN && path [ 1 , i ] == path [ 2 , i ] ) i ++ ; return path [ 1 , i - 1 ] ; } static void addEdge ( int a , int b ) { tree [ a ] . Add ( b ) ; tree [ b ] . Add ( a ) ; } public static void Main ( String [ ] args ) { for ( int i = 0 ; i < MAXN ; i ++ ) tree [ i ] = new List < int > ( ) ; addEdge ( 1 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 2 , 4 ) ; addEdge ( 2 , 5 ) ; addEdge ( 2 , 6 ) ; addEdge ( 3 , 7 ) ; addEdge ( 3 , 8 ) ; Console . Write ( " LCA ( 4 , ▁ 7 ) ▁ = ▁ " + LCA ( 4 , 7 ) + " STRNEWLINE " ) ; Console . Write ( " LCA ( 4 , ▁ 6 ) ▁ = ▁ " + LCA ( 4 , 6 ) + " STRNEWLINE " ) ; } }

Index/key variables: MAXN, a, b, cur, i
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static readonly int MAXN = 100000 ; static readonly int level = 18 ; static List < int > [ ] tree = new List < int > [ MAXN ] ; static int [ ] depth = new int [ MAXN ] ; static int [ , ] parent = new int [ MAXN , level ] ; static void dfs ( int cur , int prev ) { depth [ cur ] = depth [ prev ] + 1 ; parent [ cur , 0 ] = prev ; for ( int i = 0 ; i < tree [ cur ] . Count ; i ++ ) { if ( tree [ cur ] [ i ] != prev ) dfs ( tree [ cur ] [ i ] , cur ) ; } } static void precomputeSparseMatrix ( int n ) { for ( int i = 1 ; i < level ; i ++ ) { for ( int node = 1 ; node <= n ; node ++ ) { if ( parent [ node , i - 1 ] != - 1 ) parent [ node , i ] = parent [ parent [ node , i - 1 ] , i - 1 ] ; } } } static int lca ( int u , int v ) { if ( depth [ v ] < depth [ u ] ) { u = u + v ; v = u - v ; u = u - v ; } int diff = depth [ v ] - depth [ u ] ; for ( int i = 0 ; i < level ; i ++ ) if ( ( ( diff >> i ) & 1 ) == 1 ) v = parent [ v , i ] ; if ( u == v ) return u ; for ( int i = level - 1 ; i >= 0 ; i -- ) if ( parent [ u , i ] != parent [ v , i ] ) { u = parent [ u , i ] ; v = parent [ v , i ] ; } return parent [ u , 0 ] ; } static void addEdge ( int u , int v ) { tree [ u ] . Add ( v ) ; tree [ v ] . Add ( u ) ; } static void memset ( int value ) { for ( int i = 0 ; i < MAXN ; i ++ ) { for ( int j = 0 ; j < level ; j ++ ) { parent [ i , j ] = - 1 ; } } } public static void Main ( String [ ] args ) { memset ( - 1 ) ; for ( int i = 0 ; i < MAXN ; i ++ ) tree [ i ] = new List < int > ( ) ; int n = 8 ; addEdge ( 1 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 2 , 4 ) ; addEdge ( 2 , 5 ) ; addEdge ( 2 , 6 ) ; addEdge ( 3 , 7 ) ; addEdge ( 3 , 8 ) ; depth [ 0 ] = 0 ; dfs ( 1 , 0 ) ; precomputeSparseMatrix ( n ) ; Console . Write ( " LCA ( 4 , ▁ 7 ) ▁ = ▁ " + lca ( 4 , 7 ) + " STRNEWLINE " ) ; Console . Write ( " LCA ( 4 , ▁ 6 ) ▁ = ▁ " + lca ( 4 , 6 ) + " STRNEWLINE " ) ; } }

Index/key variables: MAXN, cur, i, prev, u, v
Accumulator variables: i, j, node
Iterator variables: i, j, node
Class/struct names: GFG
C# program:
using System ; public class GFG { public class Query { public int L , R ; public Query ( int L , int R ) { this . L = L ; this . R = R ; } } ; static int LCE ( String str , int n , int L , int R ) { int length = 0 ; while ( R + length < n && str [ L + length ] == str [ R + length ] ) length ++ ; return ( length ) ; } static void LCEQueries ( String str , int n , Query [ ] q , int m ) { for ( int i = 0 ; i < m ; i ++ ) { int L = q [ i ] . L ; int R = q [ i ] . R ; Console . WriteLine ( " LCE ▁ ( " + L + " , ▁ " + R + " ) ▁ = ▁ " + LCE ( str , n , L , R ) ) ; } return ; } public static void Main ( String [ ] args ) { String str = " abbababba " ; int n = str . Length ; Query [ ] q = new Query [ 3 ] ; q [ 0 ] = new Query ( 1 , 2 ) ; q [ 1 ] = new Query ( 1 , 6 ) ; q [ 2 ] = new Query ( 0 , 5 ) ; int m = q . Length ; LCEQueries ( str , n , q , m ) ; } }

Index/key variables: i
Accumulator variables: i, length
Iterator variables: i
Class/struct names: GFG, Query
C# program:
using System ; class GFG { static bool findPair ( int [ ] a , int n , int z ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( i != j && a [ i ] + a [ j ] == z ) return true ; return false ; } static void Main ( ) { int [ ] a = { 1 , - 2 , 1 , 0 , 5 } ; int z = 0 ; int n = a . Length ; if ( findPair ( a , n , z ) ) Console . WriteLine ( " True " ) ; else Console . WriteLine ( " False " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void print ( int [ ] a , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i != j ) Console . WriteLine ( a [ i ] + " ▁ " + a [ j ] ) ; } } } static void Main ( ) { int [ ] a = { 1 , 2 , 3 } ; int n = a . Length ; print ( a , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int maximumSum ( int [ ] arr , int N ) { int Sum = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) Sum += ( arr [ i ] - arr [ i - 1 ] ) ; } return Sum ; } public static void Main ( ) { int [ ] arr = { 1 , 5 , 3 } ; int N = arr . Length ; Console . Write ( maximumSum ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: Sum, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxNumberOfXAddedUtil ( string str , char X ) { int countX = 0 ; int countNotX = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == X ) { countX ++ ; } else if ( countX < 3 ) { countNotX ++ ; countX = 0 ; } } if ( countX >= 3 ) return - 1 ; else return 2 * ( countNotX + 1 ) - ( str . Length - countNotX ) ; } static void maxNumberOfXAdded ( string str , char X ) { int ans = maxNumberOfXAddedUtil ( str , X ) ; Console . Write ( ans ) ; } public static void Main ( ) { string str = " xxyxy " ; char X = ' x ' ; maxNumberOfXAdded ( str , X ) ; } }

Index/key variables: i
Accumulator variables: countNotX, countX, i
Iterator variables: i
Class/struct names: GFG