//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , c  = 1 , sum , j ,diff;
pair < int  , int > p[3003];
int main(){
      cin>>n>>m;
      for(int i = 0 ; i < n ; i++){
            cin>>p[i].first>>p[i].second;
      }
      sort(p,p+n);
      cout<<endl;
      for(int i = 0 ; i  < n ; i++){
         if(c<=p[i].first+1){
                  while(p[i].second>0){
                            if(i!=n-1)  j=i+1;
                        if(c>p[i].first+1) break;
                         sum+=min(p[i].second,m);
                        if(p[i].second>=m){
                              p[i].second -= m;
                        }
                        else{
                              diff=m-p[i].second;
                              while(diff>0){
                                   if(i==n-1) break;
                                   if(p[j].second>=diff){
                                    p[j].second -= diff;
                                    sum+=diff;
                                    diff = 0;
                                   }
                                   else{
                                         sum += p[j].second;

                                         p[j].second = 0 ;
                                         diff=0;
                                   }
                              }
                              p[i].second = 0;
                        }
                         c++;

            }
         }

      }
       cout<<sum<<endl;

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , c  = 1 , sum , j ,diff;
pair < int  , int > p[3003];
int main(){
      cin>>n>>m;
      for(int i = 0 ; i < n ; i++){
            cin>>p[i].first>>p[i].second;
      }
      sort(p,p+n);
      cout<<endl;
      for(int i = 0 ; i  < n ; i++){
         if(c<=p[i].first+1){
                  while(p[i].second>0){
                            if(i!=n-1)  j=i+1;
                        if(c>p[i].first+1) break;
                         sum+=min(p[i].second,m);
                        if(p[i].second>=m){
                              p[i].second -= m;
                        }
                        else{
                              diff=m-p[i].second;
                              while(diff>0){
                                   if(i==n-1) break;
                                   if(p[j].second>=diff){
                                    p[j].second -= diff;
                                    sum+=diff;
                                    diff = 0;
                                   }
                                   else{
                                         diff-=p[j].second;
                                         sum+=diff;
                                         j++;
                                   }
                              }
                              p[i].second = 0;
                        }
                         c++;

            }
         }

      }
       cout<<sum<<endl;

}


//#include <fsociety>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <iostream>
//end of libraries ;
using namespace std;
int n , m , c  = 1 , sum , j ,diff;
pair < int  , int > p[3003];
int main(){
      cin>>n>>m;
      for(int i = 0 ; i < n ; i++){
            cin>>p[i].first>>p[i].second;
      }
      sort(p,p+n);
      cout<<endl;
      for(int i = 0 ; i  < n ; i++){
         if(c<=p[i].first+1){
                  while(p[i].second>0){
                            if(i!=n-1)  j=i+1;
                         sum+=min(p[i].second,m);
                        if(p[i].second>=m){
                              p[i].second -= m;
                        }
                        else{
                              diff=m-p[i].second;
                              while(diff>0){
                                   if(i==n-1) break;
                                   if(p[j].second>=diff){
                                    p[j].second -= diff;
                                    sum+=diff;
                                    diff = 0;
                                   }
                                   else{
                                         sum += p[j].second;
                                         p[j].second = 0 ;
                                         diff=0;
                                   }
                              }
                              p[i].second = 0;
                        }
                         c++;
                         if(c>p[i].first+1) break;

            }
         }

      }
       cout<<sum<<endl;

}


#include<bits/stdc++.h>

using namespace std;

#define i64 long long int
#define db(x) cout<< #x << " -> "<< x <<endl

int arr[3005];

int main()
{
    int n,v;
    int a,b;
    memset(arr,0,sizeof(arr));
    cin>>n>>v;
    for(int i=1; i<=n; i++)
    {
        cin>>a>>b;
        arr[a]+=b;
    }
    sort(arr,arr+n);
    long long int ans=0;
    int y=0;
    for(int i=1; i<=n ; i++)
    {
     if(arr[i-1]>0)
     {
         y=min(arr[i-1],v);
         ans+=y;
     }
     int x=min(arr[i],v-y);
     ans+=x;
     arr[i]-=x;
    }
    if(n!=1)
    {
    ans+=min(arr[n],v);
    }
    cout<<ans<<endl;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define i64 long long int
#define db(x) cout<<#x<<" -> "<<x<<endl
int arr[3005];
int n,v;
int a,b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>v;
    if(n==1){
        cin>>a>>b;
        cout<<2*v<<endl;
        return 0;
    }
    for(int i=1; i<=n; i++){
        cin>>a>>b;
        arr[a]+=b;
    }
    int sum=0;
    sum+=min(v,arr[1]);
    arr[1]-=min(v,arr[1]);
    for(int i=2; i<=n; i++){
        int temp=min(v,arr[i-1]);
        sum+=temp+min(v-temp,arr[i]);
        arr[i]-=min(v-temp,arr[i]);
        //db(sum);
    }
    sum+=min(v,arr[n]);
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define i64 long long int

vector< pair<int,int> > vec;

bool mycomp(pair<int,int> &v1, pair<int,int> &v2)
{
    return v1.first<v2.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,v;
    int a,b;
    cin>>n>>v;
    for(int i=1; i<=n; i++)
    {
        cin>>a>>b;
        vec.push_back(make_pair(a,b));
    }
    sort(vec.begin(),vec.end(),mycomp);
    if(n==1)
    {
        cout<<min(vec[0].second,v)<<endl;
        return 0;
    }

    int ans=0;
    if(vec[0].second>=v)
    {
        ans+=(vec[0].second-v);
        vec[0].second-=ans;
    }
    else
    {
        ans+=min(vec[0].second,v);
        vec[0].second=0;
    }
    int x=0;
    for(int i=1; i<n; i++)
    {
        if(vec[i-1].second>0){
            ans+=min(vec[i-1].second,v);
            x+=min(vec[i-1].second,v);
        }
        if(x<v){
            ans+=min(vec[i].second,(v-x));
            x+=min(vec[i].second,(v-x));
            vec[i].second-=min(vec[i].second,(v-x));
        }
        x=0;
    }
    ans+=min(vec[n-1].second,v);
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define i64 long long int
#define db(x) cout<<#x<<" -> "<<x<<endl
int arr[3005];
int n,v;
int a,b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>v;
    for(int i=1; i<=n; i++){
        cin>>a>>b;
        arr[a]+=b;
    }
    int sum=0;
    for(int i=1; i<=3001; i++){
        int temp=min(v,arr[i-1]);
        sum+=temp+min(v-temp,arr[i]);
        arr[i]-=min(v-temp,arr[i]);
    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define i64 long long int
#define db(x) cout<<#x<<" -> "<<x<<endl
int arr[3005];
int n,v;
int a,b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>v;
    /*if(n==1){
        cin>>a>>b;
        cout<<2*v<<endl;
        return 0;
    }*/
    for(int i=1; i<=n; i++){
        cin>>a>>b;
        arr[a]+=b;
    }
    int sum=0;
    for(int i=1; i<=3001; i++){
        int temp=min(v,arr[i-1]);
        sum+=temp+min(v-temp,arr[i]);
        arr[i]-=min(v-temp,arr[i]);
        //db(sum);
    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define i64 long long int
#define db(x) cout<< #x << " -> "<< x <<endl

int arr[3005];

int main()
{
    int n,v;
    int a,b;
    memset(arr,0,sizeof(arr));
    cin>>n>>v;
    for(int i=1; i<=n; i++)
    {
        cin>>a>>b;
        arr[a]+=b;
    }
    //sort(arr,arr+n);
    long long int ans=0;
    int y=0;
    for(int i=1; i<=n ; i++)
    {
     if(arr[i-1]>0)
     {
         y=min(arr[i-1],v);
         ans+=y;
     }
     int x=min(arr[i],v-y);
     ans+=x;
     arr[i]-=x;
    }
    if(n!=1)
    {
    ans+=min(arr[n],v);
    }
    cout<<ans<<endl;
    return 0;

}


#include<bits/stdc++.h>

using namespace std;

#define i64 long long int

vector< pair<int,int> > vec;

bool mycomp(pair<int,int> &v1, pair<int,int> &v2)
{
    return v1.first<v2.first;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,v;
    int a,b;
    cin>>n>>v;
    for(int i=1; i<=n; i++)
    {
        cin>>a>>b;
        vec.push_back(make_pair(a,b));
    }
    sort(vec.begin(),vec.end());
    if(n==1)
    {
        cout<<min(vec[0].second,v)<<endl;
        return 0;
    }

    int ans=0;
    if(vec[0].second>=v)
    {
        ans+=(vec[0].second-v);
        vec[0].second-=ans;
    }
    else
    {
        ans+=min(vec[0].second,v);
        vec[0].second=0;
    }
    int x=0;
    for(int i=1; i<n; i++)
    {
        if(vec[i-1].second>0){
            ans+=min(vec[i-1].second,v);
            x+=min(vec[i-1].second,v);
        }
        if(x<v){
            ans+=min(vec[i].second,(v-x));
            x+=min(vec[i].second,(v-x));
            vec[i].second-=min(vec[i].second,(v-x));
        }
        x=0;
    }
    ans+=min(vec[n-1].second,v);
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define i64 long long int
#define db(x) cout<< #x << " -> "<< x <<endl

int arr[3005];

int main()
{
    int n,v;
    int a,b;
    memset(arr,0,sizeof(arr));
    cin>>n>>v;
    for(int i=1; i<=n; i++)
    {
        cin>>a>>b;
        arr[a]+=b;
    }
    long long int ans=0;
    int y=0;
    for(int i=1; i<=3005 ; i++)
    {
        if(arr[i-1]>0)
        {
            y=min(arr[i-1],v);
            ans+=y;
            arr[i-1]-=y;
        }
        int x=min(arr[i],v-y);
        ans+=x;
        //db(ans);
        arr[i]-=x;
    }
    //db(ans);
    /*if(n!=1)
    {
        ans+=min(arr[n],v);
    }*/
    cout<<ans<<endl;
    return 0;

}


#include<bits/stdc++.h>

using namespace std;

#define i64 long long int
#define db(x) cout<< #x << " -> "<< x <<endl

int arr[3005];

int main()
{
    int n,v;
    int a,b;
    memset(arr,0,sizeof(arr));
    cin>>n>>v;
    for(int i=1; i<=n; i++)
    {
        cin>>a>>b;
        arr[a]+=b;
    }
    long long int ans=0;
    int y=0;
    for(int i=1; i<=3005 ; i++)
    {
        if(arr[i-1]>0)
        {
            y=min(arr[i-1],v);
            ans+=y;
            arr[i-1]-=y;
        }
        int x=min(arr[i],v-y);
        ans+=x;
        //db(ans);
        arr[i]-=x;
    }
    //db(ans);
    if(n!=1)
    {
        ans+=min(arr[n],v);
    }
    cout<<ans<<endl;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define i64 long long int
#define db(x) cout<<#x<<" -> "<<x<<endl
int arr[3005];
int n,v;
int a,b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>v;
    if(n==1){
        cin>>a>>b;
        cout<<2*v<<endl;
        return 0;
    }
    for(int i=1; i<=n; i++){
        cin>>a>>b;
        arr[a]+=b;
    }
    int sum=0;
    for(int i=1; i<=3001; i++){
        int temp=min(v,arr[i-1]);
        sum+=temp+min(v-temp,arr[i]);
        arr[i]-=min(v-temp,arr[i]);
        //db(sum);
    }
    cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define i64 long long int
#define db(x) cout<<#x<<" -> "<<x<<endl
int arr[3005];
int n,v;
int a,b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>v;
    for(int i=1; i<=n; i++){
        cin>>a>>b;
        arr[a]+=b;
    }
    int sum=0;
    sum+=min(v,arr[1]);
    arr[1]-=min(v,arr[1]);
    for(int i=2; i<=n; i++){
        int temp=min(v,arr[i-1]);
        sum+=temp+min(v-temp,arr[i]);
        arr[i]-=min(v-temp,arr[i]);
        //db(sum);
    }
    sum+=min(v,arr[n]);
    cout<<sum<<endl;
    return 0;
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp115
{
    class Program
    {
        static void Vivod(double[,] Mat, int n)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Console.Write(Mat[i, j].ToString("F8") + " ");
                }
                Console.WriteLine();
            }
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            double[,] W = new double[n,n], A = new double[n, n], B = new double[n, n];
            for(int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                for (int j = 0; j < n; j++)
                {
                    W[i, j] = double.Parse(s.Split(' ')[j]);
                    A[i, j] = W[i, j];
                    B[i, j] = W[i, j];
                }
            }
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                {
                    if(i > 0 && i > 0)
                    {
                        if(W[i,j] != W[j,i])
                        {
                            double sred = (W[i, j] + W[j, i])/2;
                            A[i, j] = sred;
                            A[j, i] = sred;
                        }
                    }
                }

            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                {
                    if(A[i,j]+B[i,j] != W[i,j])
                    {
                        B[i, j] = W[i, j] - A[i, j];
                    }
                }
            Vivod(A, n);
            Vivod(B, n);
        }
    }
}


package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

var w, a, b [170][170]float64

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		for j := 0; j < n-1; j++ {
			fmt.Fscanf(reader, "%f ", &w[i][j])
		}
		fmt.Fscanf(reader, "%f\n", &w[i][n-1])
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				a[i][j] = w[i][j]
			} else {
				a[i][j] = (w[i][j] + w[j][i]) / 2
				b[i][j] = w[i][j] - a[i][j]
			}
		}
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Printf("%f ", a[i][j])
		}
		fmt.Printf("\n")
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Printf("%f ", b[i][j])
		}
		fmt.Printf("\n")
	}
}


