akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b);
#define chmin(a, b) a = min(a, b);
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define MOD 1000000007

struct mint {
	int i;
	mint() : i(0) {}
	mint(int x) {
		i = int(x % MOD);
		if (i < 0) i += MOD;
	}
	template<class T> mint(T x) {
		i = int(x % MOD);
		if (i < 0) i += MOD;
	}
	mint operator+(const mint x) const {return i + x.i;}
	mint operator-(const mint x) const {return i - x.i;}
	mint operator*(const mint x) const {return (long long)i * x.i;}
	mint operator/(const mint x) const {return (long long)i * x.pow(MOD - 2).i;}
	mint inv() {return pow(MOD - 2);}
	template<class T> mint pow(T p) const {
		long long r = 1;
		long long t = i;
		for(; p > 0; p >>= 1) {
			if (p & 1) r = r * t % MOD;
			t = t * t % MOD;
		}
		return r;
	}
	template<class T1, class T2> static mint pow(T1 a, T2 b) {
		long long r = 1;
		long long t = (long long)(a % MOD);
		for(; b > 0; b >>= 1) {
			if (b & 1) r = r * t % MOD;
			t = t * t % MOD;
		}
		return r;
	}
	mint& operator+=(const mint x) {
		i = (i + x.i) % MOD;
		return *this;
	}
	mint& operator-=(const mint x) {
		i = i - x.i;
		if (i < 0) i += MOD;
		return *this;
	}
	mint& operator*=(const mint x) {
		i = (int)((long long)i * x.i % MOD);
		return *this;
	}
	mint& operator/=(const mint x) {
		i = (long long)i * x.pow(MOD - 2).i % MOD;
		return *this;
	}
};

std::ostream& operator<<(std::ostream& os, const mint& m) {
	return os << m.i;
}

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> x(n), y(m);
	rep(i, n) cin >> x[i];
	rep(i, m) cin >> y[i];
	sort(y.begin(), y.end());
	vector<P> z;
	for(int xi: x) {
		if (y[0] < xi && xi < y[m-1]) {
			int l = *(lower_bound(y.begin(), y.end(), xi) - 1),
			    r = *lower_bound(y.begin(), y.end(), xi);
			z.emplace_back(xi - l, r - xi);
		}
	}
	sort(z.begin(), z.end(), [](P x, P y) {
		return x.first < y.first 
		    || x.first == y.first && x.second > y.second;
	});
	z.erase(unique(z.begin(), z.end()), z.end());
	int sz = z.size();
	vector<int> idx(sz);
	rep(i, sz) idx[i] = i;
	sort(idx.begin(), idx.end(), [&](int i, int j) {
		return z[i].second < z[j].second
		    || z[i].second == z[j].second && z[i].first > z[j].first;
	});
	rep(i, sz) idx[i] += 1;
	BIT<mint> dp(sz + 1);
	dp.add(0, 1);
	for(int i: idx) {
		dp.add(i, dp.sum(i-1));
	}
	cout << dp.sum(sz) << endl;
}


Measured memory_bytes: 5620
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ans=0
dp=[0]*n
for i in range(n):
  if i>=k:
    if t[i-k]=='s' and t[i]=='s':
      if dp[i-k]!='r':
        ans+=r
        dp[i]='r'
      else:
        dp[i]='s'
    elif t[i-k]=='p' and t[i]=='p':
      if dp[i-k]!='s':
        ans+=s
        dp[i]='s'
      else:
        dp[i]='p'
    elif t[i-k]=='r' and t[i]=='r':
      if dp[i-k]!='p':
        ans+=p
        dp[i]='p'
      else:
        dp[i]='r'
    else:
      if t[i]=='r':
        ans+=p
        dp[i]='p'
      elif t[i]=='p':
        ans+=s
        dp[i]='s'
      else:
        ans+=r
        dp[i]='r'
  else:
    if t[i]=='r':
        ans+=p
        dp[i]='p'
    elif t[i]=='p':
        ans+=s
        dp[i]='s'
    else:
        ans+=r
        dp[i]='r'
