akhauriyash/Code-Regression huggingface dataset:
import sys
x,k,d = map(int, sys.stdin.readline().rstrip("\n").split())
t,d_large = divmod(x, d)
t = abs(t)
if k <= t:
    if x >= 0:
        print(abs(x-d*k))
    else:
        print(abs(x+d*k))
else:
    d_small = abs(d_large - d)
    dd = t-k
    if dd % 2 == 0:
        print(d_large)
    else:
        print(d_small)

Measured memory_bytes: 61764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
const ll MOD = 1e9+7;
ll LLINF = 1LL << 60;
int INF = INT_MAX;

int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,0,n) cin>>a[i];

    sort(all(a));

    ll head=a[n-1];

    a.pop_back();
    ll temp=0;
    ll mini=LLINF;
    ll tail;
    rep(i,0,n-1){
        temp= abs(a[i]-head/2.0);
        if(mini>temp){
            mini=temp;
            tail=a[i];
        }
    }
    cout<<head<<" "<<tail<<endl;

}

Measured memory_bytes: 1024
from functools import lru_cache

appeared = [False] * 1000001


@lru_cache(256)
def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1


def a(s):
    yield s
    y = s
    while True:
        y = f(y)
        yield y


def main():
    s = int(input())
    seq_a = a(s)
    i = 1
    while True:
        elem = next(seq_a)
        if appeared[elem]:
            print(i)
            return
        else:
            appeared[elem] = True
            i += 1


if __name__ == '__main__':
    main()


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
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;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n, t; std::cin >> n >> t;
  vector<pi> ab(n);
  rep(i, n) {
    std::cin >> ab[i].fi >> ab[i].se;
  }
  vvi dp1(n, vi(t)), dp2(n, vi(t));
  rep(i, n) {
    drep(j, t) {
      if (i == 0) dp1[i][j] = (j-ab[i].fi >= 0 ? ab[i].se : 0);
      else if (j-ab[i].fi < 0) dp1[i][j] = dp1[i-1][j];
      else dp1[i][j] = max(dp1[i-1][j], dp1[i-1][j-ab[i].fi]+ab[i].se);
    }
  }
  drep(i, n) {
    drep(j, t) {
      if (i == n-1) dp2[i][j] = (j-ab[i].fi >= 0 ? ab[i].se : 0);
      else if (j-ab[i].fi < 0) dp2[i][j] = dp2[i+1][j];
      else dp2[i][j] = max(dp2[i+1][j], dp2[i+1][j-ab[i].fi]+ab[i].se);
    }
  }
  int ans = 0;
  rep(i, n) {
    if (i == 0) chmax(ans, dp2[i+1][t-1] + ab[i].se);
    else if (i == n-1) chmax(ans, dp1[n-2][t-1] + ab[i].se);
    else {
      rep(j, t) chmax(ans, dp1[i-1][j] + dp2[i+1][t-j-1] + ab[i].se);
    }
  }
  std::cout << ans << "\n";
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;
  vll a(n);
  rep(i, n) {
    cin >> a[i];
  }

  map<ll, ll> m;

  ll ans = 0;
  m[-a[0]] = 1;
  REP(i, n) {
    ans += m[a[i] - i];
    m[-i - a[i]] += 1;
  }

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


Measured memory_bytes: 27388
package main

import (
	"fmt"
  //"sort"
	//"strconv"
)