package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	// "time"
)

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func main() {
	// defer func(start time.Time) {
	// 	fmt.Println(time.Since(start))
	// }(time.Now())

	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	n := nextInt()

	w := make([][]int, n)
	// a := make([][]float32, n)
	// b := make([][]float32, n)

	for i := range w {
		// a[i] = make([]float32, n)
		// b[i] = make([]float32, n)
		w[i] = make([]int, n)

		for j := range w[i] {
			w[i][j] = nextInt()
		}
	}

	// Method 1 fast
	// for i:=0; i<n; i++ {
	// 	for j:=0; j<i; j++ {
	// 		a[j][i] = float32(w[j][i] + w[i][j])/2
	// 		a[i][j] = a[j][i]
	// 		b[j][i] = float32(w[j][i]) - a[j][i]
	// 		b[i][j] = -b[j][i]
	// 	}
	// 	a[i][i] = float32(w[i][i])
	// 	b[i][i] = 0
	// }

	// for i:=0; i<n; i++ {
	// 	for j:=0; j<n; j++ {
	// 		fmt.Fprint(writer, a[i][j], " ")
	// 	}
	// 	fmt.Fprintln(writer)
	// }

	// for i:=0; i<n; i++ {
	// 	for j:=0; j<n; j++ {
	// 		fmt.Fprint(writer, b[i][j], " ")
	// 	}
	// 	fmt.Fprintln(writer)
	// }

	// Method 2 slow
	// for i:=0; i<n; i++ {
	// 	for j:=0; j<n; j++ {
	// 		fmt.Fprint(writer, float32(w[j][i] + w[i][j])/2, " " )
	// 	}
	// 	fmt.Fprintln(writer)
	// }

	// for i := 0; i < n; i++ {
	// 	for j := 0; j < n; j++ {
	// 		fmt.Fprint(writer, float32(w[i][j] - w[j][i])/2, " ")
	// 	}
	// 	fmt.Fprintln(writer)
	// }

	// Method 3 fast
	iface := make([]interface{}, n)

	for i:=0; i<n; i++ {
		for j:=0; j<n; j++ {
			iface[j] = interface{}(float32(w[j][i] + w[i][j])/2)
		}
		fmt.Fprintln(writer, iface...)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			iface[j] = interface{}(float32(w[i][j] - w[j][i])/2)
		}
		fmt.Fprintln(writer, iface...)
	}
}


package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n := getI()
  w := make([][]int, n)
  a := make([][]float64, n)
  b := make([][]float64, n)
  for r := 0; r < n; r++ {
    w[r] = make([]int, n)
    a[r] = make([]float64, n)
    b[r] = make([]float64, n)
    for c := 0; c < n; c++ {
      w[r][c] = getI()
    }
  }
  for r := 0; r < n; r++ {
    a[r][r] = float64(w[r][r])
    for c := r+1; c < n; c++ {
      x, y := float64(w[r][c]), float64(w[c][r])
      mean := (x+y)/2
      diff := (x-y)
      a[r][c], a[c][r] = mean, mean
      b[r][c], b[c][r] = diff/2, -diff/2
    }
  }
  for r := 0; r < n; r++ {
    writer.WriteString(fmt.Sprintf("%.1f", a[r][0]))
    for c := 1; c < n; c++ {
      writer.WriteString(fmt.Sprintf(" %.1f", a[r][c]))
    }
    writer.WriteString("\n")
  }
  for r := 0; r < n; r++ {
    writer.WriteString(fmt.Sprintf("%.1f", b[r][0]))
    for c := 1; c < n; c++ {
      writer.WriteString(fmt.Sprintf(" %.1f", b[r][c]))
    }
    writer.WriteString("\n")
  }
}


// wa on test 4
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {

	var (
		W       [200][200]int16
		n, i, j int32
		olv     *bufio.Reader
		ir      *bufio.Writer
	)

	olv = bufio.NewReader(os.Stdin)
	ir = bufio.NewWriter(os.Stdout)

	fmt.Scan(&n)
	for i = 0; i < n; i++ {
		for j = 0; j < n; j++ {
			fmt.Fscan(olv, &W[i][j])
		}
	}

	// A kiirasa
	for i = 0; i < n; i++ {
		for j = 0; j < n; j++ {
			if i == j {
				fmt.Fprintf(ir, "%.8f ", float64(W[i][i]))
			} else {
				fmt.Fprintf(ir, "%.8f ", 0.5*float64(W[i][j]+W[j][i]))
			}
		}
		fmt.Fprintln(ir)
	}

	for i = 0; i < n; i++ {
		for j = 0; j < n; j++ {
			if i == j {
				fmt.Fprint(ir, "0.00000000 ")
			} else {
				fmt.Fprintf(ir, "%.8f ",
					float64(W[i][j])-0.5*float64(W[i][j]+W[j][i]))
			}
		}
		fmt.Fprintln(ir)
	}

	ir.Flush()
}


package main

import(
	"fmt"

)

func main() {
	var n int
	var mat [][]int
	var a [][]float64
	var b [][]float64

	fmt.Scanf("%d", &n)
	mat = make([][]int, n)
	a = make([][]float64, n)
	b = make([][]float64, n)
	for i := 0; i < n; i++ {
		mat[i] = make([]int, n)
		a[i] = make([]float64, n)
		b[i] = make([]float64, n)
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &mat[i][j])
		}
	}
	var aItem float64
	var bItem float64
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				bItem = 0
				aItem = float64(mat[i][j])
			}else{
				aItem = (float64(mat[i][j]) + float64(mat[j][i])) / 2.0
				bItem = float64(mat[i][j]) - aItem
			}
			a[i][j] = aItem
			a[j][i] = aItem
			b[i][j] = bItem
			b[j][i] = bItem * -1

		}
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Print(" ", a[i][j])
		}
		fmt.Println()
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Print(" ", b[i][j])
		}
		fmt.Println()
	}
}


package main

import(
	"fmt"

)

func main() {
	var n int
	var mat [][]int
	var a [][]float64
	var b [][]float64

	fmt.Scanf("%d", &n)
	fmt.Scanf(" ")
	// fmt.Scanf("\n")
	mat = make([][]int, n)
	a = make([][]float64, n)
	b = make([][]float64, n)
	for i := 0; i < n; i++ {

		mat[i] = make([]int, n)
		a[i] = make([]float64, n)
		b[i] = make([]float64, n)
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &mat[i][j])
		}
		if i < n -1 {
			fmt.Scanf(" ")
		}
		// fmt.Scanf("\n")
	}
	fmt.Println(mat)
	var aItem float64
	var bItem float64
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				bItem = 0
				aItem = float64(mat[i][j])
			}else{
				aItem = (float64(mat[i][j]) + float64(mat[j][i])) / 2.0
				bItem = float64(mat[i][j]) - aItem
			}
			a[i][j] = aItem
			a[j][i] = aItem
			b[i][j] = bItem
			b[j][i] = bItem * -1

		}
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Print(" ", a[i][j])
		}
		fmt.Println()
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Print(" ", b[i][j])
		}
		fmt.Println()
	}
}


package main

import(
	"fmt"

)

func main() {
	var n int
	var mat [][]int
	var a [][]float64
	var b [][]float64

	fmt.Scanf("%d", &n)
	fmt.Scanf(" ")
	// fmt.Scanf("\n")
	mat = make([][]int, n)
	a = make([][]float64, n)
	b = make([][]float64, n)
	for i := 0; i < n; i++ {

		mat[i] = make([]int, n)
		a[i] = make([]float64, n)
		b[i] = make([]float64, n)
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &mat[i][j])
		}
		if i < n -1 {
			fmt.Scanf(" ")
		}
		// fmt.Scanf("\n")
	}
	var aItem float64
	var bItem float64
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				bItem = 0.0
				aItem = float64(mat[i][j])
				a[i][j] = aItem
				b[i][j] = bItem
			}else{
				aItem = (float64(mat[i][j]) + float64(mat[j][i])) / 2.0
				bItem = float64(mat[i][j]) - aItem
				a[i][j] = aItem
				a[j][i] = aItem
				b[i][j] = bItem
				b[j][i] = bItem * -1
			}

		}
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Printf("%f ", a[i][j])
		}
		fmt.Println()
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Printf("%f ", b[i][j])
		}
		fmt.Println()
	}
}


from __future__ import division
n=int(input())
w=[list(map(int,raw_input().split())) for k in range(n)]
for i in range(n):
    print(" ".join(map(str,[(w[i][j]+w[j][i])/2 for j in range(n)])))
for i in range(n):
    print(" ".join(map(str,[(w[i][j]-w[j][i])/2 for j in range(n)])))


def printf(l,n):
  for i in range(n):
    for j in range(n):
      print l[i][j],
    if n!=n-1:print ""
n = int(raw_input())
l = []
for _ in range(n):
  l.append(map(int,raw_input().split()))
a = [[0]*n for _ in range(n)]
b = [[0]*n for _ in range(n)]
for i in range(n):
  for j in range(n):
    a[i][j] = (l[i][j]+l[j][i])/2.0
    b[i][j] = (l[i][j]-l[j][i])/2.0

printf(a,n)
printf(b,n)


def printf(l,n):
  for i in range(n):
    for j in range(n):
      print l[i][j],
    if n!=n-1:print ""
n = int(raw_input())
l = []
for _ in range(n):
  l.append(map(int,raw_input().split()))
a = [[0]*n for _ in range(n)]
b = a[::][::]
for i in range(n):
  for j in range(n):
    a[i][j] = (l[i][j]+l[j][i])/2
    b[i][j] = (l[i][j]-l[j][i])/2
printf(a,n)
printf(b,n)


def printf(l,n):
  for i in range(n):
    for j in range(n):
      print l[i][j],
    if n!=n-1:print ""
n = int(raw_input())
l = []
for _ in range(n):
  l.append(map(int,raw_input().split()))
a = [[0]*n for _ in range(n)]
b = a[::][::]
for i in range(n):
  for j in range(n):
    a[i][j] = (l[i][j]+l[j][i])/2.0
    b[i][j] = (l[i][j]-l[j][i])/2.0

printf(a,n)
printf(b,n)


def printf(l,n):
  for i in range(n):
    for j in range(n):
      print l[i][j],
    if i!=n-1:print ""
n = int(raw_input().split())
l = []
a = [[0]*n for _ in range(n)]
b = [[0]*n for _ in range(n)]
for _ in range(n):
  l.append(map(int,raw_input().split()))
for i in range(n):
  for j in range(n):
    a[i][j] = (l[i][j]+l[j][i])/2

