akhauriyash/Code-Regression huggingface dataset:
using namespace std; 
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define vect vector<ll>
#define maap map<ll,ll>  
#define MOD 1000000007
#define mit map::iterator
#define pii pair<ll,ll>
#define rep(i,a,b)	for(ll i=a;i< b;i++)
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
typedef  long long   int  ll;
//stringstream convert; 
  //  convert << number; 
  //  string s = convert.str();
 ll fact[500005],invfact[500005]; 
 ll power(ll x, ll y)
{
	ll z = 1;
	while(y > 0)
	{
		if(y % 2 == 1)
			z = (z*x)%MOD;
		x = (x*x)%MOD;
		y /= 2;
	}
	return z;
}
 ll inv(ll x)
{
	return power(x,MOD-2);
}
ll divide(ll x, ll y)
{
	return (x*inv(y))%MOD;
}
ll C(ll n, ll k)
{
	if(k > n) return 0;
	return divide(fact[n], (fact[n - k]*fact[k])%MOD);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
bool isPrime(int n) {
 
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
} 
void init(){
	ll p=MOD;
	fact[0]=1;
	ll i;
	for(i=1;i<500005;i++){
		fact[i]=(i*fact[i-1])%p;
	}
	i--;
	invfact[i]=power(fact[i],p-2);
	for(i--;i>=0;i--){
		invfact[i]=(invfact[i+1]*(i+1))%p;
	}
}
ll s;
ll fun(ll a)
{
	if(a==0)
	return 0;
	return a+fun(a-1);
}
priority_queue < pair<ll,ll> , vector<pair<ll,ll> >,greater<pair<ll,ll> > > gq;

#define MAXN   10000001 
ll spf[MAXN]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXN; i++) 
        spf[i] = i; 
    for (ll i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
    for (ll i=3; i*i<MAXN; i++) 
    {
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
set<ll> getFactorization(ll x) 
{ 
    set<ll> ret; 
    while (x != 1) 
    { 
        ret.insert(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}
ll sm(ll n)
{
	ll i;
	ll k=0;
	while(n>0)
	{
		k=k+n%10;
		n=n/10;
	}
	return k;
}
void ghost()
{   
  	ll i=0,j=0,k=0,l=0,n,r=0,q=0,y=100000000000,m,w;
    	string s,t;
    	cin>>s>>t;
    	n=s.size();
    	k=t.size();
		ll dp[n+1][k+1];
		for(i=0;i<=n;i++)
		{
			for(j=0;j<=k;j++)
			{
				if(i==0||j==0)
				dp[i][j]=0;
				else if (s[i-1]==t[j-1])
					dp[i][j]=1+dp[i-1][j-1];
				else
					dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
				}
			}
			string ans="";
			while(n>0&&k>0)
			{
				if(dp[n][k]==dp[n-1][k])
				n--;
			else	if(dp[n][k]==dp[n][k-1])
				k--;
			else	if(s[n-1]==t[k-1])
				{
					ans.pb(s[n-1]);
					n--;
					k--;
				}
			}
			reverse(ans.begin(),ans.end());
		cout<<ans;
	}
signed main()
{int test=1;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
fast
//cin>>test;
while(test--)
ghost();
return 0;
}

  

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

int main()
{
    int n;
    cin>>n;
    int val;
    vector<long long> v;
    int i;
    for(i=0;i<n;i++)
    {
        cin>>val;
        v.push_back(val);
    }
    int long long ans=0;
    int j;
    long long sum=0;
    for(i=0;i<n;i++)
    {
        sum=sum+v[i];
    }

    for(i=0;i<n;i++)
    {
        sum=sum-v[i];
        ans=(ans+((sum)%1000000007*(v[i]%1000000007))%1000000007)%1000000007;
    }
    cout<<ans;
    
  return 0;
}

Measured memory_bytes: 5312
//diverta2019_b.cpp
//Sat May 11 20:39:39 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int a[3];
	int n;
	cin >> a[0] >> a[1] >> a[2] >> n;

	sort(a,a+3);

	int ans = 0;
	for (int i=0;i<=n/a[2];i++){
		int total = a[2]*i;
		for (int j=0;j<=(n-total)/a[1];j++){
			int total2 = total + a[1]*j;
			if ((n-total2)%a[0]==0){
				ans++;
			}
//			cout << i << " " << j << " " << ans << endl;
		}
	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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



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

	double a, b;
    cin>>a>>b;
    
    double a1, a2;
    
    a1 = (b - 2 * a) / 2.0;
    a2 = a - a1;
    
    
    
    if(a1 >= 0 && a2 >= 0 && a1 == int(a1) && a2 == int(a2)){
    	cout<<"Yes"<<endl;	
		
    	
	}else{
		cout<<"No"<<endl;
	}
    
    
    
		
	
		
  return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	vector<string>abc(3);
	for (int i = 0; i < 3; i++)cin >> abc.at(i);
	int turn = 0;
	while (true) {
		if (abc.at(turn).length() == 0) {
			char s = 'A' + turn;
			cout << s << endl;
			return 0;
		}
		char x = abc.at(turn).at(0);
		if(abc.at(turn).length()>=1)abc.at(turn) = abc.at(turn).substr(1);
		turn = x - 'a';
		//cout << abc.at(0) << " " << abc.at(1) << " " << abc.at(2) << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 1999999999
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

#ifdef INPUT
stringstream input(R"(
3 2
)");
#define cin input
#endif

int main()
{
    int n,k;
    cin >> n >> k;

    if (2*k-1<=n)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }

int main(){
    ll a, b;
    cin >> a >> b;
    ll sum = 0;
    FOR(i, 1, b-a) {
        sum += i;
    }
    cout << sum-a << "\n";
}


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

using namespace std;

int main()
{
  int A,B;
  string S;
  cin>> A>> B;
  cin>> S;

  string ret="Yes";
  for(int i=0;i<A;i++)if(S[i]=='-')ret="No";
  if(S[A]!='-')ret="No";
  for(int i=A+1;i<A+B+1;i++)if(S[i]=='-')ret="No";
  cout<< ret<< endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second
struct Dinic{
  const int INF=1<<28;
  
  struct edge {
    int to,cap,rev;
    edge(){}
    edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
  };

  int n;
  vector<vector<edge> > G;
  vector<map<int,int> > M;
  vector<int> level,iter;

  Dinic(){}
  Dinic(int sz):n(sz),G(n),M(n),level(n),iter(n){}
  
  void add_edge(int from,int to,int cap){
    M[from][to]=G[from].size();
    M[to][from]=G[to].size();
    G[from].push_back(edge(to,cap,G[to].size()));
    // undirected
    //G[to].push_back(edge(from,cap,G[from].size()-1));
    // directed
    G[to].push_back(edge(from,0,G[from].size()-1));
  }
  
  void bfs(int s){
    fill(level.begin(),level.end(),-1);
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
      int v=que.front();que.pop();
      for(int i=0;i<(int)G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap>0&&level[e.to]<0){
          level[e.to]=level[v]+1;
          que.push(e.to);
        }
      }
    }
  }
  
  int dfs(int v,int t,int f){
    if(v==t) return f;
    for(int &i=iter[v];i<(int)G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[v]<level[e.to]){
        int d = dfs(e.to,t,min(f,e.cap));
         if(d>0){
           e.cap-=d;
           G[e.to][e.rev].cap+=d;
           return d;
         }
      }
    }
    return 0;
  }
  
  int flow(int s,int t,int lim){
    int fl=0;
    for(;;){
      bfs(s);
      if(level[t]<0||lim==0) return fl;
      fill(iter.begin(),iter.end(),0);
      int f;
      while((f=dfs(s,t,lim))>0){
         fl+=f;
         lim-=f;
      }
    }
  }

  int flow(int s,int t){
    return flow(s,t,INF);
  }

  //cap==1 only
  bool back_edge(int s,int t,int from, int to){
    for(int i=0;i<(int)G[from].size();i++) {
      edge& e=G[from][i];
      if(e.to==to) {
        if(e.cap==0&&flow(from,to,1)==0) {
          flow(from,s,1);
          flow(t,to,1);
          return 1;
        }
      }
    }
    return 0;
  }
};
int main(){
    int n;
    cin>>n;
    Dinic D(n*2+2);
    int st=n*2;
    int en=n*2+1;
    int ax[n],ay[n],bx[n],by[n];
    r(i,n){
        cin>>ax[i]>>ay[i];
    }
    r(i,n){
        cin>>bx[i]>>by[i];
    }
    r(i,n)r(j,n){
        if(ax[i]<bx[j]&&ay[i]<by[j]){
            D.add_edge(i,j+n,1);
        }
    }
    r(i,n)D.add_edge(st,i,1);
    r(i,n)D.add_edge(i+n,en,1);
    cout<<D.flow(st,en,1e7)<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const long long inf=1e18;
int n;
long long now,a[1000010];
int main()
{
	now=1; scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for (int i=1;i<=n;i++) if (a[i]==0) {printf("0\n"); return 0;}
	for (int i=1;i<=n;i++)
	{
		long long x=a[i];
		if (now<=inf/x) now=now*x;else {printf("-1\n"); return 0;}
	}
	printf("%lld\n",now);
return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define LINY "YES\n"
#define Liny "Yes\n"
#define LINN "NO\n"
#define Linn "No\n"
#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"

ll min(ll x,ll y){return (x<y ? x:y);}
ll max(ll x,ll y){return (x>y ? x:y);}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}



int main(){
  int a[5]; CINA(a,5);
  int k; cin>>k;
  cout << (a[4]-a[0]>k? ":(" : "Yay!");
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    long int a,b,c[2000000],d[2000000],count=0;
    scanf("%ld%ld",&a,&b);
  for(int i=0;i<a;i++){
      scanf("%ld%ld",&c[i],&d[i]);
  }
  for(int i=0;i<a;i++){
      if(c[i]*c[i]+d[i]*d[i]<=b*b)count++;
  }
  printf("%ld",count);
  return 0;
}


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

int main() {
  string str;
  
  while(getline(cin,str)) {
    int a[10][10];
    for(int i=0; i<10; i++) a[0][i]=str[i]-'0';
    
    for(int i=1; i<10; i++) {
      for(int j=0; j<10-i; j++) {
	a[i][j]=(a[i-1][j]+a[i-1][j+1])%10;
      }
    }
    cout << a[9][0] << endl;
  }
  
  return 0;
}

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

void solve () {
    double n;
    cin >> n;
    vector<int> a(n);
    double sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    double avg = round(sum / n);
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long x = avg - a[i];
        ans += x * x;
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3744
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int N;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  char s[3];

  int dig = 0;
  while (N > 0) {
    s[dig++] = N % 10;
    N /= 10;
  }

  for (int i = 0; i < 3 / 2; i++) {
    if (s[i] != s[2 - i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
S=input()
L=[0]*(len(S)+1)
#print(L)
for i in range(len(S)):
  if S[i]=='<':
    L[i+1]=max(L[i+1],L[i]+1)
for i in range(len(S)-1,-1,-1):
  if S[i]=='>':
    L[i]=max(L[i],L[i+1]+1)
print(sum(L))

Measured memory_bytes: 23336
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long N;
    cin >>N;
    long long T=sqrt(N);
    long long stand=N-1;
     long long a;
    for(long long i=1;i<=T;i++){
        if(N%i==0){
         a=N/i;
         stand=min(stand,(a+i-2));
        }
    }
    cout <<stand <<endl;
}

Measured memory_bytes: 3688
#![allow(unused_imports)]
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]

use std::{cmp, fmt};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};

fn main() {
    let a: Vec<i64> = {
        let mut sc = InputScanOnce::new(io::stdin(), 1024);
        let n = sc.next();
        sc.vec(n)
    };
    let cs = {
        let (mut cs, mut s) = (vec![0], 0);
        for &x in &a {
            s += x;
            cs.push(s);
        }
        cs
    };
    let mut m = BTreeMap::<i64, usize>::new();
    for c in cs {
        let n = if let Some(n) = m.remove(&c) { n + 1 } else { 1 };
        m.insert(c, n);
    }
    let r = m.values().map(|&n| n * (n - 1) / 2).sum::<usize>();
    println!("{}", r);
}

struct InputScanOnce {
    buf: Vec<u8>,
    pos: usize,
}

#[allow(dead_code)]
impl InputScanOnce {
    fn new<R: Read>(mut reader: R, estimated: usize) -> Self {
        let mut buf = Vec::with_capacity(estimated);
        let _ = io::copy(&mut reader, &mut buf).unwrap();
        InputScanOnce { buf: buf, pos: 0 }
    }

    #[inline]
    fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: fmt::Debug,
    {
        let mut start = None;
        loop {
            match (self.buf[self.pos], start.is_some()) {
                (b' ', true) | (b'\n', true) => break,
                (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                (_, false) => start = Some(self.pos),
            }
        }
        let target = &self.buf[start.unwrap()..self.pos];
        unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        T::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
        T3::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        T::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }

    fn strings_as_mat<T, F: FnMut(u8) -> T>(&mut self, h: usize, mut f: F) -> Vec<Vec<T>> {
        (0..h)
            .map(|_| {
                let l = self.next::<String>();
                l.as_bytes().iter().cloned().map(&mut f).collect()
            })
            .collect()
    }
}


Measured memory_bytes: 12468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;


int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt;
  int max1 = -1;
  for(int i = 0;i < n;i++){
    cnt = 0;
    for(char c = 'a';c <= 'z';c++){
      bool right = false;
      bool left = false;
      for(int j = 0;j < i + 1;j++){
        if(s[j] == c) right = true;
      }
      for(int j = i + 1;j < n;j++){
        if(s[j] == c) left = true;
      }
      if(right == true && left == true) cnt++;
    }
    max1 = max(max1,cnt);
  }
  cout << max1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int z;
        cin >> z;
        if(z == 0)
            return 0;

        int ret = INT_MAX;
        for(int x=1; x*x*x<=z*z*z; ++x){
            for(int y=1; x*x*x+y*y*y<=z*z*z; ++y){
                ret = min(ret, z*z*z - x*x*x - y*y*y);
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int N;
	scanf("%d", &N);
	int a, b, c, d;
	a = b = 0;
	scanf("%d", &c);
	d = c;
	for(int i=1; i<N; ++i) {
		int e;
		scanf("%d", &e);
		a = min(a+abs(e-c), b+abs(e-d));
		swap(a, b);
		c = d;
		d = e;
	}
	printf("%d\n", b);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int h,n;
  cin  >> h >> n;
  rep(i,n){
    int x;
    cin >> x;
    h -= x;
    
  }
  
  if(h <= 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  }


Measured memory_bytes: 256
from collections import defaultdict


class TwoSat:
    def __init__(self, V):
        self.N = len(V)
        self.ans = None
        self.__e = []
        self.__v = V

    def add_clause(self, i, f, j, g):
        self.__e.append((2*i + (0 if f else 1), 2*j + (1 if g else 0)))
        self.__e.append((2*j + (0 if g else 1), 2*i + (1 if f else 0)))

    @staticmethod
    def scc(V, E):
        g = defaultdict(list)
        rg = defaultdict(list)
        for u, v in E:
            g[u].append(v)
            rg[v].append(u)

        o = []
        done = set()
        for u in V:
            if u in done:
                continue

            s = [(u, True)]
            while s:
                u, f = s.pop()
                if f:
                    if u in done:
                        continue
                    done.add(u)
                    s.append((u, False))
                    for v in g[u]:
                        if v in done:
                            continue
                        s.append((v, True))
                else:
                    o.append(u)

        done = set()
        ans = []
        while o:
            u = o.pop()
            if u in done:
                continue

            s = [u]
            vv = [u]
            done.add(u)
            while s:
                u = s.pop()
                for v in rg[u]:
                    if v in done:
                        continue
                    vv.append(v)
                    s.append(v)
                    done.add(v)
            ans.append(vv)

        return ans

    def satisfiable(self):
        scc = TwoSat.scc(self.__v, self.__e)
        cid = [-1] * (self.N)

        for i, s in enumerate(scc):
            for v in s:
                cid[v] = i

        for i in range(self.N//2):

            if cid[2*i] == cid[2*i+1]:
                self.ans = None
                return False

        self.ans = []
        for i in range(self.N//2):
            self.ans.append(cid[2*i] < cid[2*i+1])

        return True


def atcoder_practice2_h():
    # https://atcoder.jp/contests/practice2/submissions/16823214
    N, D = map(int, input().split())
    XY = [list(map(int, input().split())) for _ in range(N)]

    ts = TwoSat(list(range(2*N)))
    for i, (x1, y1) in enumerate(XY):
        for j in range(i+1, N):
            x2, y2 = XY[j]
            if abs(x1 - x2) < D:
                ts.add_clause(i, False, j, False)

            if abs(y1 - y2) < D:
                ts.add_clause(i, True, j, True)

            if abs(x1 - y2) < D:
                ts.add_clause(i, False, j, True)

            if abs(y1 - x2) < D:
                ts.add_clause(i, True, j, False)

    if not ts.satisfiable():
        print('No')
    else:
        print('Yes')
        for i, b in enumerate(ts.ans):
            print(XY[i][0 if b else 1])


if __name__ == "__main__":
    atcoder_practice2_h()


Measured memory_bytes: 71292
using System;
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = a * b;
    if(c % 2 == 0){Console.WriteLine("Even");}
    else{Console.WriteLine("Odd");}
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

ll solve(ll n,ll m){
    if(n*2>=m){
        return m/2;
    }else{
        return n + (m-n*2)/4;
    }
}

int main(){
    ll n,m;cin>>n>>m;
    ll out = solve(n,m);
    cout<<out;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vi> map(h + 2, vi(w + 2, -2));
  queue<pair<int, int>> q;
  rep(i, h) rep(j, w) {
    char c;
    cin >> c;
    if(c == '#') {
      map[i + 1][j + 1] = 0;
      q.push(make_pair(i + 1, j + 1));
    } else
      map[i + 1][j + 1] = -1;
  }
  int ans = 0;
  vi di = {-1, 0, 0, 1};
  vi dj = {0, -1, 1, 0};
  while(!q.empty()) {
    int i = q.front().first;
    int j = q.front().second;
    q.pop();
    rep(dir, 4) {
      int ni = i + di[dir], nj = j + dj[dir];
      if(map[ni][nj] == -1) {
        q.push(make_pair(ni, nj));
        map[ni][nj] = map[i][j] + 1;
        ans = map[ni][nj];
      }
    }
  }
  cout << ans << endl;
}

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


int main(){
    string S; cin >> S;
    string ans = "Good";
    for (int i = 1; i < 4; i++) {
        if (S[i] == S[i - 1]) ans = "Bad";
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n<1000)
    cout<<"ABC"<<endl;
    else
        cout<<"ABD"<<endl;
    return 0;
}


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

int main(){
    map<string, int> set;
    string str;
    int mode = 0;
    int max_length = 0;

    while(cin >> str){
        if(set.find(str) != set.end()){
            set[str]++;
        }else{
            set.insert(pair<string, int>(str, 1));
        }
    }

    map<string, int>::iterator it = set.begin();
    map<string, int>::iterator mode_cursor = set.begin();
    map<string, int>::iterator max_cursor = set.begin();

    while(it != set.end()){
        if(mode < it->second){
            mode = it->second;
            mode_cursor = it;
        }
        if(max_length < it->first.size()){
            max_length = it->first.size();
            max_cursor = it;
        }
        it++;
    }

    cout << mode_cursor->first << " " << max_cursor->first << endl;

    return 0;
}

Measured memory_bytes: 0
N,M = map(int, input().split())
my_list = []
for i in range(M):
    line = input().split()
    my_list.append((int(line[0]), int(line[1])))

max_l = 0
min_r = 10 ** 6

for l,r in my_list:
    max_l = max(max_l, l)
    min_r = min(min_r, r)
print(max(0, min_r - max_l + 1))

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

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	long long ans = 0;
	if (k % 2 == 0 && n >= k / 2) {
		long long p = (n - k / 2) / k + 1;
		ans += p;
		ans += p * (p - 1) * 3;
		if (p > 2) {
			ans += p * (p - 1) * (p - 2);
		}
	}
	long long p = n / k;
	ans += p;
	ans += p * (p - 1) * 3;
	if (p > 2) {
		ans += p * (p - 1) * (p - 2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict

def main():
    N = int(input())
    pos = [list(map(int,input().split())) for _ in range(N)]
    if N == 1:
        print(1)
    else:
        d = defaultdict(int)
        for i in range(N):
            for j in range(N):
                slope = (pos[i][0]-pos[j][0],pos[i][1]-pos[j][1])
                if slope[0] != 0 or slope[1] != 0:
                    d[slope] += 1
        if len(d) == 0:
            print(N)
        else:
            print(N-max(d.values()))

if __name__ == "__main__":
    main()

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

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int data = sc.nextInt();
		int[][] hand = new int[4][9];
		String color;
		int r_cnt, g_cnt, b_cnt;
		int s_or_f;

		for(int n=0; n<data; n++){
			s_or_f = 1;
			r_cnt = 0;
			g_cnt = 0;
			b_cnt = 0;
			for(int i=0; i<9; i++){
				hand[0][i] = sc.nextInt();
			}
			for(int i=0; i<9; i++){
				color = sc.next();
				if("R".equals(color)){
					hand[1][r_cnt] = hand[0][i];
					r_cnt++;
				}if("G".equals(color)){
					hand[2][g_cnt] = hand[0][i];
					g_cnt++;
				}else if("B".equals(color)){
					hand[3][b_cnt] = hand[0][i];
					b_cnt++;
				}
			}
			if(r_cnt%3==0 && g_cnt%3==0 && b_cnt%3==0){
				if(r_cnt!=0) s_or_f = rummy(hand[1], r_cnt-1);
				if(s_or_f==1 && g_cnt!=0) s_or_f = rummy(hand[2], g_cnt-1);
				if(s_or_f==1 && b_cnt!=0) s_or_f = rummy(hand[3], b_cnt-1);
				if(s_or_f==1){
					System.out.println(1);
				}else{
					System.out.println(0);
				}
			}else{
				System.out.println(0);
			}
		}
	}

	static int rummy(int[] hand, int cnt){
		int i;
		int[] index = new int[2];

		while(true){
			i = 0;
			Arrays.sort(hand, 0, cnt+1);
			while(hand[i]==0){
				i++;
				if(i>cnt) return 1;
			}
			if(hand[i]==hand[i+1]){
				if(hand[i]==hand[i+2]){
					Arrays.fill(hand, i, i+3, 0);
					continue;
				}
			}
			index[0] = Arrays.binarySearch(hand, i+1, cnt+1, hand[i]+1);
			if(index[0]>=0){
				index[1] = Arrays.binarySearch(hand, i+2, cnt+1, hand[i]+2);
				if(index[1]>=0){
					hand[i] = 0;
					hand[index[0]] = 0;
					hand[index[1]] = 0;
					continue;
				}else{
					return 0;
				}
			}else{
				return 0;
			}
		}
	}
}

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

int main() {
  int a, b, price;
  cin >> a >> b;
  
  bool cor = false;
  for (int i = 1; i < 1010; i++){
    if (a <= i * 0.08 && i * 0.08 < a + 1 && b <= i * 0.1  && i * 0.1 < b+1){
      price = i;
      cor = true;
      break;
    }
  }
  if (cor == true){
    cout << price << endl;
  }
  else {
    cout <<-1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N=1e5+5;
ll dp[N], arr[N];
ll n;
ll solve(ll x)
{
    if(x==n-1)
        return 0;
    else if(dp[x]!=-1)
        return dp[x];
    ll ret = solve(x+1)+abs(arr[x+1]-arr[x]);
    if(x+2<=n-1)
        ret=min(ret, abs(arr[x+2]-arr[x])+solve(x+2));
    dp[x] = ret ;
    return ret ;
}


int main()
{
     _69e27
     memset(dp, -1, sizeof dp);
     cin >> n;
     for(int i=0; i<n; i++)
        cin >> arr[i];
     cout << solve(0);


    return 0 ;
}


Measured memory_bytes: 4992
s=list(input())
n=len(s)
ans="AC"
if(s[0]!="A"):
    ans="WA"
else:
    s[0]=s[0].swapcase()
cnt=0
check=0
for i in range(n-3):
    if(s[i+2]=="C"):
        check+=1
        s[i+2]=s[i+2].swapcase()
if(check!=1):
    ans="WA"
if(str.islower(''.join(s))==False):
    ans="WA"
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void solve() {
	ll n; cin >> n;
	ll ans = n+3;
	rep1(i, 1000000) {
		if (n%i == 0) {
			ans = min(ans, i + n / i - 2);
		}
	}
	cout << ans << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 256
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

const size_t N = 1e5 + 5;

int n, a[N], b[N];

int main() {
    n = read();
    generate_n(a, n + 1, read);
    generate_n(b, n, read);
    LL ans = 0;

    for (int i = 0; i < n; ++i) {
        if (a[i] < b[i]) {
            ans += a[i];
            b[i] -= a[i];
            if (a[i + 1] < b[i]) {
                ans += a[i + 1];
                a[i + 1] = 0;
            } else {
                a[i + 1] -= b[i];
                ans += b[i];
            }
        } else {
            ans += b[i];
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(N, X);
  GVI(L, N);
  int i = 0, now = 0;
  while (i < N) {
    now += L[i];
    if (now > X) {
      break;
    }
    i++;
  }
  print(i + 1);
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int N,B[105][5][5][5],M[2][30],i,j,k,t,d,x,y,z,u;
int r(int p){return 0<=p&&p<5;}


int c(int x,int y,int z,int d)
{
	int i,j,k,R=0;
	for(i=x-1;i<x+2;i++)
		for(j=y-1;j<y+2;j++)
			for(k=z-1;k<z+2;k++)
				if(r(i)&&r(j)&&(i!=x||j!=y||k!=z)&&r(k)&&B[d][k][j][i])
					R++;
	return R;
}

int main()
{
	for(u=1;scanf("%d",&N),N;u++)
	{
		if(u>1)puts("");
		memset(B,0,sizeof(B));
		memset(M,0,sizeof(M));
		for(i=0;i<5;i++)
			for(j=0;j<5;j++)
				for(k=0;k<5;k++)
					scanf("%1d",&B[0][i][j][k]);
		for(i=0;i<2;i++)
		{
			scanf("%d",&k);
			for(j=0;j<k;j++,M[i][t]=1)
				scanf("%d",&t);
		}
		for(d=0;d<N;d++)
		{
			for(z=0;z<5;z++)
				for(y=0;y<5;y++)
					for(x=0;x<5;x++)
					{
						if(!B[d][z][y][x]&&M[0][c(x,y,z,d)])
							B[d+1][z][y][x]=1;
						else if(B[d][z][y][x]&&!M[1][c(x,y,z,d)])
							B[d+1][z][y][x]=0;
						else
							B[d+1][z][y][x]=B[d][z][y][x];
					}
		}
		printf("Case %d:\n",u);
		for(z=0;z<5;z++)
		{
			for(y=0;y<5;y++)
				for(x=0;x<5;x++)
				printf("%d%s",B[N][z][y][x],x==4?"\n":"");
			if(z<4)puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 672
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x



if __name__ == '__main__':
    N, M = mulinputs()
    total = sum(list(mulinputs()))

    # 出力
    if total <= N:
        print(N-total)
    else:
        print(-1)


Measured memory_bytes: 11440
#!/usr/bin/env python3
import sys


def solve(N: int):
    ret = N // 3
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 1e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;



signed main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);
   int A, B, C, ans = INF;
   cin >> A >> B >> C;
   if (C % 2 == 0) ans  = 0;
   else ans = min(ans, A * B);

   if (B % 2 == 0) ans = 0;
   else ans = min(ans, A * C);

   if (A % 2 == 0) ans = 0;
   else ans = min(ans, B * C);

   cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, K;
ll a[100010], b[100010], c[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }  
  ll pos = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] > 0) pos += a[i];
  }
  for (int i = 0; i < N; i++) {
    b[i] = a[i];
    if (i != 0) b[i] += b[i - 1];
  }
  for (int i = 0; i < N; i++) {
    c[i] = a[i] > 0 ? a[i] : 0;
    if (i != 0) c[i] += c[i - 1];
  }
  ll ans = 0;
  for (int i = 0; i + K - 1 < N; i++) {
    ll tmp = b[i + K - 1] - (i == 0 ? 0 : b[i - 1]);
    ll sum = pos - (c[i + K - 1] - (i == 0 ? 0 : c[i - 1]));
    ans = max(ans, max(sum, sum + tmp));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void fast(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
}

ll dp[4000][4000];
ll arr[4000];
ll n;

ll solve(ll low, ll high){
    if(high-low<=1) return max(arr[low],arr[high]);
    
    if(dp[low][high]!=-1) return dp[low][high];
    
    ll ans1 = solve(low+1, high-1);
    ll ans2 = solve(low+2, high);
    ll ans3 = solve(low, high-2);
    
    ll case1 = min(ans1, ans2)+arr[low];
    ll case2 = min(ans1, ans3)+arr[high];
    
    return dp[low][high] = max(case1, case2);
}

int main() {
    fast();
    memset(dp,-1,sizeof(dp));
    cin >>n;
    ll sum=0;
    for(ll i=0;i<n;i++){
        cin >>arr[i];
        sum += arr[i];
    }
    
    cout<<2*solve(0,n-1)-sum;
    
    return 0;
}


Measured memory_bytes: 128732
n,m = map(int,input().split())

A = []
for i in range(n):
    A.append(input())

B = []
for i in range(m):
    B.append(input())

for i in range(n-m+1):
    for j in range(n-m+1):
        f = True
        for k in range(m):
            for l in range(m):
                if A[i+k][j+l] != B[k][l]:
                    f = False
        if f:
            print("Yes")
            exit()

print("No")


Measured memory_bytes: 3064
#include "bits/stdc++.h" 
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

double H, W, x, y;

void solve(){
  double m_x = H/2.0;
  double m_y = W/2.0;
  bool can = false;
  if(m_x == x && m_y == y){
    can = true;
  }
  cout << H * W / 2.0 << " ";
  if(can){
    cout << "1" << endl;
  }else{
    cout << "0" << endl;
  }
}

int main(){
  cin >> H >> W >> x >> y;
  solve();
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n, x, y;
    vector<ll> G[3000];

    cin >> n >> x >> y;
    x--;
    y--;

    vector<int> ans(n);

    for (int i = 0; i < n; i++)
    {
        if (i < n - 1)
        {
            G[i].push_back(i + 1);
        }

        if (i + 1 < n)
        {
            G[i + 1].push_back(i);
        }
    }

    G[x].push_back(y);
    G[y].push_back(x);

    for (int i = 0; i < n; i++)
    {
        queue<ll> q;
        q.push(i);
        vector<ll> d(n, -1);
        d[i] = 0;

        while (q.size())
        {
            int p = q.front();
            q.pop();

            for (auto k : G[p])
            {
                if (d[k] == -1)
                {
                    q.push(k);
                    d[k] = d[p] + 1;
                    ans[d[k]]++;
                }
            }
        }
    }

    for (int i = 1; i < n; i++)
    {
        cout << ans[i] / 2 << endl;
    }
}

Measured memory_bytes: 384
object Main extends App {
    val input = scala.io.StdIn.readLine.split(" ").map(_.toInt).toSeq
    val A = input(0)
    val B = input(1)

    val answer = A - B * 2 match {
      case n if n < 0 => 0
      case n => n
    }

    println(answer)
}

Measured memory_bytes: 25512
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
const int mod=1e9+7;
int n,k,a[21],f[1001],fac[1001],inv[1001],g[1001];
#define inc(x,y) x+=y,x>=mod?x-=mod:0
inline int C(int x,int y) {
	if(x<y||x<0||y<0) return 0;
	return (ll)fac[x]*inv[y]%mod*inv[x-y]%mod;
}
inline int kuai(int p,int q,int mod) {int tot=1;for(;q;p=(ll)p*p%mod,q>>=1) if(q&1) tot=(ll)tot*p%mod;return tot;}
int main()
{
	read(n),read(k);
	for(res i=1;i<=k;++i) read(a[i]);
	fac[0]=1;
	for(res i=1;i<=n;++i) fac[i]=(ll)fac[i-1]*i%mod;
	inv[n]=kuai(fac[n],mod-2,mod);
	for(res i=n-1;~i;--i) inv[i]=(ll)inv[i+1]*(i+1)%mod;
	f[0]=1;
	for(res i=1;i<=k;++i) {
	  memset(g,0,sizeof(g));
	  for(res j=0;j<=a[i];++j)
	    for(res l=n;l>=j;--l) inc(g[l],(ll)f[l-j]*C(n-j,a[i]-j)%mod*inv[j]%mod);
	  memcpy(f,g,sizeof(g));
	}
	print((ll)f[n]*fac[n]%mod,'\n');
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll  long long
ll ans[400000], a[400000];

int main()
{
    IO;
    ll i, j, n, m1, m2, k, t,a1,a2, l, th, h, r, mx, pr=.000000001, x, y;
    string s;
    cin>>s; n=s[s.size()-1]-'0';
    if(n==3) cout<<"bon"<<endl;
    else if(n==0||n==1||n==6||n==8) cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
//#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int W, H, N;
	cin >> W >> H >> N;
	int minx, miny, maxx, maxy;
	minx = miny = 0;
	maxx = W;
	maxy = H;
	rep(i, N) {
		int tmpx, tmpy, tmpa;
		cin >> tmpx >> tmpy >> tmpa;
		if (tmpa == 1 && minx<tmpx) {
			minx = tmpx;
		}
		else if (tmpa == 2 && maxx>tmpx) {
			maxx = tmpx;
		}
		else if (tmpa == 3 && miny<tmpy) {
			miny = tmpy;
		}
		else if (tmpa == 4 && maxy>tmpy) {
			maxy = tmpy;
		}
	}
	int x = maxx - minx;
	int y = maxy - miny;
	if (x < 0)x = 0;
	if (y < 0)y = 0;
	print(x*y);
}

Measured memory_bytes: 3648
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,k=INTM()
    a=n%k
    b=k-a
    print(min(a,b))
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 9172