diff --git a/paradigm/ternary_search.cpp b/paradigm/ternary_search.cpp
index 55ee026c0d831421951fa24d50980a030f99510e..c512ef4bc6458c466258d3142250f3a08f08d23f 100644
--- a/paradigm/ternary_search.cpp
+++ b/paradigm/ternary_search.cpp
@@ -20,8 +20,8 @@ double ternary_search(double l, double r) {
     if (fabs(r - l) < EPS)
       return (l + r) / 2.0;
 
-    lt = l + (r - l) / 3.0;
-    rt = r - (r - l) / 3.0;
+    lt = (r - l) / 3.0 + l;
+    rt = ((r - l) * 2.0) / 3.0 + l;
 
     // < | minimum of f
     // > | maximum of f
diff --git a/problems/trees_partition.cpp b/problems/trees_partition.cpp
index fef08902ded6c5eaf4bc3257e625feb59d53256e..149cfe8e0ae32ce0dcd20c9da4a6943467e04b13 100644
--- a/problems/trees_partition.cpp
+++ b/problems/trees_partition.cpp
@@ -12,8 +12,8 @@ using namespace std;
 typedef unsigned long long ll;
 typedef pair<ll,ll> ii;
 
-vector<int> t1[MAX], t2[MAX];
 ll hsh[MAX];
+vector<int> t1[MAX], t2[MAX];
 
 unordered_map<ll, int> M;
 ll ans = 0, tot = 0;
diff --git a/structure/bit2d.cpp b/structure/bit2d.cpp
index 43aa80141a7e67620242ad74f53853eba3b5b7ca..211d4b2d8353c5a0cbe2635f775ad4baa00ab3fd 100644
--- a/structure/bit2d.cpp
+++ b/structure/bit2d.cpp
@@ -11,9 +11,9 @@ int tree[MAXN][MAXM];
 
 // Perform query in array (tree) in the (idx,idy) position
 int query(int idx, int idy) {
-  int sum = 0, m;
+  int sum = 0;
   for (; idx > 0; idx -= (idx & -idx))
-    for (m = idy; m > 0; m -= (m & -m))
+    for (int m = idy; m > 0; m -= (m & -m))
       sum += tree[idx][m];
 
   return sum;
@@ -21,8 +21,7 @@ int query(int idx, int idy) {
 
 // Add a value (val) to a single position (idx,idy) in the array (tree).
 void update(int idx, int idy, int val) {
-  int m;
   for (; idx <= MAXN; idx += (idx & -idx))
-    for (m = idy; m <= MAXM; m += (m & -m))
+    for (int m = idy; m <= MAXM; m += (m & -m))
       tree[idx][m] += val;
 }