for i in range(n):
  for j in range(n):
    b[i][j] = (l[i][j]-l[j][i])/2

printf(a,n)
printf(b,n)


n=int(input())
arr=[]
for i in range(n):
	arr.append(list(map(int,input().split())))
a=[]
b=[]
for i in range(n):
	a.append([])
	b.append([])
	for j in range(n):
		a[i].append((arr[i][j]+arr[j][i])/2)
		b[i].append(arr[i][j]-a[i][j])
for i in range(n):
	print(*a[i])
for i in range(n):
	print(*b[i])


n=int(input())
w=[list(map(int,input().split()))for i in range(n)]
a=[[0for i in range(n)]for i in range(n)]
b=[[0for i in range(n)]for i in range(n)]
for i in range(n):
    for j in range(n):
        a[i][j]=(w[i][j]+w[j][i])/2
        b[i][j]=(w[i][j]-w[j][i])/2
for i in a:
    print(*i)
for i in b:
    print(*i)


n=int(input())
w=[list(map(int,input().split()))for i in range(n)]
a=[[0for i in range(n)]for i in range(n)]
b=[[0for i in range(n)]for i in range(n)]
for i in range(n):
    for j in range(n):
        if i==j:
            a[i][j]=w[i][j]
        else:
            a[i][j]=w[i][j]//2
            b[i][j]=w[i][j]-a[i][j]
for i in a:
    print(*i)
for i in b:
    print(*i)


n=int(input())
a=[[] for i in range(n)]
arr1=[[None for i in range(n)] for i in range(n)]
arr2=[[None for i in range(n)] for i in range(n)]
for i in range(n):
    x=[int(x) for x in input().split()]
    for item in x:
        a[i].append(item)
for i in range(n):
    for j in range(n):
        arr1[i][j]=(float(a[i][j]+a[j][i]))/2
        arr2[i][j]=(float(a[i][j]-a[j][i]))/2
for i in range(n):
    print(*arr1[i])
for i in range(n):
    print(*arr2[i])


n = int(input())

w = []
for i in range(n):
    wi = [int(x) for x in input().split()]
    w.append(wi)

a = []
b = []

for i in range(n):
    r1 = []
    r2 = []
    for j in range(n):
        if i<j:
            a1 = (w[i][j]+w[j][i])/2
            b1 = (w[i][j]-w[j][i])/2
        elif i>j:
            a1 = (w[i][j]+w[j][i])/2
            b1 = (w[i][j]-w[j][i])/2
        else:
            a1 = w[i][j]
            b1 = 0
        r1.append(a1)
        r2.append(b1)
    a.append(r1)
    b.append(r2)

for i in range(n):
    print(*a[i])

for i in range(n):
    print(*b[i])


s = input().strip().split('\n')
n = int(s[0])
W = [[int(sss) for sss in ss.split()] for ss in s[1:]]
A = [[0 for _ in range(n)] for _ in range(n)]
B  = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
    for j in range(i, n):
        A[i][j] = (W[i][j] + W[j][i]) / 2
        A[j][i] = A[i][j]

        B[i][j] = (W[i][j] - W[j][i]) / 2
        B[j][i] = - B[i][j]

print('\n'.join([' '.join([str(i) for i in x]) for x in A]))
print('\n'.join([' '.join([str(i) for i in x]) for x in B]))


s = s.strip().split('\n')
n = int(s[0])
W = [[int(sss) for sss in ss.split()] for ss in s[1:]]
A = [[0 for _ in range(n)] for _ in range(n)]
B  = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
    for j in range(i, n):
        A[i][j] = (W[i][j] + W[j][i]) / 2
        A[j][i] = A[i][j]

        B[i][j] = (W[i][j] - W[j][i]) / 2
        B[j][i] = - B[i][j]

print('\n'.join([' '.join([str(i) for i in x]) for x in A]))
print('\n'.join([' '.join([str(i) for i in x]) for x in B]))


def print_matrix(X):
        print('\n'.join([' '.join([str(i) for i in x]) for x in X]))

s = s.strip().split('\n')
n = int(s[0])
W = [[int(sss) for sss in ss.split()] for ss in s[1:]]
A = [[0 for _ in range(n)] for _ in range(n)]
B  = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
    for j in range(i, n):
        A[i][j] = (W[i][j] + W[j][i]) / 2
        A[j][i] = A[i][j]

        B[i][j] = (W[i][j] - W[j][i]) / 2
        B[j][i] = - B[i][j]

print_matrix(A)
print_matrix(B)


n = int(input())
W = [[int(s) for s in input().split()] for _ in range(n)]
A = [[0 for _ in range(n)] for _ in range(n)]
B  = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
    for j in range(i, n):
        A[i][j] = (W[i][j] + W[j][i]) / 2
        A[j][i] = A[i][j]

        B[i][j] = (W[i][j] - W[j][i]) / 2
        B[j][i] = - B[i][j]

print('\n'.join([' '.join([str(i) for i in x]) for x in A]))
print('\n'.join([' '.join([str(i) for i in x]) for x in B]))


# input
n = int(input())
matrix = []
a = n
while a>0:
    x = []
    x = input().split()
    matrix.append(x)
    a -= 1

# A
a = 0
while a<n:
    b = 0
    out = ''
    while b<n:
        if a == b:
            if b == 0:
                out = str(float(matrix[a][b]))
            else:
                out += ' ' + str(float(matrix[a][b]))
        else:
            if b == 0:
                out = str((float(matrix[a][b]) + float(matrix[b][a]))/2)
            else:
                out += ' ' + str((float(matrix[a][b]) + float(matrix[b][a]))/2)
        b += 1
    print(out)
    a += 1

# B
a = 0
while a<n:
    b = 0
    out = ''
    while b<n:
        if a == b:
            if b == 0:
                out = str(float(0))
            else:
                out += ' ' + str(float(0))
        else:
            if b == 0:
                out = str((float(matrix[a][b]) - float(matrix[b][a]))/2)
            else:
                out += ' ' + str((float(matrix[a][b]) - float(matrix[b][a]))/2)
        b += 1
    print(out)
    a += 1


n=int(input())
l=[]
for i in range(n):
    l.append(list(map(float,input().split())))
a,b=[],[]
for i in range(n):
    d=[]
    for j in range(n):
        d.append(0.0)
    a.append(d)
for i in range(n):
    for j in range(n):
        x=l[i][j]+l[j][i]
        a[i][j]=x/2
        a[j][i]=x/2
for i in range(n):
    print(*a[i])
for i in range(n):
    d=[]
    for j in range(n):
        d.append(0.0)
    b.append(d)
for i in range(n):
    for j in range(n):
        b[i][j]=l[i][j]-a[i][j]
        b[j][i]=l[j][i]-a[j][i]
for i in range(n):
    print(*b[i])


n=int(input())
w=[]
for i in range(n):
    w.append([int(i) for i in input().split()])
a=[[0 for i in range(n)]for j in range(n)]
b=[[0 for i in range(n)]for j in range(n)]
for i in range(n):
    a[i][i]=w[i][i]
for i in range(n-1):
    for j in range(i+1,n):
        x=(w[i][j]+w[j][i])/2
        y=(w[i][j]-w[j][i])/2
        a[i][j]=x
        a[j][i]=x
        b[i][j]=y
        b[j][i]=-y
for i in a:
    for j in i:
        print(j,'',end='')
    print()
for i in b:
    for j in i:
        print(j,'',end='')
    print()


import sys
n = int(sys.stdin.readline())
A = [[0]*n for i in range(n)]
for i in range(n):
    I = sys.stdin.readline().split()
    for j in range(n):
        A[i][j] = int(I[j])
B = [[0]*n for i in range(n)]
for i in range(n):
    for j in range(n):
        B[i][j] = (A[i][j]+A[j][i])/2
        print(B[i][j], end=" ")
    print()
for i in range(n):
    for j in range(n):
        print(A[i][j]-B[i][j], end=" ")
    print()


def printMatrix(matrix):
    for matrixrow in matrix:
        row=''
        for value in matrixrow:
            row+=str(value)+' '
        print(row)
n=int(input())
w=[[0 for i in range(n)] for i in range(n)]
a=[[0 for i in range(n)] for i in range(n)]
b=[[0 for i in range(n)] for i in range(n)]
for i in range(n):
    row=input().split(' ')
    for e in range(n):
        w[i][e]=int(row[e])
for i in range(n):
    for e in range(n):
        a[e][i]=a[i][e]=(w[i][e]+w[e][i])/2
        b[e][i]=w[e][i]-a[e][i]
printMatrix(a)
printMatrix(b)


n=int(input())
mat=[]
for i in range(n):
    l=list(map(int,input().split()))
    mat.append(l)
x=[[False]*n for i in range(n)]
y=[[False]*n for i in range(n)]
for i in range(n):
    for j in range(n):
        if x[i][j]==False:
            k=mat[i][j]+mat[j][i]
            x[i][j]=k/2
            x[j][i]=k/2
for i in range(n):
    for j in range(n):
        if y[i][j]==False:
            if mat[i][j]>x[i][j]:
                y[i][j]=-(x[i][j]-mat[i][j])
                y[j][i]=x[i][j]-mat[i][j]
            elif mat[i][j]==x[i][j]:
                y[i][j]=mat[i][j]-x[i][j]
                y[j][i]=mat[i][j]-x[i][j]
            else:
                y[i][j]=mat[i][j]-x[i][j]
                y[j][i]=-(mat[i][j]-x[i][j])
for i in range(n):
    for j in range(n):
        print('%.8f'%x[i][j],end=" ")
    print("")
for i in range(n):
    for j in range(n):
        print('%.8f'%y[i][j],end=" ")
    print("")


def transpose(m, d):
    new = []
    for i in range(d):
        new.append([m[j][i] for j in range(d)])
    return new

def sum(a,b, dim):
    new = []
    for i in range(dim):
        new.append([(a[i][j]+b[i][j])/2 for j in range(dim)])
    return new

def diff(a,b, dim):
    new = []
    for i in range(dim):
        new.append([(a[i][j]-b[i][j])/2 for j in range(dim)])
    return new

def print_matrix(a,dim):
    for i in range(dim):
        row = ''
        for j in range(dim):
            row+= str(a[i][j])
            row+=' '
        print(row)

dim = int(input())
w = []
for _ in range(dim):
    w.append([int(i) for i in input().split()])
wt = transpose(w, dim)
print_matrix(sum(w, wt, dim), dim)
print_matrix(diff(w,wt,dim), dim)


using System;
using System.Text;

namespace ThreeMatrices
{
    partial class ThreeMatrices
    {
        static void Main(string[] args)
        {
            int n;
            double[,] w, a, b;
            double mid;
            StringBuilder answer = new StringBuilder();

            n = NextInt();
            w = new double[n, n];
            a = new double[n, n];
            b = new double[n, n];

            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    w[i, j] = NextDouble();

            for (int i = 0; i < n; i++)
            {
                for (int j = i; j < n; j++)
                {
                    if (i == j)
                    {
                        a[i, j] = w[i, j];
                        b[i, j] = 0.0;
                    }
                    else
                    {
                        mid = (w[i, j] + w[j, i]) / 2;
                        a[i, j] = mid;
                        a[j, i] = mid;
                        b[i, j] = w[i, j] - mid;
                        b[j, i] = w[j, i] - mid;
                    }
                }
            }

            for (int i = 0; i < n; i++)
            {
                answer.Clear();

                for (int j = 0; j < n; j++)
                {
                    answer.Append(a[i,j] + " ");
                }

                Console.WriteLine(answer.ToString().Replace(",", "."));
            }

            for (int i = 0; i < n; i++)
            {
                answer.Clear();

                for (int j = 0; j < n; j++)
                {
                    answer.Append(b[i, j] + " ");
                }

                Console.WriteLine(answer.ToString().Replace(",", "."));
            }
        }
    }

    partial class ThreeMatrices
    {
        static string[] tokens = new string[0];
        static int cur_token = 0;

        static void ReadArray(char sep)
        {
            cur_token = 0;
            tokens = Console.ReadLine().Split(sep);
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int NextInt()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return int.Parse(tokens[cur_token++]);
        }

