#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,a[2000][200],dem=0,z=1,demm=0;
    cin>>n;
    for(int i=1;i<=n;i++)
        {for(int j=1;j<=3;j++)
            {cin>>a[i][j];
            if (a[i][j]==1) dem+=1;
            }
            if (dem>=2) demm++;
            dem=0;
            }
    cout<<demm;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	int n;
	cin>>n;
	int x[101][3];
	int count=0,t=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>x[i][j];

		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(x[i][j]>0)
			count++;

		}
		if(count>1)
		t++;

		count=0;

	}
cout<<t;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	int n;
	cin>>n;
	int x[1000][3];
	int count=0,t=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>x[i][j];

		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(x[i][j]>0)
			count++;

		}
		if(count>1)
		t++;

		count=0;

	}
cout<<t;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x[3];
	int count=0,t=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>x[j];

		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(x[j]>0)
			count++;

		}
		if(count>1)
		t++;

		count=0;

	}
cout<<t;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x[3];
	int count=0,t=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>x[i];

		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(x[i]>0)
			count++;

		}
		if(count>1)
		t++;

		count=0;

	}
cout<<t;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x[50][3];
	int count=0,t=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>x[i][j];

		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(x[i][j]>0)
			count++;

		}
		if(count>1)
		t++;

		count=0;

	}
cout<<t;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x[3];
	int count=0,t=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>x[i];

		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(x[j]>0)
			count++;

		}
		if(count>1)
		t++;

		count=0;

	}
cout<<t;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x[5][3];
	int count=0,t=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>x[i][j];

		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(x[i][j]>0)
			count++;

		}
		if(count>1)
		t++;

		count=0;

	}
cout<<t;
return 0;
}


#include<stdio.h>

int main()
{
    int n,i,a[5],sum=0,count=0;
    scanf("%d",&n);
    while(n--){
    for(i=0;i<3;i++){
      scanf("%d",&a[i]);
    }
    sum=0;
    for(i=0;i<3;i++){
      if(a[i]==1) sum++;
    }
    if(sum>=2) count++;
    }
    printf("%d\n",count);
    return 0;

}


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

int main()
{
	int t;
	int count=0;
	int array[50];
	cin>>t;
	while (t--)
	{
		for(int i=0;i<=3;i++)
		{
			cin>>array[i];
		}
	}

	for(int i=0;i<=3;i++)
		{
			if (array[2]==1||array[3]==1)
				count++;

		}
		cout<<count<<endl;

	return 0;
}


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

int main()
{
	int t;
	int count=0;
	int array[50];
	cin>>t;
	while (t--)
	{
		for(int i=0;i<=3;i++)
		{
			cin>>array[i];
		}
	}

	if (array[1]==1&&array[2]==1&&array[3]==1)
				count++;
			else if(array[1]==array[2]==1||array[1]==array[3]==1||array[2]==array[3]==1)
				count++;

		cout<<count<<endl;
		return 0;
	}


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

int main()
{
	int t;
	int count=0;
	int array[50];
	cin>>t;
	while (t--)
	{
		for(int i=0;i<3;i++)
		{
			cin>>array[i];
		}
	}
 for(int j=0;j<3;j++)

 {
	if (array[1]==1&&array[2]==1&&array[3]==1)
				count++;
			else if(array[1]==array[2]==1||array[1]==array[3]==1||array[2]==array[3]==1)
               count++;
           continue;

 }
        cout<<count<<endl;

 		return 0;
	}


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

int main()
{
	int t;
	int count=0;
	int array[50];
	cin>>t;
	while (t--)
	{
		for(int i=0;i<=3;i++)
		{
			cin>>array[i];
		}
	}

	if (array[1]==1||array[2]==1||array[3]==1)
				count++;
			else if (array[1]==1||array[3]==1)
				count++;
			else if(array[2]==1||array[3]==1)
				count++;

		cout<<count<<endl;
		return 0;
	}


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

int main()
{
	int t;
	int count=0;
	int array[50];
	cin>>t;
	while (t--)
	{
		for(int i=0;i<3;i++)
		{
			cin>>array[i];
		}
	}
 for(int j=0;j<t;j++)

 {
	if (array[1]==1&&array[2]==1&&array[3]==1)
				count++;
			else if(array[1]==array[2]==1||array[1]==array[3]==1||array[2]==array[3]==1)
               count++;
           continue;

 }
        cout<<count<<endl;

 		return 0;
	}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[3];
	int count = 0;
	int result = 0;

	while (n--){
		for (int i =0; i<3;i++){
			cin >> a[i];
			if (a[i] == 1)
				count = i;
		}
		if (count>=1)
		result++;
	}
cout << result << endl;
return 0;
}


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

int main()
{
	int t;
	int count=0;
	int array[50];
	cin>>t;
	while (t--)
	{
		for(int i=0;i<=3;i++)
		{
			cin>>array[i];
		}
	}

	if (array[2]==1||array[3]==1)
				count++;

		cout<<count<<endl;
		return 0;
	}


#include <iostream>
using namespace std;
int main()
{
    int n,Petya,Vasya,Tonya;
    cin>>n;
    int temp;
    temp=0;
    while(n--)
    {
        cin>>Petya;
        cin>>Vasya;
        cin>>Tonya;
       if(Petya+Vasya+Tonya>=2)
        temp++;
    }
    cout<<temp<<endl;
    return 0;

}


#include <iostream>
using namespace std;
int main()
{
    int n,Petya,Vasya,Tonya;
    cin>>n;
    int arr[n],ptr,temp;
    while(n--)
    {
        int count;
        count =0;
        cin>>Petya;
        cin>>Vasya;
        cin>>Tonya;
        if(Petya)
            count++;
        if(Vasya)
            count++;
        if(Tonya)
            count++;
        if(count>=2)
            temp++;
    }
    cout<<temp<<endl;
    return 0;

}