func main() {
  var N int
  A := make([][]int, 3)
  for i:=0; i<3; i++{
    A[i]=make([]int,3)
  }
  fmt.Scanf("%d %d %d",&A[0][0],&A[0][1],&A[0][2])
  fmt.Scanf("%d %d %d",&A[1][0],&A[1][1],&A[1][2])
  fmt.Scanf("%d %d %d",&A[2][0],&A[2][1],&A[2][2])
  fmt.Scanf("%d",&N);
  b:=make([]int, N)
  for i:=0; i<N; i++{
    fmt.Scanf("%d",&b[i]);
    for j:=0;j<3;j++{
      for k:=0;k<3;k++{
        if b[i]==A[j][k]{
          A[j][k]=0
        }
      }
    }
  }
  if A[0][0]==A[0][1]&&A[0][1]==A[0][2]||A[1][0]==A[1][1]&&A[1][1]==A[1][2]||A[2][0]==A[2][1]&&A[2][1]==A[2][2]||A[0][0]==A[1][1]&&A[1][1]==A[2][2]||A[0][2]==A[1][1]&&A[1][1]==A[2][0]||A[0][0]==A[1][0]&&A[1][0]==A[2][0]||A[0][1]==A[1][1]&&A[1][1]==A[2][1]||A[0][2]==A[1][2]&&A[1][2]==A[2][2]{
    fmt.Print("Yes")
  }else{
      fmt.Print("No")
  }

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void solve(){
  int x;
  cin>>x;
  if(x>=30) cout<<"Yes\n";
  else cout<<"No\n";
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;
const ll INF=1e16;
int main()
{
    int n, m; ll p; cin>>n>>m>>p;
    vector<P> g[2510], gr[2510];
    for(int i=0; i<m; i++){
        int a, b; ll c; cin>>a>>b>>c;
        a--; b--; c-=p;
        g[a].push_back({b, c});
        gr[b].push_back({a, c});
    }
    bool ok[2510]={};
    ok[n-1]=1;
    queue<int> que;
    que.push(n-1);
    while(!que.empty()){
        int x=que.front();
        que.pop();
        for(auto p:gr[x]){
            int y=p.first;
            if(!ok[y]){
                ok[y]=1;
                que.push(y);
            }
        }
    }
    ll d[2510];
    fill(d, d+n, -INF);
    d[0]=0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            for(auto p:g[j]){
                int k=p.first;
                if(d[k]<d[j]+p.second){
                    d[k]=d[j]+p.second;
                }
            }
        }
    }
    for(int i=0; i<n; i++){
        int cnt=0;
        for(int j=0; j<n; j++){
            for(auto p:g[j]){
                int k=p.first;
                if(d[k]<d[j]+p.second){
                    d[k]=d[j]+p.second;
                    if(d[k]>-INF/2 && ok[k]) cnt++;
                }
            }
        }
        if(cnt>0){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<max(0ll, d[n-1])<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
const ll M=1000000007;
//------------------------------------------//

int main(){
    char c;
    int ans=0;
    rep(i,4){
        cin>>c;
        if(c=='+') ans++;
        else ans--;
    }
    cout<<ans<<endl;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll k;cin>>k;
  ll n=50;
  vector<ll>r;
  ll g = (n-1)+k/n-k%n;
  cout<<50<<endl;
  rep(i, n-k%n)cout<<g<<' ';
  rep(i, k%n)cout<<g+n<<' ';

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,m,c; cin >> n >> m >> c;
  int b[m]; REP(i,m) cin >> b[i];
  int a[n][m]; REP(i,n) REP(j,m) cin >> a[i][j];

  int ans = 0;
  REP(i,n) {
    int tot = c;
    REP(j,m) { tot += a[i][j] * b[j]; }
    if (tot > 0) ans++;
  }

  COUT(ans);
  return 0;
}


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

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;

#define pb push_back

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string a, b;;
	cin >> a >> b;
	int n = a.size(), m = b.size(), ans = 1e9;
	auto f = [&] (int i) {
		string sub = a.substr(i, m);
		int cnt = 0;
		for (int j = 0; j < m; j++)
			if (sub[j] != b[j])
				cnt++;
		return cnt;
	};
	for (int i = 0; i + m <= n; i++) 
		ans = min(ans, f(i));
	cout << ans;
   return 0;
}

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

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

    ll n; cin >> n;
    vector<ll> h(n); for (int i=0; i<n; ++i) cin >> h[i];
    vector<ll> a(n); for (int i=0; i<n; ++i) cin >> a[i];
    ll res=0;
    set<pair<ll, ll>> st;
    st.insert({0ll, 0ll});
    for (int i=0; i<n; ++i) {
      auto it=prev(st.lower_bound({h[i], 0}));
      ll cost=a[i]+(*it).second;
      it++;
      while (it!=st.end()) {
        auto nxt=next(it);
        if ((*it).second<=cost) {
          st.erase(it);
        } else {
          break;
        }
        it=nxt;
      }
      st.insert({h[i], cost});
      res=max(res, cost);
    }

    cout << res << endl;
    return 0;
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl
#define HYPP(x) hypot(x.first,x.second)

const lli MOD = 998244353;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;


int main() {
	int N, L;
	cin >> N >> L;
	vector<string> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec[i];
	}
	sort(vec.begin(), vec.end());
	for (int i = 0; i < N; i++) {
		cout <<  vec[i];
	}
	cout << endl;
	return 0;
}


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

int main() {
	cout << fixed << setprecision(10);

	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	double w = x1 - x2;
	double h = y1 - y2;
	double d = sqrt(w * w + h * h);

	cout << d << endl;

	return 0;
}



Measured memory_bytes: 3276
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, A[200004];
ll K;
ll init[200004];

int main() {
  INCANT;
  cin >> N >> K;
  int a;
  rep(i, N) {
    cin >> a;
    a--;
    A[i]=a;
  }
  fill(init, init+N, -1);
  init[0]=0;
  int next=0;
  ll cnt=0;
  while(cnt < K) {
    cnt++;
    next = A[next];
    if (init[next]>=0) break;
    init[next]=cnt;
  }
  if (cnt==K) {
    cout << next+1 << endl;
    return 0;
  }
  ll circle=cnt-init[next];
  ll amari = (K-cnt)%circle;
  rep(i, N) {
    if (init[i]==amari+init[next]) {
      cout << i+1 << "\n";
      break;
    }
  }
  
  return 0;
}

Measured memory_bytes: 6000
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    t = 0
    tb = 0
    cur = 0
    cnt = 0
    for i in range(n):
        t += a[i]
        tb = tb ^ a[i]
        if t == tb:
            cnt += (i - cur + 1)
        else:
            while True:
                t -= a[cur]
                tb = tb ^ a[cur]
                cur += 1
                if t == tb:
                    cnt += (i - cur + 1)
                    break
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 72944
main :: IO ()
main = getContents >>=
  print .
  (\(res1,res2) -> if res1 < res2 then res1 else res2) .
  (\(n,l) -> (sum . map (\v -> (v-n)*(v-n)) $ l,
              sum . map (\v -> (v-(n+1))*(v-(n+1))) $ l)) .
  (\(n,l) -> (sum l `quot` n, l)) .
  (\list -> (head list, tail list)) .
  map (read :: String -> Int) .
  words

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int D, T, S;
	cin >> D >> T >> S;
	if(T >= (D + S - 1) / S)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(n) for(ll i=0; i<n; i++)

int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  cout << c-min(a-b,c) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
#include<cstdint>
#include<limits>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int64_t INF = std::numeric_limits<int64_t>::max();

void solve() {
  int64_t N, A, B, C, D; std::cin >> N >> A >> B >> C >> D;
  std::map<int64_t, int64_t> dp;
  auto calc = [&](auto&& f, int64_t n)->int64_t {
    if(n <= 1) return n*D;
    if(dp.count(n) > 0) return dp[n];
    int64_t res = INF;
    if(n < INF/D) res = n*D;
    // ceil[n/2]
    int64_t m = (n+1)/2;
    res = std::min(res, (m*2 - n)*D + A + f(f, m));
    if(n%2 != 0) {
      m = n/2;
      res = std::min(res, (n - m*2)*D + A + f(f, m));
    }
    m = (n+2)/3;
    res = std::min(res, (m*3 - n)*D + B + f(f, m));
    if(n%3 != 0) {
      m = n/3;
      res = std::min(res, (n - m*3)*D + B + f(f, m));
    }
    m = (n+4)/5;
    res = std::min(res, (m*5 - n)*D + C + f(f, m));
    if(n%5 != 0) {
      m = n/5;
      res = std::min(res, (n - m*5)*D + C + f(f, m));
    }
    return dp[n] = res;
  };
  std::cout << calc(calc, N) << "\n";
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int T; std::cin >> T;
  for(int i = 0; i < T; ++i) solve();
  return 0;
}


Measured memory_bytes: 4424
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
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(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int k;
    cin >> k;

    int x = 7;
    int cnt = 1;
    rep(i, 1e6) {
        if (x % k == 0) {
            cout << cnt << endl;
            return 0;
        }
        cnt++;
        x = 10 * x + 7;
        x %= k;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3648
N, M = map(int, input().split())

LR = [list(map(int, input().split())) for _ in range(M)]

L = []
R = []
for i in LR:
  L.append(i[0])
  R.append(i[1])
  
if min(R) - max(L) < 0:
  print(0)
else:
  print(min(R) - max(L) + 1)

Measured memory_bytes: 29092
A, B, C, D, E, F = map(int, input().split())

w = set()
for i in range(F // (100 * A) + 1):
    for j in range(F // (100 * B) + 1):
        a = (A * i + B * j) * 100
        if a < F:
            w.add(a)
w.remove(0)

s = set()
t = E * F // 100
for i in range(t // C + 1):
    for j in range(t // D + 1):
        b = C * i + D * j
        if b < F:
            s.add(b)
s = list(s)
s.sort()

best_concentration = -1
best_a = -1
best_b = -1
for a in w:
    for b in s:
        if a + b > F:
            break
        if b > E * a // 100:
            break
        concentration = 100 * b / (a + b)
        if concentration > best_concentration:
            best_concentration = concentration
            best_a = a
            best_b = b
print(best_a + best_b, best_b)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;

int main(){
   int n;
   cin>>n;
   vector<int> w(n);
   for(int i=0;i<n;i++)cin>>w[i];
   int ans=1000000000;
   for(int i=0;i<n-1;i++){
      int s1=0,s2=0;
      for(int j=0;j<=i;j++){
         s1+=w[j];
      }
      for(int j=i+1;j<n;j++){
         s2+=w[j];
      }
      ans=min(ans,abs(s1-s2));
   }
   cout<<ans<<endl;
}

   


Measured memory_bytes: 888
n, k = map(int, input().split())
heights = [int(x) for x in input().split()]

dp = [[float("inf") for _ in range(k + 1)] for _ in range(n)]
for i in range(0, k + 1):
    dp[0][i] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i + j < n:
            # dp[i + j][j] = min(dp[i + j][j], dp[i][j] + abs(heights[i] - heights[i + j]))
            val1 = dp[i + j][j]
            val2 = dp[i][0] + abs(heights[i] - heights[i + j])
            if val2 < val1:
                dp[i + j][j] = val2
                if dp[i + j][0] > val2:
                    dp[i + j][0] = val2
        # if i == 0 and j == 1:
        #     print("here")
        #     print(dp[i][j], abs(heights[i] - heights[i + j]))
# result = float("inf")
# for i in range(1, k + 1):
#     result = min(result, dp[-1][i])
# print(result)
# print(dp)
print(dp[-1][0])

Measured memory_bytes: 257348
count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
N = int(input())

for i in range(N):
    b, f, r, v = map(int, input().split())
    count[b-1][f-1][r-1] += v
    
for f, k in enumerate(count):
    for j in k:
        for i in j:
            print(" {}".format(i), end="")
        print()
    if f < 3:
        print("#"*20)



Measured memory_bytes: 5624
#include<bits/stdc++.h>
#define ll long long int
using namespace std;


int main(void) {
  int n,m;
  cin >> n >> m;

  vector<int> penalty(n+1,0);
  vector<bool> ac(n+1, false);

  int ans_p=0,ans_ac=0;
  for (int i = 0; i < m; i++) {
    int p;
    string s;
    cin >> p >> s;

    if(s=="WA"){
      penalty[p]++;
    } else {
      if(!ac[p]){
	ac[p] = true;
	ans_p+=penalty[p];
	ans_ac++;
      }
    }
  }

  cout << ans_ac << " " << ans_p << endl;
  
  return 0;
}


Measured memory_bytes: 640
s=input()
D=dict()
D["b"]="d"
D["d"]="b"
D["p"]="q"
D["q"]="p"
chk=True
for i in range(len(s)):
  if D[s[i]]!=s[-1-i]:
    chk=False
    break
print("Yes" if chk else "No")

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, ii> iii;
typedef vector<pair<pair<int,int>,int>> viii;
typedef vector<pair<pair<ll,ll>,ll>> viiil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000
#define MOD 1000000007;

vi adj[200005];
vi rev[200005];
int col[200005];
vi t;
bool valid;

void dfs(int n) {
    if (col[n] == 1) {
        valid = false;
        return;
    }
    if (col[n] == 2) {
        return;
    }
    col[n] = 1;
    for (int a : adj[n]) {
        dfs(a);
    }
    if (col[n] != 2) {
        t.pb(n);
    }
    col[n] = 2;

}

void solve() {
    valid = true;
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        adj[a].pb(b);
        rev[b].pb(a);
    }
    rep(i, n) {
        if (col[i] == 0) {
            dfs(i);
        }
    }
    reverse(t.begin(), t.end());
    
    int dp[n];
    memset(dp, 0, sizeof dp);
    
    int pos[n];
    rep(i, n) {
        pos[t[i]] = i;
    }
    
    for (int i = 1 ; i < n ; i++) {
        int vt = t[i];
        int ans = 0;
        for (int j : rev[vt]) {
            //cout << vt << " " << i << " " << j << endl;
            ans = max(ans, dp[pos[j]] + 1);
        }
        dp[i] = ans;
    }
    int mx = 0;
    rep(i, n) {
        mx = max(mx, dp[i]);
    }
    cout << mx << endl;
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        //solve();
    }
}

int main() {
    //querySolve();
    solve();

}


Measured memory_bytes: 21852
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define N 200010
int n,a[N],b[N];
int main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    int j=0,bef=-1;
    rep(i,n){
	if(bef!=a[i])j=0;
	if(a[i]==b[i]){
	    for(;j<n;j++){
		if(a[j]!=a[i]&&b[j]!=a[i]){
		    swap(b[i],b[j]);
		    break;
		}
	    }
	    if(a[i]==b[i]){
		cout<<"No\n";
		return 0;
	    }
	}
	bef=a[i];
    }
    cout<<"Yes\n";
    rep(i,n){
	if(i)cout<<" ";
	cout<<b[i];
    }
    cout<<"\n";
}

Measured memory_bytes: 5172
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> card(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> card[i];
    }
    sort(card.begin(), card.end(), greater<ll>());
    
    ll a = 0;
    ll b = 0;

    for (ll i = 0; i < N; i++)
    {
        if (i % 2 == 0) {
            a += card[i];
        } else {
            b += card[i];
        }
    }
    cout << (a-b) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int A,B,T;
	scanf("%d %d %d",&A,&B,&T);
	double t = (double)T + 0.5;
	int cnt = 0;
	for (int i = 1; ; i++) {
		if (A*i > t) break;
		cnt += B;
	}
	printf("%d\n",cnt);
	return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, A;
std::map<int, int> numCards;
std::vector<int> heaps;
int heapSize, msb;
int BIT[300100];
std::stack<P> history;

void add(int k, int v){
    while(k <= heapSize){
        BIT[k] += v;
        k += k & -k;
    }
}

void add2(int k, int v){
    history.emplace(k, v);
    add(k, v);
}

int prefixSum(int k){ // [1, k]
    int sum = 0;
    
    while(k > 0){
        sum += BIT[k];
        k -= k & -k;
    }

    return sum;
}

int leftmostBit(int x){
    int n = 0;

    for(int i=16;i>0;i/=2){
        if(x >> i){
            x >>= i;
            n += i;
        }
    }
    
    return 1 << n;
}

int simulate(int k){
    int res = 0;
    int kv = heaps[k];

    while(kv > 0){
        res += 1;

        // for(int i=1;i<=heapSize;++i){
        //     printf("%d ", heaps[i] + prefixSum(i));
        // }
        // puts("");

        int lb = 0;

        {
            int x = kv;

            for(int i=msb;i>0;i/=2){
                if(lb + i <= heapSize && heaps[lb + i] + BIT[lb + i] > x){
                    x -= BIT[lb + i];
                    lb += i;
                }
            }
            
            lb += 1;
        }

        int ub = 0;
        
        {
            int x = kv;
            
            for(int i=msb;i>0;i/=2){
                if(ub + i <= heapSize && heaps[ub + i] + BIT[ub + i] >= x){
                    x -= BIT[ub + i];
                    ub += i;
                }
            }

            ub += 1;
        }

        // printf("lb, ub: %d, %d\n", lb, ub);

        int m = ub - (k - (lb - 1));

        add2(1, -1);
        add2(lb, +1);
        add2(m, -1);
        add2(ub, +1);

        if(m <= k){
            kv -= 1;
        }
    }

    until(history.empty()){
        int i, v;
        std::tie(i, v) = history.top();
        history.pop();
        
        add(i, -v);
    }

    return res;
}

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

    scanf("%d", &N);

    for(int i=0;i<N;++i){
        scanf("%d", &A);

        numCards[A] += 1;
    }

    for(auto &p : numCards){
        heaps.emplace_back(p.second);
    }
    
    heapSize = heaps.size();
    msb = leftmostBit(heapSize);

    heaps.emplace_back(std::numeric_limits<int>::max());

    std::sort(heaps.rbegin(), heaps.rend());

    for(int k=1;k<=N;++k){
        int res = 0;

        if(k <= heapSize){
            res = simulate(k);
        }

        printf("%d\n", res);
    }
}



Measured memory_bytes: 25584
class _Node {
  constructor(key, parent = null, left = null, right = null) {
    this.key = key;
    this.parent = parent;
    this.left = left;
    this.right = right;
  }

//   getChildrenNumber() {return (this.left && 1 || 0 ) + (this.right && 1 || 0 );}

  getChildrenNumber() {return Number(this.left !== null) + Number(this.right !== null);}



  isLeftChild() {
    if (this.parent === null) return null;
    return this.parent.left === this;
  }

  getLeftOrRight() {return this.isLeftChild() ? 'left' : 'right';}

  getSuccessor() {
    let n;
    if (this.right !== null) {
      n = this.right;
      while (n.left !== null) n = n.left;
    } else {
      n = this.parent;
      while (!n.isLeftChild && n.parent != null) n = n.parent;
    }
    return n;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    if (this.root === null) {
      this.root = new BinaryTree.Node(key);
      return;
    }
    let x = this.root, y;
    let newNode = new BinaryTree.Node(key);
    while (x !== null) {
      y = x;
      x = x[key < x.key ? 'left' : 'right'];
    }
    newNode.parent = y;
    y[key < y.key ? 'left' : 'right'] = newNode;
  }

  find(key, n = this.root) {
    if (n === null || n.key === key) return n;
    return this.find(key, n[key < n.key ? 'left' : 'right']);
  }

  delete(key) {
    const n = this.find(key);
    const leftOrRight = n.getLeftOrRight();
    switch (n.getChildrenNumber()) {
    case 0:
      n.parent[leftOrRight] = null;
      break;
    case 1:
      n.parent[leftOrRight] = n.left || n.right;
      n.parent[leftOrRight].parent = n.parent;
      break;
    default:
      const skey = n.getSuccessor().key;
      this.delete(skey);
      n.key = skey;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch (cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    case 'f': console.log(tree.find(Number(cmd.split(' ')[1])) ? 'yes' : 'no'); break;
    case 'd': tree.delete(Number(cmd.split(' ')[1])); break;
    default: tree.print();
    }
  });
})();



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

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}

bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

int n;
int a[100000];

int main(){
    cin >> n;
    int cou2 = 0, cou4 = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2 == 0)   cou2++;
        if(a[i] % 4 == 0)   cou4++;
    }

    cou2 = cou2 - cou4;
    n -= cou2;
    if(cou2 != 0)   n++;

    if(cou4 + 1 >= n - cou4)   cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  set<int> st;
  int a, b, c; cin >> a >> b >> c;
  st.insert(a);
  st.insert(b);
  st.insert(c);
  cout << st.size() << endl;
  return;
}