        static long NextLong()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return long.Parse(tokens[cur_token++]);
        }

        static double NextDouble()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return double.Parse(tokens[cur_token++]);
        }

        static decimal NextDecimal()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return decimal.Parse(tokens[cur_token++]);
        }

        static string NextToken()
        {
            if (cur_token == tokens.Length)
                ReadArray(' ');
            return tokens[cur_token++];
        }

        static string ReadLine()
        {
            return Console.ReadLine();
        }
    }
}


using System;
using System.Globalization;
using System.IO;
using System.Text;

namespace Three_matrices
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static void Main(string[] args)
        {
            int n = Next();
            var nn = new int[n,n];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    nn[i, j] = Next();
                }
            }

            var a = new double[n, n];
            var b = new double[n, n];
            for (int i = 0; i < n; i++)
            {
                a[i, i] = nn[i, i];
                for (int j = i+1; j < n; j++)
                {
                    a[i, j] = 1.0*(nn[i, j] + nn[j, i])/2;
                    a[j, i] = a[i, j];

                    b[i, j] = -a[i, j] + nn[i, j];
                    b[j, i] = -b[i, j];
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    writer.Write("{0} ", (a[i,j]).ToString("#0.0000000", CultureInfo.InvariantCulture));
                }
                writer.WriteLine();
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    writer.Write("{0} ", (b[i, j]).ToString("#0.0000000", CultureInfo.InvariantCulture));
                }
                writer.WriteLine();
            }

            writer.Flush();
        }

        private static int Next()
        {
            int c;
            int res = 0;
            bool m = false;
            do
            {
                c = reader.Read();
                if (c == '-')
                    m = true;
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return m ? -res : res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}


#if DEBUG
using System.Reflection;
using System.Threading.Tasks;
#endif

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Numerics;
using System.Globalization;

namespace _230b
{
    class Program
    {
        static string _inputFilename = "input.txt";
        static string _outputFilename = "output.txt";
        static bool _useFileInput = false;

        static void Main(string[] args)
        {
            StreamWriter file = null;
#if DEBUG
			Console.SetIn(getInput());
#else
            if (_useFileInput)
            {
                Console.SetIn(File.OpenText(_inputFilename));
                file = new StreamWriter(_outputFilename);
                Console.SetOut(file);
            }
#endif

            try
            {
                solution();
            }
            finally
            {
                if (_useFileInput)
                {
                    file.Close();
                }
            }
        }

        static void solution()
        {
            #region SOLUTION
            var n = readInt();
            var w = new int[n, n];
            for (int i = 0; i < n; i++)
            {
                var d = readIntArray();
                for (int j = 0; j < n; j++)
                {
                    w[i, j] = d[j];
                }
            }

            var a = new double[n, n];
            var b = new double[n, n];

            for (int i = 0; i < n; i++)
            {
                a[i, i] = w[i, i];
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    var wn = w[i, j];
                    var wn2 = w[j, i];
                    var ai = (wn + wn2) / 2d;
                    var bi = wn - ai;
                    var bi2 = -bi;

                    a[i, j] = ai;
                    a[j, i] = ai;
                    b[i, j] = bi;
                    b[j, i] = bi2;
                }
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Console.Write("{0} ", a[i, j].ToString(CultureInfo.InvariantCulture));
                }

                Console.WriteLine();
            }

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    Console.Write("{0} ", b[i, j].ToString(CultureInfo.InvariantCulture));
                }

                Console.WriteLine();
            }
            //var n = readInt();
            //var m = readInt();

            //var a = readIntArray();
            //var b = readIntArray();
            #endregion
        }

        static int readInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long readLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int[] readIntArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => int.Parse(i)).ToArray();
        }

        static long[] readLongArray()
        {
            return Console.ReadLine().Split(' ').Where(i => !string.IsNullOrEmpty(i)).Select(i => long.Parse(i)).ToArray();
        }

#if DEBUG
		static StreamReader getInput()
		{
			var resName = Assembly.GetCallingAssembly().GetManifestResourceNames()[0];
			var resource = Assembly.GetCallingAssembly().GetManifestResourceStream(resName);

			return new StreamReader(resource);
		}
#endif
    }
}


import java.util.*

fun main(args: Array<String>)
{
    val scanner = Scanner(System.`in`)

    val n = scanner.nextInt()

    val w = Array<Array<Double>>(n){ Array<Double>(n){ .0 } }
    val a = Array<Array<Double>>(n){ Array<Double>(n){ .0 } }
    val b = Array<Array<Double>>(n){ Array<Double>(n){ .0 } }

    for( i in 0 until n)
        for (j in 0 until n) w[i][j] = scanner.nextDouble()

    w.withIndex().forEach {
        val (i, wi) = it
        wi.withIndex().forEach {
            val (j, wij) = it
            if( i == j ) a[i][j] = wij
            else {
                b[i][j] = (wij - w[j][i]) / 2;
                a[i][j] = wij - b[i][j];
            }
        }
    }

    a.forEach { it.forEach { print("$it ") }; println() }
    b.forEach { it.forEach { print("$it ") }; println() }

}


#include <bits/stdc++.h>

using namespace std;

#define all(n) (n).begin(),(n).end()
#define rall(n) (n).rbegin(),(n).rend()

#define mp make_pair
#define pb push_back
#define sz size()
#define FO(i,x) for(int i=0;i<x;i++)
#define F first
#define S second
#define ll long long
#define ld long double

#define READ(s) freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)
//  int dx[]={-2,-2,-1,-1,1,1,2,2}; int dy[]={-1,1,-2,2,-2,2,-1,1}; // Knight Dir
//  int dx[]={-1,-1,-1,0,1,1,1,0}; int dy[]={-1,0,1,1,1,0,-1,-1};  // 8 Dir
//  int dx[]={0,1,-1,0};  int dy[]={1,0,0,-1};

double w[200][200];
int main(){
    // READ("in.txt");
    //WRITE("in.txt");
    int n;
    cin>>n;
    FO(i,n) FO(j,n) cin>>w[i][j];

    FO(i,n){
         FO(j,n){
            if(i==j) printf("%.8f ", w[i][j]);
            else printf("%.8f ", (w[i][j]+w[j][i])/2.0);
         }
         cout<<endl;
    }

    FO(i,n){
         FO(j,n){
            if(i==j) printf("%.8f ", 0.0);
            else printf("%.8f ",w[i][j]-(w[i][j]+w[j][i])/2.0);
         }
         cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define f first
#define s second
#define ff(i,a,b) for(ll i=a;i<=b;++i)
#define FF(i,a,b) for(ll i=a;i>=b;--i)
#define N_ 25025

float W[172][172],A[172][172],B[172][172];
int n;

void init(){
	scanf("%d",&n);
	ff(i,1,n) ff(j,1,n) scanf("%f",&W[i][j]);
}

void process(){
	ff(i,1,n)
	ff(j,1,n){
		float Y=W[j][i];
		float X=W[i][j];
		A[i][j]=(X+Y)/2;
		A[j][i]=(X+Y)/2;
		B[i][j]=(X-Y)/2;
		B[j][i]=(Y-X)/2;
	}

	ff(i,1,n){
		ff(j,1,n) printf("%.10f ",A[i][j]);
		printf("\n");
	}
	ff(i,1,n){
		ff(j,1,n) printf("%.10f ",B[i][j]);
		printf("\n");
	}
}

int main(){
	init();
	process();
	return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;

typedef long long int LL;
typedef pair<int,int> PII;

void print(vector<vector<double>>& m, int n) {
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j)
            cout << " " << m[i][j];
        cout << endl;
    }
}

int main(int argc, char*argv[]) {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            cin >> a[i][j];

    vector<vector<double>> A(n, vector<double>(n));
    vector<vector<double>> W(n, vector<double>(n, 0.));
    for (int i = 0; i < n; ++i) {
        A[i][i] = a[i][i];
        for (int j = i+1; j < n; ++j) {
            double x = a[i][j];
            double y = a[j][i];
            A[i][j] = A[j][i] = (x+y)/2.0;
            W[i][j] = x - A[i][j];
            W[j][i] = y - A[i][j];
        }
    }

    print(A, n);
    print(W, n);
    return EXIT_SUCCESS;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int _b=(b),i=(a); i<_b; ++i)
#define ROF(i,b,a) for(int _a=(a),i=(b); i>_a; --i)
#define _1 first
#define _2 second
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define MSET(m,v) memset(m,v,sizeof(m))
#define MAX_PQ(T) priority_queue <T>
#define MIN_PQ(T) priority_queue <T,vector<T>,greater<T>>
typedef long long LL; typedef long double LD; typedef unsigned int uint;
typedef pair<int,int> PII; typedef pair<LL,LL> PLL;
typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VP;
template<typename A, typename B> inline bool mina(A &x, B y) { return (x > y)? (x=y,1):0; }
template<typename A, typename B> inline bool maxa(A &x, B y) { return (x < y)? (x=y,1):0; }

// More templates here

#define MAXN (200)

int N;
int W[MAXN][MAXN];

int main()
{
	cin >> N;
	FOR(i,0,N) FOR(j,0,N) scanf("%d", &W[i][j]);
	FOR(i,0,N)
	{
		FOR(j,0,N)
		{
			if(i == j) printf("%d.0 ", W[i][j]);
			else printf("%.1lf ", (W[i][j] + W[j][i]) / 2.);
		}
		cout << endl;
	}
	FOR(i,0,N)
	{
		FOR(j,0,N)
		{
			if(i == j) printf("0.0 ");
			else printf("%.1lf ", (W[i][j] - W[j][i]) / 2.);
		}
		cout << endl;
	}

	return 0;
}


// Exercício:
// Tempo para programar:
// Dificuldade:
// Tema:
// Complexidade: O( ? )

#include <iomanip>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <list>

using namespace std;

typedef long long ll;

typedef vector<ll>vi;
typedef pair<ll,ll>ii;
typedef vector<ii>vii;

#define INF 0x3F3F3F3F
#define ler(x) scanf("%lld",&x);
#define imp(x) printf("%lld",x);
#define REP(n) for(ll i=0;i<n;++i)
#define PI 2*acos(0.0)
#define pb push_back
#define MAXN 100000

//g++ -std=c++11

int main()
{
	int n;
	cin >> n;
	double w[n][n];
	double sumc = 0;
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			cin >> w[i][j];
		}
	}

	double a[n][n];
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			a[i][j] = (w[i][j]+w[j][i])/2;
			printf("%.8lf ",a[i][j]);
		}
		cout << endl;
	}

	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;++j)
		{
			printf("%.8lf ",w[i][j]-a[i][j]);
		}
		cout << endl;
	}

	return 0;
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <vector>

#if LOCAL
	#define DO_NOT_SEND
#endif

typedef long long LL;

int IntMaxVal = (int) 1e20;
int IntMinVal = (int) -1e20;
LL LongMaxVal = (LL) 1e20;
LL LongMinVal = (LL) -1e20;

#define FOR(i, a, b) for(int i = a; i < b ; ++i)
#define FORD(i, a, b) for(int i = a; i >= b; --i)

#define minimize(a, b) { a = min(a, b); }
#define maximize(a, b) { a = max(a, b); }

#define all(v) v.begin(),v.end()

using namespace std;

#define next(type, i) type i; cin >> i;
template<typename T> struct argument_type;
template<typename T, typename U> struct argument_type<T(U)> { typedef U type; };
#define nextVector(t, v, size) vector< argument_type<void(t)>::type > v(size); { for (int i = 0 ; i < size ; i++) cin >> v[i]; }

#define range(name, start, count) vector<int> name(count); { for (int i = 0 ; i < count ; i++) name[i] = i + start; }

template <typename T1, typename T2> istream& operator >>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T> &v) { for (int i = 0 ; i < v.size() ; i++) os << v[i] << ' '; os << endl; return os; }
template <typename T1, typename T2> ostream& operator <<(ostream& s, pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; }

template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