print(ans)

Measured memory_bytes: 4084
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <string>

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

int main()
{
    int n, k;
    cin >> n >> k;
    int counter = 0;
    for (int i = 0; i < n; i++)
    {
        int h;
        cin >> h;
        if (h >= k)
            counter++;
    }

    cout << counter << endl;

    return 0;
}

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

int main(){
	int a,b,c;
	int ans;
	
	string cunning="77675555555555555555555555555555555555555455555555555555555555555";
	
	for(int i=0;i<104;i++){
		cin>>a>>b;c=a+b;
		//-----test-----
		if(i<cunning.size()){
			cout<<cunning[i]<<endl;
			continue;
		}
		//--------------
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
 
int main(){
  double X;
  long int save = 100;
  int count = 0;
  
  scanf("%lf",&X);
  
  while(save < X){
    save += save*0.01;
    count++;
  }
  
  
  printf("%d\n",count);
  return 0;
  
}

Measured memory_bytes: 1732
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    vector<long long int> A(N, 0);
    long long int sum = 0, mini = 0, S = 0;
    for (int i = 0; i < N; ++i) {
        cin >> A[i]; S += A[i];
    }
    mini = S;
    for (int i = 0; i < N; ++i) {
        sum += A[i];
        mini = min(mini, abs(sum - (S - sum)));
    }
    printf("%d\n", mini);
}


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

int main(){

/*
    int A,B,N,M,H,W;
    int i,j,k;
    int min = 1000000000;
    int max = 0;
    int a,b,c,d;
    int count=0,count_two=0,v;
    string moji[50];
*/

    string a,b,c;
    cin >> a >> b >> c;
    
    cout << a[0] << b[0] << c[0] << endl;
 
    return 0;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
auto& errStream=cerr;
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int n=read(),q=read();
	vi a(n);
	REP(i,n)
		a[i]=read();
	vi r(n+1,0),s(n+1,0);
	REP(i,n){
		r[i+1]=r[i]+a[i];
		s[i+1]=(i-1>=0?s[i-1]:0)+a[i];
	}
	REP(_,q){
		int x=read();
		int bot=1,top=n;
		while(top-bot>1){
			const int mid=(bot+top)/2;
			bool ok=true;
			if(a[n-mid]<=x)
				ok=false;
			else{
				int len=a[n-mid]-x;
				int pos=lower_bound(ALL(a),x-len)-a.begin();
				if(n-mid-pos<mid-1)
					ok=false;
			}
			if(ok)
				bot=mid;
			else
				top=mid;
		}
		int ans=r[n]-r[n-bot];
		if(n-bot*2>=0)
			ans+=s[n-bot*2];
		print(ans);
	}
}


Measured memory_bytes: 4096
#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

const double PI = acos(-1);
constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class Task{
public:
    void solve(istream& in, ostream& out){
        int N;
        in>>N;
        vc<lint> pref(N+1, 0);
        REP(i, N){
            int a;
            in>>a;
            pref[i+1] = pref[i] + a;
        }
        lint ans = ten(18);
        REP(i, N-1){
            chmin(ans, abs(2*pref[i+1]-pref[N]));
        }
        out<<ans<<'\n';
    }
};

int main(){
    istream& in(cin);
    ostream& out(cout);
    ios_base::sync_with_stdio(false);
    in.tie(nullptr), out.tie(nullptr);
    Task solver;
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 4780
N, Y = map(int, input().split())

ans = [0, 0, 0]
for x in range(N+1):
    for y in range(N-x+1):
        if x * 1000 + y * 5000 + (N-x-y) * 10000 == Y:
            print(N-x-y, y, x)
            exit()
print(-1, -1, -1)


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

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String str = br.readLine();
            int length = str.length();
            System.out.print(str.substring(0, 1));
            System.out.print(length - 2);
            System.out.println(str.substring(length - 1, length));
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
}


Measured memory_bytes: 21332
from collections import deque
"""
-1 -> not visited
else -> step count
"""
def bfs(maze, visited, sh, sw):
    stack = deque([[sh, sw]])
    visited[sh][sw] = 1
    while stack:
        h, w = stack.popleft()
        # ゴールの条件
        if h == H - 1 and w == W - 1:
            break
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_h, new_w = h+j, w+k
            if new_h < 0 or new_h >= H or \
               new_w < 0 or new_w >= W:
                continue
            elif maze[new_h][new_w] != "#" and \
                 visited[new_h][new_w] == -1:
                visited[new_h][new_w] = visited[h][w] + 1
                stack.append([new_h, new_w])
    
    return visited[H-1][W-1]

if __name__ == "__main__":
    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]

    sh, sw = 0, 0

    visited = [[-1] * W for _ in range(H)]
    
    step_cnt = bfs(maze, visited, sh, sw)

    white_cnt = sum([i.count(".") for i in maze])

    if step_cnt > 0:
        print(white_cnt - step_cnt)
    else:
        print(-1)

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