int main(){
  solve();
  return 0;
}


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

int main(void){
  // ios::sync_with_stdio(false);
  // cin.tie(NULL);
  // cout.tie(NULL);

  int N;
  cin >> N;
  vector<int> A(N), B(N);
  int first = 0, second = 0;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    if(first <= A[i]) {
      second = first;
      first = A[i];
    }
    else if(second <= A[i]) {
      second = A[i];
    }
  }

  for(int i = 0; i < N; i++) {
    if(A[i] == first) {
      cout << second << endl;
    }
    else {
      cout << first << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 4816
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 1000000000
#define PI 3.14159265358979323846
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int a[5];
	for(int i = 0; i<  5; i++)
	{
		cin >> a[i];
		if(a[i]==0)
		{
			cout << i+1 << '\n';
			return 0;
		}
	}
}

Measured memory_bytes: 3608
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long
const int max_n = 1e5;
const ll mod = 998244353;
const ll INF = 1LL<<60;
#define fo(i,n) for( ll int i=0;i<n;++i)
#define fos(j,i,n) for(ll int j=i;j<n;++j)
#define N 100004
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define abs(x) (x<0?(-x):x)
#define dis(k) cout << k << endl
#define forr(i,n) for( ll int i= n-1;i>=0;--i)
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
typedef vector< ll int > vi;
typedef vector< vi > vvi;
typedef pair< ll int,ll int > ii;

int main(){
	fast;
	int t;
	t=1;
	//cin >> t;
	while(t--){
		double l;
		cin >> l;
		l/=3;
		printf("%.12f\n",l*l*l);

	}
	return 0;
}


Measured memory_bytes: 256
def abc050_b():
    number_of_problem = int(input())
    time_to_solve_list = [int(i) for i in input().split()]

    variety_of_drinks = int(input())

    problem_vs_time = []

    for _ in range(variety_of_drinks):
        buf = list(map(int, input().split()))
        problem_num = buf[0] - 1
        time_to_solve = buf[1]

        problem_vs_time.append([problem_num, time_to_solve])

    for key, value in problem_vs_time:
        buf = time_to_solve_list[key]
        time_to_solve_list[key] = value

        print(sum(time_to_solve_list))
        time_to_solve_list[key] = buf


if __name__ == '__main__':
    abc050_b()


Measured memory_bytes: 3064
using System;
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int rainCount = 0;

            for(int i=0;i<input.Length;i++)
            {
                if(input[i] == 'R')
                {
                    rainCount++;
                }
            }
            if (input[1] == 'S' && rainCount>0)
            {
                rainCount = 1;
            }

            Console.Write(rainCount);
        }
    }