int main() {
	srand (time(NULL));
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    next(int, n);

    int w[n][n];
    FOR (i, 0, n) FOR (j, 0, n) cin >> w[i][j];

    double a[n][n];
    double b[n][n];

    FOR (i, 0, n) {
    		a[i][i] = w[i][i];
    		b[i][i] = 0;
    }

    FOR (i, 0, n) FOR (j, i + 1, n) {
    	double mid = (w[i][j] + w[j][i]) / 2.0;
    	a[i][j] = a[j][i] = mid;
    	b[i][j] = w[i][j] - mid;
    	b[j][i] = -b[i][j];
    }

    FOR (i, 0, n) {
    	FOR (j, 0, n) cout << a[i][j] << ' ';
    	cout << endl;
    }
    FOR (i, 0, n) {
    	FOR (j, 0, n) cout << b[i][j] << ' ';
    	cout << endl;
    }
}


#include <iostream>
#include <cmath>
#include <set>
#include <string>
#include <cstring>
using namespace std;

double a[171][171];
double b[171][171];
double w[171][171];

int main() {
    int n;
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    int x;
                    cin >> x;
                    w[i][j] = x;
            }
    }
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    a[i][j] = a[j][i] = (w[i][j] + w[j][i]) / 2;
                    b[i][j] = w[i][j] - a[i][j];
            }
    }
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    cout << fixed << setprecision(10) << a[i][j] << " ";
            }
            cout << endl;
    }
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    cout << fixed << setprecision(10) << b[i][j] << " ";
            }
            cout << endl;
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <set>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;

double a[171][171];
double b[171][171];
double w[171][171];

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    int x;
                    cin >> x;
                    w[i][j] = x;
            }
    }
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    a[i][j] = a[j][i] = (w[i][j] + w[j][i]) / 2;
                    b[i][j] = w[i][j] - a[i][j];
            }
    }
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    cout << fixed << setprecision(10) << a[i][j] << " ";
            }
            cout << endl;
    }
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    cout << fixed << setprecision(10) << b[i][j] << " ";
            }
            cout << endl;
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <set>
#include <string>
#include <cstring>
#include <iomanip>
using namespace std;

double a[171][171];
double b[171][171];
double w[171][171];

int main() {
    int n;
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    int x;
                    cin >> x;
                    w[i][j] = x;
            }
    }
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    a[i][j] = a[j][i] = (w[i][j] + w[j][i]) / 2;
                    b[i][j] = w[i][j] - a[i][j];
            }
    }
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    cout << fixed << setprecision(10) << a[i][j] << " ";
            }
            cout << endl;
    }
    for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                    cout << fixed << setprecision(10) << b[i][j] << " ";
            }
            cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define Sort(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
using namespace std;

typedef long long int64;
typedef pair<int,int> pii;

inline int64 gcd(int64 a, int64 b) {return __gcd(a,b);};
inline int64 lcm(int64 a, int64 b) {return a*b/gcd(a,b);};

int main() {
	ios_base::sync_with_stdio(0);
	cout<<setprecision(5)<<fixed;
	int n;
	cin>>n;
	vector <vector<double> > tab(n,vector<double>(n));
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			cin>>tab[i][j];

	vector <vector<double> > res1(n,vector<double>(n,-1));
	vector <vector<double> > res2(n,vector<double>(n,-1));

	for(int i = 0; i < n; i++) {
		res2[i][i] = 0;
		res1[i][i] = tab[i][i];
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(res1[i][j] != -1) continue;

			double a = (tab[i][j]+tab[j][i])/2;
			double b = tab[i][j]-a;
			res1[i][j] = res1[j][i] = a;
			res2[i][j] = b;
			res2[j][i] = -b;

		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cout<<res1[i][j]<<" ";
		}
		cout<<endl;
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cout<<res2[i][j]<<" ";
		}
		cout<<endl;
	}
}


#include <bits/stdc++.h>
#define Sort(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
using namespace std;

typedef long long int64;
typedef pair<int,int> pii;

inline int64 gcd(int64 a, int64 b) {return __gcd(a,b);};
inline int64 lcm(int64 a, int64 b) {return a*b/gcd(a,b);};

int main() {
	ios_base::sync_with_stdio(0);
	cout<<setprecision(5)<<fixed;
	int n;
	cin>>n;
	vector <vector<double> > tab(n,vector<double>(n));
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			cin>>tab[i][j];

	vector <vector<double> > res1(n,vector<double>(n,-1));
	vector <vector<double> > res2(n,vector<double>(n,-1));

	for(int i = 0; i < n; i++) {
		res1[i][i] = 0;
		res2[i][i] = tab[i][i];
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(res1[i][j] != -1) continue;

			double a = (tab[i][j]+tab[j][i])/2;
			double b = tab[i][j]-a;
			res1[i][j] = res1[j][i] = a;
			res2[i][j] = b;
			res2[j][i] = -b;

		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cout<<res1[i][j]<<" ";
		}
		cout<<endl;
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cout<<res2[i][j]<<" ";
		}
		cout<<endl;
	}
}


#include <stdio.h>
#include <vector>

int main() {
    int n;
    scanf("%d", &n);
    std::vector<std::vector<int> > W(n, std::vector<int>(n));
    std::vector<std::vector<double> > A(n, std::vector<double>(n));
    std::vector<std::vector<double> > B(n, std::vector<double>(n));
    for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
        scanf("%d", &W[i][j]);
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
        // W[i][j] = A[i][j] + B[i][j]
            // W[j][i] = A[i][j] - B[i][j]
        A[i][j] = A[j][i] = (double)(W[i][j] + W[j][i]) / 2;
        if (W[i][j] != W[j][i]) {
        B[i][j] = (double)(W[i][j] - W[j][i]) / 2;
        B[j][i] = -B[i][j];
        } else B[j][i] = B[i][j] = 0;
    }
    }
    for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j)
        if (!j) printf("%.8f", A[i][j]);
        else printf(" %.8f", A[i][j]);
    printf("\n");
    }
    for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j)
        if (!j) printf("%.8f", B[i][j]);
        else printf(" %.8f", B[i][j]);
    printf("\n");
    }
}


//be name khoda

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

double w[171][171],a[200][200],b[200][200];

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>w[i][j];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            double k=(w[i][j]+w[j][i])/2;
            a[i][j]=k;
            b[i][j]=w[i][j]-k;
        }
    for(int i=0;i<n;i++,cout<<endl)
        for(int j=0;j<n;j++)
            cout<<a[i][j]<<" ";
    for(int i=0;i<n;i++,cout<<endl)
        for(int j=0;j<n;j++)
            cout<<b[i][j]<<" ";
    return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;

double w[2000][2000], a[2000][2000], n;

int main() { _
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> w[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = (w[i][j]+w[j][i])/2;
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << w[i][j]-a[i][j] << " ";
    }
    cout << "\n";
  }
  return 0;
}


#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <fstream>
using namespace std;
double PI = 3.14159;
int dX[] = { 1, -1, 0, 0 };
int dY[] = { 0, 0, 1, -1 };
int n;
double a[171][171], b[171][171], w[171][171];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
            cin >> w[i][j];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            a[i][j] = a[j][i] = (w[i][j] + w[j][i]) / 2;
            b[i][j] = (w[i][j] - w[j][i]) / 2;
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
            cout <<fixed << setprecision(4) << a[i][j] << " ";
        cout << "\n";
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
            cout << fixed << setprecision(4) << b[i][j] << " ";
        cout << "\n";
    }
}


#include <iostream>
#include <vector>
using namespace std;

int main() {

    int n;
    cin >> n;

    vector<vector<double>> W(n, vector<double>(n, 0.0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> W[i][j];
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << (W[i][j]+W[j][i])/2 << " ";
        }
        cout << endl;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cout << (W[i][j]-W[j][i])/2 << " ";
        }
        cout << endl;
    }

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;
const int M = 200;
double w[M][M],a[M][M],b[M][M];
int n;
int main()
{
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            scanf("%lf",&w[i][j]);
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = i; j < n;j++)
        {
            if(i == j)
            {
                a[i][j] = w[i][j];
                b[i][j] = 0;
            }
            else
            {
                double temp = (w[i][j]+w[j][i]) / 2;
                a[i][j] = a[j][i] = temp;
                b[i][j] = w[i][j] - temp;
                b[j][i] = w[j][i] - temp;
            }
        }
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(j != 0) printf(" ");
            printf("%.8lf",a[i][j]);
        }
        printf("\n");
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            if(j != 0) printf(" ");
            printf("%.8lf",b[i][j]);
        }
        printf("\n");
    }
    return 0;
}


#include <iostream>
#include <iomanip>
using namespace std;

const int MAXN=200;
double w[MAXN][MAXN];
double a[MAXN][MAXN];
double b[MAXN][MAXN];

int main()
{
    //ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++) cin >> w[i][j];
    }

    for(int i=0; i<n; i++)
    {
        for(int j=0; j<=i; j++)
        {
            double x=w[i][j];
            double y=w[j][i];

            double aa=(x+y)*0.5;
            double bb=(x-y)*0.5;

            //cout << "aa,bb: " << aa << ' ' << bb << endl;

            a[i][j]=a[j][i]=aa;
            b[i][j]=bb;
            b[j][i]=-bb;
        }
    }

    cout << setprecision(6);
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++) cout << a[i][j] << ' ';
        cout << '\n';
    }

    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++) cout << b[i][j] << ' ';
        cout << '\n';
    }
    return 0;
}


// Paste me into the FileEdit configuration dialog
#include <algorithm>
#include <functional>

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <vector>
#include <string>
#include <sstream>
#include <iostream>

using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define mp make_pair
#define pb push_back
#define sz(s) (int)((s).size())

#define MAX 200
double w[MAX][MAX], a[MAX][MAX], b[MAX][MAX];
int n;

int main() {
  scanf("%d", &n);
  FOR(i, 0, n)
    FOR(j, 0, n) {
      scanf("%lf", &w[i][j]);
    }

  FOR(i, 0, n) {
    FOR(j, 0, n)  {
      a[i][j] = (w[i][j] + w[j][i]) / 2;
      b[i][j] = w[i][j] - a[i][j];
      printf("%.8lf ", a[i][j]);
    }
    printf("\n");
  }

  FOR(i, 0, n) {
    FOR(j, 0, n)
      printf("%.8lf ", b[i][j]);
    printf("\n");
  }

  return 0;
}


#include <bits/stdc++.h>
#define all(v)  v.begin() , v.end()
#define REP(i,n) for (int i = 0; i < (int)n; ++i)
#define ECHO(content) cout << content << '\n'
#define VAR(v) #v << " = " << v<<" "
#define adebug(x,n) cout <<#x<<endl; REP(i,0,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,0,m)REP(j,0,n)cout<<x[i][j]<<char(j+1==n?10:32)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int W[n][n];

    double A[n][n],B[n][n];

    REP(i,n) REP(j,n) cin >> W[i][j];

    REP(i,n) REP(j,n) {
        double ai = (W[i][j] + W[j][i]) / 2.0;
        double bi = W[i][j]  - ai;
        A[i][j]  = A[j][i] = ai;
        B[i][j] = bi;
        B[j][i] = -bi;
    }
    cout.precision(8);
    REP(i,n) REP(j,n) cout<< fixed << A[i][j] << char(j+1==n?10:32);
    REP(i,n) REP(j,n) cout<< fixed << B[i][j] << char(j+1==n?10:32);

    return 0;
}


#include <bits/stdc++.h>
#define all(v)  v.begin() , v.end()
#define REP(i,n) for (int i = 0; i < (int)n; ++i)
#define ECHO(content) cout << content << '\n'
#define VAR(v) #v << " = " << v<<" "
#define adebug(x,n) cout <<#x<<endl; REP(i,0,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,0,m)REP(j,0,n)cout<<x[i][j]<<char(j+1==n?10:32)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int W[n][n];

    double A[n][n],B[n][n];

    REP(i,n) REP(j,n) cin >> W[i][j];

    REP(i,n) REP(j,n) {
        double ai = (W[i][j] + W[j][i]) / 2.0;
        double bi = W[i][j]  - ai;
        A[i][j]  = A[j][i] = ai;
        B[i][j] = bi;
        B[j][i] = -bi;
    }
    cout.precision(8);
    REP(i,n) REP(j,n) cout<< A[i][j] << char(j+1==n?10:32);
    REP(i,n) REP(j,n) cout<< B[i][j] << char(j+1==n?10:32);

    return 0;
}