int n, sum1[200010], sum2[200010], ans = 0x3f3f3f3f;
char s[200010];

int main()
{
    scanf("%d%s", &n, s + 1);
    for (int i = 1; i <= n; i++)
        sum1[i] = sum1[i - 1] + (s[i] == '#');
    for (int i = n; i > 0; i--)
        sum2[i] = sum2[i + 1] + (s[i] == '.');
    for (int i = 0; i <= n; i++)
        ans = min(ans, sum1[i] + sum2[i + 1]);
    printf("%d\n", ans);
}

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


int main(){
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<string> st;
  int n=s.size();
  //set<string> st;
  for(int j=1;j<min(n,5)+1;j++){
    for(int i=0;i<n-j+1;++i){
      st.push_back(s.substr(i,j));
    }
  }

  sort(st.begin(),st.end());
  st.erase(unique(st.begin(),st.end()),st.end());
  cout << st[k-1] << endl;

  return 0;
}


Measured memory_bytes: 1788
local s=io.read()
local k=io.read("n")

local t={}
for i=1,#s do
    t[i]=s:sub(i,i)
end

local a=0
local b=0
if t[1]==t[#s] then
    for i=1,#s do
        a=a+1
        if t[i]~=t[i+1] then
            break
        end
    end
    for i=#s,1,-1 do
        b=b+1
        if t[i]~=t[i-1] then
            break
        end
    end
end

local c=0
for i=1,#s-1 do
    if t[i]==t[i+1] then
        t[i+1]=0
        c=c+1
    end
end

if a==#s then
    print(#s*k//2)
elseif a==0 then
    print(c*k)
else
    print(c*k-(a//2+b//2-(a+b)//2)*(k-1))
end

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

const int M = 1046527;
string H[M];

int getChar(char ch) {
  if (ch == 'A') return 1;
  if (ch == 'C') return 2;
  if (ch == 'G') return 3;
  if (ch == 'T') return 4;
  return 0;
}

long long getKey(string str) {
  long long sum {0}, p {1};
  for (char ch : str) {
    sum += p * (getChar(ch));
    p *= 5;
  }

  return sum;
}

int h1(int key) {
  return key % M;
}

int h2(int key) {
  return 1 + (key % (M-1));
}

bool find(string str) {
  long long key, i {0};
  key = getKey(str);
  while (true) {
    int h = (h1(key) + i * h2(key)) % M;
    if (H[h] == str) {
      return true;
    } else if (H[h].size() == 0) {
      return false;
    }
    i++;
  }
  return false;
}

void insert(string str) {
  long long key, i {0}, h;
  key = getKey(str);
  while (true) {
    h = (h1(key) + i * h2(key)) % M;
    if (H[h] == str) return;
    else if (H[h].size() == 0) {
      H[h] = str;
      return;
    }
    i++;
  }
}

int main() {
  int n;
  string command, str;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> command >> str;
    if (command == "insert") {
      insert(str);
    }
    if (command == "find") {
      if (find(str)) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}



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

char s[200010];

int main()
{
    int a, b;

    scanf("%s", s);
    int x = strlen(s);
    for (int i = 0; i < x; i++) {
        if (s[i] == 'A') {
            a = i;
            break;
        }
    }
    for (int i = x - 1; i >= 0; i--) {
        if (s[i] == 'Z') {
            b = i;
            break;
        }
    }
    printf("%d\n", b - a + 1);
}


Measured memory_bytes: 384
using System;
using System.Linq;

public class Program
{
    public static void Main(string[] args)
    {
        var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var total = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray().Sum();
        Console.WriteLine(vals[0] <= total ? "Yes" : "No");
    }
}

Measured memory_bytes: 18144
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin>>s;
	int n=s.size(),sum=0,ma=0;
	for(int i=0; i<n; i++) {
		if(s[i]=='A'||s[i]=='T'||s[i]=='G'||s[i]=='C') {
			sum++;
		} else {
			if(sum>ma) {
				ma=sum;
			}
			sum=0;
		}
	}
	if(sum>ma) {
		ma=sum;
	}
	cout<<ma<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <cstdint>
#include <bits/stdc++.h>
#include <queue>
#include <set>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for (int i = n - 1; i >= 0; i--)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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 (b < a)
  {
    a = b;
    return 1;
  }
  return 0;
}

using namespace std;
using uif = uint_fast64_t;
using ll = long long int;

int qp(int a, ll b)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % mod;
    a = 1ll * a * a % mod;
  } while (b >>= 1);
  return ans;
}
int qp(int a, ll b, int mo)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % mo;
    a = 1ll * a * a % mo;
  } while (b >>= 1);
  return ans;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll, ll);
