akhauriyash/Code-Regression huggingface dataset:
n = int(input())
A = []
for i in range(2):
    A.append(list(map(int, input().split())))
c = 0
B = []
for i in range(n):
    c += A[0][i]
    s = c
    for j in range(i, n):
        s += A[1][j]
    B.append(s)
print(max(B))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
	ll n;
	cin>>n;
	ll m;
	cin>>m;
	ll arr[m];
	ll sum = 0; 
	for(int i = 0;i<m;i++)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	if(sum>n)
	cout<<"-1";
	else
	cout<<n-sum;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5e5 + 10;
int mod1=998244353,base1=19260817,inv1;
int mod2=353448299,base2=20000003,inv2;
int s[N], pw1[N], pw2[N], rev1[N], rev2[N];

int q_pow(int x, int y, int mod) {
  int ans = 1;
  for(; y; y >>= 1) {
    if(y & 1) ans = 1ll * ans * x % mod;
    x = 1ll * x * x % mod;
  }
  return ans;
}

int h1[N], h2[N];
typedef pair<int, int> P;
map<P, int> mp;

int main() {
  int n;
  scanf("%d", &n);
  inv1 = q_pow(base1, mod1 - 2, mod1);
  inv2 = q_pow(base2, mod2 - 2, mod2);
  pw1[0] = pw2[0] = rev1[0] = rev2[0] = 1;
  for(int i = 1; i <= (n << 1); ++i) {
    pw1[i] = 1ll * pw1[i - 1] * base1 % mod1;
    pw2[i] = 1ll * pw2[i - 1] * base2 % mod2;
    rev1[i] = 1ll * rev1[i - 1] * inv1 % mod1;
    rev2[i] = 1ll * rev2[i - 1] * inv2 % mod2;
  }
  s[0] = n;
  for(int i = 1; i <= n; ++i) {
    char ch; cin >> ch;
    if(ch == '+') {
      s[i] = s[i - 1];
      h1[i] = (h1[i - 1] + pw1[s[i]]) % mod1;
      h2[i] = (h2[i - 1] + pw2[s[i]]) % mod2;
    } else if(ch == '-') {
      s[i] = s[i - 1];
      h1[i] = (h1[i - 1] - pw1[s[i]] + mod1) % mod1;
      h2[i] = (h2[i - 1] - pw2[s[i]] + mod2) % mod2;
    } else if(ch == '>') {
      s[i] = s[i - 1] + 1;
      h1[i] = h1[i - 1];
      h2[i] = h2[i - 1];
    } else {
      s[i] = s[i - 1] - 1;
      h1[i] = h1[i - 1];
      h2[i] = h2[i - 1];
    }
    mp[P(h1[i], h2[i])]++;
  }
  ll ans = 0;
  for(int i = 1; i <= n; ++i) {
    int pos = h1[n], tmp = h2[n];
    int sit = s[i - 1] - n;
    if(sit >= 0) pos = 1ll * pos * pw1[sit] % mod1, tmp = 1ll * tmp * pw2[sit] % mod2;
    else pos = 1ll * pos * rev1[-sit] % mod1, tmp = 1ll * tmp * rev2[-sit] % mod2;
    pos = (pos + h1[i - 1]) % mod1;
    tmp = (tmp + h2[i - 1]) % mod2;
    ans += mp[P(pos, tmp)];
    mp[P(h1[i], h2[i])]--;
  }
  printf("%lld\n", ans);
  return 0;
}

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

bool findvec(vector<int> &vec, int num)
{
    auto itr = find(vec.begin(), vec.end(), num);
    if(itr != vec.end()) return true;
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X, N;
    cin >> X >> N;
    vector<int> ps(N);
    for(int i=0; i<N; i++) cin >> ps.at(i);

    int cp = X;
    while(true)
    {
        if(!findvec(ps, cp))
        {
            cout << cp << endl;
            break;
        }
        if(!findvec(ps, X + (X - cp)))
        {
            cout << X + (X - cp) << endl;
            break;
        }
        cp--;
    }

    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

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

	vector<pair<int,int>>AB(N);
	for (int i = 0; i < N; i++) {
		cin >> AB[i].first >> AB[i].second;
	}
	sort(AB.begin(), AB.end());

	vector<int>a;
	int cnt = 0;
	int tmpK = K;
	while (tmpK) {
		if (tmpK & 1)a.push_back(1 << cnt);

		tmpK >>= 1;
		cnt++;
	}
	reverse(a.begin(),a.end());

	ll ans = 0;
	for (int i = 0; i < a.size();i++) {
		ll tmpans = 0;

		while (AB.size()) {
			if (AB[AB.size() - 1].first > K)AB.pop_back();
			else break;
		}

		for (int j = 0; j < AB.size(); j++) {
			if (AB[j].first >= a[i])AB[j].first -= a[i];
			else tmpans += AB[j].second;
		}

		ans = max(ans, tmpans);

		sort(AB.begin(), AB.end());

		K -= a[i];
	}

	ll tmpans = 0;
	for (int j = 0; j < AB.size(); j++) {
		if (AB[j].first == 0)tmpans += AB[j].second;
	}
	ans = max(ans, tmpans);

	cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
n,m = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(m)]