Measured memory_bytes: 25848
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			HashMap<String, Integer> counts = new HashMap<String, Integer>();			
			for(int i = 0; i < N; i++) {
				final String s = sc.next();
				
				if(!counts.containsKey(s)) { counts.put(s, 0); }
				counts.put(s, counts.get(s) + 1);
			}
			
			System.out.println("AC x " + (!counts.containsKey("AC") ? 0 : counts.get("AC")));
			System.out.println("WA x " + (!counts.containsKey("WA") ? 0 : counts.get("WA")));
			System.out.println("TLE x " + (!counts.containsKey("TLE") ? 0 : counts.get("TLE")));
			System.out.println("RE x " + (!counts.containsKey("RE") ? 0 : counts.get("RE")));
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 50456
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
using namespace std;
const int64_t INF=10000000000000000;

int main(){
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=1000;i++){
		if(floor(i*0.08)==a && floor(i*0.1)==b){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;


}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;

    int h, w;
    cin >> h >> w;

    int all = H * W;
    int black = h * W + w * H - h * w;  // ignore duplicate (h*w)

    cout << all - black << '\n';
}


Measured memory_bytes: 256
from collections import deque
N,Q = map(int,input().split(" "))
cnt = [0 for _ in range(N)]
edge = [set() for i in range(N)]
for i in range(N-1):
    a,b = map(lambda x: int(x)-1, input().split(" "))
    edge[a].add(b)
    edge[b].add(a)
    