ll mod_add(ll, ll);
ll mod_mul(ll, ll);
ll mod_div(ll, ll);
void make_fact(ll);
void make_invfact(ll);

int main(void)
{

  ll n;
  cin >> n;
  string s;
  cin >> s;

  string ans = "";
  for (auto c : s)
  {
    ll diff = (ll)(c - 'A');
    ll next = (diff + n) % 26;
    ll ac = (char)('A' + next);
    ans += ac;
  }

  cout << ans << endl;
  return 0;
}

ll mod_pow(ll x, ll r)
{
  if (r == 0)
    return 1;
  else if (r == 1)
    return x % mod;
  else if (r % 2 == 0)
  {
    ll t = mod_pow(x, r / 2) % mod;
    return t * t % mod;
  }
  else
  {
    ll t = mod_pow(x, r / 2) % mod;
    ll k = t * t % mod;
    return k * x % mod;
  }
}
ll mod_add(ll a, ll b)
{
  return (a + b) % mod;
}

ll mod_mul(ll a, ll b)
{
  return (a * b) % mod;
}

ll mod_div(ll a, ll b)
{
  return mod_mul(a, mod_pow(b, mod - 2));
}

void make_fact(ll n)
{
  fac[0] = 1;
  rep(i, n)
  {
    fac[i + 1] = mod_mul(fac[i], i + 1);
  }
}

void make_invfact(ll n)
{
  invfac[n] = mod_pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
  {
    invfac[i] = mod_mul(invfac[i + 1], i + 1);
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    while(cin>>n>>m){
           int tmp=0,res=0;
           for(int i=0;i<m;i++){cin>>tmp;res=max(res,tmp);}
           res=res*2-n-1;
           if(res<=0)cout<<0<<endl;
           else cout<<res<<endl;
    }
    
}

Measured memory_bytes: 256
n=int(input());l=list(map(int,input().split()));p=[0]*n;d=[0]*n
for i in range(n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]if(i&1)else d[i-1],l[i]+d[i-2])
print(d[-1])

Measured memory_bytes: 39284
//2018年  3月 23日 金曜日 23:25:35 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;
ll S[MAX_N], AS[MAX_N];