#include <bits/stdc++.h>
#define all(v)  v.begin() , v.end()
#define REP(i,n) for (int i = 0; i < (int)n; ++i)
#define ECHO(content) cout << content << '\n'
#define VAR(v) #v << " = " << v<<" "
#define adebug(x,n) cout <<#x<<endl; REP(i,0,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,0,m)REP(j,0,n)cout<<x[i][j]<<char(j+1==n?10:32)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int W[n][n];

    double A[n][n],B[n][n];

    REP(i,n) REP(j,n) cin >> W[i][j];

    REP(i,n) REP(j,n) {
        double ai = (W[i][j] + W[j][i]) / 2.0;
        double bi = W[i][j]  - ai;
        A[i][j]  = A[j][i] = ai;
        B[i][j] = bi;
        B[j][i] = -bi;
    }

    REP(i,n) REP(j,n) cout<< A[i][j] << char(j+1==n?10:32);
    REP(i,n) REP(j,n) cout<< B[i][j] << char(j+1==n?10:32);

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pp;
typedef unsigned long long ull;
#define FOR(i, n) for(int i = 0; i < int(n); i++)
#define FORAB(i, a, b) for(int i = int(a); i <= int(b); i++)
#define FORTR(it, container) for(auto it = container.begin(); it != container.end(); it++)
#define pb push_back
#define mp make_pair
#define mset(a, val) memset(a, val, sizeof (a))
#define all(a) (a).begin(), (a).end()
#define what_is(x) cerr<< #x <<" = "<<x<<endl;
#define inp(x) cin>>x
#define outi(x) cout<<x
#define out(x) cout<<x<<endl
#define popcount(x) __builtin_popcount(x)
#define gcd(x,y) __gcd(x,y)
const int inf = 1e9;
const long long MAXINT_64 = numeric_limits<ll>::max();
const long long MININT_64 = numeric_limits<ll>::min();
const long double PI = ld(3.1415926535897932384626433832795);

double w[1718][1718];
double a[1718][1718];
double b[1718][1718];
int main(){
    ios::sync_with_stdio(false);
    int n; inp(n);
    int m= n;
    FOR(i,n){
    	FOR(j,m){
    		inp(w[i][j]);
    	}
    }
    FOR(i,n){
    	for(int j=0;j<=i;j++){
    		a[i][j] = (w[i][j]+w[j][i])/2;
    		b[i][j] = (w[i][j]-w[j][i])/2;
    	}
    }
    FOR(i,n){
    	for(int j=i+1;j<m;j++){
    		a[i][j] = a[j][i];
    		b[i][j] = -b[j][i];
    	}
    }

    FOR(i,n){
    	FOR(j,m){
    		printf("%.6lf ", a[i][j]);
    	}
    	printf("\n");
    }
    FOR(i,n){
    	FOR(j,m){
    		printf("%.6lf ", b[i][j]);
    	}
    	printf("\n");
    }
	return 0;
}


#include <stdio.h>
long long int max(long long int a,long long int b){
    if(a>b){
        return a;
    }
    return b;
}
int main()
{
   long long int i,j,test,k,m,flag=0,max=0,n;
   char a[100000],b[100000];

    scanf("%lld",&n);
    long long int o1=0,o2=0,z1=0,z2=0,count=0;
    scanf("%s%s",a,b);
    count=0;
    for(i=0;i<n;i++){
      if(a[i]!=b[i] && a[i+1]!=b[i+1] && i<n-2){
         count++;

             if(a[i]=='0'){
                  a[i]='1';
                  a[i+1]='0';
              }else{
                  a[i]='0';
                  a[i+1]='1';
              }

      }else{
          if(a[i]!=b[i]){
              count++;
              if(a[i]=='0'){
                  a[i]='1';
              }else{
                  a[i]='0';
              }

          }
      }
     // printf("%lld %c %c\n",count,a[i],b[i]);
    }

   printf("%lld",count);
    return 0;
}


#include <stdio.h>
long long int max(long long int a,long long int b){
    if(a>b){
        return a;
    }
    return b;
}
int main()
{
   long long int i,j,test,k,m,flag=0,max=0,n;
   char a[1000001],b[1000001];

    scanf("%lld",&n);
    long long int o1=0,o2=0,z1=0,z2=0,count=0;
    scanf("%s%s",a,b);
    count=0;
    for(i=0;i<n;i++){

      if(a[i]!=b[i]){
          count++;
          if(i<n-1 && a[i]==b[i+1] && b[i]==a[i+1]){
              i++;
          }
      }
     // printf("%lld %c %c\n",count,a[i],b[i]);
    }

   printf("%lld",count);
    return 0;
}


#include <stdio.h>
long long int max(long long int a,long long int b){
    if(a>b){
        return a;
    }
    return b;
}
int main()
{
   long long int i,j,test,k,m,flag=0,max=0,n;
   char a[100000],b[100000];

    scanf("%lld",&n);
    long long int o1=0,o2=0,z1=0,z2=0,count=0;
    scanf("%s%s",a,b);
    count=0;
    for(i=0;i<n;i++){

      if(a[i]!=b[i]){
          count++;
          if(i<n-1 && a[i]==b[i+1] && b[i]==a[i+1]){
              i++;
          }
      }
     // printf("%lld %c %c\n",count,a[i],b[i]);
    }

   printf("%lld",count);
    return 0;
}


#include <stdio.h>
long long int max(long long int a,long long int b){
    if(a>b){
        return a;
    }
    return b;
}
int main()
{
   long long int i,j,test,k,m,flag=0,max=0,n;
   char a[100000],b[100000];

    scanf("%lld",&n);
    long long int o1=0,o2=0,z1=0,z2=0,count=0;
    scanf("%s%s",a,b);
    count=0;
    for(i=0;i<n;i++){
      if(a[i]!=b[i] && a[i+1]!=b[i+1] && i<n-2 && a[i]!=a[i+1]){
         count++;

             if(a[i]=='0'){
                  a[i]='1';

              }else{
                  a[i]='0';

              }
            if(a[i+1]=='0'){
                  a[i+1]='1';

              }else{
                  a[i+1]='0';

              }

      }else{
          if(a[i]!=b[i]){
              count++;
              if(a[i]=='0'){
                  a[i]='1';
              }else{
                  a[i]='0';
              }

          }
      }
     // printf("%lld %c %c\n",count,a[i],b[i]);
    }

   printf("%lld",count);
    return 0;
}