#include <iostream>
using namespace std;
int main()
{
    int n,Petya,Vasya,Tonya;
    cin>>n;
    while(n--)
    {
        int count=0;
        cin>>Petya>>Vasya>>Tonya;
        if(Petya)
            count++;
        if(Vasya)
            count++;
        if(Tonya)
            count++;
       if(count==2||count==3)
        cout<<count<<endl;
    else if(count==1||count==0)
        cout<<0<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,Petya,Vasya,Tonya;
    cin>>n;
    while(n--)
    {
        int count=0;
        cin>>Petya>>Vasya>>Tonya;
        if(Petya)
            count++;
        if(Vasya)
            count++;
        if(Tonya)
            count++;
        cout<<count<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n,Petya,Vasya,Tonya;
    cin>>n;
    int arr[n],ptr,temp;
    while(n--)
    {
        cin>>Petya;
        cin>>Vasya;
        cin>>Tonya;
       if(Petya+Vasya+Tonya>=2)
        temp++;
    }
    cout<<temp<<endl;
    return 0;

}


#include <iostream>
using namespace std;
int main()
{
    int n,Petya,Vasya,Tonya;
    cin>>n;
    int arr[n],ptr,temp;
    while(n--)
    {
        int count=0;
        cin>>Petya;
        cin>>Vasya;
        cin>>Tonya;
        if(Petya)
            count++;
        if(Vasya)
            count++;
        if(Tonya)
            count++;
        if(count>=2)
            temp++;
    }
    cout<<temp<<endl;
    return 0;

}


#include <iostream>
using namespace std;
int main()
{
    int n,Petya,Vasya,Tonya;
    cin>>n;
    int arr[n],ptr,temp;
    while(n--)
    {
        int count=0;
        cin>>Petya;
        cin>>Vasya;
        cin>>Tonya;
        if(Petya)
            count++;
        if(Vasya)
            count++;
        if(Tonya)
            count++;
        if(count>=2)
            temp++;
    }
    cout<<temp;
    return 0;

}


/**
 *    author:  Zheksenov Ramazan
 *    created: 22.03.2018
**/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>

#include <string>
#include <ctime>
#include <queue>
#include <stack>

#include <vector>
#include <map>
#include <set>
#include <deque>

#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

void freeopen() {
	#ifndef ONLINE_JUDGE
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)5e5 + 5;
const int mod = (int)1e9 + 7;

int main() {

    setlocale(LC_ALL, "rus");

	//#ifdef DEBUG
	//    freopen("input.txt", "r", stdin);
	//#endif

	ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, a, t = 0, p, q, r;

	cin >> n;
	while(n--)
	{
		cin>> p >> q >> r;
		if(p + q + r > 1)
		t++;
	}

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << " ms\n";
		tt = clock();
	#endif

	cin.get();

	return 0;
}


/**
 *    author:  Zheksenov Ramazan
 *    created: 22.03.2018
**/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>

#include <string>
#include <ctime>
#include <queue>
#include <stack>

#include <vector>
#include <map>
#include <set>
#include <deque>

#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

void freeopen() {
	#ifndef ONLINE_JUDGE
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)5e5 + 5;
const int mod = (int)1e9 + 7;

int main() {

    setlocale(LC_ALL, "rus");

	//#ifdef DEBUG
	//    freopen("input.txt", "r", stdin);
	//#endif

	ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, a, t = 0, p, q, r;

	cin >> n;
	while(n--)
	{
		cin>> p >> q >> r;
		if(p + q + r < 1)
		t++;
	}
	cout << t;

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << " ms\n";
		tt = clock();
	#endif

	cin.get();

	return 0;
}


/**
 *    author:  Zheksenov Ramazan
 *    created: 22.03.2018
**/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>

#include <string>
#include <ctime>
#include <queue>
#include <stack>

#include <vector>
#include <map>
#include <set>
#include <deque>

#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

void freeopen() {
	#ifndef ONLINE_JUDGE
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)5e5 + 5;
const int mod = (int)1e9 + 7;

int main() {

    setlocale(LC_ALL, "rus");

	//#ifdef DEBUG
	//    freopen("input.txt", "r", stdin);
	//#endif

	ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, a, t = 0, p, q, r;

	cin >> n;
	while(n--)
	{
		cin>> p >> q >> r;
		if(p + q + r > 1)
		t++;
	}
	cout << t;

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << " ms\n";
		tt = clock();
	#endif

	cin.get();

	return 0;
}


/**
 *    author:  Zheksenov Ramazan
 *    created: 22.03.2018
**/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>

#include <string>
#include <ctime>
#include <queue>
#include <stack>

#include <vector>
#include <map>
#include <set>
#include <deque>

#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

void freeopen() {
	#ifndef ONLINE_JUDGE
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)5e5 + 5;
const int mod = (int)1e9 + 7;

int main() {

    setlocale(LC_ALL, "rus");

	//#ifdef DEBUG
	//    freopen("input.txt", "r", stdin);
	//#endif

	ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, a, t = 0, p, q, r;

	cin >> n;
	while(n--)
	{
		cin>> p >> q >> r;
		if(p + q + r > 1)
	}
	cout << endl;

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << " ms\n";
		tt = clock();
	#endif

	cin.get();

	return 0;
}


/**
 *    author:  Zheksenov Ramazan
 *    created: 22.03.2018
**/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>

#include <string>
#include <ctime>
#include <queue>
#include <stack>

#include <vector>
#include <map>
#include <set>
#include <deque>

#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

void freeopen() {
	#ifndef ONLINE_JUDGE
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)5e5 + 5;
const int mod = (int)1e9 + 7;

int main() {

    setlocale(LC_ALL, "rus");

	//#ifdef DEBUG
	//    freopen("input.txt", "r", stdin);
	//#endif

	ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, a, t = 0, p, q, r;

	cin >> n;
	while(n--)
		cin>> p >> q >> r;
		if(p + q + r > 1)
		t++;

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << " ms\n";
		tt = clock();
	#endif

	cin.get();

	return 0;
}


/**
 *    author:  Zheksenov Ramazan
 *    created: 22.03.2018
**/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>

#include <string>
#include <ctime>
#include <queue>
#include <stack>

#include <vector>
#include <map>
#include <set>
#include <deque>

#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

void freeopen() {
	#ifndef ONLINE_JUDGE
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)5e5 + 5;
const int mod = (int)1e9 + 7;

int main() {

    setlocale(LC_ALL, "rus");

	//#ifdef DEBUG
	//    freopen("input.txt", "r", stdin);
	//#endif

	ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, a, t = 0, p, q, r;

	cin >> n;
	while
	{
		cin>> p >> q >> r;
		if(p + q + r > 1)
		t++;
	}
	cout << t;

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << " ms\n";
		tt = clock();
	#endif

	cin.get();

	return 0;
}


/**
 *    author:  Zheksenov Ramazan
 *    created: 22.03.2018
**/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>

#include <string>
#include <ctime>
#include <queue>
#include <stack>

#include <vector>
#include <map>
#include <set>
#include <deque>

#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

void freeopen() {
	#ifndef ONLINE_JUDGE
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)5e5 + 5;
const int mod = (int)1e9 + 7;

int main() {

    setlocale(LC_ALL, "rus");

	//#ifdef DEBUG
	//    freopen("input.txt", "r", stdin);
	//#endif

	ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, a, t = 0, p, q, r;

	cin >> n;
	while(n--)
	{
		cin>> p >> q >> r;
		if(q + r > 1)
		t++;
	}
	cout << t;

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << " ms\n";
		tt = clock();
	#endif

	cin.get();

	return 0;
}


/**
 *    author:  Zheksenov Ramazan
 *    created: 22.03.2018
**/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>

#include <string>
#include <ctime>
#include <queue>
#include <stack>

#include <vector>
#include <map>
#include <set>
#include <deque>

#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

void freeopen() {
	#ifndef ONLINE_JUDGE
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)5e5 + 5;
const int mod = (int)1e9 + 7;

int main() {

    setlocale(LC_ALL, "rus");

	//#ifdef DEBUG
	//    freopen("input.txt", "r", stdin);
	//#endif

	ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, a, t = 0, p, q, r;

	cin >> n;
	while(n++)
	{
		cin>> p >> q >> r;
		if(p + q + r > 1)
		t++;
	}
	cout << t;

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << " ms\n";
		tt = clock();
	#endif

	cin.get();

	return 0;
}


/**
 *    author:  Zheksenov Ramazan
 *    created: 22.03.2018
**/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>

#include <string>
#include <ctime>
#include <queue>
#include <stack>

#include <vector>
#include <map>
#include <set>
#include <deque>

#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

void freeopen() {
	#ifndef ONLINE_JUDGE
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)5e5 + 5;
const int mod = (int)1e9 + 7;

int main() {

    setlocale(LC_ALL, "rus");

	//#ifdef DEBUG
	//    freopen("input.txt", "r", stdin);
	//#endif

	ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, a, t = 0, p, q, r;

	cin >> n;
	while {
		if(p + q + r > 1)
		t++;
	}
	cout << t;

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << " ms\n";
		tt = clock();
	#endif

	cin.get();

	return 0;
}


/**
 *    author:  Zheksenov Ramazan
 *    created: 22.03.2018
**/

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstring>

#include <string>
#include <ctime>
#include <queue>
#include <stack>

#include <vector>
#include <map>
#include <set>
#include <deque>

#include <cassert>
#include <unordered_map>
#include <bitset>
#include <unordered_set>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define mp make_pair
#define sz(a) (int)((a).size())
#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif
#define fname "."

void freeopen() {
	#ifndef ONLINE_JUDGE
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	#endif
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;
typedef pair < int, ull > pu;
typedef pair < ll, ll > pl;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int inf = (int)1e9 + 123;
const ll infl = (ll)1e18 + 123;
const double eps = 1e-9;

const int MAX_N = (int)5e5 + 5;
const int mod = (int)1e9 + 7;

int main() {

    setlocale(LC_ALL, "rus");

	//#ifdef DEBUG
	//    freopen("input.txt", "r", stdin);
	//#endif

	ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, a, t = 0, p, q, r;

	cin >> n;
	while(n--)
	{
		cin>> p >> q >> r;
		if(p + q > 1)
		t++;
	}
	cout << t;

	#ifdef _DEBUG
		cerr << "TIME = " << clock() - tt << " ms\n";
		tt = clock();
	#endif

	cin.get();

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(ar[i][j] != 1)
				count++;
		}
		k = n - count;
		cout << k << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if((ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1) or (ar[i][0] == 1 and ar[i][1] == 1) or (ar[i][0] == 1 and ar[i][2] == 1) or (ar[i][2] == 1 and ar[i][1] == 1))
				count++
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if((ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1) or (ar[i][0] = 1 and ar[i][1] = 1) or (ar[i][2] = 1 and ar[i][1] = 1) or (ar[i][0] = 1 and ar[i][2] = 1))
				count++;
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count = 0;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)

		{
			if(ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1  )
			{
				count++;
			}
			else
		    {
		    	if(ar[i][0]==1 and ar[i][1]==1)
		    	{
				count++;
			    }
			    else if(ar[i][0]==1 and ar[i][2]==1)
			    {
			    	count++;
			    }
			    else if(ar[i][1]==1 and ar[i][2]==1)
			    {
			    	count++;
			    }

			}
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1  )
			{
				count++;
			}
			else if((ar[i][0] == 1 and ar[i][1] == 1)  or (ar[i][2] == 1 and ar[i][1] == 1) or (ar[i][2] == 1 and ar[i][1] == 1))
		    {
				count++;
			}
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(ar[i][j] != 1)
				count++;
			k = n - count ;
				cout <<k;
		}
		cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count = 0;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1  )
			{
				count++;
			}
			else
		    {
		    	if(ar[i][0]==1 and ar[i][1]==1)
		    	{
				count++;
			    }
			    else if(ar[i][0]==1 and ar[i][2]==1)
			    {
			    	count++;
			    }
			    else if(ar[i][1]==1 and ar[i][2]==1)
			    {
			    	count++;
			    }

			}
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if((ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1) or (ar[i][0] == 1 and ar[i][1] == 1) or (ar[i][0] == 1 and ar[i][2] == 1) or (ar[i][2] == 1 and ar[i][1] == 1))
				count++;
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1  )
			{
				count++;
			}
			else((ar[i][0] == 1 and ar[i][1] == 1)  or (ar[i][2] == 1 and ar[i][1] == 1) or (ar[i][2] == 1 and ar[i][1] == 1))
		    {
				count++;
			}
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1  )
				count++;
			if(ar[i][0] == 1 and ar[i][1] == 1 )
				count++;
			if(ar[i][2] == 1 and ar[i][1] == 1 )
				count++;
			if(ar[i][0] == 1 and ar[i][2] == 1 )
				count++;
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1  )
			{
				count++;
			}
			else ((ar[i][0] == 1 and ar[i][1] == 1)  or (ar[i][2] == 1 and ar[i][1] == 1) or (ar[i][2] == 1 and ar[i][1] == 1))
		    {
				count++;
			}
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(a[i][j] != 1)
				count++;
			k = n - count ;
				cout <<k;
		}
		cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(ar[i][j] != 1)
				count++;
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1  )
			{
				count++;
			}
			else
		    {
		    	if(ar[i][0]==1 and ar[i][1]==1)
		    	{
				count++;
			    }
			    else if(ar[i][0]==1 and ar[i][2]==1)
			    {
			    	count++;
			    }
			    else if(ar[i][1]==1 and ar[i][2]==1)
			    {
			    	count++;
			    }

			}
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1  )
			{
				count++;
			}
			else if(ar[i][0] == 1 and ar[i][1] == 1 )
		    {
				count++;
			}
			else if(ar[i][2] == 1 and ar[i][1] == 1 )
			{
				count++;
			}
			else if(ar[i][0] == 1 and ar[i][2] == 1 )
			{
				count++;
			}
		}
		cout << count << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	int count;
	cin>>n;
	bool ar[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			int temp;
			cin >> temp;
			if(temp == 0 or temp == 1)
				ar[i][j] = temp;
		}
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
		{
			if(ar[i][0] == 1 and ar[i][1] == 1 and ar[i][2] == 1  )
			{
				count++;
			}
			else(ar[i][0] == 1 and ar[i][1] == 1 )
		    {
				count++;
			}
			else(ar[i][2] == 1 and ar[i][1] == 1 )
			{
				count++;
			}
			else(ar[i][0] == 1 and ar[i][2] == 1 )
			{
				count++;
			}
		}
		cout << count << endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a,b,c,p=0;
    cin>>n;
    for(int x=0;x<n;x++)
    {
        cin>>a>>b>>c;
        if(a+b+c>=2)
        {
            p++;
        }
    }
    cout<<p<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
   int n,a,b,c,d=0;
   cin>>n;
   for(int x=0;x<n;x++)
   {
       cin>>a>>b>>c;
       if(a+b+c>=2)
       {
           d++;
       }
   }
   cout<<d<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a,b,c,s=0;
    cin>>n;
    for(int x=1;x<=n;x++)
    {
        cin>>a>>b>>c;
        if(a+b+c>=2)
            s++;
    }
    cout<<s<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a,b,c;
    cin>>n;
    int p=0;
    for(int x=1;x<=n;x++)
    {
        cin>>a>>b>>c;
        if(a+b+c>=2)
        {
            p++;
        }
    }
    cout<<p;
    return 0;
}