for i in range(Q):
    p,x = map(int,input().split(" "))
    p -= 1
    cnt[p] += x
plug = [0 for _ in range(N)]
stack = deque([0])
while stack:
    v = stack.pop()
    plug[v] = 1

    for e in edge[v]:
        if plug[e] != 1 and e != v:
            cnt[e] += cnt[v]
            stack.append(e)

print(*cnt)

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N;
	cin >> N;
	vecl(A)
		vecl(B)
		fx(N + 1) {
		vecpl(A)
	}
	fx(N ) {
		vecpl(B)
	}
	ll ans = 0;
	fx(N) {
		ans+=min(A.at(x),B.at(x));
		if (A.at(x) < B.at(x)) {
			ans += min(B.at(x) - A.at(x),A.at(x+1));
			A.at(x + 1) = max(A.at(x+1)-(B.at(x)-A.at(x)),0LL);
		}
	}
	ce(ans)
    return 0;
}



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

int main() {
    int n; cin >> n;
    vector<int> l(n);
    for(int i=0; i<n; i++) cin >> l[i];
    sort(l.begin(),l.end());
    int cnt = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            for(int k=j+1; k<n; k++){
                if(l[i] == l[j] || l[i] == l[k] || l[j] == l[k]) continue;
                if(l[i] + l[j] > l[k]) cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
int main() {
  int A,B,C,tmp;
  scanf("%d" "%d" "%d",&A,&B,&C);
  if (B/A > C) {
    printf("%d\n", C );
  }else{
    printf("%d\n",B/A );
  }
  return 0;
}


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


int main()
{
	
	int n;
	cin>>n;
	vector<int>a;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
	}

	vector<vector<ll>>dp(n,vector<ll>(n,0));
	for(int i=0;i<n;i++)
		dp[i][i]=a[i];
	for(int i=1;i<n;i++)
		dp[i-1][i]=abs(dp[i][i]-dp[i-1][i-1]);

	for(int g=2;g<n;g++)
	{
		for(int i=0,j=g;j<n;i++,j++)
		{
			dp[i][j]=max(dp[j][j]-dp[i][j-1],dp[i][i]-dp[i+1][j]);
		}
	}
	cout<<dp[0][n-1];
}

Measured memory_bytes: 73764
#include<iostream>
#include <climits>
#include<vector>
#include<list>
#include<numeric>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	
	ll N, M;
	cin >> N >> M;
	vector<ll> A(N);
	vector<ll> sum(N + 1);
	sum[0] = 0;
	REP(i, N) {
		cin >> A[i];
		sum[i + 1] = (sum[i] + A[i]) % M;
	}
	ll res = 0;
	map<ll, ll> m;
	for (int l = 0;l <= N;l++) {
		res += m[sum[l]];
		m[sum[l]]++;
	}
	cout << res << "\n";



	return 0;
}