#include <stdio.h>
long long int max(long long int a,long long int b){
    if(a>b){
        return a;
    }
    return b;
}
int main()
{
   long long int i,j,test,k,m,flag=0,max=0,n;
   char a[100000],b[100000];

    scanf("%lld",&n);
    long long int o1=0,o2=0,z1=0,z2=0,count=0;
    scanf("%s%s",a,b);
    count=0;
    for(i=0;i<n;i++){
      if(a[i]!=b[i] && a[i+1]!=b[i+1] && i<n-2){
         count++;

             if(a[i]=='0'){
                  a[i]='1';

              }else{
                  a[i]='0';

              }
            if(a[i+1]=='0'){
                  a[i+1]='1';

              }else{
                  a[i+1]='0';

              }

      }else{
          if(a[i]!=b[i]){
              count++;
              if(a[i]=='0'){
                  a[i]='1';
              }else{
                  a[i]='0';
              }

          }
      }
     // printf("%lld %c %c\n",count,a[i],b[i]);
    }

   printf("%lld",count);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int abs(int a){
	return (a<0)?-a:a;
}
void merge(int *a,int l,int m,int r){
	int t[r-l+1];
	int i = l,j = m+1,k=0;
	while(i<=m && j<=r) t[k++] = (a[i]<=a[j])?a[i++]:a[j++];
	while(i<=m) t[k++] = a[i++];
	while(j<=r) t[k++] = a[j++];
	for(int i  = l;i<=r;i++) a[i] = t[i-l];
}
void sort(int *a, int l,int r){
	if(l<r){
		int m = (l+r)/2;
		sort(a,l,m);
		sort(a,m+1,r);
		merge(a,l,m,r);
	}
}

void solve(){
	int n,Ans = 0;
	scanf("%d",&n);
	char *a = (char *)malloc(n*sizeof(char));
	char *b = (char *)malloc(n*sizeof(char));
	scanf("%s%s",a,b);
	for(int i = 0;i<n-1;i++){
		if(a[i]!=b[i]){
			if((a[i+1]!=b[i+1]) && (a[i+1]==b[i] && a[i]==b[i+1])) {
				a[i+1]=b[i+1];
				Ans++;
			}
			else Ans++;
		}
	}
	if(a[n-1]!=b[n-1]) Ans++;
	printf("%d\n",Ans);
}

int main(){
	solve();
	return 0;
}
/*
8
10001001
01101110
 */


#include <stdio.h>
#include <stdlib.h>

int abs(int a){
	return (a<0)?-a:a;
}
void merge(int *a,int l,int m,int r){
	int t[r-l+1];
	int i = l,j = m+1,k=0;
	while(i<=m && j<=r) t[k++] = (a[i]<=a[j])?a[i++]:a[j++];
	while(i<=m) t[k++] = a[i++];
	while(j<=r) t[k++] = a[j++];
	for(int i  = l;i<=r;i++) a[i] = t[i-l];
}
void sort(int *a, int l,int r){
	if(l<r){
		int m = (l+r)/2;
		sort(a,l,m);
		sort(a,m+1,r);
		merge(a,l,m,r);
	}
}

void solve(){
	int n,Ans = 0;
	scanf("%d",&n);
	char *a = (char *)malloc(n*sizeof(char));
	char *b = (char *)malloc(n*sizeof(char));
	scanf("%s%s",a,b);
	for(int i = 0;i<n-1;i++){
		if(a[i]!=b[i]){
			if((a[i+1]!=b[i+1]) && (a[i+1]=b[i] && a[i]==b[i+1])) {
				a[i+1]=b[i+1];
				Ans++;
			}
			else Ans++;
		}
	}
	if(a[n-1]!=b[n-1]) Ans++;
	printf("%d\n",Ans);
}

int main(){
	solve();
	return 0;
}
/*
6
110110
000000
 */


#include <stdio.h>
#include <stdlib.h>

void solve(){
	int n,Ans = 0;
	scanf("%d",&n);
	char *a = (char *)malloc((n+1)*sizeof(char));
	char *b = (char *)malloc((n+1)*sizeof(char));
	scanf("%s%s",a,b);
	for(int i = 0;i<n-1;i++){
		if(a[i]!=b[i]){
			if((a[i+1]!=b[i+1]) && (a[i+1]==b[i] && a[i]==b[i+1])) {
				a[i+1]=b[i+1];
				Ans++;
			}
			else Ans++;
		}
	}
	if(a[n-1]!=b[n-1]) Ans++;
	printf("%d\n",Ans);
}

int main(){
	solve();
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int abs(int a){
	return (a<0)?-a:a;
}
void merge(int *a,int l,int m,int r){
	int t[r-l+1];
	int i = l,j = m+1,k=0;
	while(i<=m && j<=r) t[k++] = (a[i]<=a[j])?a[i++]:a[j++];
	while(i<=m) t[k++] = a[i++];
	while(j<=r) t[k++] = a[j++];
	for(int i  = l;i<=r;i++) a[i] = t[i-l];
}
void sort(int *a, int l,int r){
	if(l<r){
		int m = (l+r)/2;
		sort(a,l,m);
		sort(a,m+1,r);
		merge(a,l,m,r);
	}
}

void solve(){
	int n,Ans = 0;
	scanf("%d",&n);
	char *a = (char *)malloc(n*sizeof(char));
	char *b = (char *)malloc(n*sizeof(char));
	scanf("%s%s",a,b);
	for(int i = 0;i<n-1;i++){
		if(a[i]!=b[i]){
			if(a[i+1]!=b[i+1]) {
				a[i+1]=b[i+1];
				Ans++;
			}
			else Ans++;
		}
	}
	if(a[n-1]!=b[n-1]) Ans++;
	printf("%d\n",Ans);
}

int main(){
	solve();
	return 0;
}


#include <stdio.h>

#define MAX (int)(10e6)
char V1[MAX+1], V2[MAX+1];
int N;
int cost;
int main()
{
    scanf("%d", &N);
    scanf("%s %s", V1, V2);

    for(int i = 0; i < N; i++)
      if(V1[i] != V2[i]) {
        // simple swap -> 01... and 10...
        if(i < N - 1 && V1[i+1] != V1[i] && V1[i+1] != V2[i+1])
            cost++, i++;
        // fancy swap -> axy... and yxa...
        //else if(i < N-2 && V1[i+1] == V1[i] && V2[i+1] == V2[i] && V1[i+2] != V2[i+2])
        //    cost += 2, i+=2;

        // general: two digits to swap are too distant
        else cost++;
      }

    printf("%d\n", cost);
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
    int n,cost=0;
    scanf("%d",&n);
    int i,a[n],b[n],xor[n];
    for(i=0;i<n;i++)
        scanf("%1d",&a[i]);
    for(i=0;i<n;i++)
        scanf("%1d",&b[i]);
    for(i=0;i<n;i++)
        xor[i] = a[i] ^ b[i];
    for(i=0;i<n;i++)
    {
        if(xor[i]==1)
        {
            if(xor[i+1]==1&&a[i+1]==b[i]&&b[i+1]==a[i])
            {
                cost++;
                xor[i] = 0;
                xor[i+1] = 0;
            }
            else
                cost++;
        }
    }
    printf("%d",cost);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
    int n,cost=0;
    scanf("%d",&n);
    int i,a[n],b[n],xor[n];
    for(i=0;i<n;i++)
        scanf("%1d",&a[i]);
    for(i=0;i<n;i++)
        scanf("%1d",&b[i]);
    for(i=0;i<n;i++)
        xor[i] = a[i] ^ b[i];
    for(i=0;i<n;i++)
    {
        if(xor[i]==1)
        {
            if(xor[i+1]==1)
            {
                cost++;
                xor[i] = 0;
                xor[i+1] = 0;
            }
            else
                cost++;
        }
    }
    printf("%d",cost);
    return 0;
}


#include<stdio.h>
#include<string.h>

int main(){
	int n;
	scanf("%d", &n);

	char a[1000001];
	char b[1000001];
	scanf("%s %s", a, b);

	int cost = 0;
	for(int i = 0 ; i < n ; i++){
		if(a[i] != b[i]){
			cost += 1;
			if(i < n - 1 && a[i+1] != b[i+1]){
				i++;
			}
		}
	}

	printf("%d\n", cost);
}


#include<stdio.h>
#include<string.h>

int main(){
	int n;
	scanf("%d", &n);

	char a[1000001];
	char b[1000001];
	scanf("%s %s", a, b);

	int cost = 0;
	for(int i = 0 ; i < n ; i++){
		if(a[i] != b[i]){
			cost += 1;
			if(i < n - 1 && a[i+1] == b[i] && b[i+1] == a[i]){
				i++;
			}
		}
	}

	printf("%d\n", cost);
}


#include <stdio.h>

int main()
{
    int n, ans = 0;
    char a[1000001];
    char b[1000001];
    scanf("%d %s %s", &n, a, b);
    for(int i = 0; i < n; ++i) {
        if(a[i] != b[i]) {
            if(i + 1 < n) {
                if(a[i] != b[i]) {
                    ++ans;
                    ++i;
                } else {
                    ++ans;
                }
            } else {
                ++ans;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


#include<stdio.h>
#define N 1000001
int main(){
    int n;
    scanf("%d",&n);
    char a[N];
    char b[N];
    scanf("%s",a);
    scanf("%s",b);
    int i;
    int answer=0;
    for(i=0;i<n-1;i++){
        //相邻的优先互换
        if(a[i]!=b[i] && a[i+1]!=b[i+1] && a[i]!=a[i+1]){
            answer++;
            a[i]=b[i];
            a[i+1]=b[i+1];
        }
    }
    for(i=0;i<n;i++){
        //统一用替换处理
        if(a[i]!=b[i]){
            answer++;
        }
    }
    printf("%d\n",answer);
    return 0;
}


#include<stdio.h>
int main()
{
	long long n,i,cnt = 0;
	scanf("%I64d",&n);
	char A[n+5];
	char B[n+5];
	scanf("%s",A);
	scanf("%s",B);
	for(i=0;i<n;i++)
	{
		if(A[i] != B[i])
		{
			if(A[i]  == B[i+1] && A[i+1] == B[i])
			{
				cnt++;
               i = i+1;
			}
			else
			cnt++;
		}
	}
	printf("%I64d",cnt);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int m, count=0,j,x=-1,y=-1;
    scanf("%d", &m);
    char a[m+1], b[m+1];
    int *pos = (int*)malloc(m*sizeof(int));
    scanf("%s %s", a, b);
    for(j=0;j<m;j++)
    {
        if(a[j]!=b[j])
        {
            count++;
            pos[j]=1;
        }
    }
    for(j=0;j<m-1;j++)
    {
        if(pos[j]==1 && pos[j+1]==1)
        {
            count--;
            pos[j]=0;
            pos[j+1]=0;
        }
    }
    printf("%d", count);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int m, count=0,j,x=-1,y=-1;
    scanf("%d", &m);
    char a[m+1], b[m+1];
    int *pos = (int*)malloc(m*sizeof(int));
    scanf("%s %s", a, b);
    for(j=0;j<m;j++)
    {
        if(a[j]!=b[j])
        {
            count++;
            pos[j]=1;
        }
    }
    for(j=0;j<m-1;j++)
    {
        if(pos[j]==1 && pos[j+1]==1 && a[j]!=a[j+1])
        {
            count--;
            pos[j]=0;
            pos[j+1]=0;
        }
    }
    printf("%d", count);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int comp(const void *a,const void *b)
{
    return (*(int *)a-*(int *)b);
}

int main()
{
    int n=0,q,m=0,ara1[1000009],ara2[1000009],i,j,sum=0,x,y;
    char a[1000009],b[1000009];
    scanf("%d",&q);
    scanf("%s%s",a,b);
    for(i=0;i<q;i++){
        if(a[i]!=b[i]){
            if(a[i]=='0'){
                ara1[m]=i;
                m++;
            }
            else{
                ara2[n]=i;
                n++;
            }
        }
    }
    qsort(ara1,m,sizeof(int),comp);
    qsort(ara2,n,sizeof(int),comp);

    if(m<=n){
        for(i=0;i<m;i++){
            x=ara1[i]+1+ara2[i]+1;
            y=abs(ara1[i]-ara2[i]);
            if(x<=y){
                sum=sum+x;
            }
            else{
                sum=sum+y;
            }
        }
        for(i=m;i<n;i++){
            sum=sum+ara2[i]+1;
        }
    }

    else{
        for(i=0;i<n;i++){
            x=ara2[i]+1+ara1[i]+1;
            y=abs(ara1[i]-ara2[i]);
            if(x<=y){
                sum=sum+x;
            }
            else{
                sum=sum+y;
            }
        }
        for(i=n;i<m;i++){
            sum=sum+ara1[i]+1;
        }
    }
    printf("%d",sum);
    return 0;
}


#include <stdio.h>

int foo(char *a, char *b)
{
	if (*a != *b) {
		if ( *(a+1) != *(b+1))
			return 2;
		else return 1;
	}
	return 0;
}

int main()
{
	int n;
	scanf("%d", &n);
	char A[n+1];
	char B[n+1];
	scanf("%s", A);
	scanf("%s", B);
	int i, sum=0;
	for (i=0; i < n-1;) {
		int cnt = 0;
		if (( cnt = foo(A+i, B+i) )) {
			i += cnt;
			sum++;
		} else i++;
	}
	if (A[n-1]!=B[n-1]) sum++;
	printf("%d\n", sum);
}


#include <stdio.h>

int foo(char *a, char *b)
{
	if (*a != *b) {
		if ( (*(a+1) != *(b+1)) && (*(b) != *(b+1)))
			return 2;
		else return 1;
	}
	return 0;
}

int main()
{
	int n;
	scanf("%d", &n);
	char A[n+1];
	char B[n+1];
	scanf("%s", A);
	scanf("%s", B);
	int i, sum=0;
	for (i=0; i < n-1;) {
		int cnt = 0;
		if (( cnt = foo(A+i, B+i) )) {
			i += cnt;
			sum++;
		} else i++;
	}
	if (A[n-1]!=B[n-1]) sum++;
	printf("%d\n", sum);
}


#include <stdio.h>

int foo(char *a, char *b)
{
	if (*a != *b) {
		if ( (*(a+1) != *(b+1)) && (*(b) != *(b+1)))
			return 2;
		else return 1;
	}
	return 0;
}

int main()
{
	int n;
	scanf("%d", &n);
	char A[n+1];
	char B[n+1];
	scanf("%s", A);
	scanf("%s", B);
	int i, sum=0;
	for (i=0; i < n-1;) {
		int cnt = 0;
		if (( cnt = foo(A+i, B+i) )) {
			i += cnt;
			sum++;
		} else i++;
	}
	if ( i!=n && A[n-1]!=B[n-1]) sum++;
	printf("%d\n", sum);
}


#include <stdio.h>

int foo(char *a, char *b)
{
	if (*a != *b) {
		if ( (*(a+1) != *(b+1)) && (*(b) != *(b+1)))
			return 2;
		else return 1;
	}
	return 0;
}

int main()
{
	int n;
	scanf("%d", &n);
	char A[n+1];
	char B[n+1];
	scanf("%s", A);
	scanf("%s", B);
	int i, sum=0;
	for (i=0; i < n-1;) {
		int cnt = 0;
		if (( cnt = foo(A+i, B+i) )) {
			i += cnt;
			sum++;
		} else i++;
	}
	if ( i < n-1 && A[n-1]!=B[n-1]) sum++;
	printf("%d\n", sum);
}


#include <stdio.h>
int main()
{
    long long int n,cnt=0;
    scanf("%lld", &n);
    char str1[1000007];
    char str2[1000007];
        scanf("%s", str1);
        scanf("%s", str2);
        for( int i=0;i<n;i++)
        {
            if(str1[i]!=str2[i])
            cnt++;
            if(i<n-1 && str1[i+1]==str2[i] && str1[i]==str2[i+1])
                i++;
                 }
        printf("%lld", cnt);
return 0;
}


#include <stdio.h>
int main()
{
    long long int n,cnt=0;
    scanf("%lld", &n);
    char str1[1000007];
    char str2[1000007];
    scanf("%s", str1);
    scanf("%s", str2);
    for( int i=0;i<n;i++)
    {
        if(i!=n-1)
        {
            if(str1[i]!=str2[i] && str1[i+1]!=str2[i+1] && str1[i+1]!=str2[i])
            {
                printf("a");
                cnt++;
                str1[i]=str2[i];
                str1[i+1]=str2[i+1];

            }
            else if(str1[i]!=str2[i])
            {
                cnt++;i++;
            }
            else
                if (str1[i]!=str2[i])
                {
                    cnt++;i++;
                }
        }
    }
    printf("%lld", cnt);
    return 0;
}


#include <stdio.h>
int main()
{
    long long int n,cnt=0;
    scanf("%lld", &n);
    char str1[1000007];
    char str2[1000007];
        scanf("%s", str1);
        scanf("%s", str2);
        printf("%s\n", str1);
        printf("%s\n", str2);
        for( int i=0;i<n;i++)
        {
            if(str1[i]!=str2[i])
            cnt++;
        }
        printf("%lld", cnt);
return 0;
}


#include<stdio.h>

int main()
{
    int n,count=0;
    scanf("%d",&n);
    char a[n+1],b[n+1];
    scanf("%s%s",a,b);
    a[n]='\0';
    b[n]='\0';
    for(int i=0;i<n;i++)
    {
    if(a[i]!=b[i])
    {
    if(a[i]!=a[i+1]&&a[i]==b[i+1])
    {
    count++;
    i++;
    }
    else
    count++;
    }
    }
    printf("%d",count);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define SIZE 1000000
void swap(char *a,int i, int j) {
	int k = a[i];
	a[i] = a[j];
	a[j] = k;
	return ;
}
/*void sort(int *a, int n) {
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - i - 1; j++) {
			if (a[j] > a[j + 1]) {
				swap(a, j, j + 1);
			}
		}
	}
	return;

}
void merge1(int l, int m, int r)
{
	int i1 = 0;
	int i2 = 0;
	int res[SIZE];
	while ((l + i1 < m) && (m + i2 < r)) {
		if (a[l + i1] < a[m + i2]) {
			res[i1 + i2] = a[l + i1];
			i1++;
		}
		else {
			res[i1 + i2] = a[m + i2];
			i2++;
		}
	}
	while (l + i1 < m) {
		res[i1 + i2] = a[l + i1];
		i1++;
	}
	while (m + i2 < r) {
		res[i1 + i2] = a[m + i2];
		i2++;
	}
	for (int i = 0; i < i1 + i2; i++) {
		a[l + i] = res[i];
	}
}
void mergesort(int l, int r) {
	if (l + 1 >= r) return;
	int m = (l + r) / 2;
	mergesort(l, m);
	mergesort(m, r);
	merge1(l, m, r);
}
*/
int main() {
	char b[SIZE];
	char c[SIZE];
	int n;
	scanf("%d", &n);
	scanf("%s", b);
	scanf("%s", c);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (b[i] != c[i]) {
			if (i + 1 < n) {
				if (b[i + 1] != c[i + 1] && b[i] != b[i + 1]) {
					ans++;
					swap(b, i, i + 1);
				}
			}
		}
	}
	for (int i = 0; i < n; i++)
		if (b[i] != c[i]) ans++;
	printf("%d\n", ans);
	return 0;

}


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define SIZE 200000
void swap(char *a,int i, int j) {
	int k = a[i];
	a[i] = a[j];
	a[j] = k;
	return ;
}
/*void sort(int *a, int n) {
	for (int i = 0; i < n - 1; i++) {
		for (int j = 0; j < n - i - 1; j++) {
			if (a[j] > a[j + 1]) {
				swap(a, j, j + 1);
			}
		}
	}
	return;

}
void merge1(int l, int m, int r)
{
	int i1 = 0;
	int i2 = 0;
	int res[SIZE];
	while ((l + i1 < m) && (m + i2 < r)) {
		if (a[l + i1] < a[m + i2]) {
			res[i1 + i2] = a[l + i1];
			i1++;
		}
		else {
			res[i1 + i2] = a[m + i2];
			i2++;
		}
	}
	while (l + i1 < m) {
		res[i1 + i2] = a[l + i1];
		i1++;
	}
	while (m + i2 < r) {
		res[i1 + i2] = a[m + i2];
		i2++;
	}
	for (int i = 0; i < i1 + i2; i++) {
		a[l + i] = res[i];
	}
}
void mergesort(int l, int r) {
	if (l + 1 >= r) return;
	int m = (l + r) / 2;
	mergesort(l, m);
	mergesort(m, r);
	merge1(l, m, r);
}
*/
int main() {
	char b[SIZE];
	char c[SIZE];
	int n;
	scanf("%d", &n);
	scanf("%s", b);
	scanf("%s", c);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (b[i] != c[i]) {
			if (i + 1 < n) {
				if (b[i + 1] != c[i + 1] && b[i] != b[i + 1]) {
					ans++;
					swap(b, i, i + 1);
				}
			}
		}
	}
	for (int i = 0; i < n; i++)
		if (b[i] != c[i]) ans++;
	printf("%d\n", ans);
	return 0;

}


using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

namespace ConsoleApp
{
    public class Program
    {
        public static void Main()
        {
            // int n = Convert.ToInt32(Console.ReadLine());
            // long[] array = Array.ConvertAll(Console.ReadLine().Split(' '), Convert.ToInt64);
            // StringBuilder stringBuilder = new StringBuilder();
            // for (int t = Convert.ToInt32(Console.ReadLine()); t > 0; t--)
            // {
            // }
            Console.ReadLine();
            string a = Console.ReadLine();
            string b = Console.ReadLine();
            int result = 0;
            for (int i = 0; i < a.Length;)
            {
                if (a[i] != b[i])
                {
                    if (i + 1 < a.Length && a[i] != a[i + 1] && b[i] != b[i + 1])
                    {
                        i += 2;
                    }
                    else
                    {
                        i++;
                    }
                    result++;
                }
                else
                {
                    i++;
                }
            }
            Console.WriteLine(result);
        }
    }
}


using System;
using System.Collections.Generic;

namespace _1037C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            HashSet<int>[] dg = new HashSet<int>[2]
            {
                new HashSet<int>(),
                new HashSet<int>()
            };

            for(int i = 0; i < n; ++i)
            {
                if(s[i] == t[i])
                    continue;
                dg[s[i] - '0'].Add(i);
            }

            int sl = 0;
            for(int i = 0; i < n; ++i)
            {
                if(s[i] == t[i])
                    continue;

                if(dg[(s[i] - '0') ^ 1].Contains(i + 1))
                {
                    ++sl;
                    ++i;
                }
                else
                    ++sl;
            }
            Console.WriteLine(sl);
        }
    }
}


using System;
using System.Collections.Generic;

namespace _1037C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            List<int>[] dg = new List<int>[2]
            {
                new List<int>(),
                new List<int>()
            };

            for(int i = 0; i < n; ++i)
            {
                if(s[i] == t[i])
                    continue;
                dg[s[i] - '0'].Add(i);
            }

            // int mn = Math.Min(dg[0].Count, dg[1].Count);
            // int sl = 0;
            // for(int i = 0; i < mn; ++i)
            //     sl += Math.Min(2, Math.Abs(dg[0][i] - dg[1][i]));
            // sl += Math.Max(dg[0].Count, dg[1].Count) - Math.Min(dg[0].Count, dg[1].Count);

            int rs = Best(dg[0].Count, dg[1].Count, dg[0], dg[1], new Dictionary<int, IDictionary<int, int>>());
            System.Console.WriteLine(rs);
        }

        protected static int Best(int i, int j, List<int> zeroes, List<int> ones, IDictionary<int, IDictionary<int, int>> tb)
        {
            if(i == 0)
                return j;
            if(j == 0)
                return i;

            if(tb.ContainsKey(i) && tb[i].ContainsKey(j))
                return tb[i][j];

            int sl0 = Best(i - 1, j - 1, zeroes, ones, tb) + Math.Abs(zeroes[i - 1] - ones[j - 1]);
            int sl1 = Best(i - 1, j, zeroes, ones, tb) + 1;
            int sl2 = Best(i, j - 1, zeroes, ones, tb) + 1;

            int sl =  Math.Min(sl0, Math.Min(sl1, sl2));

            if(!tb.ContainsKey(i))
                tb.Add(i, new Dictionary<int, int>());
            tb[i].Add(j, sl);
            return sl;
        }
    }
}