void solve() {
	cin >> N >> K;
	rep(i, 0, N) {
		ll a;
		cin >> a;
		S[i + 1] = S[i] + a;
		AS[i + 1] = AS[i] + max(a, 0LL);
	}
	ll res = 0;
	rep(i, 0, N - K + 1) {
		MAX(res, max(S[i + K] - S[i], 0LL) + (AS[N] - AS[0]) - (AS[i + K] - AS[i]));
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main() {
	int q; scanf("%d", &q);
	while (q --) {
		int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d);
		int L = (a + b) / (min(a, b) + 1);
		int x, y;
		if (1LL * a * L <= b) {x = 0; y = a + b;}
		else if (1LL * b * L <= a) {x = a + b; y = 0;}
		else {
			x = (1LL * a * L - b) / (L - 1);
			y = (1LL * b * L - a) / (L - 1);
		}
		for (int i = c; i <= d; ++ i) {
			if (i <= x) putchar(i % (L + 1) == 0 ? 'B' : 'A');
			else if (a + b - i + 1 <= y) putchar((a + b - i + 1) % (L + 1) == 0 ? 'A' : 'B');
			else putchar(a - x + x / (L + 1) - y / (L + 1) == 0 ? 'B' : 'A');
		}
		puts("");
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll N;
  cin >> N;
  vll a(N);
  vll d(N+1, 0);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    d.at(i+1) = d.at(i) + a.at(i);
  }
  ll ans = INF;
  for(int i = 1; i < N; i++){
    ll snuke = d.at(i) - d.at(0);
    ll arai = d.at(N) - d.at(i);
    chmin(ans, abs(snuke-arai));
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
    long long n;
    cin>>n;
    vector<long long> a(n);
    for(long long i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(!is_sorted(a.begin(),a.end()))
    {
        prev_permutation(a.begin(),a.end());
        for(long long i=0;i<n;i++)
        {
            if(i)
                cout<<" ";
            cout<<a[i];
        }
        cout<<endl;
        next_permutation(a.begin(),a.end());
    }
    for(long long i=0;i<n;i++)
    {
        if(i)
            cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
    if(next_permutation(a.begin(),a.end()))
    {
        for(long long i=0;i<n;i++)
        {
            if(i)
                cout<<" ";
            cout<<a[i];
        }
        cout<<endl;
        prev_permutation(a.begin(),a.end());
    }
    return 0;
}



Measured memory_bytes: 3116
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;


int main()
{
	ll N;
	cin >> N;

	if (N % 2 == 1)
	{
		cout << 0 << endl;
		return 0;
	}

	ll ans = 0;
	for (ll i = 10; N >= i; i *= 5)
	{
		ans += N / i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int main(){
  int k,s;
  cin >> k >> s;
  int cnt = 0;
  for(int x = 0;x<=k;++x){
    for(int y = 0;y<=k;++y){
        if(s >= x + y){
          if(s - (x+y) <= k) cnt++;
        };
    }
  }
  cout << cnt << endl;
}

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<double> VD;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793238

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

ll N;

signed main() {
    cin >> N;
    VL H(N);
    ll ans = 0, cnt = 0;
    REP(i, N) {
        cin >> H[i];
        if(i && H[i - 1] >= H[i]) {
            cnt++;
        } else {
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    cout << max(ans, cnt) << "\n";
}


Measured memory_bytes: 1024
n = int(input())
list_p = list(map(int,input().split()))
list_q = list(map(int,input().split()))
list1 = sorted(list_p)
list2 = sorted(list_q)

import math

lista=[]
listb=[]

for i in range(n-1):
    lista.append((list1.index(list_p[i]))*math.factorial(n-i-1))
    listb.append((list2.index(list_q[i]))*math.factorial(n-i-1))
    list1.remove(list_p[i])
    list2.remove(list_q[i])
    
print(abs(sum(lista)-sum(listb)))

Measured memory_bytes: 3064
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

VV(int) G0;
VV(int) G1;
vint ans = {INT_MAX};
vint cand;

pii farest(int u, int par = -1, int d = 0){
	pii ret(d, u);
	for(int v : G0[u]){
		if(v == par){ continue; }
		pii p = farest(v, u, d + 1);
		chmax(ret, p);
	}
	return ret;
}

bool reroot(int u, int par){
	auto &g = G1[u];
	for(int v : G0[u]){
		if(v == par){ continue; }
		g.push_back(v);
		if(!reroot(v, u)){ return false; }
	}
	sort(ALL(g), [](int x, int y){ return G1[x].size() > G1[y].size(); });
	if(g.size() > 1 && !G1[g[1]].empty()){ return false; }
	return true;
}

void calccand(int u){
	auto &g = G1[u];
	if(g.empty()){
		cand.push_back(cand.size() + 1);
	}
	else{
		int sz = g.size();
		calccand(g[0]);
		int self = cand.size() + 1;
		for(int i = 1; i < sz; ++i){
			cand.push_back(cand.size() + 2);
		}
		cand.push_back(self);
	}
}

void check(int root){
	initvv(G1, G0.size(), 0);
	if(reroot(root, -1)){
		cand.clear();
		calccand(root);
		chmin(ans, cand);
	}
}

void mainmain(){
	int n;
	scanf("%d", &n);
	G0.resize(n + 1);
	for(int i = 1; i < n; ++i){
		int v, w;
		scanf("%d%d", &v, &w);
		G0[v].push_back(w);
		G0[w].push_back(v);
	}

	int r1 = farest(1).second;
	int r2 = farest(r1).second;

	check(r1);
	check(G0[r1][0]);
	check(r2);
	check(G0[r2][0]);

	if(ans[0] == INT_MAX){ ans = {-1}; }
	const char *spl = "";
	for(int x : ans){
		printf("%s%d", spl, x);
		spl = " ";
	}
	puts("");
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 20476
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC70(void);
void ABC71(void);
void ABC72(void);
void ABC73(void);
void ABC74(void);
void ABC75(void);
void ABC76(void);
void ABC77(void);
void ABC78(void);
void ABC79(void);

int main(void){
    ABC72();
}

void ABC72(){
    string s;
    cin>>s;
    for(int i=0;i<s.length();i+=2){
        cout<<s[i];
    }
    cout<<endl;
}

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

using namespace std;

#define int long long
#define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt(x) __builtin_popcount(x)
#define lbit(x) __builtin_ffsll(x)
#define rbit(x) __builtin_clzll(x)
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()

template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
// const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793238

ll N, M;

signed main() {
    LCIN(N);
    ll cnt = 0;
    cout << (N-1) / 2 << "\n";
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!(n: usize, a: [usize; n]);
    let mut b = vec![0; 100002];
    for x in a {
        b[x] += 1;
        b[x + 1] += 1;
        b[x + 2] += 1;
    }
    println!("{}", b.iter().max().unwrap());
}


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

int main(){
    int n;
    cin>>n;
    
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(&a[0],&a[n]);
    for(int i=1;i<n-1;i++) a[0]+=a[i];
    
    if(a[n-1]>=a[0])cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
A,B= list(map(int,input().split()))
import collections
a=[]
if A == 1:
   print(B)
   exit()
def solve(N):
   for i in range(2, int(N**0.5) + 1):
      if N % i == 0:
         while N % i == 0:
            a.append(i)
            N //= i
   return a
f_ans=1
ans=list(collections.Counter(solve(B)).most_common())
for i,j in ans:
   if j // A < 1:
      break
   else:
      f_ans*=i**(j // A)
print(f_ans)

Measured memory_bytes: 9636
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int low = 0, high = 1;
    rep(i, 1, N) {
        if (A[i] <= A[i - 1]) {
            low = 1, high = N;
        }
    }

    list<pair<int, int>> digit;

    while (high - low > 1) {
        int mid = (low + high) / 2;
        bool ans = true;

        digit.clear();
        digit.emplace_back(A[0], 0);

        rep(i, 1, N) {
            if (A[i] > A[i - 1]) {
                digit.emplace_back(A[i], 0);
            }
            else {
                while (!digit.empty() && digit.back().first > A[i]) {
                    digit.pop_back();
                }

                if (digit.empty() || digit.back().first != A[i]) {
                    digit.emplace_back(A[i], 0);
                }
                digit.back().second++;

                auto it = prev(digit.end());
                while ((*it).second == mid) {
                    if ((*it).first == 1) {
                        ans = false;
                        break;
                    }

                    auto pre = it == digit.begin() || (*prev(it)).first != (*it).first - 1 ?
                        digit.emplace(it, (*it).first - 1, 0) :
                        prev(it);

                    (*pre).second++;
                    (*it).second = 0;
                    it = pre;
                }
                if (!ans) break;
            }
        }

        if (ans) high = mid;
        else low = mid;
    }

    write(high);
}

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

int main(){
    int n;
    cin >> n;
    vector <int> b(n-1);
    rep(i,n-1) cin >> b[i];
    ll ans;
    ans=b[0];
    rep(i,n-2){
        
        ans+=min(b[i],b[i+1]);
        
    }
    ans+=b[n-2];
    cout << ans << endl;

    return 0;
}

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

int main()
{
    int d, g;
    cin >> d >> g;
    vector<int> p(d);
    vector<int> c(d);
    for (int i = 0; i < d; i++)
    {
        cin >> p[i] >> c[i];
    }
    int min_problems = 100000001;
    for (int tmp = 0; tmp < (1 << d); tmp++)
    {
        int score = 0;
        int problems = 0;
        bitset<10> bs(tmp);
        for (int i = 0; i < 10; i++)
        {
            if (bs.test(i) == true)
            {
                score += p[i] * (i + 1) * 100 + c[i];
                problems += p[i];
            }
        }
        if (score < g) 
        {
            int max_unsolved;
            for (int i = d - 1; i >= 0; i--)
            {
                if (bs.test(i) == false)
                {
                    max_unsolved = i;
                    break;
                }
            }
            for (int i = 0; i < p[max_unsolved] - 1; i++)
            {
                score += (max_unsolved + 1) * 100;
                problems++;
                if (score >= g) break;
            }
        }
        if (score >= g)
        {
            min_problems = min(problems, min_problems);
        }
    }
    cout << min_problems << endl;
}

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

int main() {
	int W, a, b;
	cin >> W >> a >> b;
	if(a <= b && a+W >= b){
		cout << 0 << endl;
		return 0;
	}
	if(b <= a && b+W >= a){
		cout << 0 << endl;
		return 0;
	}
	
	cout << min(abs(b-a-W),abs(a-b-W)) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0066
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) return;
                Console.WriteLine(judge(line));
            }
        }

        private static char judge(string line)
        {
            List<int[]> winPattern = new List<int[]>
            {
                 new int[] {0,1,2}
                ,new int[] {3,4,5}
                ,new int[] {6,7,8}
                ,new int[] {0,3,6}
                ,new int[] {1,4,7}
                ,new int[] {2,5,8}
                ,new int[] {0,4,8}
                ,new int[] {2,4,6}
            };

            foreach (int[] item in winPattern)
            {
                var res = item.Select(x => line[x]).Distinct();
                if (res.Count() == 1 && res.First() != 's') return res.First();
            }
            return 'd';
        }
    }

}



Measured memory_bytes: 16168
#include<stdio.h>
long long int abs(long long int a){
  return a<0?-1*a:a;
}
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  long long int c[a],d[a-b+1];
  for(int i=0; i<a; i++){scanf("%lld",&c[i]);}
  for(int i=0; i<a-b+1; i++){
    long long int e=abs(c[i])<abs(c[i+b-1])?abs(c[i]):abs(c[i+b-1]);
    d[i]=(c[i+b-1]-c[i])+e;
  }
  long long int f=d[0];
  for(int i=1; i<a-b+1; i++){
    if(f>d[i]){f=d[i];}
  }
  printf("%lld",f);
  return 0;}


Measured memory_bytes: 1280
n=int(input())
a=list(map(int,input().split()))
from collections import Counter
C=Counter(a)
q=int(input())
s=sum(a)
for _ in range(q):
    b,c=map(int,input().split())
    s+=c*C[b]
    s-=b*C[b]
    print(s)
    C[c]+=C[b]
    C[b]=0


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

int main() {
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = min(a, d);
	int temp = min(a, d);
	a -= temp, d -= temp;
	temp = min(b, d);
	a -= temp, d -= temp;
	ans -= min(d, c);
	cout << ans;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
typedef long long int ll;
const ll N = 1e5 +9;
const ll p = 31;
// const ll m = 1e9 + 7;
const ll inf= 1e14;
const ll mod = 1e9+7;
#define x first
#define y second
#define pb push_back
#define mp make_pair
using pii = pair<ll, ll>;
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
    
int main()
{   
    ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);                          

    ll T= 1;
    // cin >> T;
    while(T--){
        string s;cin>>s;
        ll ct[1000];
        memset(ct,0,sizeof(ct));
        for(int i = 0;i<4;i++){
            ct[s[i]]++;
        }
        bool f  =0;
        for(int i = 0;i<4;i++){
            if(ct[s[i]]!=2 && ct[s[i]]!=0){
                f = 1;
            }
        }
        if(f){
            cout<<"No"<<'\n';
        }
        else{
            cout<<"Yes"<<'\n';
        }
    }
    return 0;
}   

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		int x3 = 0, y3 = 0, x4 = 0, y4 = 0, diff = 0, a = 0, b = 0;

		if (x1 == x2) {
			diff = Math.abs(y1 - y2);
			y3 = y2;
			y4 = y1;
			if (y1 > y2) {
				x3 = x1 + diff;
				x4 = x1 + diff;
			} else {
				x3 = x1 - diff;
				x4 = x1 - diff;
			}
		} else if (y1 == y2) {
			diff = Math.abs(x1 - x2);
			x3 = x2;
			x4 = x1;
			if (x1 > x2) {
				y3 = y1 - diff;
				y4 = y1 - diff;
			} else {
				y3 = y1 + diff;
				y4 = y1 + diff;
			}
		} else {
			a = x1 - x2;
			b = y1 - y2;
			y3 = y2 - a;
			x3 = x2 + b;
			y4 = y3 + b;
			x4 = x3 + a;

		}

		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);

		sc.close();
	}
}

Measured memory_bytes: 21844
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int T[110] = { 0 };
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	T[A]++;
	T[B]--;
	T[C]++;
	T[D]--;

	rep(i, 0, 105)
	{
		T[i + 1] += T[i];
	}

	int ans = 0;
	rep(i, 0, 105)
	{
		if (T[i] == 2)ans++;
	}

	cout << ans << endl;

	return 0;
}

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

typedef long long ll;


int main()
{
	
	ll r, c, m;
	cin >> r >> c >> m;

	vector<ll> R(r);
	vector<ll> C(c);

	ll max_row = 0, max_col = 0;


	map<pair<ll, ll>, bool> M;

	while(m--){
		ll i, j;
		cin >> i >> j;
		R[i-1]++;
		C[j-1]++;

		M[make_pair(i-1, j-1)] = 1;

		max_row = max(max_row, R[i-1]);
		max_col = max(max_col, C[j-1]);
	}

	vector<ll> max_rows, max_cols;

	for(int i = 0; i < r; i++){
		if(R[i] == max_row)
			max_rows.push_back(i);
	}

	for(int i = 0; i < c; i++){
		if(C[i] == max_col)
			max_cols.push_back(i);
	}

	ll ans = max_row + max_col - 1;
	bool f = 0;

	for(int i = 0; i < max_rows.size() and !f; i++){
		for(int j = 0; j < max_cols.size() and !f; j++){
			if(M[make_pair(max_rows[i], max_cols[j])] == 0){
				f = 1;
			}
		}
	}

	if(f)
		ans++;

	cout << ans << "\n";
}

Measured memory_bytes: 35076