l_max,r_min = 0,10**5
for l,r in src:
    l_max = max(l_max,l)
    r_min = min(r_min,r)
else:
    if r_min-l_max < 0:
        print(0)
    else:
        print(r_min-l_max+1)

Measured memory_bytes: 16628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define ln "\n"
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define ppll pair<ll,pll>
#define vll vector<ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define sll stack<ll>
#define qll queue<ll>
#define pqll priority_queue<ll>
#define mp make_pair
#define f first
#define s second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define Test ll tt;cin>>tt; while(tt--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define init(x,n,v) for(ll i=0;i<=n;i++) x[i]=v
#define scan(x,n)  for(ll i=0;i<n;i++) cin>>x[i]
#define scan1(x,n) for(ll i=1;i<=n;i++) cin>>x[i]
#define all(x) x.begin(),x.end()
ll mod = 1e9+7;
#define N 300005

int main() 
{
	fast_io;
	// Test
    ll n,i,w,k,j;
    cin>>n>>w;
    pll arr[n+1];
    for(i=1;i<=n;i++)cin>>arr[i].f>>arr[i].s;
    sort(arr,arr+n);
    ll dp[n+1][w+1];
    for(i=0;i<=n;i++)
     for(j=0;j<=w;j++)
      if(i==0||j==0)
       dp[i][j]=0;
     else if(arr[i].f>j)dp[i][j]=dp[i-1][j];
     else dp[i][j]=max(dp[i-1][j],arr[i].s+dp[i-1][j-arr[i].f]);
    
    cout<<dp[n][w];
    return 0;
}

Measured memory_bytes: 79104
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

// VerifyはEDPC Z

// Convex Hull Trick
// Li-Chao-tree
// 直線群ax + bの中から、あるx(X)について
// 最小を取る直線の値aX + bをクエリO(logN)で得られる
// update で直線を追加
// @ei1333のライブラリ、クエリが（先読み）単調増加のときなど、特殊なときにはより計算量を落とす実装が存在する
// 初期化のvector x　はクエリのvector(x[i] := i回目に聞かれるクエリの値)
// query(i) := i回目のクエリに答える（xの値を与えるわけではないことに注意）

template< typename T >
struct LiChaoTree {
    struct Line {
        T a, b;
        Line(T a, T b):a(a), b(b) {}

        inline T get(T x) const {return a * x + b;};

        inline bool over(const Line &b, const T &x) const {
            return get(x) < b.get(x);
        }
    };

    vector< T > xs;
    vector< Line > seg;
    int sz;

    LiChaoTree(const vector< T > &x, T INF): xs(x) {
        sz = 1;
        while(sz < xs.size()) sz <<= 1;
        while(xs.size() < sz) xs.emplace_back(xs.back() + 1);
        seg.assign(2 * sz - 1, Line(0,INF));
    }

    void update(Line &x, int k, int l, int r) {
        int mid = (l + r) >> 1;
        auto latte = x.over(seg[k], xs[l]), malta = x.over(seg[k], xs[mid]);
        if(malta) swap(seg[k], x);
        if(l + 1 >= r)return;
        else if(latte != malta) update(x, 2 * k + 1, l, mid);
        else update(x, 2 * k + 2, mid, r);
    }

    void update(T a, T b) { // ax + b
        Line l(a, b);
        update(l, 0, 0, sz);
    }

