akhauriyash/Code-Regression huggingface dataset:
while True:
 n,k = map(int,input().split())
 if n==0 and k==0: break
 
 a = [int(input()) for i in range(n)]

 s = sum(a[0:k])
 max = s

 for i in range(k,n):
  s = s+a[i]-a[i-k]
  if s > max: max = s
 
 print(max)


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	auto A=vecin(N);
	int K=*max_element(ALL(A));
	vector<int> B(N),C(K+1,0);
	
	for(int i=0;i<N;i++){
		C[A[i]]++;
	}
	for(int i=1;i<=K;i++){
		C[i] += C[i-1];
	}
	for(int i=N-1;i>=0;i--){
		B[C[A[i]]-1] = A[i];
		C[A[i]]--;
	}

	REP(i,N-1){
		cout << B[i] << ' ';
	}
	out(B[N-1]);

	return 0;
}



Measured memory_bytes: 18684
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	string input;
	cin >> input;
	input[5] = input[13] = ' ';
	cout << input << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

#define ff              first
#define ss              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii             map<ll,ll>
#define pqb             priority_queue<ll>
#define pqs             priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mx 3000
ll n,m;

int main(){

    FIO;
    ll a,c,d,e,f=0,sum=0,ck,k,p,q,r,t,add=0,w,x,y,z;
    cin>>n>>x;
    unordered_set<int> s;
    for(int i=0;i<x;i++)
    {
        cin>>a;
        s.insert(a);
    }
    if(s.find(n)==s.end()){
        cout<<n;return 0;
    }
    int i=1;
    while(1){
        if(s.find(n-i)==s.end())
        {
            cout<<n-i;return 0;
        }
        if(s.find(n+i)==s.end()){
            cout<<n+i;return 0;
        }
        i++;
    }
}





Measured memory_bytes: 3632
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-

n=int(input())
w=[]
ans=chk=0
for i in range(n):
    a=int(input())
    t=[]
    for j in range(a):
        x,y=map(int,input().split())
        t.append((x,y))
    w.append(t)
for i in range(1,2**n):
    l=[0]*n
    for j in range(n):
        if i&1: l[j]=1
        i=i>>1
    chk=1
    for j in range(n):
        if l[j]:
            for k in w[j]:
                if l[k[0]-1]!=k[1]:
                    chk=0
                    break
    if chk: ans=max(ans,sum(l))
print(ans)


Measured memory_bytes: 73872
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int A;
  cin >> A;
  int B = 0;
  for(int i = 1800; i >= 400; i -= 200) {
    B++;
    if(i <= A) {
      cout << B << endl;
      break;
    }
  }
}


Measured memory_bytes: 3596
while 1:
    a=[i+1 for i in range(10)]
    try:b=list(map(int,input().split()))
    except:break
    s=20-sum(b[:2])
    for i in range(3):a.pop(a.index(b[i]))
    print('YES' if sum([1 for i in a if i<=s])/7>=0.5 else 'NO')

Measured memory_bytes: 7704
#include<cstdio>
#include<vector>
const int N=3e5+5;
int n,m,L[N],R[N],B[N],c[N],s;
std::vector<int>X[N],Y[N];
inline void add(int i,int x){for(;i<=m;i+=i&-i)B[i]+=x;}
inline int ask(int i){int x=0;for(;i;i&=i-1)x+=B[i];return x;}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%d%d",L+i,R+i);
		int l=R[i]-L[i]+1;
		++c[l],X[l].push_back(L[i]),Y[l].push_back(R[i]+1);
	}
	for(int i=m;i;--i)c[i]+=c[i+1];
	for(int i=1;i<=m;++i){
		s=c[i];
		for(int j=i;j<=m;j+=i)s+=ask(j);
		printf("%d\n",s);
		for(int x:X[i])add(x,1);
		for(int x:Y[i])add(x,-1);
	}
	return 0;
}

Measured memory_bytes: 25984
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;

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

  int x;
  cin >> x;

  int cur = 0;
  for (int i = 0; ; i++) {
    cur += i;
    if (x <= cur) { cout << i << endl; return 0; }
  }
  return 0;
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

string s;
int ans = 0;
int main() {
    cin >> s;
    rep(i,0,3) if(s[i] == '1') ans++;
    pout(ans);
    return 0;
}

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

string str, order, re;
char tmp;
int q, a, b;