#include <iostream>
#include<climits>
#include<sstream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int a,b,c,cont=0;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b>>c;
        if((a+b+c)>=2)
        {
            cont++;
        }
    }
    cout<<cont<<endl;
    return 0;
}


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

int main()
{
    int n,a,b,c,min=0;
    cin>>n;
    for(int x=0;x<n;x++)
    {
        cin>>a>>b>>c;
        if(a+b+c>=2)
        {
            min++;
        }
    }
    cout<<min<<endl;
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int a,b,c;
    int cont=0;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b>>c;
        if(a+b+c>1){cont++;}
    }
    cout<<cont<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n,a,b,c,pro=0;
    cin>>n;
    int arr[n];
    for(int x=0;x<n;x++)
    {
        cin>>a;
        cin>>b;
        cin>>c;
        if(a==1&&b==1||a==1&&c==a||b==1&&c==1||a==1&&b==1&&c==1)
        {
            pro++;
        }
    }
    cout<<pro<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x,y,z,c=0,ans=0;
    cin >> n;
    for ( int i=1 ; i<=n ; i++ )
    {
        cin >> x >> y >> z;
        if ( x==1 ) c++;
        if ( y==1 ) c++;
        if ( z==1 ) c++;
        if ( c>=2)
        {
            c=0;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x,c=0,ans=0;
    cin >> n;
    for ( int i=1 ; i<=n*n ; i++ )
    {
        cin >> x;
        if ( x==1 ) c++;
        if ( n%i==0 && c>=2 )
        {
            c=0;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x,y,z,c=0,ans=0;
    cin >> n;
    for ( int i=1 ; i<=n ; i++ )
    {
        cin >> x >> y >> z;
        if ( x==1 ) c++;
        if ( y==1 ) c++;
        if ( z==1 ) c++;
        if ( c>=2 )
        {
            c=0;
            ans++;
        }
        else if (c<2) c=0;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x,c=0,ans=0;
    cin >> n;
    for ( int i=1 ; i<=n*n ; i++ )
    {
        cin >> x;
        if ( x==1 ) c++;
        if ( i%n==0 && c>=2 )
        {
            ans++;
            c=0;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x,y,z,c=0,ans=0;
    cin >> n;
    for ( int i=1 ; i<=n ; i++ )
    {
        cin >> x >> y >> z;
        if ( (x==1 && y==1) || (y==1 && z==1) || (z==1 && x==1) ) c++;
        if ( c>=2)
        {
            c=0;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x,y,z,c=0,ans=0;
    cin >> n;
    for ( int i=1 ; i<=n ; i++ )
    {
        cin >> x >> y >> z;
        if ( x==1 || y==1 || z==1 ) c++;
        if ( c>=2 )
        {
            c=0;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    while(n--){
        int a,b,c,sol=0;
        cin>>a>>b>>c;
        if(a==0&&b==0 || a==0&&c==0 || c==0&&b==0){
            cout<<sol;
        }
        else{
            sol++;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    while(n--){
        int a,b,c,sol=0;
        cin>>a>>b>>c;
        if(a==0&&b==0 || a==0&&c==0 || c==0&&b==0){
            cout<<sol;
        }
        else{
            sol++;
            cout<<sol;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    while(n--){
        int a,b,c,sol=0;
        if(a==0&&b==0 || a==0&&c==0 || c==0&&b==0){
            cout<<sol;
        }
        else{
            sol++;
            cout<<sol;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
	int n,d=0;
	cin>>n;
	while(n--)
	{
	    int a,b,c;
		cin>>a>>b>>c;
		if(a+b+c>1)
			d++;
	}
	cout<<d;
}


#include<iostream>
using namespace std;

int main()
{
    int n,sol=0;
    cin>>n;
    while(n--){
        int a,b,c;
        if(a==0&&b==0 || a==0&&c==0 || c==0&&b==0){
            cout<<sol;
        }
        else{
            sol++;
            cout<<sol;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin>>n,sol=0;
    while(n--){
        int a,b,c;
        cin>>a>>b>>c;
        if(a+b+c>1){
            sol++;
        }
        else{
            cout<<sol;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    while(n--){
        int a,b,c,sol=0;
        if(a==0||c==0||b==0){
            sol++;
            cout<<sol;
        }
        else{
            cout<<sol=0;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    while(n--){
        int a,b,c,sol=0;
        if(a==0|| c==0 ||b==0){
            sol++;
            cout<<sol;
        }
        else{
            cout<<sol;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n,sol=0;
    cin>>n;
    while(n--){
        int a,b,c;
        cin>>a>>b>>c;
        if(a+b+c>1){
            sol++;
        }
            cout<<sol;
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n,sol=0;
    cin>>n;
    while(n--){
        int a,b,c;
        cin>>a>>b>>c;
        if(a+b+c>1){
            sol++;
        }
        else{
            cout<<sol;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    while(n--){
        int a,b,c,sol=0;
        cin>>a>>b>>c;
        if(a+b+c>1){
            sol++;
        }
        else{
            cout<<sol;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int n,i,d,a,b,c;
d=0;
vector<int>v;
cin>>n;
for(i=0;i<n;i++)
{cin>>a>>b>>c;
v.clear();
v.push_back(a);
v.push_back(b);
v.push_back(c);
sort(v.begin(),v.end());
if(v[0]==v[2] && (v[0]==1)
{d=d+1;}
}
cout<<d;
return 0;
}


#include<bits/stdc++.h>
int main()
{int n,i,d,a,b,c;
d=0;
vector<int>v;
cin>>n;
for(i=0;i<n;i++)
{cin>>a>>b>>c;
v=[];
v.push_back(a);
v.push_back(b);
v.push_back(c);
sort(v.begin(),v.end());
if(v[0]==v[2] && (v[0]==1)
{d=d+1;}
}
cout<<d;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int n,i,d,a,b,c;
d=0;
vector<int>v;
cin>>n;
for(i=0;i<n;i++)
{cin>>a>>b>>c;
v.clear();
v.push_back(a);
v.push_back(b);
v.push_back(c);
sort(v.begin(),v.end(),greater<int>());
if((v[0]==v[1]) && (v[0]==1))
{
d=d+1;}
}
cout<<d;
return 0;
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntArray();
        var b = ReadIntArray();

        long ans, sum;
        int min;
        if (m == 0)
        {
            ans = 0;
            sum = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                sum += a[i];
                ans = Math.Max(ans, sum - b[i]);
            }
        }
        else if (m > 1)
        {
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
                min = Math.Min(b[i], min);
            ans = 0;
            ans = Math.Max(ans, a[n - 1] - b[n - 1]);
            ans = Math.Max(ans, a.Sum(aa => (long)aa) - min);
        }
        else
        {
            var rdp = new long[n];
            rdp[n - 1] = a[n - 1] - b[n - 1];
            long rsum = a[n - 1];
            for (int i = n - 2; i >= 0; i--)
            {
                rsum += a[i];
                rdp[i] = Math.Max(rdp[i + 1], rsum - b[i]);
            }

            ans = 0;
            sum = a[0];
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
            {
                min = Math.Min(min, b[i]);
                sum += a[i];
                ans = Math.Max(ans, Math.Max(0, sum - min) + Math.Max(0, rdp[i + 1]));
            }

            sum = a.Sum(aa => (long)aa);
            min = a[1];
            for (int i = 2; i < n; i++)
                min = Math.Min(min, a[i]);
            ans = Math.Max(ans, sum - min - b[0]);

            ans = Math.Max(ans, rdp[1]);
        }

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntArray();
        var b = ReadIntArray();

        long ans, sum;
        int min;
        if (m == 0)
        {
            ans = 0;
            sum = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                sum += a[i];
                ans = Math.Max(ans, sum - b[i]);
            }
        }
        else if (m > 1)
        {
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
                min = Math.Min(b[i], min);
            ans = 0;
            ans = Math.Max(ans, a[n - 1] - b[n - 1]);
            ans = Math.Max(ans, a.Sum(aa => (long)aa) - min);
        }
        else
        {
            var rsums = new long[n];
            rsums[n - 1] = a[n - 1];
            for (int i = n - 2; i >= 0; i--)
                rsums[i] = rsums[i + 1] + a[i];

            ans = 0;
            sum = a[0];
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
            {
                min = Math.Min(min, b[i]);
                sum += a[i];
                ans = Math.Max(ans, Math.Max(0, sum - min) + Math.Max(0, rsums[i + 1] - b[i + 1]));
            }

            //sum = a.Sum(aa => (long)aa);
            //min = a[1];
            //for (int i = 2; i + 1 < n; i++)
            //    min = Math.Min(min, a[i]);
            //ans = Math.Max(ans, sum - b[0]);

            for (int i = 1; i < n; i++)
                ans = Math.Max(ans, rsums[i] - b[i]);
        }

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntArray();
        var b = ReadIntArray();

        long ans, sum;
        int min;
        if (m == 0)
        {
            ans = 0;
            sum = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                sum += a[i];
                ans = Math.Max(ans, sum - b[i]);
            }
        }
        else if (m > 1)
        {
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
                min = Math.Min(b[i], min);
            ans = 0;
            ans = Math.Max(ans, a[n - 1] - b[n - 1]);
            ans = Math.Max(ans, a.Sum(aa => (long)aa) - min);
        }
        else
        {
            var rsums = new long[n];
            rsums[n - 1] = a[n - 1];
            for (int i = n - 2; i >= 0; i--)
                rsums[i] = rsums[i + 1] + a[i];

            ans = 0;
            sum = a[0];
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
            {
                min = Math.Min(min, b[i]);
                sum += a[i];
                ans = Math.Max(ans, Math.Max(0, sum - min) + Math.Max(0, rsums[i + 1] - b[i + 1]));
            }

            sum = a.Sum(aa => (long)aa);
            min = a[1];
            for (int i = 2; i < n; i++)
                min = Math.Min(min, a[i]);
            ans = Math.Max(ans, sum - min - b[0]);

            for (int i = 1; i < n; i++)
                ans = Math.Max(ans, rsums[i] - b[i]);
        }

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntArray();
        var b = ReadIntArray();

        long ans, sum;
        int min;
        if (m == 0)
        {
            ans = 0;
            sum = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                sum += a[i];
                ans = Math.Max(ans, sum - b[i]);
            }
        }
        else if (m > 1)
        {
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
                min = Math.Min(b[i], min);
            ans = 0;
            ans = Math.Max(ans, a[n - 1] - b[n - 1]);
            ans = Math.Max(ans, a.Sum(aa => (long)aa) - min);
        }
        else
        {
            var rsums = new long[n];
            rsums[n - 1] = a[n - 1];
            for (int i = n - 2; i >= 0; i--)
                rsums[i] = rsums[i + 1] + a[i];

            ans = 0;
            sum = a[0];
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
            {
                min = Math.Min(min, b[i]);
                sum += a[i];
                ans = Math.Max(ans, Math.Max(0, sum - min) + Math.Max(0, rsums[i + 1] - b[i + 1]));
            }

            sum = a.Sum(aa => (long)aa);
            min = a[1];
            for (int i = 2; i + 1 < n; i++)
                min = Math.Min(min, a[i]);
            ans = Math.Max(ans, sum - b[0]);

            for (int i = 1; i < n; i++)
                ans = Math.Max(ans, rsums[i] - b[i]);
        }

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntArray();
        var b = ReadIntArray();

        long ans = 0, sum;
        int min;
        if (m == 0)
        {
            sum = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                sum += a[i];
                ans = Math.Max(ans, sum - b[i]);
            }
        }
        else if (m > 1)
        {
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
                min = Math.Min(b[i], min);
            ans = Math.Max(ans, a[n - 1] - b[n - 1]);
            ans = Math.Max(ans, a.Sum(aa => (long)aa) - min);
        }
        else
        {
            var rdp = new long[n];
            rdp[n - 1] = a[n - 1] - b[n - 1];
            long rsum = a[n - 1];
            for (int i = n - 2; i >= 0; i--)
            {
                rsum += a[i];
                rdp[i] = Math.Max(rdp[i + 1], rsum - b[i]);
            }

            sum = a[0];
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
            {
                min = Math.Min(min, b[i]);
                sum += a[i];
                ans = Math.Max(ans, Math.Max(0, sum - min) + Math.Max(0, rdp[i + 1]));
            }

            sum = a.Sum(aa => (long)aa);
            min = a[1];
            for (int i = 2; i < n; i++)
                min = Math.Min(min, a[i]);
            ans = Math.Max(ans, sum - min - b[0]);

            ans = Math.Max(ans, Math.Max(0, rdp[1]) + Math.Max(0, a[0] - b[0]));
        }

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntArray();
        var b = ReadIntArray();

        long ans, sum;
        int min;
        if (m == 0)
        {
            ans = 0;
            sum = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                sum += a[i];
                ans = Math.Max(ans, sum - b[i]);
            }
        }
        else if (m > 1)
        {
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
                min = Math.Min(b[i], min);
            ans = 0;
            ans = Math.Max(ans, a[n - 1] - b[n - 1]);
            ans = Math.Max(ans, a.Sum(aa => (long)aa) - min);
        }
        else
        {
            var rsums = new long[n];
            rsums[n - 1] = a[n - 1];
            for (int i = n - 2; i >= 0; i--)
                rsums[i] = rsums[i + 1] + a[i];

            ans = 0;
            sum = a[0];
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
            {
                min = Math.Min(min, b[i]);
                sum += a[i];
                ans = Math.Max(ans, Math.Max(0, sum - min) + Math.Max(0, rsums[i + 1] - b[i + 1]));
            }

            sum = a.Sum(aa => (long)aa);
            min = a[1];
            for (int i = 2; i + 1 < n; i++)
                min = Math.Min(min, a[i]);
            ans = Math.Max(ans, sum - b[0]);

            //for (int i = 1; i < n; i++)
            //    ans = Math.Max(ans, rsums[i] - b[i]);
        }

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntArray();
        var b = ReadIntArray();

        long ans, sum;
        if (m == 0)
        {
            ans = 0;
            sum = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                sum += a[i];
                ans = Math.Max(ans, sum - b[i]);
            }

            Write(ans);
            return;
        }
        if (m > 1)
        {
            Write(Math.Max(0, a.Sum(aa => (long)aa) - b.Min()));
            return;
        }

        var rsums = new long[n];
        rsums[n - 1] = a[n - 1];
        for (int i = n - 2; i >= 0; i--)
            rsums[i] = rsums[i + 1] + a[i];

        ans = 0;
        sum = a[0];
        int min = a[0];
        for (int i = 1; i + 1 < n; i++)
        {
            min = Math.Min(min, b[i]);
            sum += a[i];
            ans = Math.Max(ans, Math.Max(0, sum - min) + Math.Max(0, rsums[i + 1] - b[i + 1]));
        }

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntArray();
        var b = ReadIntArray();

        long ans, sum;
        int min;
        if (m == 0)
        {
            ans = 0;
            sum = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                sum += a[i];
                ans = Math.Max(ans, sum - b[i]);
            }
        }
        else if (m > 1)
        {
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
                min = Math.Min(b[i], min);
            ans = 0;
            ans = Math.Max(ans, a[n - 1] - b[n - 1]);
            ans = Math.Max(ans, a.Sum(aa => (long)aa) - min);
        }
        else
        {
            var rsums = new long[n];
            rsums[n - 1] = a[n - 1];
            for (int i = n - 2; i >= 0; i--)
                rsums[i] = rsums[i + 1] + a[i];

            ans = 0;
            sum = a[0];
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
            {
                min = Math.Min(min, b[i]);
                sum += a[i];
                ans = Math.Max(ans, Math.Max(0, sum - min) + Math.Max(0, rsums[i + 1] - b[i + 1]));
            }

            sum = a.Sum(aa => (long)aa);
            min = a[1];
            for (int i = 2; i < n; i++)
                min = Math.Min(min, a[i]);
            ans = Math.Max(ans, sum - b[0]);

            for (int i = 1; i < n; i++)
                ans = Math.Max(ans, rsums[i] - b[i]);
        }

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


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

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        int n = ReadInt();
        int m = ReadInt();
        var a = ReadIntArray();
        var b = ReadIntArray();

        long ans, sum;
        int min;
        if (m == 0)
        {
            ans = 0;
            sum = 0;
            for (int i = n - 1; i >= 0; i--)
            {
                sum += a[i];
                ans = Math.Max(ans, sum - b[i]);
            }

            Write(ans);
            return;
        }
        if (m > 1)
        {
            min = b[0];
            for (int i = 1; i + 1 < n; i++)
                min = Math.Min(b[i], min);
            ans = 0;
            ans = Math.Max(ans, a[n - 1] - b[n - 1]);
            ans = Math.Max(ans, a.Sum(aa => (long)aa) - min);
            Write(ans);
            return;
        }

        var rsums = new long[n];
        rsums[n - 1] = a[n - 1];
        for (int i = n - 2; i >= 0; i--)
            rsums[i] = rsums[i + 1] + a[i];

        ans = 0;
        sum = a[0];
        min = b[0];
        for (int i = 1; i + 1 < n; i++)
        {
            min = Math.Min(min, b[i]);
            sum += a[i];
            ans = Math.Max(ans, Math.Max(0, sum - min) + Math.Max(0, rsums[i + 1] - b[i + 1]));
        }

        Write(ans);
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


//spnauti-rusT {{{
use std::io::*; use std::str::{self,*}; use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::{self,*};
#[allow(unused_imports)] use std::iter::{self,*};
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_imports)] use std::cell::*;
#[allow(unused_macros)] macro_rules! min {
	($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b < *a {*a=b; true} else {false} }};
}
#[allow(unused_macros)] macro_rules! max {
	($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b > *a {*a=b; true} else {false} }};
}
#[allow(unused_macros)] macro_rules! l {
	($($v:ident),+ =$e:expr) => {$(let$v=$e;)+};
	($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};
	(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};
	(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};
}
#[allow(unused_macros)] macro_rules! v {
	([$d:expr]$($s:tt)+) => {vec![v!($($s)+);$d]};
	([]) => {Vec::new()}; ([$e:expr]) => {Vec::with_capacity($e)}; (=$e:expr) => {$e};
}
#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }
#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }
#[allow(dead_code)] fn writer() -> BufWriter<Stdout> { BufWriter::new(stdout()) }
struct WordReaderC {buf: Vec<u8>, pos: usize, q: std::io::StdinLock<'static>}//'
#[allow(dead_code)] impl WordReaderC {
	fn new() -> Self {
		let r = unsafe {&*Box::into_raw(Box::new(stdin()))};
		Self { q: r.lock(), buf: Vec::new(), pos: 0 }
	}
	fn next_line(&mut self) -> bool {
		self.buf.clear(); self.pos = 0;
		self.q.read_until(b'\n', &mut self.buf).unwrap_or(0) > 0
	}
	fn is_ws(c: u8) -> bool {
		c == b' ' || c == b'\r' || c == b'\n' || c == b'\t'
	}
	fn byte(&mut self) -> Option<u8> {
		if self.pos == self.buf.len() { if !self.next_line() { return None; } }
		self.pos += 1; Some(self.buf[self.pos - 1])
	}
	fn vb(&mut self) -> Vec<u8> {
		let mut s = Vec::with_capacity(8);
		let mut f = false;
		loop {
			if let Some(c) = self.byte() {
				if !Self::is_ws(c) {
					s.push(c);
					f = true;
				} else if f { break; }
			} else { break; }
		}
		s
	}
	fn s(&mut self) -> String { String::from_utf8(self.vb()).expect("invalid utf8") }
	fn i(&mut self) ->    i32 { self.p() }
	fn l(&mut self) ->    i64 { self.p() }
	fn u(&mut self) ->  usize { self.p() }
	fn f(&mut self) ->    f64 { self.p() }
	fn vi(&mut self, n: usize) -> Vec<i32> { self.vp(n) }
	fn vl(&mut self, n: usize) -> Vec<i64> { self.vp(n) }
	fn vu(&mut self, n: usize) -> Vec<usize> { self.vp(n) }
	fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> { self.ip(n).into_iter() }
	fn iu(&mut self, n: usize) -> impl Iterator<Item=usize> { self.ip(n).into_iter() }
	fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
		let w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::<T>().unwrap()
	}
	fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
		(0..n).map(|_|self.p()).collect()
	}
	fn ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
		self.vp(n).into_iter()
	}
}
//------------------- End rusT }}}

fn main() {
	let mut rin = reader();
	let mut rout = writer();

	l!(n,k = rin.u());
	l!(a,d = rin.vl(n));
	let mut sol = (a[n-1] - d[n-1]).max(0);
	if k == 0 {
		let mut sum = 0;
		for i in (0..n).rev() {
			sum += a[i];
			max!(sol, sum - d[i]);
		}
	} else if k == 1 {
		{
			let sum1 = a[0..n-1].iter().sum::<i64>();
			let min1 = *d[0..n-1].iter().min().unwrap();
			max!(sol, sum1 - min1 + (a[n-1] - d[n-1]).max(0));
		}
		{
			let sum = a[1..n].iter().sum::<i64>();
			max!(sol, sum - d[1]);
		}
		{
			let mut pre = v!([n]);
			let mut sum = 0;
			for i in 0..n {
				sum += a[i];
				pre.push(sum - d[i]);
			}
			let mut sum = 0;
			let mut max = 0;
			for i in (1..n).rev() {
				sum += a[i];
				max!(max, sum - d[i]);
				max!(sol, pre[i-1].max(0) + max);
			}
		}
	} else {
		let sum = a.iter().sum::<i64>();
		let min = *d[0..n-1].iter().min().unwrap();
		max!(sol, sum - min);
	}
	writeln!(rout, "{}", sol).ok();
}


//spnauti-rusT {{{
use std::io::*; use std::str::{self,*}; use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::{self,*};
#[allow(unused_imports)] use std::iter::{self,*};
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_imports)] use std::cell::*;
#[allow(unused_macros)] macro_rules! min {
	($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b < *a {*a=b; true} else {false} }};
}
#[allow(unused_macros)] macro_rules! max {
	($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b > *a {*a=b; true} else {false} }};
}
#[allow(unused_macros)] macro_rules! l {
	($($v:ident),+ =$e:expr) => {$(let$v=$e;)+};
	($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};
	(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};
	(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};
}
#[allow(unused_macros)] macro_rules! v {
	([$d:expr]$($s:tt)+) => {vec![v!($($s)+);$d]};
	([]) => {Vec::new()}; ([$e:expr]) => {Vec::with_capacity($e)}; (=$e:expr) => {$e};
}
#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }
#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }
#[allow(dead_code)] fn writer() -> BufWriter<Stdout> { BufWriter::new(stdout()) }
struct WordReaderC {buf: Vec<u8>, pos: usize, q: std::io::StdinLock<'static>}//'
#[allow(dead_code)] impl WordReaderC {
	fn new() -> Self {
		let r = unsafe {&*Box::into_raw(Box::new(stdin()))};
		Self { q: r.lock(), buf: Vec::new(), pos: 0 }
	}
	fn next_line(&mut self) -> bool {
		self.buf.clear(); self.pos = 0;
		self.q.read_until(b'\n', &mut self.buf).unwrap_or(0) > 0
	}
	fn is_ws(c: u8) -> bool {
		c == b' ' || c == b'\r' || c == b'\n' || c == b'\t'
	}
	fn byte(&mut self) -> Option<u8> {
		if self.pos == self.buf.len() { if !self.next_line() { return None; } }
		self.pos += 1; Some(self.buf[self.pos - 1])
	}
	fn vb(&mut self) -> Vec<u8> {
		let mut s = Vec::with_capacity(8);
		let mut f = false;
		loop {
			if let Some(c) = self.byte() {
				if !Self::is_ws(c) {
					s.push(c);
					f = true;
				} else if f { break; }
			} else { break; }
		}
		s
	}
	fn s(&mut self) -> String { String::from_utf8(self.vb()).expect("invalid utf8") }
	fn i(&mut self) ->    i32 { self.p() }
	fn l(&mut self) ->    i64 { self.p() }
	fn u(&mut self) ->  usize { self.p() }
	fn f(&mut self) ->    f64 { self.p() }
	fn vi(&mut self, n: usize) -> Vec<i32> { self.vp(n) }
	fn vl(&mut self, n: usize) -> Vec<i64> { self.vp(n) }
	fn vu(&mut self, n: usize) -> Vec<usize> { self.vp(n) }
	fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> { self.ip(n).into_iter() }
	fn iu(&mut self, n: usize) -> impl Iterator<Item=usize> { self.ip(n).into_iter() }
	fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
		let w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::<T>().unwrap()
	}
	fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
		(0..n).map(|_|self.p()).collect()
	}
	fn ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
		self.vp(n).into_iter()
	}
}
//------------------- End rusT }}}

fn main() {
	let mut rin = reader();
	let mut rout = writer();

	l!(n,k = rin.u());
	l!(a,d = rin.vl(n));
	let mut sol = (a[n-1] - d[n-1]).max(0);
	if k == 0 {
		let mut sum = 0;
		for i in (0..n).rev() {
			sum += a[i];
			max!(sol, sum - d[i]);
		}
	} else if k == 1 {
		let sum1 = a[0..n-1].iter().sum::<i64>();
		let min1 = *d[0..n-1].iter().min().unwrap();
		max!(sol, sum1 - min1 + (a[n-1] - d[n-1]).max(0));
		let sum2 = a[1..n].iter().sum::<i64>();
		max!(sol, sum2 - d[1]);
	} else {
		let sum = a.iter().sum::<i64>();
		let min = *d[0..n-1].iter().min().unwrap();
		max!(sol, sum - min);
	}
	writeln!(rout, "{}", sol).ok();
}


//spnauti-rusT {{{
use std::io::*; use std::str::{self,*}; use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::{self,*};
#[allow(unused_imports)] use std::iter::{self,*};
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_imports)] use std::cell::*;
#[allow(unused_macros)] macro_rules! min {
	($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b < *a {*a=b; true} else {false} }};
}
#[allow(unused_macros)] macro_rules! max {
	($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b > *a {*a=b; true} else {false} }};
}
#[allow(unused_macros)] macro_rules! l {
	($($v:ident),+ =$e:expr) => {$(let$v=$e;)+};
	($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};
	(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};
	(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};
}
#[allow(unused_macros)] macro_rules! v {
	([$d:expr]$($s:tt)+) => {vec![v!($($s)+);$d]};
	([]) => {Vec::new()}; ([$e:expr]) => {Vec::with_capacity($e)}; (=$e:expr) => {$e};
}
#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }
#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }
#[allow(dead_code)] fn writer() -> BufWriter<Stdout> { BufWriter::new(stdout()) }
struct WordReaderC {buf: Vec<u8>, pos: usize, q: std::io::StdinLock<'static>}//'
#[allow(dead_code)] impl WordReaderC {
	fn new() -> Self {
		let r = unsafe {&*Box::into_raw(Box::new(stdin()))};
		Self { q: r.lock(), buf: Vec::new(), pos: 0 }
	}
	fn next_line(&mut self) -> bool {
		self.buf.clear(); self.pos = 0;
		self.q.read_until(b'\n', &mut self.buf).unwrap_or(0) > 0
	}
	fn is_ws(c: u8) -> bool {
		c == b' ' || c == b'\r' || c == b'\n' || c == b'\t'
	}
	fn byte(&mut self) -> Option<u8> {
		if self.pos == self.buf.len() { if !self.next_line() { return None; } }
		self.pos += 1; Some(self.buf[self.pos - 1])
	}
	fn vb(&mut self) -> Vec<u8> {
		let mut s = Vec::with_capacity(8);
		let mut f = false;
		loop {
			if let Some(c) = self.byte() {
				if !Self::is_ws(c) {
					s.push(c);
					f = true;
				} else if f { break; }
			} else { break; }
		}
		s
	}
	fn s(&mut self) -> String { String::from_utf8(self.vb()).expect("invalid utf8") }
	fn i(&mut self) ->    i32 { self.p() }
	fn l(&mut self) ->    i64 { self.p() }
	fn u(&mut self) ->  usize { self.p() }
	fn f(&mut self) ->    f64 { self.p() }
	fn vi(&mut self, n: usize) -> Vec<i32> { self.vp(n) }
	fn vl(&mut self, n: usize) -> Vec<i64> { self.vp(n) }
	fn vu(&mut self, n: usize) -> Vec<usize> { self.vp(n) }
	fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> { self.ip(n).into_iter() }
	fn iu(&mut self, n: usize) -> impl Iterator<Item=usize> { self.ip(n).into_iter() }
	fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
		let w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::<T>().unwrap()
	}
	fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
		(0..n).map(|_|self.p()).collect()
	}
	fn ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
		self.vp(n).into_iter()
	}
}
//------------------- End rusT }}}