Measured memory_bytes: 5760
//#include "grader.h"
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
//#define   Y            imag()
//#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
//#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
//#define    dp(a,b)          (((conj(a))*(b)).real())
//#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
//#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     PT                    complex<double>
#define outfile freopen("out.out", "w", stdout);
#define infile  freopen("in.in", "r", stdin);
#define PI acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void FS(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
const int N=10009;
vector< vector<int> > v(N);
set< pair<int,int> ,greater<pair<int,int> > > st;
int val[N],vis[N];
ll ans=0;
vector<int> c;
vector<pair<int,int>> v1;
void dfs(int no)
{
    vis[no]=1;
    for(int i=0;i<sz(v[no]);i++)
    {
        int nw=v[no][i];
        if(vis[nw])
            continue;
        ans+=min(val[no],val[nw]);
        dfs(nw);
    }
}
void calc()
{
    dfs(1);
}
queue<int> q;
void bfs(int no)
{
    q.push(no);
    int id=0;
    while(!q.empty())
    {
        int siz=sz(q);
        while(siz--)
        {
        int cur=q.front();
        val[cur]=c[id++];
        q.pop();
        vis[cur]=1;
        for(int i=0;i<sz(v[cur]);i++)
        {
            int nw=v[cur][i];
            if(vis[nw])
                continue;
            q.push(nw);
        }
        }
    }
}
void my_assign()
{
    bfs(1);
}
int main()
{
    int n;
    cin>>n;

    for(int i=1;i<=n-1;i++)
    {
        int f,t;
        cin>>f>>t;
        v[f].pb(t);
        v[t].pb(f);
    }
    for(int i=0;i<n;i++)
    {
        int no;
        cin>>no;
        c.pb(no);
    }
    sort(allr(c));
    for(int i=1;i<sz(c);i++)
        ans+=c[i];
    cout<<ans<<endl;
    my_assign();
    for(int i=1;i<=n;i++)
        cout<<val[i]<<" ";
}





















