akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main(void){

  int a, b;
  while(cin >> a >> b, a + b){
    double TTT = 150*150 + 150*150,
           t = a*a + b*b;
    int A, B;
    for(int h = 1 ; h <= 150 ; h++){
      for(int w = h + 1 ; w <= 150 ; w++){
	if(t < h*h + w*w && h*h + w*w < TTT){
	  TTT = h*h + w*w;
	  A = h;
	  B = w;
	}else if(a < h && t == h*h + w*w ){
	  TTT = h*h + w*w;
	  A = h;
	  B = w;
	  goto end;
	}
      }
    }
  end:;
    cout << A << " " << B << endl;
  }
 return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


// 長さを長くするべきかどうか
bool longer(int x, int length, vector<long long>& A, int N)
{
    // 2*length が N 以上の時はこれ以上長くできない
    if(N <= 2*length) return false; 
    /** 今、青木くんが右側で取れるのは N-1-length まで。
     *  まだ左側のものを取れる可能性がある (つまり、abs(A[N-1-2*length]-x) <= abs(A[N-1-length]-x))
     *  ときは長くし得るが、それ以外のときは短くしないとダメ
     *  -> つまり、length を長くしていくと、
     */
    return abs(A[N-1-2*length]-x) <= abs(A[N-1-length]-x);
}

// 高橋くんがとる右側の数列の長さを二分探索
int searchLength(int x, vector<long long>& A, int N)
{
    int l = 0;
    int r = N;
    while(r-l > 1){
        int c = (l+r)/2;
        if(longer(x, c, A, N)) l = c;
        else r = c;
    }
    return r;
}

int main()
{
    int N, Q;
    cin >> N >> Q;
    vector<long long> A(N), X(Q);
    REP(i, N) cin >> A[i];
    REP(i, Q) cin >> X[i];

    vector<long long> cumsum_A(A), alt_A(A);
    REP(i, N-1){
        cumsum_A[i+1] += cumsum_A[i];
        if(i < N-2) alt_A[i+2] += alt_A[i];
    }

    REP(i, Q){
        int length = searchLength(X[i], A, N);
        // cout << length << " ";
        long long ans = cumsum_A[N-1]-cumsum_A[N-1-length];
        if(N-1-2*length >= 0) ans += alt_A[N-1-2*length]; // 左の残りがあれば足す
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 4864
#include<stdio.h>
int main()
{
	int N;
	scanf("%d", &N);
	
	int W[N];
	int k;
	int sum = 0;
	
	for(k=0; k<N; k++){
		scanf("%d", &W[k]);
		sum = sum + W[k];
	}
	
	int res = sum;
	int go = 0;
	
	for(k=0; k<N; k++){
		go = go + W[k];
		if( sum - 2*go >= 0 && sum - 2*go < res ) res = sum - 2*go;
		else if(2*go - sum < res) res = 2*go - sum;
	}
	
	printf("%d", res);
	
	
	return 0;
	
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int a[] = new int[9];

		for (int i = 0; i < 9; i += 3) {
			String str[] = br.readLine().split(" ");
			for (int j = 0; j < 3; j++) {
				a[i + j] = Integer.parseInt(str[j]);
			}
		}
		int n = Integer.parseInt(br.readLine());

		for (int i = 0; i < n; i++) {
			int b = Integer.parseInt(br.readLine());

			for (int j = 0; j < 9; j++) {
				if (a[j] == b) {
					a[j] = 0;
				}
			}
		}

		if ((a[0] == 0 && a[1] == 0 && a[2] == 0) || (a[3] == 0 && a[4] == 0 && a[5] == 0)
				|| (a[6] == 0 && a[7] == 0 && a[8] == 0) || (a[0] == 0 && a[3] == 0 && a[6] == 0)
				|| (a[1] == 0 && a[4] == 0 && a[7] == 0) || (a[2] == 0 && a[5] == 0 && a[8] == 0)
				|| (a[0] == 0 && a[4] == 0 && a[8] == 0) || (a[2] == 0 && a[4] == 0 && a[6] == 0)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21332
S = input()
start = 0
max = 0
count = 0
for i in range(len(S)):
    if(S[i] != "A")&(S[i] != "T")&(S[i] != "G")&(S[i] != "C"):
        if max < count:
            max = count
        count = 0
    else:
        count = count + 1
if ((S[i] == "A")|(S[i] == "T")|(S[i] == "G")|(S[i] == "C"))&(max < count):
    max = count
print(max)

Measured memory_bytes: 3064
/*{{{*/
//#define HOME
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define F first
#define S second

template<class T> void _R(T &_x) { cin >> _x; }
void _R(int &_x) { scanf("%d", &_x); }
void _R(int64_t &_x) { scanf("%" SCNd64, &_x); }
void _R(double &_x) { scanf("%lf", &_x); }
void _R(char &_x) { scanf(" %c", &_x); }
void _R(char *_x) { scanf("%s", _x); }
template<class T, class U> void _R(pair<T, U> &_x) {_R(_x.F); _R(_x.S);}
void R() {}
template<class T, class... U> void R(T &_head, U &... _tail) { _R(_head); R(_tail...); }

template<class T> void _W(const T &_x) { cout << _x; }
void _W(const int &_x) { printf("%d", _x); }
void _W(const int64_t &_x) { printf("%" PRId64, _x); }
void _W(const double &_x) { printf("%.16f", _x); }
void _W(const char &_x) { putchar(_x); }
void _W(const char *_x) { printf("%s", _x); }
template<class T, class U> void _W(const pair<T, U> &_x) {_W(_x.F); putchar(' '); _W(_x.S);}
template<class T> void _W(const vector<T> &_x) { for (auto i = _x.begin(); i != _x.end(); _W(*i++)) if (i != _x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &_head, const U &... _tail) { _W(_head); putchar(sizeof...(_tail) ? ' ' : '\n'); W(_tail...); }
template<class T, class... U> void DB(const T &_head, const U &... _tail) {
#ifdef HOME
    W('#', _head, _tail...);
#endif
}

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define RAN(x,n) (x).begin(), (x).begin()+(n)
#define UNIQUE(x) {sort(ALL(x)); (x).erase(unique(ALL(x)), (x).end());}

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
//#define ITER(i,t) for (auto i = t.begin(); i != t.end(); ++i)
#define IT3(i,st,ed) for (auto i = st; i != ed; ++i)
#define IT2(i,range) IT3(i,range)

#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define MS(X, v) memset((X), (v), sizeof((X)))

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

inline int LG (const unsigned int &_x) { return 31-__builtin_clz(_x); }  // floor: LG(x), ceil: LG(x-1)+1
/*}}}*/

vector<string> ds{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main(){
    string day;
    R(day);
    FOR(i, 7){
        if(day == ds[i]){
            W(7 - i);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

bool is_prime[10001];

int main() {
  int n,p1,q1;
  for(int i=0;i<10001;i++) {
    is_prime[i] = true;
  }

  is_prime[0] = is_prime[1] = false;

  for(int i=2;i<10001;i++) {
    if(is_prime[i]) {
      for(int j=2*i;j<10001;j+=i) {
        is_prime[j] = false;
      }
    }
  }

  while(cin >> n) {

    if(n==0) break;

    for(int i=0;i<10001;i++) {
      if(is_prime[n-i]) {
        q1 = n-i;
        if(is_prime[n-i-2]) {
          p1 = n-i-2;
          break;
        }
      }
    }
    printf("%d %d\n",p1,q1);
  }
}

Measured memory_bytes: 876
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	k := nextInt()
	h := make([]int, n)

	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}

	dp := make([]int, n)
	dp[0] = 0
	for i := 1; i < n; i++ {
		mincost := 10000000000
		for j := max(i-k, 0); j < i; j++ {
			costnow := dp[j] + abs(h[i]-h[j])
			//fmt.Println("i,j=", i, j, " dp[j]=", dp[j], " abs=", abs(h[i]-h[j]))
			mincost = min(mincost, costnow)
		}
		dp[i] = mincost

	}

	fmt.Println(dp[n-1])

}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 4120
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int a, b, c;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b >> c;
  cout << (a * b) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    ll n;
    cin>>n;
    ll x=1;
    while(x<=n)
    {
      x*=2;
    }
    ll ans=x-1;
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    ll ans = 0;
    int n; cin>>n;
    vector <int> A(n);
    vector <int> B(n);
    vector <int> C(n);
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    for(int i=0;i<n;i++){
        cin>>B[i];
    }
    for(int i=0;i<n;i++){
        cin>>C[i];
    }
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());
    for(int j=0;j<n;j++){
        int key = B[j];
        auto iter1 = lower_bound(A.begin(),A.end(),key);
        auto iter2 = upper_bound(C.begin(),C.end(),key);
        ll x1 =distance(A.begin(),iter1);
        ll x2 =distance(iter2, C.end());
        ans+= x1*x2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1408
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  long long int a,b;
  cin>>a>>b;
  if(a==0){
    if(b!=100)
      cout<<b<<endl;
    else
      cout<<101<<endl;
  }
  else if(a==1){
    if(b!=100)
      cout<<100*b<<endl;
    else
      cout<<10100<<endl;
    }
  else{
    if(b!=100)
      cout<<b*10000<<endl;
    else
      cout<<1010000<<endl;
  }   
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int n;
    while(cin >> n, n) {
        vector<string> v(n);
        int max_len = 0;
        for(int i=0; i<n; ++i) {
            string s;
            cin >> s;
            v[i] = '0' + s;
            max_len = max(max_len, (int)v[i].length());
        }
        vector<vector<bool>> f(26, vector<bool>(26, false));
        bool ok = true;
        for(int i=1; i<max_len; ++i) {
            string prev;
            for(int j=0; j<n; ++j) {
                if(j != 0 && i == v[j].length() && prev == v[j].substr(0, i)) {
                    if(v[j-1].length() > v[j].length()) {
                        ok = false;
                        break;
                    }
                }
                if(i >= v[j].length()) {
                    continue;
                }
                if(j == 0) {
                    prev = v[j].substr(0, i);
                } else if(prev == v[j].substr(0, i)) {
                    if(v[j][i] != v[j-1][i]) {
                        f[v[j-1][i] - 'a'][v[j][i] - 'a'] = true;
                    }
                } else {
                    prev = v[j].substr(0, i);
                }
            }
            if(!ok) break;
        }
        for(int k=0; k<26; ++k) {
            for(int i=0; i<26; ++i) {
                for(int j=0; j<26; ++j) {
                    f[i][j] = (bool)f[i][j] || (bool)f[i][k] && (bool)f[k][j];
                }
            }
        }
        for(int i=0; i<26; ++i) {
            for(int j=0; j<26; ++j) {
                ok &= !((bool)f[i][j] && (bool)f[j][i]);
            }
        }
        cout << (ok ? "yes" : "no") << endl;
    }
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b && b == c)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;

struct process{
    string name;
    int time ; 
};

int min(int a,int b){
    return (a<=b) ? a : b ;
}

int main() {
    int n,q,t ;
    cin >> n >> q ;
    //string name ;
    queue<process> qu ;

    for(int i=0;i<n;i++){
        struct process tmp ;
        cin >>tmp.name ;
        cin >>tmp.time ;
        qu.push(tmp) ;
    }

       int elps = 0 ;
    while(!qu.empty()){
        struct process tmp ;
        int tmp_time ;
        tmp = qu.front() ; qu.pop() ;
        tmp_time = min(tmp.time,q) ;
        elps+=tmp_time ;
        if(tmp.time>q){
          tmp.time = tmp.time-q ;
          qu.push(tmp) ;
        }else{
          cout << tmp.name << " " << elps << endl ;
        }
    }

    //cout << qu.front().time << endl ;
    return 0;
}



Measured memory_bytes: 6200
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 3e3+4;

#define ll long long

long double p[MAXN], dp[MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);	cout.tie(0);

	int n;	cin >> n;
	for(int i=0; i<n; i++)
		cin >> p[i];
	dp[0][0] = 1;
	for(int i=1; i<=n; i++)
		for(int j=0; j<=i; j++)	{
			if(j)
				dp[i][j] += dp[i-1][j-1] * p[i-1];
			dp[i][j] += dp[i-1][j] * (1 - p[i-1]);
		}
	long double R = 0;
	for(int i = 0; i <= n; i++)
		if(i > n-i)
			R+= dp[n][i];
	cout << fixed << setprecision(10) <<  R;		
	return 0;
}


Measured memory_bytes: 139264
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[3] = {1,0,-1};
int dy[3] = {1,0,-1};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  string S[101];
  int N,L;
  cin >> N >> L;
  REP(i,N)cin >> S[i];
  sort(S,S+N);
  REP(i,N)cout << S[i];
  cout << endl;
 
  return 0;  
}



Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)

template <class T>
std::vector<std::vector<T>> Imos2D(const std::vector<std::vector<T>>& a) {
    int h = a.size(), w = a[0].size();
    std::vector<std::vector<T>> s(h + 1, std::vector<T>(w + 1, 0));
    FOR(i,0, h) FOR(j,0, w) s[i + 1][j + 1] = a[i][j];
    FOR(i,0, h + 1) FOR(j,0, w) s[i][j + 1] += s[i][j];
    FOR(i,0, h) FOR(j,0, w + 1) s[i + 1][j] += s[i][j];
    return s;
}

template <class T>
int sum(const std::vector<std::vector<T>>& s, int i, int j, int h, int w) {
    return s[h][w] - s[i-1][w] + s[i-1][j-1] - s[h][j-1];
}


int main(){
  ll N,M,Q;
  cin>>N>>M>>Q;
  vector<vector<ll>> v = vector<vector<ll>> (N,vector<ll>(N,0));
  ll a,b;
  FOR(i,0,M){
    cin>>a>>b;
    v[a-1][b-1]++;
  }

vector<vector<ll>> s = Imos2D(v);
/*
  FOR(i,0,N){
    FOR(j,0,N+1){
      v[i+1][j] += v[i][j];
    }
  }
  FOR(i,0,N+1){
    FOR(j,0,N){
      v[i][j+1] += v[i][j];
    }
  }


  FOR(i,0,Q){
    cin>>a>>b;
    cout<<v[b][b]-v[a-1][b]-v[b][a-1]+v[a-1][a-1]<<endl;
  }
*/
  FOR(i,0,Q){
    cin>>a>>b;
    cout<<sum(s,a,a,b,b)<<endl;
  }
  

}


Measured memory_bytes: 4864
s = str(input())
a = 0
b = 0
for i in range(len(s)+1):
    if s[i] == "A":
        a = i+1
        break
    else:
        pass
for i in reversed(range(len(s))):
    if s[i] == "Z":
        b = i+1
        break
    else:
        pass
print(b - a + 1)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

const int MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
    int N, T, A;
    cin >> N;
    cin >> T >> A;
    vector<int> H(N);
    rep(i, N)
    {
        cin >> H.at(i);
    }

    int index = 0;
    double min = INF;
    rep(i, N)
    {
        double temp = T - H.at(i) * 0.006;
        double dif = abs(A - temp);
        if (dif < min) {
            min = dif;
            index = i;
        }
    }

    cout << index + 1 << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int[] L = new int[N];

		for(int i = 0;i < N;i++) {
			L[i] = scn.nextInt();
		}
		Arrays.sort(L);


		int ans = 0;
		for(int i = 0;i < N-1;i++) {
			for(int j = i+1;j < N;j++) {
				int l = L[i] + L[j];
				int lb = lowerbound(L,l);
				ans += lb - j - 1;
			}
		}

		System.out.println(ans);

	}



	public static int lowerbound(int[] A, int k) {//k<=Aiを満たす最小のi
		int lb = -1, ub = A.length;
		while(ub-lb > 1) {
			int mid = (lb + ub)/2;
			if(A[mid] >= k) {
				ub = mid;
			}else {
				lb = mid;
			}
		}
		return ub;
	}
}


Measured memory_bytes: 27220
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,m; cin>>n>>m;
    vector<string> a(n),b(m);
    rep(i,n) cin>>a[i];
    rep(i,m) cin>>b[i];

    bool allin=false;

    rep(i,n){
        rep(j,n){
            if(i+m-1>=n || j+m-1>=n) continue;
            bool in=true;
            rep(k,m)rep(l,m) if(a[i+k][j+l]!=b[k][l]) in=false;
            if(in) allin=true;
        }
    }

    if(allin) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
main() {
	string s,u="[<++++++++++>-]>",c=">+++++[<++++++>-]>+++++[<++++++++>-]>+++++"+u+"++++++"+u+"+++++++"+u+"++++++++"+u+"+++++++++"+u+"++++++++++"+u+"+++++++++++"+u+"++++++++++++"+u+"<<<<<<<<<<<";
	int p=0,i,j,a,b,d;
	for(cin>>s,i=0;i<s.length();++i){
		a=s[i]/10-3,b=a-p,p=a,d=s[i]-(a+3)*10;
		for(j=b>0?b:-b;j--;)c+=(b>=0?62:60);
		for(j=d;j--;)c+=43;
		c+=46;
		for(j=d;j--;)c+=45;
	}
	cout<<c<<endl;
}

Measured memory_bytes: 1244
//B - Palindromic Numbers: 3Min;
//Assunto: String;
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100005
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

bool palindromo(int x) {
    string s = to_string(x);
    int i = 0, j = s.size()-1;
    while(i <= j) {
        if(s[i] != s[j]) return false;
        i++; j--;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int a, b, ans = 0;
    cin >> a >> b;
    loop(i, a, b+1) if(palindromo(i)) ans++;
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int n,ans;
char s[1000005];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>s+1;
    n=strlen(s+1);
    s[0]='0';
    for(int i=n;i>=0;i--){
        if(s[i]>'5'||(s[i]=='5'&&s[i-1]>='5')){
            ans+='9'+1-s[i];
            s[i-1]++;
        }else{
            ans+=s[i]-'0';
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1280
from bisect import bisect_left
from collections import defaultdict

n = int(input())
if n == 1:
    print(0)
    exit()


def prime_factor(n):
    # (素因数, 数)のリストで出てくる
    d = defaultdict(int)
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            d[i] += 1
            n //= i
    if n != 1:
        d[n] += 1
    return list(d.items())


soinsu = prime_factor(n)
kouho = [i * (i + 1) // 2 for i in range(10000)]
ans = 0
for key, val in soinsu:
    pos = bisect_left(kouho, val + 1)
    ans += pos - 1
print(ans)


Measured memory_bytes: 68316
#include <iostream>

using namespace std;

int main()
{
    int k, s;
    int ans = 0;

    cin >> k >> s;

    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            if (s-(i+j) <= k && s-(i+j) >= 0) {
                ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    h, w = ns()
    n = ni()
    a = na()

    mat = [[-1 for i in range(w)] for j in range(h)]

    toLeft = True
    idx = 0
    for i in range(h):
        toLeft = not toLeft
        for j in range(w):
            a[idx] -= 1
            dirc = -1 if toLeft else 1
            adj = -1 if toLeft else 0
            mat[i][dirc * j + adj] = idx + 1
            if a[idx] == 0:
                idx += 1

    for m in mat:
        print(*m, sep=" ")


if __name__ == '__main__':
    main()


Measured memory_bytes: 5948
<?php
  $s = trim(fgets(STDIN));
  $len = strlen($s);
  $hug = 0;
  for($i=0; $i<$len; $i++){
      if($i>($len-1)-$i) break;
      if($s[$i] != $s[($len-1)-$i]){
          $hug++;
      }
  }
  echo $hug;

Measured memory_bytes: 4856
#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <deque>
#include <algorithm>
#include <math.h>
#include <random>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define int long long
#define double long double
#define Matrix vector<vector<int> >
#define kektor vector
#define pp pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;

int RandInt(int min, int max) {
    if (max < min) {
        swap(min, max);
    }
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<int> dist(min, max);
    return dist(mt);
}

struct Node {
	int l, r, x; 
	Node(int _l, int _r, int _x) : l(_l), r(_r), x(_x) {} 
	Node() : l(-1), r(-1), x(0) {} 
};

const int maxn = 2e5 + 1, mod = 1e9;
bool debug = false;


void solve() {
	int n;
	vector<int> el;
	cin >> n;                  
	for (int i = 0; i < n; ++i) {
		int a; 
		cin >> a;
		el.pb(a);	
	}
	sort(all(el));
	reverse(all(el));
	int ans = 0;
	int ans1 = 0;
	for (int i = 0; i < n; ++i) {
		if (i % 2 == 0) {
			ans += el[i];
		} else {
			ans1 += el[i];
		}          
	}
	cout << ans - ans1;
}            

signed main() {
    /*!

    !*/
    cout.precision(10);
    cout << fixed;
    if (!debug) {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
  //  freopen("TASK.in", "r", stdin);
   //freopen("TASK.out", "w", stdout);
    solve();
    return 0;
}


Measured memory_bytes: 256
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=100010;
int a[N],n,f[N],len;
int main(){
	n=gi();for(int i=1;i<=n;i++)a[i]=gi();
	for(int i=n;i;i--){
		if(f[len]<=a[i])f[++len]=a[i];
		else{
			int k=upper_bound(f+1,f+len+1,a[i])-f;
			f[k]=a[i];
		}
	}
	printf("%d\n",len);
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    int c = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        c ^= a & 1;
    }
    cout << (c ? "NO\n" : "YES\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;

int main() {
	char s;
	cin>>s;
	if(s=='A') cout << 'T' << endl;
	else if(s=='C') cout << 'G' << endl;
	else if(s=='G') cout << 'C' << endl;
	else cout << 'A' << endl;
}


Measured memory_bytes: 256
/*why so serious?*/
#include<bits/stdc++.h>
using namespace std;
#define   int      long long
#define   fast()   ios_base::sync_with_stdio(0);cin.tie(0)
#define   all(x)   x.begin(),x.end()
#define   pb       push_back
#define   F        first
#define   S        second

int32_t main()
{char ch;
 cin>>ch;
 if(ch=='A')
 cout<<'T';
 if(ch=='T')
 cout<<'A';
 if(ch=='G')
 cout<<'C';
 if(ch=='C')
 cout<<'G';
 return 0;
}



Measured memory_bytes: 764
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> p(N);
  for(int i = 0; i < N; i++){
    string a;
    int b;
    cin >> a >> b;
    p[i] = make_tuple(a,100-b,i+1);
  }
  sort(p.begin(), p.end());
  for(int i = 0; i < N; i++){
    int num;
    tie(ignore, ignore, num) = p[i];
    cout << num <<endl;
  }
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = []
A.append([list(map(int, input().split())) for _ in range(N)])
ans = 0  
temp = 0

for i in range(N):
  for j in range(M):
    temp += B[j] * A[0][i][j]
  if temp + C > 0:
    ans += 1
  temp = 0

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

typedef long long LL;

class Combination
{
public:
	Combination(LL sz, LL m) :
		size(sz+1),
		mod(m),
		param(size, 1)
	{
		for(LL i=2; i<size; i++)
		{
			param[i] = param[i-1] * i;
			param[i] %= mod;
		}
	}

	LL nCr(LL n, LL c)
	{
		LL ret = param[n];
		ret *= inverse(c);
		ret %= mod;
		ret *= inverse(n-c);
		ret %= mod;

		return ret;
	}

private:
	LL inverse(LL n)
	{
		LL ret = 1;
		LL a = param[n];
		for(LL i=mod-2; i>0; i/=2)
		{
			if(i&1)
			{
				ret *= a;
				ret %= mod;
			}
			a *= a;
			a %= mod;
		}
		return ret % mod;
	}

	const LL size;
	const LL mod;
	vector<LL> param;
};

int main(void)
{
	int H, W, A, B;
	cin >> H >> W >> A >> B;

	const LL mod = 1E9 + 7;
	Combination comb(H+W-2, mod);

	LL ret = 0;
	for(int i=B; i<W; i++)
	{
		ret += comb.nCr((H-A-1)+i, i) * comb.nCr((A-1)+(W-i-1), W-i-1) % mod;
		ret %= mod;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

void solve(ll K) {
    int N = 50;
    vector<ll> a(N, N-1);
    ll q = K / N, r = K % N;
    rep(i,N) a[i] += q;
    rep(i,N){
        if (i < r) a[i] += (N - (r-1));
        else a[i] -= r;
    }

    cout << N << endl;
    rep(i,N) {
        cout << a[i];
        if (i < N-1) cout << " ";
    }
    cout << endl;
}

int main() {
    ll K; cin >> K;
    solve(K);
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let _: usize = read();
    let a: usize = read();
    let b: usize = read();
    let c: usize = read();
    let d: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();

    let mut ok = true;
    for i in a-1..c-1 {
        if s[i] == '#' && s[i+1] == '#' {
            ok = false;
        }
    }
    for i in b-1..d-1 {
        if s[i] == '#' && s[i+1] == '#' {
            ok = false;
        }
    }
    if a < b && d < c{
        let mut check = false;
        for i in b-1..d {
            if s[i-1] != '#' && s[i] != '#' && s[i+1] != '#' {
                check = true;
            }
        }
        if !check {
            ok = false;
        }
    } else if b < a && c < d {
        let mut check = false;
        for i in a-1..c {
            if s[i-1] != '#' && s[i] != '#' && s[i+1] != '#' {
                check = true;
            }
        }
        if !check {
            ok = false;
        }
    }

    println!("{}", if ok {"Yes"} else {"No"});
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    set <int> s2;
    bool f=1;
    for(int i=0;i<s.length();i++)
    {
        if(s2.count(s[i]))
        {
            f=0;
            break;
        }
        else
            s2.insert(s[i]);
    }
    if(f)
        cout<<"yes\n";
    else
        cout<<"no\n";
    
    return 0;   
}




 
 


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N; cin >> N;
  map<int, int> M;
  for (int i = 0; i < N; i++) {
    int A; cin >> A;
    if (M.count(A)) M[A]++;
    else M[A] = 1;
  }
  int cnt = 0;
  for (auto p : M) {
    if (p.second % 2 == 0) cnt++;
  }
  if (cnt % 2 == 1) cout << M.size() - 1 << endl;
  else cout << M.size() << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 200'010;
int a[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a, a + n);
    reverse(a, a + n);
    ll ans = 0, cnt = 1;
    while (cnt < n) {
        ans += a[cnt / 2];
        cnt++;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 4540
from heapq import heappop, heappush

import numpy as np

from numba import njit


@njit('UniTuple(i8[:],4)(i1[:],i8,i8,i8)', cache=True)
def reachable(field, h2, w2, k):
    # 各マスから上下左右にどこまで行けるか
    hw = h2 * w2
    up = np.full(hw, -1, dtype=np.int64)
    dw = np.full(hw, -1, dtype=np.int64)
    lf = np.full(hw, -1, dtype=np.int64)
    rg = np.full(hw, -1, dtype=np.int64)
    lf_tmp = -1
    for i in range(w2, hw - w2):
        if field[i]:
            if lf_tmp == -1:
                lf_tmp = i
            lf[i] = max(lf_tmp, i - k)
        else:
            lf_tmp = -1
    rg_tmp = -1
    for i in range(hw - w2, w2 - 1, -1):
        if field[i]:
            if rg_tmp == -1:
                rg_tmp = i
            rg[i] = min(rg_tmp, i + k)
        else:
            rg_tmp = -1
    wk = w2 * k
    for j in range(1, w2):
        up_tmp = -1
        for i in range(j, hw, w2):
            if field[i]:
                if up_tmp == -1:
                    up_tmp = i
                up[i] = max(up_tmp, i - wk)
            else:
                up_tmp = -1
        dw_tmp = 0
        for i in range(hw - w2 + j, w2 - 1, -w2):
            if field[i]:
                if dw_tmp == -1:
                    dw_tmp = i
                dw[i] = min(dw_tmp, i + wk)
            else:
                dw_tmp = -1
    return up, dw, lf, rg


@njit('i8(i8,i8,i8,i1[:],i8,i8,i8,i8)', cache=True)
def solve(h2, w2, k, field, x1, y1, x2, y2):
    s = x1 * w2 + y1
    t = x2 * w2 + y2
    up, dw, lf, rg = reachable(field, h2, w2, k)

    INF = 10 ** 18
    ans = [[INF, INF] for _ in field]
    ans[s][0] = ans[s][1] = 0

    q = [(0, s)]
    while q:
        cost, v = heappop(q)
        if v == t:
            return cost
        nc = cost + 1

        for u in range(up[v], v, w2):
            if ans[u][0] <= nc:
                break
            ans[u][0] = nc
            heappush(q, (nc, u))

        for u in range(dw[v], v, -w2):
            if ans[u][0] <= nc:
                break
            ans[u][0] = nc
            heappush(q, (nc, u))

        for u in range(lf[v], v, 1):
            if ans[u][1] <= nc:
                break
            ans[u][1] = nc
            heappush(q, (nc, u))

        for u in range(rg[v], v, -1):
            if ans[u][1] <= nc:
                break
            ans[u][1] = nc
            heappush(q, (nc, u))

    return -1


h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
h2 = h + 2
w2 = w + 2

field_tmp = [input() for _ in range(h)]
field = [0] * w2
for row in field_tmp:
    field.append(0)
    field.extend(map('@.'.index, row))
    field.append(0)
field.extend([0] * w2)
field = np.array(field, dtype=np.int8)
print(solve(h2, w2, k, field, x1, y1, x2, y2))


Measured memory_bytes: 534320
n, k = input().split()
n, k = int(n), int(k)
balls = input().split()
dic = {}
for x in balls:
	if x not in dic:
		dic[x] = 1
	else:
		dic[x] += 1
change = 0
qnt = list(dic.values())
qnt.sort()
dif = len(qnt) - k
for x in range(0, dif):
	change += qnt[x]
print(change)

Measured memory_bytes: 91348
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
string s;

int go(int x) {
  int n = s.length();
  int cnt=0;
  for (int i=0; i<n; i++) {
    int d = s[i]-'0';
    if (i%2==0 && d!=x) cnt++;
    if (i%2==1 && d==x) cnt++;
  }
  return cnt;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
cin>>s;
	cout<< (min(go(0),go(1))) <<endl;

  

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using ld = long double;

template <typename T>
int sz(T &x) {
  return (int)(x.size());
}


const int mod = 998244353;
const int inf = 1'000'000'007;


int power(int x, int y) {
  if (y == 0) {
    return 1;
  }
  int z = power(x, y >> 1);
  z = z * 1ll * z % mod;
  if (y & 1) {
    z = z * 1ll * x % mod;
  }
  return z;
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (i > 0) {
      a[i] += a[i - 1];
    }
  }

  vector<ll> pref(n), suff(n);
  for (int i = 0; i < n; ++i) {
    pref[i] = (!i ? 0ll : pref[i - 1]) + max(a[i] - (!i ? 0ll : a[i - 1]), 0ll);
  }
  for (int i = n - 1; i >= 0; --i) {
    suff[i] = (i == n - 1 ? 0ll : suff[i + 1]) + max(i ? a[i] - a[i - 1] : a[i], 0ll);
  }

  ll ans = 0;
  for (int i = 0; i + k - 1 < n; ++i) {
    ll cur = (i == 0ll ? 0ll : pref[i - 1]) + (i + k == n ? 0ll : suff[i + k]);
    cur += max(a[i + k - 1] - (i == 0ll ? 0ll : a[i - 1]), 0ll);
    ans = max(ans, cur);
  }
  cout << ans << "\n";
}

int main() {
  #ifndef LOCAL58
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
  #endif

  int t;
  t = 1;
  while(t--) {
    solve();
  }

  return 0;
}


Measured memory_bytes: 5584
// AOJ 2155: Infected Computer
// 2017.10.20 bal4u@uu
// 2018.2.4

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

typedef struct { int t, s, d; } T;
T tbl[20002], *end;
char f[20002];

//int cmp(T *a, T *b) { return a->t - b->t; }

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define THRESHOLD 10
#define STACKSIZE 35

void quicksort(T *a, int n)
{
	int i, j, l, r, p;
	int lsp[STACKSIZE], rsp[STACKSIZE];
	T t, *m;
	
	l = 0, r = n-1, p = 0;
	while (1) {
		if (r-l <= THRESHOLD) {
			if (!p--) break;
			l = lsp[p], r = rsp[p];
		}
		m = a + ((l+r)>>1);
		i = l, j = r;
		while (1) {
			while (a[i].t < m->t) i++;
			while (m->t < a[j].t) j--;
			if (i >= j) break;
			t = a[i], a[i] = a[j], a[j] = t;
			i++, j--;
		}
		if (i-l > r-j) {
			if (i-l > THRESHOLD) {
				lsp[p] = l;
				rsp[p] = i-1;
				p++;
			}
			l = j+1;
		} else {
			if (r-j > THRESHOLD) {
				lsp[p] = j+1;
				rsp[p] = r;
				p++;
			}
			r = i-1;
		}
	}
	for (i = 1; i < n; i++) {
		t = a[i];
		for (j = i-1; j >= 0 && a[j].t > t.t; j--) a[j+1] = a[j];
		a[j+1] = t;
	}
}

int main()
{
	int n, m, ans;
	T *t;
	char *q;

	while (n = in()) {
		m = in();
		memset(f, 0, n+1);
		end = tbl + m; for (t = tbl; t < end; t++) t->t = in(), t->s = in(), t->d = in();
		quicksort(tbl, m);
//		qsort(tbl, m, sizeof(T), cmp);
		f[1] = 1; for (t = tbl; t < end; t++) f[t->d] |= f[t->s];
		ans = 0, q = f+1; while (n--) ans += *q++;
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2040
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int steps = Integer.parseInt(br.readLine());
		int cards[][] = new int [steps+1][2*n];
		for (int i=0; i<2*n; i++){
			cards[0][i] = i;
		}
		for (int i=0; i<steps; i++){
			int shuffle = Integer.parseInt(br.readLine());
			if(shuffle == 0){
				for (int j=0; j<n; j++){
					cards[i+1][2*j] = cards[i][j];
					cards[i+1][2*j+1] = cards[i][n+j];
				}
			}else{
				for (int j=0; j<2*n; j++){
					cards[i+1][j] = cards[i][(j+shuffle)%(2*n)];
				}
			}
		}

		for (int i=0; i<2*n; i++){
			System.out.println(cards[steps][i] + 1);
		}
	}
}

Measured memory_bytes: 25400
import java.util.*;
public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine();
        String str2 = sc.nextLine();
        String ring = str1 + str1.substring(0, str1.length());
        if(ring.contains(str2)){
            System.out.println("Yes");
        }
        else System.out.println("No");

    }
}


Measured memory_bytes: 26244
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

def inpl_strl(): return list(sys.stdin.readline())

K = inp()
S = input()
if K >= len(S):
    print(S)
else:
    print(f'{S[:K]}...')

Measured memory_bytes: 10060
import collections

def factor(m):
  q = m
  r = []
  i = 2
  while i * i <= m:
    if q % i:
      i += 1
    else:
      r.append(i)
      q //= i
  if q != 1:
    r.append(q)
  return r

n, m = map(int, input().split())
p = 10 ** 9 + 7

r = factor(m)
v = collections.Counter(r)
c = 1
for value in v.values():
  temp = 1
  for i in range(value):
    temp *= value + n - 1 - i
  for i in range(value):
    temp //= i + 1
  temp %= p
  c = c * temp % p
print(c)
  
  
  

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int a, b;
  cin >> a >> b;
  if(a+b < 10) cout << a+b << endl;
  else cout << "error" << endl;
  return 0;
}

Measured memory_bytes: 256
H, W, M = list(map(int, input().split()))

h = [0] * H
w = [0] * W

hw = {}

for _ in range(M):
    a, b = list(map(int, input().split()))
    h[a - 1] += 1
    w[b - 1] += 1
    temp = "x" + str(a - 1) + "y" + str(b - 1)
    hw[temp] = 1

hm = max(h)
wm = max(w)

hp = [i for i, v in enumerate(h) if v == hm]
wp = [i for i, v in enumerate(w) if v == wm]

for x in hp:
    for y in wp:
        temp = "x" + str(x) + "y" + str(y)
        if temp not in hw:
            print(hm + wm)
            exit()
else:
    print(hm + wm - 1)



Measured memory_bytes: 67080
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;

const int maxn = 2100;

bool f[maxn][maxn * 40];
int a[maxn];

int main(int argc, char * argv[])
{
	int n;
	int sumi = 0;
	int maxi = 0;
	scanf("%d", &n);
	for (int i = 1;i <= n;++i)
	{
		scanf("%d", &a[i]);
		maxi = max(maxi, a[i]);
		sumi += a[i];
	}
	random_shuffle(a + 1, a + n + 1);
	f[0][0] = true;
	maxi *= 40;
	for (int i = 1;i <= n;++i)
	{
		for (int j = 0;j <= maxi;++j)
		{
			if (abs(j-a[i]) <= maxi) f[i][abs(j - a[i])] |= f[i - 1][j];
			if (j+a[i] <= maxi) f[i][j + a[i]] |= f[i - 1][j];
		}
	}
	int ret = 0;
	for (;ret <= maxi;++ret) if (f[n][ret]) break;
	printf("%d\n", (sumi + ret) / 2);
	return 0;
}


Measured memory_bytes: 166144
import sys


def partition(A, p, r):
    # 要素の最後をxに代入
    x = A[r]
    i = p-1
    ans = ""

    for j in range(r):
        if A[j] <= x:
            i += 1
            tmpA = A[i]
            A[i] = A[j]
            A[j] = tmpA

    tmpB = A[i+1]
    A[i+1] = A[r]
    A[r] = tmpB
    for j in range(n):
        if j > 0:
            ans += " "
        if j == i+1:
            ans += "["+str(A[j])+"]"
        else:
            ans += str(A[j])
    print(ans)


n = int(input())
A = list(map(int, input().split()))
r = len(A)-1
p = 0
partition(A, p, r)
# for i in range(n):
#     if A[i] == A[r]:
#         sys.stdout.write('[' + str(A[i])+']' + ' ')
#     else:
#         sys.stdout.write(str(A[i]) + ' ')
# print()



Measured memory_bytes: 16388
#include <bits/stdc++.h>

#define endl '\n'
#define pb push_back
#define mod 1000000007
typedef int integer;
#define int long long
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 0
#endif
using namespace std;

template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << ": " << arg1 << endl;
}

template<typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = (int) 5e5 + 2;
int ar[NN];
int b[NN];
int n, m, k;
string s;



integer main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = 1; i * d <= r; i++){
        if (i * d >= l) ans++;
    }
    cout << ans;


}



Measured memory_bytes: 3596
#include<iostream>
#include<string>
using namespace std;

int main () {
    int a, b, c;
    cin >> a >> b >> c;
    if ((a == b && a == c && b == c) || (a != b && a != c && b != c)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256