fn main() {
	let mut rin = reader();
	let mut rout = writer();

	l!(n,k = rin.u());
	l!(a,d = rin.vl(n));
	let mut sol = (a[n-1] - d[n-1]).max(0);
	if k == 0 {
		let mut sum = 0;
		for i in (0..n).rev() {
			sum += a[i];
			max!(sol, sum - d[i]);
		}
	} else if k == 1 {
		{
			let sum1 = a[0..n-1].iter().sum::<i64>();
			let min1 = *d[0..n-1].iter().min().unwrap();
			max!(sol, sum1 - min1 + (a[n-1] - d[n-1]).max(0));
		}
		{
			let sum = a[1..n].iter().sum::<i64>();
			max!(sol, sum - d[1]);
		}
		{
			let mut pre = v!([n]);
			let mut sum = 0;
			for i in 0..n {
				sum += a[i];
				pre.push(sum - d[i]);
			}
			let mut sum = 0;
			let mut max = 0;
			for i in (1..n).rev() {
				sum += a[i];
				max!(max, sum - d[i]);
				max!(sol, pre[i-1].max(0) + max);
			}
		}
		{
			let sum = a.iter().sum::<i64>();
			let min = *a[1..n].iter().min().unwrap();
			max!(sol, sum - min - d[0]);
		}
	} else {
		let sum = a.iter().sum::<i64>();
		let min = *d[0..n-1].iter().min().unwrap();
		max!(sol, sum - min);
	}
	writeln!(rout, "{}", sol).ok();
}