Measured memory_bytes: 1024
import java.util.*

fun binarySearch(S: List<Int>, t: Int): Int {
    tailrec fun search(S: List<Int>, t: Int, s: Int, e: Int): Int {
        if (s > e) {
            return -1
        }
        val index = (s + e) / 2
        val v = S[index]
        return when {
            (v == t) -> index
            (v > t) -> search(S, t, s, index - 1)
            else -> search(S, t, index + 1, e)
        }
    }
    return search(S, t, 0, S.size - 1)
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val S = mutableListOf<Int>()
    repeat(n) {
        S.add(scanner.nextInt())
    }
    val q = scanner.nextInt()
    val T = mutableListOf<Int>()
    repeat(q) {
        T.add(scanner.nextInt())
    }
    var count = 0
    for (t in T) {
        if (binarySearch(S, t) != -1) {
            count++
        }
    }
    println(count)
}



Measured memory_bytes: 88492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<bool> vb;
#define INF (1e9)

int main() {
    ll N, K, ans = 0;
    cin >> N >> K;
    vi A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }

    ll now = 0, idx = 0;
    vi b(N, -1);
    while (b[now] == -1) {
        b[now] = idx;
        now = A[now];
        idx++;
    }
    ll before = b[now], loop = idx - before;

    if (K > before) {
        K = (K - before) % loop + before;
    }

    now = 0;
    for (ll i = 0; i < K; i++) {
        now = A[now];
    }

    cout << now + 1 << endl;
}


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

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

  int monitoringNum = D * 2 + 1;
  int answer = N / monitoringNum;
  if (N % monitoringNum != 0) {
    answer += 1;
  }

  cout << answer << endl;
}

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

int main() {
  int n;cin>>n;
  vector<int> h(n);
  rep(i,n)cin>>h[i];
  int ans=0,cnt=0;
  rep(i,n-1){
    if(h[i+1]<=h[i])cnt++;
    else cnt=0;
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3636