int main(){
  cin >> str >> q;
  for(int i = 0; i < q; i++){
    cin >> order >> a >> b;
    if(order == "print"){
      for(int j = a; j <= b; j++){
        cout << str[j];
      }
      cout << endl;
    }else if(order == "reverse"){
      reverse(str.begin()+a, str.begin()+b+1);
    }else if(order == "replace"){
      cin >> re;
      str.replace(a, b - a + 1, re);
    }
  }
}

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

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

    if (N < 10) {
        cout << N << endl;
    }
    else if (N < 100) {
        cout << "9" << endl;
    }
    else if (N < 1000) {
        cout << N - 100 + 1 + 9 << endl;
    }
    else if (N < 10000) {
        cout << "909" << endl;
    }
    else if (N < 100000) {
        cout << N - 10000 + 1 + 909 << endl;
    }
    else cout << "90909" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	ll H,W,N;
	int a[100001],b[100001];
	map<pint,int> kuro;
	scan(H>>W>>N);
	rep(k,N){
		int a,b;
		scan(a>>b);
		a--;
		b--;
		for(int i=max(0,a-2);i<=min((ll)a,H-3);i++){
			for(int j=max(0,b-2);j<=min((ll)b,W-3);j++){
				kuro[{i,j}]++;
			}
		}
	}
	int kosu[10]={};
	int nonzero=0;
	for(auto x:kuro){
		kosu[x.second]++;
		nonzero++;
	}
	rep(j,10){
		if(j==0) prin((H-2)*(W-2)-nonzero);
		else prin(kosu[j]);
	}
	return 0;
}


Measured memory_bytes: 56448
# Wrote in Mar 22, 2020 22:29 by reetok
require 'time'
require 'prime'
require 'bigdecimal'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=".to_i")
  t = []
  n.times do
    t.push(eval("gets.chomp#{datatype}"))
  end
  return t
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
class Integer
  def divisor_list
    devisors = [1]
    2.upto(self/2) do |i|
      devisors << i if self%i == 0
    end
    devisors << self
    return devisors.uniq.sort
  end
end
class Array
  def upper(a) #aより上
    self.sort.select{|n|n>=a}
  end
  def downer(a) #aより下
    self.sort.select{|n|n<=a}
  end
end
#---------------

n,m = inp

puts (1..n).to_a.combination(2).to_a.count+(1..m).to_a.combination(2).to_a.count

Measured memory_bytes: 2680
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_V 5000
using namespace std;
typedef long long ll;
typedef pair<vector<vector<char> >,int> P;
const long long int MOD = 1000000007;
const int INF = 1000000000;

struct edge{int to, cap, rev; };

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from, int to, int cap){
	G[from].push_back((edge){to, cap, G[to].size()});
	G[to].push_back((edge){from, 0, G[from].size()-1});
}