using System;
using System.Collections.Generic;

namespace _1037C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            List<int>[] dg = new List<int>[2]
            {
                new List<int>(),
                new List<int>()
            };

            for(int i = 0; i < n; ++i)
            {
                if(s[i] == t[i])
                    continue;
                dg[s[i] - '0'].Add(i);
            }

            // int mn = Math.Min(dg[0].Count, dg[1].Count);
            // int sl = 0;
            // for(int i = 0; i < mn; ++i)
            //     sl += Math.Min(2, Math.Abs(dg[0][i] - dg[1][i]));
            // sl += Math.Max(dg[0].Count, dg[1].Count) - Math.Min(dg[0].Count, dg[1].Count);

            int rs = Best(dg[0].Count, dg[1].Count, dg[0], dg[1], new Dictionary<int, IDictionary<int, int>>());
            System.Console.WriteLine(rs);
        }

        protected static int Best(int i, int j, List<int> zeroes, List<int> ones, IDictionary<int, IDictionary<int, int>> tb)
        {
            if(i == 0 && j == 0)
                return 0;

            if(i <= 0 || j <= 0)
                return  int.MaxValue / 2;

            if(tb.ContainsKey(i) && tb[i].ContainsKey(j))
                return tb[i][j];

            int sl0 = Best(i - 1, j - 1, zeroes, ones, tb) + Math.Abs(zeroes[i - 1] - ones[j - 1]);
            int sl1 = Best(i - 1, j, zeroes, ones, tb) + 1;
            int sl2 = Best(i, j - 1, zeroes, ones, tb) + 1;

            int sl =  Math.Min(sl0, Math.Min(sl1, sl2));

            if(!tb.ContainsKey(i))
                tb.Add(i, new Dictionary<int, int>());
            tb[i].Add(j, sl);
            return sl;
        }
    }
}


using System;
class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.In.ReadToEnd().Split(new char[] { ' ', '\n', '\t', '\r' }, StringSplitOptions.RemoveEmptyEntries);
            int price = 0;
            for(int i = 0, lst = -9; i<input[1].Length; i++)
            {
                if (input[1][i] != input[2][i])
                {
                    if (lst != i - 1 || input[1][i] == input[1][lst])
                    {
                        price++;
                        lst = i;
                    }
                }
            }
            Console.WriteLine(price);
        }
    }


using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{

    class Program
    {
        struct Point
        {
            public int l;
            public int r;
            public Point(int l, int r)
            {
                this.l = l;
                this.r = r;
            }
        }
        static void Main(string[] args)
        {
            long[] n = ((Console.ReadLine().Split(' ')).Select(long.Parse)).ToArray();
            //int [] array = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();
            int n1 = 0, n2 = 0;
            for (int i = 0; i < n[0]; i++)
            {
                if (s1[i] != s2[i])
                {
                    n1++;
                    for (int j = i+1; j < n[0]; j++)
                    {
                        if (s1[j] == s2[i] && s2[j] == s1[i])
                        {
                            n2 += j - i;
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(Math.Min(n1, n2));
            Console.ReadLine();
        }
        static string FindSecondMax(List<Point> list)
        {
            Point point = new Point(int.MaxValue, int.MaxValue);
            Point maxpoint = new Point(int.MaxValue, int.MaxValue);
            foreach (Point p in list)
            {
                if (Rast(p) >= Rast(point))
                {
                    maxpoint = point;
                    point = p;
                }
                else if(Rast(p) > Rast(maxpoint)){ maxpoint = p; }
            }
            return $"{maxpoint.l} {maxpoint.r}";
        }

        private static int Rast(Point point)
        {
            return (int)(Math.Sqrt(point.l * point.l + point.r * point.r));
        }

        private static long S(long v)
        {
            long sum = 0;
            while (v != 0)
            {
                sum += v % 10;
                v /= 10;
            }
            return sum;
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{

    class Program
    {
        struct Point
        {
            public int l;
            public int r;
            public Point(int l, int r)
            {
                this.l = l;
                this.r = r;
            }
        }
        static void Main(string[] args)
        {
            long[] n =
                ((Console.ReadLine().Split(' ')).Select(long.Parse)).ToArray();
            //int [] array = ((Console.ReadLine().Split(' ')).Select(int.Parse)).ToArray();
            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();

            int n1 = 0;
            for (int i = 0; i < n[0]; i++)
            {
                if (s1[i] != s2[i])
                {
                    if (i + 1 < n[0] && s1[i + 1] == s2[i])
                    {
                        i++;
                    }
                    n1++;
                }
            }
            Console.WriteLine(n1);
            Console.ReadLine();
        }

    }
}


using System;
class Program
    {
        static void Main(string[] args)
        {
            int result = 0;
            {
                string[] input = Console.In.ReadToEnd().Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
                bool changed = false;
                for (int i = 0, lim = input[1].Length - 1; i < lim; i++)
                {
                    changed = false;
                    if(input[1][i]!=input[2][i])
                    {
                        result++;
                        if (input[1][i + 1] != input[2][i + 1] && input[1][i] != input[1][i + 1]) { i++; changed = true; }
                    }
                }
                if (input[1][input[1].Length - 1] != input[2][input[2].Length - 1] && !changed) result++;
            }
            Console.WriteLine(result);
        }
    }