    T query(int k) { // xs[k]
        const T x = xs[k];
        k += sz - 1;
        T ret = seg[k].get(x);
        while(k > 0) {
            k = (k - 1) >> 1;
            ret = min(ret, seg[k].get(x));
        }
        return ret;
    }
};


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,c; cin >> n >> c;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    vector<ll> dp(n);
    LiChaoTree<ll> lichao(h, INF);
    dp[0] = 0;
    lichao.update(-2 * h[0], h[0] * h[0]);
    reps(i,n-1){
        // debug(lichao.query(i));
        dp[i] = lichao.query(i) + c + h[i] * h[i];
        lichao.update(-2 * h[i], h[i] * h[i] + dp[i]);\
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 14696
package main

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

func main() {
	N := ReadInt()
	m := make(map[string]bool)
	for i := 0; i < N; i++ {
		s := ReadString()
		m[s] = true
	}
	fmt.Println(len(m))
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 15784
#include <bits/stdint-intn.h>
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    Int n, m; cin >> n >> m;
    vint hh(n); vin(hh);
    vpint h(n);
    rep(i, n) {
        h[i] = make_pair(hh[i], i);
    }
    sort(all(h),[&](pint x, pint y){if(x.first==y.first)return h[x.second].first<h[y.second].first;return x.first>y.first;});

    //rfor(p, h) cout << p.first << " " << p.second << endl;

    vpint ab(m); vpin(ab);
    
    vector<set<Int>> nodes(n);
    rfor(p, ab) {
        auto [x, y] = p;
        x--; y--;
        nodes[x].insert(y);
        nodes[y].insert(x);
    }
    vint ans(n, -1);

    //rfor(v, nodes) put_line(v);

    rfor(p, h) {
        auto[hight, i] = p;
        if(ans[i] == -1) ans[i] = 1;
        rfor(x, nodes[i]) {
            if(hight >= hh[x]) ans[x] = 0;
        }
        //put_line(ans);
    }
    //put_line(ans);


    Int cnt = 0;
    rfor(x, ans) if(x == 1) cnt++;
    println(cnt);


    return 0;
}


Measured memory_bytes: 21972
def divisors(n):
    res = []
    for d in range(1, int(n**0.5)+1):
        if n%d==0:
            res.append(d)
            res.append(n//d)
    res = sorted(set(res))
    return res

# 素因数分解
def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

K = int(input())
N = 3
invK = modinv(K)
P = [0] * (K+1)
mod = 10**9+7
for i in range(1, K+1):
    p = pow(K//i * invK, N, mod)
    P[i] = p
KN = pow(K, N, mod)
ans = 0


# https://kazuma8128.hatenablog.com/entry/2018/07/29/231819
for i in range(K, 1, -1):
    #print(i, divisors(i))
    for d in divisors(i):
        if d!=i:
            P[d] -= P[i]
for i, p in enumerate(P[1:], 1):
    n = p * KN % mod
    #print(i, n)
    ans = (ans + n * i) % mod
print(ans)


Measured memory_bytes: 9532
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  v(ll) A(N);
  rep(i,N) {
    cin >> A[i];
  }
  ll ans = 0;
  rep(i,N) {
    while(A[i] % 2 == 0 && A[i] > 0) {
      A[i] =  A[i] / 2;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int sumke(int a){
    int sum = 0;
    while(a != 0){
        sum += a % 10;
        a /= 10;
    }
    return sum;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;

    int sum;
    int ans = 0; 

    for(int i = 1; i <= N; i++){
        sum = 0;
        sum = sumke(i);
        if(sum >= A && sum <= B){
            ans += i;
        }
    }

    cout << ans << endl;

}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << H*W - h*W - w*H + h*w << endl;
}

Measured memory_bytes: 256
N = int(input())
S = input()

count_W = []
count = 0
for i in range(N):
    if i == 0:
        count_W.append(0)
    else:
        if S[i-1:i] == 'W':
            count += 1
        count_W.append(count)

count_E = []
for i in range(N):
    count_E.append(0)
count = 0
for i in range(N - 1, -1, -1):
    if S[i+1:i+2] == 'E':
        count += 1
    count_E[i] = count

total_list = []
for i in range(N):
    to_E = count_W[i]
    to_W = count_E[i]
    total_list.append(to_E + to_W)

print(min(total_list))


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

using namespace std;

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

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

    return gcd(b, a%b);
}

const ll L = 1e5+5;

ll modexp(ll a, ll b, ll c)
{
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b>>=1;
    }

    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    string s;
    cin >> s;

    ll n = sz(s);

    vector <ll> r(n+5), l(n+5);
    vector <ll> ans(n+5, 0);

    ll cur = n-1;

    for(ll i=n-2; i>=0; i--)
    {
        if(s[i] == 'R')
        {
            l[i] = cur;
        }

        else
        {
            cur = i;
        }
    }

    cur = 0;

    for(ll i=1; i<n; i++)
    {
        if(s[i] == 'L')
        {
            r[i] = cur;
        }

        else
        {
            cur = i;
        }
    }

    for(ll i=0; i<n; i++)
    {
        if(s[i] == 'R')
        {
            if((l[i]-i)%2 == 0)
            {   
                ans[l[i]]++;
            }

            else
            {
                ans[l[i]-1]++;
            }
        }

        else
        {
            if((i-r[i])%2 == 0)
            {
                ans[r[i]]++;
            }

            else
            {
                ans[r[i]+1]++;
            }
        }
    }

    for(ll i=0; i<n; i++)
    {
        cout << ans[i] << " ";
    }
    cout << endl;


    return 0;
}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define pb push_back
#define frab(i, a, b) for (int i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
const int N = 3e5 + 10;

vector <int> g[N];
char s[N];
int cnta[N], cntb[N];

void eraseA(int v, set <pair <int, int> >& white, int* cnta) {
    for (auto u: g[v]) {
        if (white.count({cnta[u], u})) {
            white.erase(white.find({cnta[u], u}));
            cnta[u]--;
            white.insert({cnta[u], u});
        }
    }
}

int main() {
    //freopen("a.in", "r", stdin);
    int n, m;
    scanf("%d %d", &n, &m);
    scanf("%s", &s);
    fr(i, m) {
        int v, u;
        scanf("%d %d", &v, &u);
        --v, --u;
        g[v].pb(u);
        g[u].pb(v);
        if (s[u] == 'A')
            cnta[v]++;
        else
            cntb[v]++;
        if (s[v] == 'A')
            cnta[u]++;
        else
            cntb[u]++;
    }
    set <pair <int, int> > white, black;
    fr(i, n) {
        white.insert({cnta[i], i});
        black.insert({cntb[i], i});
    }
    while (white.size() && black.size()) {
        auto itw = white.begin();
        auto itb = black.begin();
        //cout << itw->second << " " << itb->second << endl;
        if (itw->first && itb->first) {
            cout << "Yes";
            return 0;
        }
        if (!(itw->first)) {
            int v = itw->second;
            white.erase(itw);
            assert(black.count({cntb[v], v}));
            black.erase(black.find({cntb[v], v}));
            if (s[v] == 'A')
                eraseA(v, white, cnta);
            else
                eraseA(v, black, cntb);

        }
        else if (!(itb->first)) {
            int v = itb->second;
            black.erase(itb);
            assert(white.count({cnta[v], v}));
            white.erase(white.find({cnta[v], v}));
            if (s[v] == 'A')
                eraseA(v, white, cnta);
            else
                eraseA(v, black, cntb);

        }
    }
    cout << "No";
}


Measured memory_bytes: 32512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    long long ans0 = 0;
    // +-
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a[i];
        // -
        if (i&1) {
            if (sum >= 0) {
                ans0 += sum + 1;
                sum = -1;
            }
        }
        // +
        else {
            if (sum <= 0) {
                ans0 += 1 - sum;
                sum = 1;
            }
        }
    }

    // -+
    long long ans1= 0;
    sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a[i];
        // -
        if (~i&1) {
            if (sum >= 0) {
                ans1 += sum + 1;
                sum = -1;
            }
        }
        // +
        else {
            if (sum <= 0) {
                ans1 += 1 - sum;
                sum = 1;
            }
        }
    }

    cout << min(ans0, ans1) << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3712
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
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)*}
    };
}
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)*}
    };
}
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, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! printvec {
    ( $item:expr ) => {
        for &i in &$item {
            print!("{} ", i);
        }
        println!("");
    }
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
#[derive(PartialEq, PartialOrd, Clone, Debug)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}
#[allow(dead_code)]
const MOD: usize = 1000000007;


fn main() {
    input!{
        S: chars, T: chars,
    }
    let mut ans = 0;
    for i in 0..3 {
        if S[i] == T[i] {
            ans += 1;
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 4476
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;

vector< ll > divisor(ll n) {
  vector< ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(),ret.end());
  return (ret);
}

ll fun(ll b, ll n){
    ll ans=0;
    while(n>=b){
        ll x=n%b;
        ans+=x;
        n=(n-x)/b;
    }
    ans+=n;
    return ans;
}

ll N,S;

int main(){
    cin>>N>>S;
    ll sa=(N-S);
    vector<ll> x=divisor(sa);
    bool OK=true;
    ll ans=-1;

    if(sa<0) OK=false;
    if(sa==0) {OK=false; ans=N+1;}
    if(OK){
        for(int i=0;i<x.size();i++){
            if(fun(x.at(i)+1,N)==S){
                ans=x.at(i)+1;
                break;
            }
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

struct state{
    int a,b,c,d;
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    vector<vector<int>> a(h,vector<int>(w));
    rep(i,h)rep(j,w){
        cin>>a[i][j];
    }
    vector<state> ans;
    rep(i,h){
        if(i%2==0){
            rep(j,w-1){
                if(a[i][j]%2){
                    a[i][j]--;
                    a[i][j+1]++;
                    ans.push_back({i+1,j+1,i+1,j+2});
                }
            }
            if(a[i][w-1]%2 && i!=h-1){
                a[i][w-1]--;
                a[i+1][w-1]++;
                ans.push_back({i+1,w,i+2,w});
            }
        }else{
            for(int j=w-1;j>=1;j--){
                if(a[i][j]%2){
                    a[i][j]--;
                    a[i][j-1]++;
                    ans.push_back({i+1,j+1,i+1,j});
                }
            }
            if(a[i][0]%2 && i!=h-1){
                a[i][0]--;
                a[i+1][0]++;
                ans.push_back({i+1,1,i+2,1});
            }
        }
    }
    cout<<ans.size()<<endl;
    for(auto &x:ans){
        cout<<x.a<<' '<<x.b<<' '<<x.c<<' '<<x.d<<endl;
    }
}

Measured memory_bytes: 5236
#include <stdio.h>

int main(void)
{
	unsigned n, time;
	unsigned t[200000];
	unsigned i;
	unsigned sum = 0;
	
	scanf("%u %u", &n, &time);
	for(i=0; i<n; i++)
		scanf("%u", &t[i]);
	
	for(i=1; i<n; i++){
		unsigned diff = t[i]-t[i-1];
		
		if(diff > time)
			diff = time;
		
		sum += diff;
	}
	
	printf("%u\n", sum+time);
	
	
	return 0;
}


Measured memory_bytes: 896
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    ll n, k;
    cin >> n >> k;
    ll min = n%k;
    cout << std::min(min, abs(min - k)) << "\n";
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int N;
    scanf("%d", &N);
    int temp = 0;
    for(int i = 1; i <= 9; i++){
        if((double)N / i <= 9 && (double)N / i >= 1 && N % i == 0){
            temp = 1;
            break;
        }
    }
    if(temp == 1){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
long long  j,n,t,y,u,i,b,bm,b2,d1,d2,r,res,pm,s,f,m,a[110][1001000],c[1001000],d[1001000],m1,m2,n1,n2,f1,f2;
int main()
{
    res=-10000000;
    cin >> n >> m;
    for(i = 1; i <= n; i ++)
    {
        cin >> d[i] >> c[i];
    }
    a[0][0] = 0;
    for(i = 1; i <= m; i ++)
        a[0][i] = -10000000;

    for(i = 1; i <= n; i ++)
    {
        for(j = 0; j <= m; j ++)
        {
            n1 = a[i - 1][j];
            if(j >= d[i])
            {
                n1= max(n1, a[i - 1][j - d[i]] + c[i]);
            }
            a[i][j] = n1;
        }
    }
    for(i = 0; i <= m; i++)
    {
        if(a[n][i] > res)
            res = a[n][i];
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 284928
object Main{
  def main(args: Array[String]){
    val input=io.Source.stdin.getLines().mkString("\n")
    println(solve(input).trim())
  }

  def solve(input:String):String={
    val k = input.split("\n")(0).split(" ")(1).toInt
    val hs = input.split("\n")(1).split(" ").map(_.toInt)
    hs.filter{_>=k}.size.toString
  }
}


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

int main() {
  int K;
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> K;
  
  cout << a.at(K - 1) << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++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(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

struct fruit {
    int color;
    ll value;

    bool operator<(const fruit& other) const {
        if (value < other.value) return true;
        else return false;
    }
};

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C);
    vector<fruit> whole;
    REP(i, A) {
        cin >> p[i];
        whole.push_back(fruit{1, p[i]});
    }
    REP(i, B) {
        cin >> q[i];
        whole.push_back(fruit{2, q[i]});
    }
    REP(i, C) {
        cin >> r[i];
        whole.push_back(fruit{0, r[i]});
    }

    sort(ALL(p));
    sort(ALL(q));
    sort(ALL(r));
    sort(ALL(whole));

    reverse(ALL(p));
    reverse(ALL(q));
    reverse(ALL(r));
    reverse(ALL(whole));

    int p_idx = 0, q_idx = 0, r_idx = 0, red_idx = 0, green_idx = 0;
    ll ans = 0;
    REP(i, X+Y) {
        if(whole[i].color == 1)  {
            p_idx++;
            red_idx++;
        } else if(whole[i].color == 2) {
            q_idx++;
            green_idx++;
        } else if(whole[i].color == 0) {
            r_idx++;
        }
        ans += whole[i].value;
    }

    // cerr << "red_idx = " << red_idx << " green_idx = " << green_idx << endl;
    // cerr << "p_idx = " << p_idx << " q_idx = " << q_idx << " r_idx = " << r_idx << endl;
    if(red_idx > X) {
        p_idx--;
        while(red_idx > X) {
            if(q[q_idx] >= r[r_idx])
                ans += q[q_idx++];
            else
                ans += r[r_idx++];
            ans -= p[p_idx--];
            red_idx--;
            green_idx++;
        }
    }
    if(green_idx > Y) {
        q_idx--;
        // cerr << "reduce" << endl;
        while(green_idx > Y) {
            ans -= q[q_idx--];
            if(p[p_idx] >= r[r_idx])
                ans += p[p_idx++];
            else
                ans += r[r_idx++];
            green_idx--;
            red_idx++;
        }
    }

    // cerr << "red_idx = " << red_idx << " green_idx = " << green_idx << endl;
    // cerr << "p_idx = " << p_idx << " q_idx = " << q_idx << " r_idx = " << r_idx << endl;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12396
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
int n;
int nu[200200];
struct SEG{
    int ma[2000200];
    void build(int rt,int l,int r)
    {
        ma[rt]=-inf;
        if(l==r)return;
        int mid=(l+r)/2;
        build(rt*2,l,mid);
        build(rt*2+1,mid+1,r);
    }
    void change(int rt,int l,int r,int p,int v)
    {
        if(l==r){ma[rt]=v;return;}
        int mid=(l+r)/2;
        if(mid>=p)change(rt*2,l,mid,p,v);
        else change(rt*2+1,mid+1,r,p,v);
        ma[rt]=max(ma[rt*2],ma[rt*2+1]);
    }
    int query(int rt,int l,int r,int st,int ed)
    {
        if(l>ed||r<st)return -inf;
        if(l>=st&&r<=ed)return ma[rt];
        int mid=(l+r)/2;
        return max(query(rt*2,l,mid,st,ed),query(rt*2+1,mid+1,r,st,ed));
    }
}seg[2];
int val[200200];
int cnt[200200];
char ans[200200];
bool check(int v,int c)
{
    if(c<0)return 0;
    return seg[c&1].query(1,1,n,v,n)>=c;
}
int main()
{
    scanf("%d",&n);
    int mx=0;
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&nu[i]);
        val[i]=1;
        if(nu[i]>mx)val[i]++,mx=nu[i];
    }
    seg[1].build(1,1,n);
    int m0,m1;
    for(int i=n;i;--i)
    {
        cnt[i]=cnt[i+1]+val[i]-1;
        m0=seg[0].query(1,1,n,nu[i],n);
        m1=seg[1].query(1,1,n,nu[i],n);
        if(val[i]==2)
        {
            seg[0].change(1,1,n,nu[i],m0+2);
            seg[1].change(1,1,n,nu[i],m1+2);
        }
        else
        {
            seg[0].change(1,1,n,nu[i],m1+1);
            seg[1].change(1,1,n,nu[i],m0+1);
        }
    }
    int lx=0,ly=0;
    mx=0;int my=0;
    for(int i=1;i<=n;++i)
    {
        seg[0].change(1,1,n,nu[i],0);
        seg[1].change(1,1,n,nu[i],-inf);
        if(check(my,lx+(nu[i]>mx)+cnt[i+1]-ly))ans[i]='0';
        else if(check(max(mx,nu[i]),ly+cnt[i+1]-lx-(nu[i]>mx)))ans[i]='0';
        else ans[i]='1';
        if(ans[i]=='0')lx+=(nu[i]>mx),mx=max(mx,nu[i]);
        else ly+=(nu[i]>my),my=max(my,nu[i]);
    }
    if(lx!=ly)
    {
        puts("-1");
        return 0;
    }
    printf("%s\n",ans+1);
    return 0;
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int money(int n) {
	if (n==1) return 3;
	else if (n==2) return 2;
	else if (n==3) return 1;
	else  return 0;
}

int main() {
	int x,y;
	cin>>x>>y;
	int ans = 0;
	ans += money(x);
	ans += money(y);
	if (x==1&&y==1) ans += 4;
	ans *= 100000;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
function main()
	N=parse(Int,readline())
	INF=10^9
	mx=[INF,INF,INF,INF]
	my=mx[:]
	Mx=-mx
	My=Mx[:]
	for i=1:N
		x,y,d=split(readline())
		x=parse(Int,x)
		y=parse(Int,y)
		if d=="L"
			d=1
		elseif d=="R"
			d=2
		elseif d=="U"
			d=3
		elseif d=="D"
			d=4
		end
		mx[d]=min(mx[d],x)
		my[d]=min(my[d],y)
		Mx[d]=max(Mx[d],x)
		My[d]=max(My[d],y)
	end
	T=[0.0]
	push!(T,(mx[1]-mx[2])/2)
	push!(T,mx[1]-min(mx[3],mx[4]))
	push!(T,min(mx[3],mx[4])-mx[2])
	push!(T,(Mx[1]-Mx[2])/2)
	push!(T,Mx[1]-max(Mx[3],Mx[4]))
	push!(T,max(Mx[3],Mx[4])-Mx[2])
	push!(T,(my[4]-my[3])/2)
	push!(T,my[4]-min(my[1],my[2]))
	push!(T,min(my[1],my[2])-my[3])
	push!(T,(My[4]-My[3])/2)
	push!(T,My[4]-max(My[1],My[2]))
	push!(T,max(My[1],My[2])-My[3])
	ans=10^18
	for t=T
		if t<0;continue;end
		X=max(Mx[1]-t,Mx[2]+t,Mx[3],Mx[4])-min(mx[1]-t,mx[2]+t,mx[3],mx[4])
		Y=max(My[1],My[2],My[3]+t,My[4]-t)-min(my[1],my[2],my[3]+t,my[4]-t)
		ans=min(ans,X*Y)
	end
	println(ans)
end
main()

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

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

int n, m;
const int mod = 1e9 + 7;

const int maxn = 5005;
int dp[maxn][maxn];
int power[maxn];
int inv[maxn];
int sum[maxn][maxn];

void add(int &a, int b){
    a += b;
    if(a >= mod)
        a -= mod;
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    power[0] = 1;
    inv[0] = 1;
    int val = (mod + 1) / 2;
    for(int i = 1;i < maxn;i++){
        power[i] = power[i - 1] * 2 % mod;
        inv[i] = 1LL * inv[i - 1] * val % mod;
    }
    cin >> n >> m;
    dp[0][m] = 1; 
    sum[0][0] = 0;
    for(int i = 1;i <= m;i++){
        sum[0][i] = sum[0][i - 1];
        add(sum[0][i], 1LL * dp[0][i] * power[i] % mod);
    }
    for(int i = 1;i <= n;i++){
        sum[i][0] = 0;
        for(int j = 1;j <= m;j++){
            add(dp[i][j], 1LL * dp[i - 1][j] * (j + 1) % mod);
            //for(int k = j + 1;k <= m;k++){
            //    int delta = k - j;
            //    int len = delta + 1;
            //    add(dp[i][j], 1LL * power[len - 2] * dp[i - 1][k] % mod * j % mod);
            //}
            int tmp1 = (sum[i - 1][m] - sum[i - 1][j] + mod) % mod;
            tmp1 = 1LL * tmp1 * inv[j + 1] % mod;
            add(dp[i][j], 1LL * tmp1 * j % mod);
            sum[i][j] = sum[i][j - 1];
            int tmp = 1LL * dp[i][j] * power[j] % mod;
            add(sum[i][j], tmp);
        }
    }
    int ans = 0;
    for(int i = 1;i <= m;i++){
        add(ans, dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 199188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
ll ans = 0;

void count(string T)
{
    int i = 0, an = 0, dn = 0;
    while (i < T.size())
    {
        while (T[i] == 'D')
        {
            ans += an;
            dn++;
            i++;
        }
        while (T[i] == 'A')
        {
            an++;
            i++;
        }
    }
}
int main()
{
    string s, t;
    cin >> s;
    int n = s.size();
    bool before = false;

    rep(i, n)
    {
        if (s[i] == 'A')
        {
            t.push_back('A');
            before = false;
        }
        else if (i + 1 < n and s[i] == 'B' and s[i + 1] == 'C')
        {
            t.push_back('D');
            i++;
        }
        else
        {
            count(t);
            t.erase();
        }
    }
    count(t);
    cout << ans;
    return 0;
}

Measured memory_bytes: 916
object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val s = sc.next

    println(
      (1 to n - 1)
        .map(i =>
          s.slice(0, i)
            .toSet
            .intersect(s.slice(i, n).toSet)
            .size
        ).max
    )
  }
}


Measured memory_bytes: 27460
#include<stdio.h>
 
#define MAX 8
#define FREE 0
#define NOTFREE 1
 
int map[MAX][MAX], queen[MAX][MAX], n, flag, a[MAX];
 
int check(int x, int y) {
    int i, j;
    
	for (i = 0; i < MAX; i++) {
		if(queen[x][i] == NOTFREE) return 0;
	}
	for (i = 0; i < MAX; i++) {
		if(queen[i][y] == NOTFREE) return 0;
	}
	for (i = x, j = y; i < MAX && j < MAX; i++, j++) {
		if(queen[i][j] == NOTFREE) return 0;
	}
	for (i = x, j = y; i >= 0 && j < MAX; i--, j++) {
		if(queen[i][j] == NOTFREE) return 0;
	}
	for (i = x, j = y; i >= 0 && j >= 0; i--, j--) {
		if(queen[i][j] == NOTFREE) return 0;
	}
	for (i = x, j = y; i < MAX && j >= 0; i++, j--) {
		if(queen[i][j] == NOTFREE) return 0;
	}

	return 1;
}
 
void putQueen(int x, int cnt) {
    int i;
    
	if (cnt >= MAX - n) {
		flag=1;
		return;
	}
	
	if (x > MAX) return;
	
	for (i = 0; i < MAX; i++) {
		if (a[x]) {
			putQueen(x+1, cnt);
			if (flag) return;
		}
 
		if (!queen[x][i] && check(x,i)) {
			queen[x][i] = NOTFREE;
			map[x][i] = NOTFREE;
			putQueen(x+1, cnt+1);
			if (flag) return;
			queen[x][i] = FREE;
			map[x][i] = FREE;
		}
	}
}
 
int main()
{
    int i, j, x, y;
    
	while (scanf("%d",&n) != EOF) {
	    for (i = 0; i < MAX; i++) {
	        a[i] = 0;
	        for (j = 0; j < MAX; j++) {
	            map[i][j] = FREE;
	            queen[i][j] = FREE;
	        }
	    }
		flag=0;
		for (i = 0; i < n; i++) {
			scanf("%d%d",&x, &y);
			a[x] = 1;
			map[x][y] = NOTFREE;
			queen[x][y] = NOTFREE;
		}
		
		putQueen(0, 0);
		
		for (i = 0; i < MAX; i++) {
			for (j = 0; j < MAX; j++) {
			    printf("%c", map[i][j] == 0 ? '.' : 'Q');
			}
			printf("\n");
		}
	}
	return 0;
}


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

int main (){
  int A,B,C,X;
  cin >> A >> B >> C >>X;
  //int n = x/50;
  
  int cnt =0;
  for(int i =0;i<=A;i++){
   for(int j=0;j<=B;j++){
     for(int k=0;k<=C;k++){
       if(500*i+100*j+50*k ==X)cnt++;
     }
   }
  }//...
  
  cout <<cnt<<endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
int n,m,l,i,j,k;
int A[100][100],B[100][100];
long int C[100][100];
int main(){
  scanf("%d %d %d",&n,&m,&l);
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf(" %d",&A[i][j]);
    }
  }
  for(i=0;i<m;i++){
    for(j=0;j<l;j++){
      scanf(" %d",&B[i][j]);
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<l;j++){
      for(k=0;k<m;k++){
        C[i][j]+=A[i][k]*B[k][j];
      }
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<l-1;j++){
      printf("%ld ",C[i][j]);
    }
    printf("%ld\n",C[i][l-1]);
  }
  return 0;
}

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

int toggle(char c)
{
	if (isupper(c)) {
		c = tolower(c);
	} else {
		c = toupper(c);
	}
	return c;
}

int main()
{
	string s;
	getline(cin, s);

	transform(s.begin(), s.end(), s.begin(), toggle);
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 1180
import sys
n,m=map(int,input().split())
a=[]
b=[]
for x in range(n):
    a.append(input())
for y in range(m):
    b.append(input())
for z in range(n-m+1):
    k=0
    l=0
    for w in range(n-m+1):
        if (a[w])[z:z+m]==b[k]:
            l+=1
            k+=1
            if l==m:
                print('Yes')
                sys.exit()
else:
    print('No')

Measured memory_bytes: 3064
S1, S2, S3, S4 = input()
Front = 10 * int(S1) + int(S2)
Back  = 10 * int(S3) + int(S4)

if 1 <= Front <= 12 and 1 <= Back <= 12:
    print('AMBIGUOUS')
elif (Front > 12 or Front == 0) and 1 <= Back <= 12:
    print('YYMM')
elif 1 <= Front <= 12 and (Back > 12 or Back == 0):
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
using ll = long long; using ld = long double; const char nl = '\n';
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */

#include <bits/extc++.h>
namespace pbds =  __gnu_pbds;
template <typename key, typename val=pbds::null_type, typename comp=less<key>>
using ostree=pbds::tree<key,val,comp,pbds::rb_tree_tag,pbds::tree_order_statistics_node_update>;
using vi = vector< int >; using vll = vector< ll >;
#define all(x) std::begin(x), std::end(x)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&);
string to_string(string const&s){return '"'+s+'"';}
string to_string(char const &c) {return to_string(string(1,c));}
string to_string(char const *c) {return to_string(string(c));}
string to_string(bool const &b) {return (b ? "1" : "0");}
template<typename... Args> string to_string(pair<Args...> const&p)
{return "("+to_string(p.first)+", "+to_string(p.second)+")";}
template <typename...Args, template<typename...> typename T> string to_string(T<Args...> const&S)
{string s = "{"; for(auto const& e: S)s+=" "+to_string(e);s+=" }"; return s;}
template<typename Tail> void debug_out(Tail t) {cerr<<" "<<to_string(t)<<" ]"<<endl;}
template<typename Head, typename... Tail> void debug_out(Head h, Tail... t)
{cerr << " " << to_string(h) << ","; debug_out(t...);}
#define pr(...) cerr<<"["<<(#__VA_ARGS__)<<"] : [", debug_out(__VA_ARGS__)
template <typename T> void dbr(T lb, T ub)
{cerr<<'{';for(auto it=lb; it!=ub; it++)cerr<<' '<<to_string(*it); cerr<<" }"<<endl;}
template<typename T, typename Comp=less<T>> bool smin(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(v, mem) ? mem = v, true : false;}
template<typename T, typename Comp=less<T>> bool smax(T &mem, T const&v, Comp const&cmp=Comp())
{return cmp(mem, v) ? mem = v, true : false;}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */



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

  ll n,a,b;cin>>n>>a>>b;
  cout << min(n*a,b) << endl;

}
/* -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- -*- */


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,n,p,m;
while(cin>>m>>n>>p){
int x[m];
n*=1000;
for(i=0;i<m;i++)cin>>x[i];
p*=1000;
l=abs(p-(n-(x[0]*6)));
j=0;
for(i=1;i<m;i++){
    k=n-(x[i]*6);
    if(abs(p-k)<l){j=i; l=abs(k-p);    }

}
cout<<j+1<<endl;
}
return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

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

  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);

  for(int i=k; i<n; i++){
    if(a.at(i-k)<a.at(i)) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;ll sum[N],X[N];
ll a[N];
int main(){
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sum[1]=X[1]=a[1];
	for(int i=2;i<=n;i++) sum[i]=sum[i-1]+a[i],X[i]=X[i-1]^a[i];
	ll ans=0;int l=1;
	for(int r=1;r<=n;r++){
		for(;sum[r]-sum[l-1]!=(X[r]^X[l-1]);l++);
		ans+=(r-l+1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4992