void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while(!que.empty()){
		int v = que.front(); que.pop();
		for(int i = 0; i < 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 < 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 max_flow(int s, int t){
	int flow = 0;
	for(;;){
		bfs(s);
		if(level[t] < 0) return flow;
		memset(iter,0, sizeof(iter));
		int f;
		while((f = dfs(s, t, INF)) > 0){
			flow += f;
		}
	}
}

int n, m, l;
int dist[100][100];
int p[1000], t[1000];

void solve(){
    rep(i,MAX_V) G[i].clear();
    rep(i,n) rep(j,n) dist[i][j] = INF;
    rep(i,n) dist[i][i] = 0;
    rep(i,m){
        int u, v, d;
        cin >> u >> v >> d;
        dist[u][v] = d;
        dist[v][u] = d;
    }
    rep(i,n) rep(j,n) rep(k,n) dist[j][k] = min(dist[j][k],dist[j][i]+dist[i][k]);
    rep(i,l){
        cin >> p[i] >> t[i];
    }
    rep(i,l){
        rep(j,l){
            if(i == j) continue;
            if(dist[p[i]][p[j]] <= t[j]-t[i]){
                add_edge(i,j+l,1);
            }
        }
    }
    rep(i,l) add_edge(2*l,i,1);
    rep(i,l) add_edge(i+l,2*l+1,1);
    cout << l-max_flow(2*l,2*l+1) << endl;
}

int main(){
    while(cin >> n >> m >> l){
        if(n == 0 && m == 0 && l == 0) break;
        solve();
    }
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N, Q; cin >> N >> Q;
	vector<pair<int, Pi>> data(N);
	vint ans(Q, -1);
	set<Pi> li;

	for (auto &v : data) {
		cin >> v.second.first >> v.second.second >> v.first;
	}
	sort(begin(data), end(data));

	for (int i = 0; i < Q; i++) {
		int D; cin >> D;
		li.emplace(D, i);
	}
	
	for (auto &v : data) {
		int s = v.second.first - v.first, t = v.second.second - v.first;

		auto eo = li.lower_bound(Pi(t, -INF));

		for (auto itr = li.lower_bound(Pi(s, -INF)); itr != eo;) {
			ans[itr->second] = v.first;
			auto nitr = itr;
			nitr++;
			li.erase(itr);
			itr = nitr;
		}
	}
	
	for (int i = 0; i < Q; i++) {
		cout << ans[i] << endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, L;
  cin >> N >> L;
  vector<int> A(N);
  for (auto&& e : A) {
    cin >> e;
  }
  for (int i = 0; i < N - 1; i++) {
    if (A[i] + A[i + 1] < L) continue;
    cout << "Possible" << '\n';
    for (int j = 0; j < i; j++) {
      cout << j + 1 << '\n';
    }
    for (int j = N - 1; j > i; j--) {
      cout << j << '\n';
    }
    return 0;
  }
  cout << "Impossible" << '\n';
  return 0;
}


Measured memory_bytes: 3724
#include<stdio.h>
int main(){
  double c[256][30];
  int n,m,u,mi,e,i,j,k,l,mj,t[10];
  double min;
  while(scanf("%d %d %d %d %d",&u,&n,&m,&mi,&e),u){
    for(i=0;i<u;i++)scanf("%d",&t[i]);
    int d[31][31]={0};
    while(m--){
      scanf("%d %d %d",&i,&j,&k);
      d[i][j]=d[j][i]=k;
    }
    int f[300][30]={0};
    for(i=0;i<1<<u;i++){
      for(j=1;j<=n;j++)c[i][j]=100000000;
    }
    c[mj=0][mi]=0;
    for(i=0;i<1<<u;i++){
      for(j=0;j<n;j++){
	f[mj][mi]=1;
	for(k=1;k<=n;k++){
	  if(d[mi][k]==0)continue;
	  for(l=0;l<u;l++){
	    if(mj&1<<l)continue;
	    if(c[mj|1<<l][k]>c[mj][mi]+1.0*d[mi][k]/t[l]){
	       c[mj|1<<l][k]=c[mj][mi]+1.0*d[mi][k]/t[l];
	    }
	  }
	}
	min=2100000000;
	for(k=1;k<=n;k++){
	  for(l=0;l<1<<u;l++){
	    if(f[l][k])continue;
	    if(min>c[l][k])min=c[mj=l][mi=k];
	  }
	}
      }
    }
    /*for(i=0;i<1<<u;i++){
      for(j=1;j<=n;j++)printf("%12.2f ",c[i][j]);
      printf("\n");
      }//*/
    min=210000000;
    for(i=0;i<1<<u;i++){
      if(min>c[i][e])min=c[i][e];
    }
    if(min-100000000)printf("%f\n",min);
    else             printf("Impossible\n");
  }
  return 0;
}
    

Measured memory_bytes: 744
#include <iostream>
#include <string>

using namespace std;
int main()
{
  string S;
  int K;
  cin >> K >> S;

  if (S.length() <= K)
  {
    cout << S << endl;
  }
  else
  {
    cout << S.substr(0, K) << "..." << endl;
  }

  return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define f first
#define s second
#define endl "\n"
#define M 1000000007
#define pb push_back
#define pf push_front
#define eb emplace_back
#define MM_PI 3.14159265358979323846
#define TEST_CASE int t;cin>>t;while(t--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
//template<typename T> T pow(T a, T b, long long m) {T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; }
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
const int maxn = 1e5 + 10;
ll n;
ll arr[maxn][3];
ll cache[maxn][3];
ll dp(int i, int taken) {
	if (i == n)return 0;
	if (cache[i][taken] != -1)return cache[i][taken];
	if (taken == 0) {
		cache[i][taken] = max(arr[i][1] + dp(i + 1, 1), arr[i][2] + dp(i + 1, 2));
	}
	else if (taken == 1) {
		cache[i][taken] = max(arr[i][0] + dp(i + 1, 0), arr[i][2] + dp(i + 1, 2));
	}
	else if (taken == 2) {
		cache[i][taken] = max(arr[i][0] + dp(i + 1, 0), arr[i][1] + dp(i + 1, 1));
	}
	return cache[i][taken];
}
void solve() {
	cin >> n;
	memset(cache, -1, sizeof(cache));
	for (int i = 0; i < n; i++) {
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	}
	ll ans = max(arr[0][0] + dp(1, 0), max(arr[0][1] + dp(1, 1), arr[0][2] + dp(1, 2)));
	cout << ans << endl;
}
int main() {

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	//IOS
	//make();
	//TEST_CASE
	solve();
	return 0;
}



Measured memory_bytes: 11136
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] sp = line.split(" ");
		int n = Integer.parseInt(sp[0]);
		line = br.readLine();
		sp = line.split(" ");
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(sp[i]);
		}

		long min = Integer.MAX_VALUE;
		long max = 0;
		int count = 0;
		for (int i = 0; i < n; i++) {
			min = Math.min(min, a[i]);
			if (a[i] - min > max) {
				max = a[i] - min;
				count = 1;
			}
			else if (a[i] - min == max) {
				max = a[i] - min;
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 34168
#include <iostream>
#include <queue>
#include <utility>
using namespace std;

int N;
int a,b;
int D1[100010] = {0};
int DN[100010] = {0};
int V[100010] = {0};

void bfs1(vector<vector<int>>& v,int src){
	queue<int> Q;
	Q.push(src);
	D1[src] = 0;
	V[src] = 1;
	while(!Q.empty()){
		int cur = Q.front();
		Q.pop();
		for(int i=0;i<v[cur].size();i++){
			if(V[v[cur][i]]==0){
				D1[v[cur][i]] = D1[cur]+1;
				Q.push(v[cur][i]);
				V[v[cur][i]] = 1;
			}
		}
	}
	for(int i=1;i<=N;i++){
		V[i]=0;
	}
}

void bfsN(vector<vector<int>>& v,int src){
	queue<int> Q;
	Q.push(src);
	DN[src] = 0;
	V[src] = 1;
	while(!Q.empty()){
		int cur = Q.front();
		Q.pop();
		for(int i=0;i<v[cur].size();i++){
			if(V[v[cur][i]]==0){
				DN[v[cur][i]] = DN[cur]+1;
				Q.push(v[cur][i]);
				V[v[cur][i]] = 1;
			}
		}
	}
}


int main(){
	cin >> N;
	vector<vector<int>> v(N+1);
	for(int i=1;i<=N-1;i++){
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	bfs1(v,1);
	bfsN(v,N);
	int c1 = 0,cN = 0;
	for(int i=1;i<=N;i++){
		if(D1[i]<=DN[i]) c1++;
		else cN++;
	}
	//cout << c1 << " " << cN << endl;
	if(c1>cN) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int main(void){
    int a, b; cin >> a >> b;

    if(b > 0) b = max(0, a);

    int sign = 0;
    if(a < 0){
        sign = (b - a) % 2;
        if(sign == 0) sign = -1;
    }
    else if(a > 0){
        sign = 1;
    }
    if(b == 0) sign = 0;

    string res = "Zero";
    if(sign == 1) res = "Positive";
    else if(sign == -1) res = "Negative";

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int INF = 10000000000;
const int MOD = 1000000007;
using Data = pair<long long, vector<ll> >;

int main() {
  int n,x;
  cin >> n >> x;
  int ans=n;
  vector<int>m(n);
  rep(i,n){
    cin >> m[i];
    x-=m[i];
  }
  sort(m.begin(),m.end());
  ans+=x/m[0];
  cout << ans << endl;
}

Measured memory_bytes: 256
#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<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(ll 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 complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    ll N, L; cin >> N >> L;
    vector<ll> apple(N);
    ll sum = 0;
    rep(i, N) {
        apple[i] = L + i;

      sum += apple[i];
    }
    ll mini, ans;
    mini = INF;
    rep(i, N) {
        if(abs(apple[i]) < mini) {
            mini = abs(apple[i]);
            ans = sum - apple[i];
        }
    }
    cout << ans << endl;
	return 0;
}

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

const int MAX_N = 102;
char str[MAX_N] = {0};
int num;

int find(int index) {
	set<char> s;
	int sum = 0;
	for (int i = 0; i < index; i++)
		s.insert(str[i]);
	for (int i = index; i < num; i++) {
		if (s.find(str[i]) != s.end()) {
			sum++;
			s.erase(str[i]);
		}
	}
	return sum;
}

int main() {
	cin >> num;
	scanf("%s", str);

	int sum = 0;
	for (int i = 1; i < num; i++) {
		sum = max(find(i),sum);
	}
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

#include <bits/stdc++.h>


using namespace std;

#define INPUT_INT(valName) int valName; cin >> valName
#define INPUT_LLINT(valName) long long int valName; cin >> valName;
#define INPUT_STR(valName) string valName; cin >> valName;
#define INPUT_LINE(valName) string valName; getline(cin,s);
#define INPUT_VECTOR_INT(valName, N) vector<int> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }
#define INPUT_VECTOR_DOUBLE(valName, N) vector<double> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }

#define OUTPUT(A) cout << (A) << endl;
#define OUTPUT2(A, B) cout << (A) << " " << (B) << endl;
#define OUTPUT3(A, B, C) cout << (A) << " " << (B) << " " << (C) << endl;

#define REP(valName, N) for(int valName = 0; valName < N; ++valName)

vector<string> split(const string& str, char delimiter) {
	vector<string> ret;
	string tmp = "";
	for (auto c : str) {
		if (c != delimiter) {
			tmp.push_back(c);
		} else {
			ret.push_back(tmp);
			tmp = "";
		}
	}
	ret.push_back(tmp);
	return ret;
}

template <typename T> void sortAsc(vector<T>& v) { sort(v.begin(), v.end(), less<T>()); }
template <typename T> void sortDesc(vector<T>& v) { sort(v.begin(), v.end(), greater<T>()); }

template <typename T> void insert(vector<T>& dest, const vector<T>& src) { copy(src.begin(), src.end(), back_inserter(dest)); }

template <long long int MOD> long long int mod_inv(long long int a) {
	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;
	return u;
}

template <long long int MOD> long long int mod_add(long long int a, long long int b) {
	return (a + b) % MOD;
}

template <long long int MOD> long long int mod_sum(long long int a, long long int b) {
	return (a - b) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b) {
	return (a % MOD) * (b % MOD) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b, long long int c) {
	return mod_mul<MOD>(a, mod_mul<MOD>(b, c));
}

template <long long int MOD> long long int mod_div(long long int a, long long int b) {
	return (a % MOD) * mod_inv<MOD>(b) % MOD;
}


//------------------------------------------------------------------------------------------------------------------------------

int f(vector<vector<int>>& A, vector<int>& consumed, int N) {
	
	bool changed = false;
	vector<int> consumedNext = consumed;

	for (int i = 0; i < N-1; ++i) {
		for (int j = i + 1; j < N; ++j) {
			
			if (A[i][consumed[i]] == A[j][consumed[j]]) {
				++consumedNext[i];
				++consumedNext[j];
				changed = true;
			}

		}
	}

	consumed = consumedNext;

}

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

	INPUT_INT(N);

	OUTPUT(N * N* N);

	return 0;
}

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

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

    vector<pair<ll,ll>> pairs(N);
    for(ll i=0;i<N;i++)
    {
        ll x,y;
        cin >> x >> y;
        pairs[i] = make_pair(x,y);
    }

    ll M = (N * (N-1)) / 2;

    vector<double> L;

    for(ll i = 0;i<N-1;i++)
    {
        for(ll j = i+1;j<N;j++)
        {
            ll x = (pairs[i].first - pairs[j].first);
            ll y = (pairs[i].second - pairs[j].second);

            double len = sqrt(x*x + y*y);
            L.push_back(len);
        }
    }

    ll kaijou=1;
    for(ll i = 2;i<=N;i++)
    {
        kaijou = kaijou * i;
    }
    ll key = (2*kaijou)/N;

    double sum = 0.0;
    for(ll i = 0;i<M;i++)
    {
        sum += L[i]*(double)key;
    }    

    double ans = (double)sum / (double)kaijou;

    printf("%.10lf\n",ans);


    return 0;
}


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

int main() {
    int n;
    cin>>n;
    int b[n-1];
    for(int i=0;i<n;i++) cin>>b[i];
    int a[n];
  	a[0]=b[0];
    for(int i=1;i<n;i++) {
        a[i]=b[i-1];
    }
  
  	for(int i=1;i<n-1;i++) {
    	if(a[i]>b[i]) a[i]=b[i];
    }
  
  	int sum=0;
  	for(int i=0;i<n;i++) {
      sum+=a[i];
      //cout<<a[i]<<endl;
    }
  	cout<<sum<<endl;
}

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

int main(){
    char x,y;
    cin>>x>>y;
    if(x>y){
        cout<<'>'<<endl;
    }
    else if(x<y){
        cout<<'<'<<endl;
    }
    else{
        cout<<'='<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <string>
#include <sstream>

using namespace std;

#define x first
#define y second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define wh(x) (x).begin(),(x).end()
#define ri(x) int x;cin>>x;
#define rii(x,y) int x,y;cin>>x>>y;
#define rl(x) ll x;cin>>x;
#define rv(v) for(auto&_cinv:v) cin>>_cinv;
#define wv(v) for(auto&_coutv:v) cout << _coutv << ' '; cout << endl;
#define ev(v) for(auto&_cerrv:v) cerr << _cerrv << ' '; cerr << endl;
#define MOD 1000000007

namespace std { 
template<typename T,typename U>struct hash<pair<T,U>>{hash<T>t;hash<U>u;size_t operator()(const pair<T,U>&p)const{return t(p.x)^(u(p.y)<<7);}};
}
template<typename T,typename F>T bsh(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){l=m+1;r=m;}else{h=m-1;}}return r;}
template<typename T,typename F>T bsl(T l,T h,const F&f){T r=-1,m;while(l<=h){m=(l+h)/2;if(f(m)){h=m-1;r=m;}else{l=m+1;}}return r;}
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

typedef pair<pii,pii> C;

C norm(C c) {
    return min(min(C{{c.x.y, c.y.x}, {c.y.y, c.x.x}}, C{{c.y.y,c.x.x},{c.x.y,c.y.x}}), min(c, {c.y,c.x}));
}

int get(const C&c, int i) {
    switch(i&3) {
        case 0: return c.x.x;
        case 1: return c.x.y;
        case 2: return c.y.x;
        case 3: return c.y.y;
    }
}

int rot(const C&c) {
    if (c.x == c.y) {
        if (c.x.x == c.x.y) return 4;
        else return 2;
    } else return 1;
}

int main(int,char**) {
    ios_base::sync_with_stdio(false);

    int N; cin >> N;

    map<C, int> P;
    vector<C> Q;
    for (int i = 0; i < N; i++) {
        int a,b,c,d; cin >> a >> b >> c >> d;
        C x{{a,b},{c,d}};
        x = norm(x);
        P[x] += 1;
        Q.push_back(x);
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        C &p = Q[i];
        for (int j = i+1; j < N; j++) {
            C &q = Q[j];
            for (int k = 0; k < 4; k++) {
                ll cur = 1;
                C u[4];
                for (int l = 0; l < 4; l++) {
                    u[l] = norm({{get(p,l+1),get(p,l)},{get(q,k-l+1),get(q,k-l)}});
                    int opts = P[u[l]];
                    if (u[l] == p) --opts;
                    if (u[l] == q) --opts;
                    for (int m = 0; m < l; m++) {
                        if (u[m] == u[l]) --opts;
                    }
                    if (opts <= 0) {
                        cur = 0;
                    } else {
                        cur *= opts*rot(u[l]);
                    }
                }
                ans += cur;
            }
        }
    }

    cout << ans/3 << endl;
}


Measured memory_bytes: 80128
def solve(l,r):
  l_max = max(l)
  r_min = min(r)
  return max(r_min - l_max + 1, 0)
  
N,M = map(int,input().split())
L = [0]*M
R = [0]*M
for i in range(M):
  L[i],R[i] = map(int,input().split())
print(solve(L,R))


Measured memory_bytes: 45016
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void print(int A[], int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		printf("%d", A[i]);
		if (i != n - 1)
			printf(" ");
	}
	printf("\n");
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}

typedef struct node
{
	int data;
	struct node* left, * right;
}NODE;

NODE* root = NULL;

void insert(int key)
{
	NODE** p, * new;

	p = &root;

	while (*p != NULL)
	{
		if (key == (*p)->data)
			return NULL;
		else if (key < (*p)->data)
			p = &(*p)->left;
		else
			p = &(*p)->right;
	}

	if ((new = (NODE*)malloc(sizeof(NODE))) == NULL)
		printf("error\n");

	new->left = new->right = NULL;
	new->data = key;
	*p = new;
}

void inorder(NODE* p)
{
	if (p == NULL)
		return;
	else
	{
		inorder(p->left);
		printf(" %d", p->data);
		inorder(p->right);
	}
}

void preorder(NODE* p)
{
	if (p == NULL)
		return;
	else
	{
		printf(" %d", p->data);
		preorder(p->left);
		preorder(p->right);
	}
}

void print_tree(NODE* p)
{
	inorder(p);
	printf("\n");
	preorder(p);
	printf("\n");
}

void find(int key)
{
	NODE* p = root;

	while (p != NULL)
	{
		if (key == p->data)
		{
			printf("yes\n");
			return;
		}
		else if (key < p->data)
			p = p->left;
		else
			p = p->right;
	}

	printf("no\n");
}

int main()
{
	int m;
	char str[10];
	int num;

	scanf("%d", &m);

	int i;

	for (i = 0; i < m; i++)
	{
		scanf("%s",str);
		if (strcmp(str, "insert") == 0)
		{
			scanf("%d", &num);
			insert(num);
		}
		else if (strcmp(str, "find") == 0)
		{
			scanf("%d", &num);
			find(num);
		}
		else
			print_tree(root);
	}

	return 0;
}


Measured memory_bytes: 14236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
const int mod=1e9+7;
const int maxn=2e5;
int main()
{
    //freopen("ce.in","r",stdin);
    ll a,b;
    cin>>a>>b;
    cout<<(a+b-1)/b<<endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (writeln!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      d: usize,
      xs: [[i64; d]; n],
    }

    let mut ans = 0;
    for i in 0..n {
        for j in i+1..n {
            let mut prd = 0;
            for k in 0..d {
                let tmp = (xs[i][k] - xs[j][k]).abs();
                prd += tmp * tmp;
            }
            let sqrt = (prd as f64).sqrt() as i64;
            if sqrt*sqrt == prd {
                ans += 1;
            }
        }
    }
    puts!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>
#include <ctime>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define eps 1e-9
#define PI acos(-1.0)
#define lc id << 1
#define rc id << 1 | 1
#define lson low, mid, lc
#define rson mid + 1, high, rc

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

const int maxn = 2e5 + 10;
const ll INF = 1e18;
ll sum[maxn];
int n;
ll ans = INF;

int main() {
#ifdef __AiR_H
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif // __AiR_H
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &sum[i]); sum[i] += sum[i - 1];
    }
    for (int i = 1; i < n; ++i) {
        ans = min(ans, abs(sum[i] - sum[n] + sum[i]));
    }
    printf("%lld\n", ans);
#ifdef __AiR_H
    printf("Time used = %.2fs\n", (double)clock() / CLOCKS_PER_SEC);
#endif // __AiR_H
    return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

struct UnionFind {
    vector<int> v;
    UnionFind(int N) : v(N, -1) {}
    int root(int x) {
        if (v[x] < 0) return x;
        else return v[x] = root(v[x]);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (v[x] > v[y]) swap(x, y);
        v[x] += v[y];
        v[y] = x;
    }
    int size(int x) {
        return -v[root(x)];
    }
};

int main() {
    int N, K, L;
    cin >> N >> K >> L;
    UnionFind uf1(N), uf2(N);
    rep(i, K) {
        int p, q;
        cin >> p >> q;
        p--; q--;
        uf1.unite(p, q);
    }
    rep(i, L) {
        int r, s;
        cin >> r >> s;
        r--; s--;
        uf2.unite(r, s);
    }

    map<P, int> mp;
    rep(i, N) {
        mp[{uf1.root(i), uf2.root(i)}]++;
    }
    rep(i, N) {
        cout << mp[{uf1.root(i), uf2.root(i)}] << " \n"[i == N-1];
    }

    return 0;
}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 9223372036854775807
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=(ll)1e5+1 ;
const ll MAX=(ll)1e12 ;
ll dp[101][N] ;
int main()
{
    fast ;
    ll n,w ; cin>>n>>w ;
    ll wt[n+1],vl[n+1] ;
    for(ll i=1;i<=n;i++) cin>>wt[i]>>vl[i] ;

    for(ll i=0;i<101;i++) for(ll j=0;j<N;j++) dp[i][j]=(ll)1e12 ;

    dp[0][0]=0 ;

    for(ll i=1;i<=n;i++)
    {
        for(ll j=N-1;j>=0;j--)
        {
           dp[i][j]=dp[i-1][j] ;
           if(j-vl[i]>=0) dp[i][j]=min(dp[i][j],dp[i-1][j-vl[i]]+wt[i]) ;
        }
    }

    ll ans=0 ;
    for(ll j=N-1;j>=0;j--)
    {
        if(dp[n][j]<=w)
        {
            ans=j ;
            break ;
        }
    }
    cout<<ans ;


}




Measured memory_bytes: 82568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<string> st[4];
void noid(int len) {
	for(int i=0;i<len;i++) {
		cout << ".";
	}
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	st[0] = {
		"aabc",
		"ddbc",
		"bcaa",
		"bcdd"
	};
	st[1] = {
		"abb.c",
		"a.ddc",
		"bbeef",
		"ad..f",
		"ad.aa"
	};
	st[2] = {
		"abcc..",
		"abdd..",
		"cc..ab",
		"dd..ab",
		"..abcc",
		"..abdd"
	};
	st[3] = {
		"abb...a",
		"a...bba",
		"bbcc.dd",
		"ef.aa..",
		"efbb...",
		"....abc",
		"....abc"
	};
	if(n < 3) {cout << -1 << '\n'; return 0;}
	if(n == 3) {
		cout << "aa.\n";
		cout << "..b\n";
		cout << "..b\n";
		return 0;
	}
	int idx = n%4;
	int sz = st[idx].size();
	int buf = (n-sz)/4;
	for(int i=0;i<buf;i++) {
		noid(2*i);
		cout << "xy";
		noid(n-(4*i)-4);
		cout << "ww";
		noid(2*i);
		cout << '\n';
		noid(2*i);
		cout << "xy";
		noid(n-(4*i)-4);
		cout << "zz";
		noid(2*i);
		cout << '\n';
	}
	for(int i=0;i<st[idx].size();i++) {
		noid((n-sz)/2);
		cout << st[idx][i];
		noid((n-sz)/2);
		cout << '\n';
	}
	for(int i=buf-1;i>=0;i--) {
		noid(2*i);
		cout << "ww";
		noid(n-(4*i)-4);
		cout << "xy";
		noid(2*i);
		cout << '\n';
		noid(2*i);
		cout << "zz";
		noid(n-(4*i)-4);
		cout << "xy";
		noid(2*i);
		cout << '\n';
	}
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#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, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 998244353;
const int INF = 1LL << 30;
const double EPS = 1e-10;

const int MAX_N = 300010;
int ext_gcd(int a,int b,int& x,int& y) {
  if(b==0){
    x=1;y=0;return a;
  }
  int q=a/b;
  int g=ext_gcd(b,a-q*b,x,y);
  int z=x-q*y;
  x=y;y=z;
  return g;
}
int inv_mod(int a,int m) {
  int x,y;
  ext_gcd(a,m,x,y);
  x%=m;
  return (m+x%m)%m;
}
int fac[MAX_N],finv[MAX_N],inv[MAX_N];
void make(){
  fac[0]=1%MOD;
  for(int i=1;i<MAX_N;i++)fac[i]=fac[i-1]*i%MOD;
  finv[MAX_N-1]=inv_mod(fac[MAX_N-1],MOD);
  for(int i=MAX_N-2;i>=0;i--)finv[i]=finv[i+1]*(i+1)%MOD;
  for(int i=1;i<MAX_N;i++)inv[i]=finv[i-1]%MOD;
}
int comb(int n, int k) {
  if (n < 0 || k < 0 || n < k) return 0;
  return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int N, A, B, K;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  make();
  cin >> N >> A >> B >> K;
  int ans = 0;
  REP(i, N+1) {
    int s = K - A * i;
    if (s >= 0 && s % B == 0) {
      s /= B;
      ans += comb(N, i) * comb(N, s) % MOD;
      ans %= MOD;
    }
  }
  cout << ans << endl;

  return 0;
}

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

ll func(ll a, ll b, ll x) {
    return a*x/b - x/b * a;
}

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    if (n < b) cout << func(a,b,n) << endl;
    else cout << func(a,b,b-1) << endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  long long ans = 0;
  vector<int>a(n);
  vector<int>table(100010,0);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    ans += a.at(i);
    table.at(a.at(i))++;
  }
  int q;
  cin >> q;
  vector<int>b(q);
  vector<int>c(q);
  for (int i = 0; i < q; i++) {
    cin >> b.at(i) >> c.at(i);
    if (table.at(b.at(i))!= 0) {
      ans += (c.at(i)-b.at(i)) * table.at(b.at(i));
      table.at(c.at(i)) += table.at(b.at(i));
      table.at(b.at(i)) = 0;
    }
    cout << ans << endl;
  } 
}

Measured memory_bytes: 4832
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
vector<int> edge[MAX_N];
bool visitA[MAX_N],visitT[MAX_N];
int dA[MAX_N],dT[MAX_N];

void dfsA(int n, int d)
{
	rep(i,edge[n].size())
	{
		int to = edge[n][i];
		if (!visitA[to])
		{
			dA[to] = d+1;
			visitA[to] = true;
			dfsA(to, d+1);
		}
	}
	return;
}

void dfsT(int n, int d)
{
	rep(i,edge[n].size())
	{
		int to = edge[n][i];
		if (!visitT[to])
		{
			dT[to] = d+1;
			visitT[to] = true;
			dfsT(to, d+1);
		}
	}
	return;
}

int main()
{
	int N,u,v;
	cin >> N >> u >> v;
	u--; v--;
	rep(i,N-1)
	{
		int a,b;
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	dA[v] = 0;
	visitA[v] = true;
	dfsA(v,0);

	dT[u] = 0;
	visitT[u] = true;
	dfsT(u,0);

	int ans = 0;
	rep(i,N)
	{
		//cout << dA[i] << " " << dT[i] << endl;
		if (dA[i] > dT[i])
		{
			ans = max(ans,dA[i]-1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10496
#include<bits/stdc++.h>
#define ll long long
#define loop(n) for(ll i = 0; i<n; i++)
#define sort(a) sort(a.rbegin(), a.rend())
using namespace std;

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

    int n, m, x, votes = 0;
    cin>>n>>m;
    vector<int> vote(n);//1votes, 2id
    for(int i = 0; i<n; i++){
        cin>>vote[i];
        votes += vote[i];
    }
    float thresh = votes/(4.0*m);
    int count = 0;
    for(int i = 0; i<n; i++){
        if(vote[i]>=thresh) count++;   
    }
    cout<<(count>=m?"Yes\n":"No\n");
    return 0;
}

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

int main(void)
{
		int a, sum = 0, c[6] = { 1,5,10,50,100,500 };
		for (int i = 0; i < 6; i++)
		{
			cin >> a;
			sum += (c[i] * a);
		}
		if (sum >= 1000)
		{
			cout << "1" << endl;
		}
		else
		{
			cout << "0" << endl;
		}
	
	
}

Measured memory_bytes: 3092