akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
int main(){
    ll n,flag=1;
    cin >> n;
    vector<ll> t(n+1,0),x(n+1,0),y(n+1,0);
    for(int i=0;i<n;i++)cin >> t.at(i+1) >> x.at(i+1) >> y.at(i+1);
    for(int i=0;i<n;i++){
        if(x.at(i+1)+y.at(i+1)-x.at(i)-y.at(i)<=t.at(i+1)-t.at(i)&&(t.at(i+1)-t.at(i)-(x.at(i+1)+y.at(i+1)-x.at(i)-y.at(i)))%2==0){
        }
        else{
            flag=0;
            break;
        }
    }
    cout << ((flag)?"Yes":"No") << endl;
}

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

using namespace std;

struct Mo_3D
{
  vector< int > left, right, index, order;
  vector< bool > v;
  int width;
  int nl, nr, time, ptr;

  Mo_3D(int n) : width((int) pow(n, 2.0 / 3.0)), nl(0), nr(0), ptr(0), time(0), v(n) {}

  void insert(int idx, int l, int r) /* [l, r) */
  {
    left.push_back(l);
    right.push_back(r);
    index.push_back(idx);
  }

  void build()
  {
    order.resize(left.size());
    iota(begin(order), end(order), 0);
    sort(begin(order), end(order), [&](int a, int b)
    {
      if(left[a] / width != left[b] / width) return left[a] < left[b];
      if(right[a] / width != right[b] / width) return bool((right[a] < right[b]) ^ (left[a] / width % 2));
      return bool((index[a] < index[b]) ^ (right[a] / width % 2));
    });
  }

  int process()
  {
    if(ptr == order.size()) return (-1);
    const auto id = order[ptr];
    while(time < index[id]) addquery(time++);
    while(time > index[id]) delquery(--time);
    while(nl > left[id]) distribute(--nl);
    while(nr < right[id]) distribute(nr++);
    while(nl < left[id]) distribute(nl++);
    while(nr > right[id]) distribute(--nr);
    return (index[order[ptr++]]);
  }

  inline void distribute(int idx)
  {
    v[idx].flip();
    if(v[idx]) add(idx);
    else del(idx);
  }

  void add(int idx);

  void del(int idx);

  void addquery(int idx);

  void delquery(int idx);
};

int N, Q, A[100000], B[100000], C[100000];
int D[100000];
int ans[100000], sum;

void Mo_3D::add(int idx)
{
  sum += D[idx];
}

void Mo_3D::del(int idx)
{
  sum -= D[idx];
}

void Mo_3D::addquery(int idx)
{
  if(A[idx] == 1) return; // ?????????1????????¨????????????(???????????????
  if(v[B[idx]]) { // ???????????\??£???????????´?????????????¶???????????????????
    distribute(B[idx]);
    D[B[idx]] += C[idx];
    distribute(B[idx]);
  } else {
    D[B[idx]] += C[idx];
  }
}

void Mo_3D::delquery(int idx)
{
  if(A[idx] == 1) return;
  if(v[B[idx]]) {
    distribute(B[idx]);
    D[B[idx]] -= C[idx];
    distribute(B[idx]);
  } else {
    D[B[idx]] -= C[idx];
  }
}

int main()
{
  scanf("%d %d", &N, &Q);

  Mo_3D mo(N);
  for(int i = 0; i < Q; i++) {
    scanf("%d %d %d", &A[i], &B[i], &C[i]);
    --B[i];
    if(A[i] == 1) mo.insert(i, B[i], C[i]);
  }

  mo.build();

  int idx;
  while((idx = mo.process()) != -1) {
    ans[idx] = sum;
  }

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

Measured memory_bytes: 5916
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
#define maxN 1001
#define endl '\n'
#define Mod 1000000007
using namespace std;
ll n;
ll f[200];
ll cnt;
bool fSNT[maxN];

void Init()
{
    fill_n(&fSNT[0],sizeof(fSNT)/sizeof(fSNT[0]),true);
    for(int i=2;i<=1000;i++)
    {
        if(fSNT[i])
        {
            f[cnt++]=i;
            for(int j=i*i;j<=1000;j+=i)
                fSNT[j]=false;
        }
    }
    //cout<<cnt<<endl;
    //for(int i=0;i<cnt;i++)
    //    cout<<f[i]<<" ";
}
ll u[200];
int main()
{
    Init();
    fill_n(&u[0],sizeof(u)/sizeof(u[0]),1);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        ll x=i;
        for(int k=0;k<cnt;k++)
        {
            while(x%f[k]==0)
            {
                x/=f[k];
                u[k]++;
            }
        }
    }
    ll Res=1;
    for(int i=0;i<cnt;i++)
    {
        Res*=u[i];
        Res%=Mod;
    }
    cout<<Res;
}


Measured memory_bytes: 256
/*
      友利奈緒かわいい！！！！！！！！！！！！
      Charlotteまだ見てない人は見ような！！！！！！！

               ／　 /:／　　　     　　　　　　　 　 ＼:ヽ　＼
  　　　　　　　 /　　／　　　　　　 　 　 　 　 　 　 　 ＼　　ヽ
  　　　　　＼__L 彡　　　　　　　　　　　　　　　　　　　 ヽ　　',
  　　　　　　　ﾌ /　　　/　　/　 /　　　,　　 　 　 　 ヽ　　', 　ｊ
  　　　　　　　ﾚ　　　 /　　/ 　/　 　 　 　 　 　 　 　 ', 　ヽ　j
  　　　 　 　 // 　 　 !　/_l＿/__ノ 　　{ ＼}　　　　 　 ',　　',/
  　　　　　　i ﾊ 　 　 {　从j　ﾊ　i　　　 ',　 ト-､}　 i i　 }　　jj
  　　　　　　( ﾊ　　　(　 川　ハ ﾊ　 !　 '　ﾊ　 ﾊ　j j　,' 　 八
  　　　 ＜＿,ｨ∧　　　斗芹ﾃミxハ ﾊ　 ﾚ　} /__ﾚﾚ　/ 　 ∧ ＼　ﾉ
  　　　 　 　 ∨　＼ 　ゝ　辷:ソ　　 　)　芹ﾚ心ヾレ′　/ ト--　´
  　　　＼ｰ‐'　ﾉ　　 ＼ゝ　　　　　　 　 　 ゞ:_ソ "/ 　／ 　ヽ
  　　　　 　 フ　　　　i八 " "　　　,　　　　　　　ム彡　　　　＼
  　　　　 　/　　/　　j　 ト　　　　　　 　 　 " "イト＜　 　 　 ＼＼
  　　　　 /　　/　　　j　/／ヽ､ 　 ∩　　 　 イ　{ {　　￣ フフへ ＼＼
  　　　　(　／　　　 ,/ / 　　i　＞――＜ニニニﾆ┐　 〃／: : ヽ　ヽヽ
  　　　　／　　ィT´/ /┌―　￣￣ /::: , ,)　 　 　 〃／／: : : : : :}　ヽヽ)
  　　　/ /　 ∧ヾi┌― { {￣　　　 ﾉ:::トﾟ<　 　 　 ∥//: : : : : : : : i　 ﾉ ﾉ
  . 　　( 人　 {:ヽヾi∨　∧V　　　 /:::/　､ヽ　　　 ∥/: : : : : : : : : :}　/
  　　　V　( ∧: :＼'∨　∧V　　 ﾉ:::/　 ∧ 〉＿__∥: : : : : :／: : : :ﾚ
  　　 　 　 /∧: : : : ∨　∧V┬ｲ:::ﾉ　 〈 TT　|　|{{: : : : ／: : : : : ∧　　 ﾉ
  　　　 　 (　ハ: : : : :∨'T∧Vi　i (　 　 V　!　!　{{: : ／ : : : : : : /　ｰ　ノ
  　　　　　V　ハ: : : : :∨ﾍ∧V　i ゝゝ　 i／⌒＼{／ : : : : : : : /ｰ― ´
  　　　　　 ∨　ヽ: : : : :∨ﾍ∧∨i　〉 〉 /　/二　 ): : : : : : : : :/
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){
    os << st[i];
    if(i!=st.size()-1) os << endl;
  }
  return os;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vi a(n);
  cin >> a;
  sort(ALL(a));
  cout << a.back()-a.front() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,t;
struct P{
	int a,b;
	bool operator < (const P&t)const{
		return b>t.b;
	}
}x[200005];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d %d",&x[i].a,&x[i].b);
	}
	sort(x+1,x+n+1);t=x[1].b;
	for(int i=1;i<=n;++i){
		t=min(t,x[i].b)-x[i].a;
		if(t<0){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
constexpr lint mod=1000000007;
struct mint{lint value;};
lint inverse(lint a){
    lint m=mod;
    lint u=0,v=1;
    while(a!=0){
        lint t=m/a;
        m-=t*a;std::swap(a,m);
        u-=t*v;std::swap(u,v);
    }
    assert(m==1);
    if(u<0)u+=mod;
    return u;
}
mint operator*(mint x,mint y){return mint{x.value*y.value%mod};}
mint&operator*=(mint&x,mint y){return x=mint{x.value*y.value%mod};}
mint operator/(mint x,mint y){return mint{x.value*inverse(y.value)%mod};}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<std::vector<lint>>g(n);
    for(lint i=0;i<n-1;i++){
        lint u,v;std::cin>>u>>v;u--,v--;
        g.at(u).push_back(v);
        g.at(v).push_back(u);
    }
    std::vector<lint>p(n,-1),ord;
    std::vector<lint>que={0};
    p.at(0)=0;
    for(lint i=0;i<(lint)que.size();i++){
        lint x=que.at(i);
        ord.push_back(x);
        auto&&v=g.at(x);
        for(lint y:v){
            if(p.at(y)!=-1)continue;
            p.at(y)=x;
            que.push_back(y);
        }
        if(x)v.erase(std::find(v.begin(),v.end(),p.at(x)));
    }
    auto rord=std::vector<lint>(ord.rbegin(),ord.rend());
    std::vector<lint>sz(n,1);
    for(lint x:rord){
        for(lint y:g.at(x))sz.at(x)+=sz.at(y);
    }
    std::vector<mint>fact(n+1);fact.at(0)=mint{1};
    for(lint i=1;i<=n;i++)fact.at(i)=fact.at(i-1)*mint{i};
    std::vector<mint>dp(n),ep(n);ep.at(0)=mint{1};
    for(lint x:rord){
        dp.at(x)=fact.at(sz.at(x)-1);
        for(lint y:g.at(x)){
            dp.at(x)*=dp.at(y)/fact.at(sz.at(y));
        }
    }
    for(lint x:ord){
        for(lint y:g.at(x)){
            ep.at(y)=dp.at(x)*ep.at(x)*fact.at(n-sz.at(y)-1)*fact.at(sz.at(y))
                /(dp.at(y)*fact.at(sz.at(x)-1)*fact.at(n-sz.at(x)));
        }
    }
    for(lint i=0;i<n;i++){
        std::cout<<(dp.at(i)*ep.at(i)*fact.at(n-1)
            /(fact.at(sz.at(i)-1)*fact.at(n-sz.at(i)))).value<<'\n';
    }
}


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

const int N = 100005;

vector<ii> adj[N];

int dis[N];

void dfs(int i, int p, int c) {
  dis[i] = c;
  for (auto &j : adj[i]) {
    if (j.fi == p) continue;
    dfs(j.fi, i, c + j.sc);
  }
}

void MAIN() {
  int n; cin >> n;
  for (int i = 1; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back(ii(v, w));
    adj[v].push_back(ii(u, w));
  }
  int q, k;
  cin >> q >> k;
  dfs(k, k, 0);
  for (int i = 0; i < q; i++) {
    int u, v;
    cin >> u >> v;
    cout << dis[u] + dis[v] << '\n';
  }
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

using namespace std;

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

#define F first
#define S second

const int MAXN = 50 + 2;

int cnt[2];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, p; cin >> n >> p;
	while (n--){
		int x;	cin >> x;
		cnt[x&1]++;
	}
	if (!p)
		cout << (1ll<<cnt[0])*(1ll<<max(0, cnt[1]-1)) << "\n";
	else{
		if (!cnt[1])
			cout << "0\n";
		else
			cout << (1ll<<cnt[0])*(1ll<<cnt[1]-1) << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define FALSE 0
#define TRUE 1

int main (int argc, char* argv[])
{
  int i, p, k, count, n;
  char flag[1000000];
  
  while (scanf("%d", &n) != EOF) {
    if (2 <= n) {
      count = 1;
    } else {
      count = 0;
    }
    for (i=0; i<=n; i++) {
      flag[i] = TRUE;
    }
    for (i=0; i<=n; i++) {
      if (flag[i]) {
	p = i + i + 3;
	for (k=i+p; k<=n; k+=p) {
	  flag[k] = FALSE;
	}
	if (p <= n) {
	  count++;
	}
      }
    }
    printf("%d\n", count);
  }
  
  return 0;
}

Measured memory_bytes: 1384
n, k = input().strip().split()
n, k = [int(n), int(k)]
ans = 0
for i in range(n):
  ii = i + 1
  temp = ii
  x    = 0
  while ( temp < k ):
    temp *= 2
    x += 1
  
  ans += 1 / ( (2**x) * n )
  
print (ans)

Measured memory_bytes: 3060
from collections import deque

N = int(input())
S = list(map(int,input().split()))
S.sort()

used = [S.pop()]
for _ in range(N):
 
    l, r = 0, len(used)
    reuse = deque()
    for i in range(len(S)):
        v = S.pop()
        if v < used[l]:
            used.append(v)
            l += 1
        else:
            reuse.appendleft(v)
        if l == r:
            break
    else:
        print('No')
        break
    S.extend(reuse)
    used.sort(reverse=True)
else:
    print('Yes')

Measured memory_bytes: 34368
NK = input()
num = NK.split()
N = num[0]
K = num[1]

P = input()
Pn = P.split()
#print(Pn)

Pn_a = [int(i) for i in Pn]
Pn_b = sorted(Pn_a)

price = 0

for i in range(int(K)):
    price += int(Pn_b[i])
    
print(price)


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	int n;
	string s;
	set<string> ss;
	cin >> n;
	loop(n) {
		cin >> s;
		ss.insert(s);
	}
	cout << ss.size() << endl;
	return 0;
}



Measured memory_bytes: 19236
/*
// A - Cats and Dogs
#include <iostream>
using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int A,B,X;
  cin>>A>>B>>X;
  cout<<(A<=X&&X<=A+B?"YES":"NO")<<endl;
  return 0;
}

// B - Toll Gates
#include <iostream>
using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int N,M,X;
  cin>>N>>M>>X;
  int Left=0,Right=0;
  while (M--) {
    int A;
    cin>>A;
    Left+=(A<X?1:0); Right+=(A>X?1:0);
  }
  cout<<min(Left,Right)<<endl;
  return 0;
}
 
// C - Many Medians
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int N;
  cin>>N;
  int X[N],Y[N];
  for (int i=0; i<N; i++) {
    cin>>X[i];
    Y[i]=X[i];
  }
  sort(Y,Y+N);
  for (int i=0; i<N; i++) {
    cout<<(X[i]<Y[N/2]?Y[N/2]:Y[N/2-1])<<endl;
  }
  return 0;
}
 */
// D - Binomial Coefficients
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  int n;
  cin>>n;
  int a[n];
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  sort(a,a+n);
  int N=a[n-1],R=a[0];
  double half=N/2.0,diff=fabs(a[0]-half);
  for (int i=1; i<n; i++) {
    if (N==a[i]) {
      continue;
    }
    if (diff>=fabs(a[i]-half)) {
      diff=fabs(a[i]-half); R=a[i];
    }
  }
  cout<<N<<" "<<R<<endl;
  return 0;
}

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

using namespace std;

int main()
{
    long long int X;
    cin >> X;
    for (int i = -200; i < 201; i++)
    {
        long long int A = 1ll * i * i * i * i * i;
        for (int j = -200; j < 200; j++)
        {
            if (A == X + 1ll * j * j * j * j * j)
            {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(10) << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

int ctoi(char c) {
  return c - 'a';
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<set<int>> vs(30);
  int n;
  string s;
  cin >> n;
  cin >> s;
  int q;
  cin >> q;
  rep(i, n) {
    vs[ctoi(s[i])].insert(i);
  }
  VI vans;
  rep(i, q) {
    int t;
    cin >> t;
    if(t == 1) {
      int x;
      char y;
      cin >> x >> y;
      x--;
      vs[ctoi(s[x])].erase(x);
      vs[ctoi(y)].insert(x);
      s[x] = y;
    }
    else if(t == 2) {
      int x, y;
      cin >> x >> y;
      x--; y--;
      int ans = 0;
      rep(i, 26) {
        auto l = vs[i].lower_bound(x);
        if(l != vs[i].end() && *l <= y) ans++;
      }
      vans.push_back(ans);
    }
  }
  for(int a : vans) {
    out(a);
  }
  return 0;
}


Measured memory_bytes: 26396
import math
import itertools

def get_length(p1, p2):
    x1 = p1[0]
    x2 = p2[0]
    y1 = p1[1]
    y2 = p2[1]

    return ((x1 - x2)**2 + (y1- y2)**2)**0.5

N = int(input())
xy = [[0, 0] for _ in range(N)]
for i in range(N):
    xy[i][0], xy[i][1] = map(int, input().split())

total_len = 0
pattern = 0
for i in itertools.permutations(list(range(N))):
    pattern += 1
    for j in range(N-1):
        total_len += get_length(xy[i[j]], xy[i[j+1]])

print(total_len / pattern)

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <cctype>
#include <map>
#include <cmath>
#include <set>
using namespace std;
string str, str1, str2;
int pos;
map<char, int> chset;

bool formula(){
    bool res;
    if (str[pos] == 'T') {pos++; return true;}
    if (str[pos] == 'F') {pos++; return false;}
    if (chset.find(str[pos]) != chset.end()) {return chset[str[pos++]];}
    if (str[pos] == '-' && str[pos + 1] != '>') {
        pos++;
        return !formula();
    }

    if (str[pos] == '(') {
        pos++;
        res = formula();
        if (str[pos] == '*') {
            pos++;
            res &= formula();
        }
        else if (str[pos] == '+') {
            pos++;
            res |= formula();
        }
        else if (str[pos] == '-' && str[pos + 1] == '>') {
            pos += 2;
            res = !res | formula();
        }
        pos++;
    }
    return res;
}

void equation(){
    set<char> S;
    string chlist = "";
    for (int i = 0; i < str.size(); i++) {
        if (islower(str[i])) {
            S.insert(str[i]);
        }
    }
    set<char>::iterator it = S.begin();
    while (it != S.end()) {
        chlist += *it;
        ++it;
    }
    
    for (int i = 0; i < pow(2, chlist.size()) - 1; i++) {
        for (int j = 0; j < chlist.size(); j++) {
            chset[chlist[j]] = (i >> j) & 1;
        }
        pos = 0;
        str = str1;
        int res1 = formula();
        pos = 0;
        str = str2;
        int res2 = formula();
        if (res1 != res2) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;
}

int main()
{
    while (true) {
        cin >> str;
        if (str == "#") {
            break;
        }
        str1 = ""; str2 = "";
        for (int i = 0; i < str.size(); i++) {
            if (str[i] == '=') {
                str2 = str1;
                str1 = "";
            }
            else {
                str1 += str[i];
            }
        }
        equation();
    }
    return 0;
}

Measured memory_bytes: 1284
Q, H, S, D = [int(x) for x in input().strip().split()]
N = int(input())
min_QHS = min(Q * 4, H * 2, S)
if min_QHS * 2 <= D:
  print(N * min_QHS)
else:
  print(D * (N // 2) + (N % 2) * min_QHS)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
typedef long long ll;

int main() {

    int N;
    cin >> N;
    vector<int> h(N);
    rep(i, N) cin >> h[i];

    int res = 0;
    while(true) {
        if (*max_element(h.begin(), h.end()) == 0) break;

        int i = 0;
        while(i < N) {
            if (h[i] == 0) i++;
            else {
                res++;
                while(i < N && h[i]>0) {
                    h[i]--;
                    i++;
                }
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
// 2011/08/21 Tazoe

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
	while(true){
		double a, b, c, d;
		cin >> a >> b >> c >> d;
		if(a==-1.0&&b==-1.0&&c==-1.0&&d==-1.0)
			break;

		// ツδ可ジツアツδ督づ可陛渉環キ
		a = a*M_PI/180.0;
		b = b*M_PI/180.0;
		c = c*M_PI/180.0;
		d = d*M_PI/180.0;

		double x = acos(sin(a)*sin(c)+cos(a)*cos(c)*cos(d-b));

		cout << (int)(6378.1*x+0.5) << endl;		// ツ渉ャツ青板点ツ暗按可コツづーツ四ツ偲個古慊禿シ
	}

	return 0;
}

Measured memory_bytes: 0
package main
import "fmt"
const mod int64 = 1000000007
func main() {
  var s string
  var n int
  var m int64 = 0
  r := map[string]int64{}
  l := map[string]int64{}
  fmt.Scan(&s)
  n = len(s)
  for i:=0;i<n;i++ {
    r[s[i:i+1]]++
  }
  for i:=0;i<n;i++ {
    r[s[i:i+1]]--
    if s[i:i+1] == "B" || s[i:i+1] == "?" {
      m += (((l["A"]*pow(3,l["?"]  ))%mod)*((r["C"]*pow(3,r["?"]  ))%mod))%mod
      m %= mod
      m += (((l["?"]*pow(3,l["?"]-1))%mod)*((r["C"]*pow(3,r["?"]  ))%mod))%mod
      m %= mod
      m += (((l["A"]*pow(3,l["?"]  ))%mod)*((r["?"]*pow(3,r["?"]-1))%mod))%mod
      m %= mod
      m += (((l["?"]*pow(3,l["?"]-1))%mod)*((r["?"]*pow(3,r["?"]-1))%mod))%mod
      m %= mod
    }
    l[s[i:i+1]]++
  }
  fmt.Println(m%mod)
}
func pow(base int64,power int64) int64 {
  if base == 1 { return 1 }
  if power < 0 { return 0 }
  if power == 0 { return 1 }
  if power%2 == 0 {
    var h int64 = pow(base,power/2)%mod
    return (h*h)%mod
  } else {
    return (base*pow(base,power-1))%mod
  }
}

Measured memory_bytes: 1280
#include<iostream>

using namespace std;

int main(){
  int n;
  while(cin >> n && n){
 int x1,y1,z1,w1,x2,y2,z2,w2;
 for(int i=0;i<n;i++){
    cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2; 
    cout << x1*x2-y1*y2-z1*z2-w1*w2 << " " << x1*y2+x2*y1+z1*w2-w1*z2 << " " << x1*z2-w2*y1+z1*x2+w1*y2 << " " << x1*w2+y1*z2-z1*y2+w1*x2 << endl;
 }
  }
  return 0;
}

Measured memory_bytes: 1160
import sys
import decimal
from decimal import Decimal, ROUND_DOWN

input = lambda: sys.stdin.readline().rstrip()


def solve():
    A, B = input().split()
    A = decimal.Decimal(A)
    B = decimal.Decimal(B)
    ans = A * B
    print(ans.quantize(Decimal('0'), rounding=ROUND_DOWN))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9876
def r_shift(c, i):
    return chr(ord('a') + int(((ord(c) + i) - ord('a'))) % 26)
s = input()
K = int(input())
r = ''
for c in s[:-1]:
    dis = 26 - (ord(c) - ord('a'))
    if dis <= K and c != 'a':
        K -= dis
        r += 'a'
    else:
        r += c
if K > 0:
    r += r_shift(s[-1], K)
else:
    r += s[-1]
print(r)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream& operator<<(ostream &os, unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;



int main()
{
  int n;
  cin >> n;
  if (n == 3 || n == 5 || n == 7) cout << "YES" << endl;
  else cout << "NO" << 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() {
  string s;cin>>s;
  for(int i=0;i<s.size();i+=2){
    cout<<s[i];
  }
  cout<<endl;
}

Measured memory_bytes: 3628
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}



int main(){
    // Failed to predict input format
    int N;
    VI A;
    cin>>N;
    REP(i, N){
        int v;
        cin>>v;
        if(v%2==0){
            A.PB(v);
        }
    }
    bool flag=true;
    REP(i,A.size()){
        if(A[i]%3==0 || A[i]%5==0){}
        else{flag=false;}
    }
    if(flag)cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iterator>

using namespace std;

long long int const LL_MAX = 10000000000000000; // 10^16

int main(){
	
	int N, M;
	
	cin >> N >> M;
	
	int a[2000];
	
	for(int i = 0; i < M; i++){
		int num1, num2;
		cin >> num1 >> num2;
		if(num1 >= num2){
			a[i] = 0;
		}else{
			a[i] = (num2 - num1) / 2;
		}
	}
	
	sort(a, a + M);
	
	int ans = 0;
	
	for(int i = 0; i < M - 1; i++){
		ans += a[i];
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
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())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
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;}
// head

char s[40];
int main() {
	scanf("%s",s);
	int l=strlen(s);
	bool a9=1;
	rep(i,1,l) if (s[i]!='9') a9=0;
	printf("%d\n",(s[0]-'1')+(l-1)*9+a9);
}


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

#define pb push_back
#define FOR(i, s, e) for (int (i) = (s); (i) < (e); (i)++)

int main() {
    string S; cin >> S;
    int N = S.size();
    vector<int> s;
    FOR(i, 0, N) s.pb(stoi(S.substr(i, 1)));

    int ans = 753;
    FOR(i, 0, N - 2) {
        int X = s[i] * 100 + s[i+1] * 10 + s[i+2];
        ans = min(ans,abs(X - 753));
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mathpi 3.14159265358979
using namespace std;
int main(){
	int k;
	cin>>k;
	vector<ll> a(k+1),dp(k+1),dpm(k+1);
	for(int i=0;i<k;i++){
		cin>>a[i];
	}
	dp[k]=2;
	dpm[k]=2;
	for(int i=k-1;i>=0;i--){
		dp[i]= (dp[i+1]/a[i]) *a[i];
		dpm[i] = (dpm[i+1]/a[i]) * a[i];
		if(dpm[i+1]%a[i]!=0)dpm[i]+=a[i];
		if(dpm[i]>dp[i]){
			cout<<-1<<endl;
			return 0;
		}
		else{
			dp[i]+=a[i]-1;
		}
	}
	cout<<dpm[0]<<" "<<dp[0]<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;

using namespace std;
using ll = long long;
typedef pair <ll, ll > pll;

int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll n, m, K;
	ll memo[10004] = {};
	ll memo2[10004] = {};
	string s;
	string s1, s2;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);
	cin >> a;
	cin >> b;
	cin >> c;
	//ans++;
	ans++;
	if (b + 2 <= c&&a>=b+1)
	{
		a -= b - 1;
		ans += b - 1;

		a--;
		ans -= b;

		a--;
		ans += c;

		ans += (a / 2)*(c-b);

		ans += a % 2;


	}
	else
	{
		ans += a;
	}
	cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map> // STL
#include <string> 
#include <vector>
#include <queue>
#include <stack>
#define mpr make_pair
#define debug() puts("okkkkkkkk")

using namespace std;

typedef long long LL;

const int inf = 1 << 26;

int n,k;
struct data{
	int val,tms;
}a[200005];

int cmp(data a, data b){
	return a.tms>b.tms;
}
#include<set>
#include<map>
set<int>S;
map<int,int>mp;
int main(){
	int ans=0,cnt=0;
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i].val);
		if(S.count(a[i].val)){a[mp[a[i].val]].tms++;}
		else{mp[a[i].val]=++cnt;a[cnt].tms++;S.insert(a[i].val);}
	}
	if(S.size()<=k){puts("0");return 0;}
	sort(a+1,a+S.size()+1,cmp);
	for(int i=S.size(),j=0;j<S.size()-k;i--,j++){
		ans+=a[i].tms;
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 20608
n,m = gets.split.map(&:to_i)
a = []
b = Array.new(n,0)

m.times do
  a << gets.split.map(&:to_i)
end

a.each do |aa|
  b[aa[0] -1] += 1
  b[aa[1] -1] += 1
end
puts b


Measured memory_bytes: 1788
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;
using static BinarySearch;


public class E
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public static readonly int INF = int.MaxValue / 2;

	public void Solve()
	{
		string S = GetString();
		string T = GetString();

		long[] cntS = new long[26];
		for(int i = 0; i < S.Length; i++)
			cntS[(int)(S[i] - 'a')]++;

		long[] cntT = new long[26];
		for(int i = 0; i < T.Length; i++)
			cntT[(int)(T[i] - 'a')]++;

		for(int i = 0; i < 26; i++)
		{
			if(cntT[i] != 0 && cntS[i] == 0)
			{
				Console.WriteLine(-1);
				return;
			}
		}

		List<int>[] pos = Enumerable.Range(0, 26).Select(_ => new List<int>()).ToArray();
		for(int i = 0; i < S.Length; i++)
			pos[(int)(S[i] - 'a')].Add(i);

		for(int i = 0; i < 26; i++)
		{
			pos[i].Add(INF);
			pos[i].Sort();
		}

		long ans = 0;
		int current = -1;
		Comparison<int> comp = (x, y) => x - y;
		for(int i = 0; i < T.Length; i++)
		{
			int c = (int)(T[i] - 'a');
			int lb = LowerBound(pos[c], current + 1, comp);
			if(pos[c][lb] == INF)
			{
				ans += S.Length - current - 1;
				current = -1;
				lb = LowerBound(pos[c], current + 1, comp);
			}
			ans += pos[c][lb] - current;
			current = pos[c][lb];
		}

		Console.WriteLine(ans);
	}
}


public static class BinarySearch
{
	public static int LowerBound<T>(List<T> array, T key, Comparison<T> comp)
	{
		int len = array.Count;
		if(comp(array[len - 1], key) < 0)
			return -1;

		int left = 0;
		int right = len - 1;
		while(right > left)
		{
			int mid = (left + right) / 2;
			if(comp(array[mid], key) >= 0)
				right = mid;
			else
				left = mid + 1;
		}

		return left;
	}

	public static int UpperBound<T>(List<T> array, T key, Comparison<T> comp)
	{
		int len = array.Count;
		if(comp(array[len - 1], key) <= 0)
			return len;

		int left = 0;
		int right = len - 1;
		while(right > left)
		{
			int mid = (left + right) / 2;
			if(comp(array[mid], key) > 0)						
				right = mid;
			else			
				left = mid + 1;	
		}

		return left;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
}


Measured memory_bytes: 15840
n, k = map(int, input().split())
h = list(map(int, input().split()))
MAXINT = 10**8
dp = [0 for _ in range(n)]

for i in range(1, n):
    cands = []
    for j in range(max(0, i-k), i):
        cands.append(dp[j] + abs(h[j]-h[i]))
    dp[i] = min(cands)

print(dp[n-1])

Measured memory_bytes: 90156
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
    int a,sum=0,temp=0;
    for(int i=0;i<5;i++){
            cin >> a;
            for(int j=0;j<10;j++){
                if((a+j)%10==0){
                    temp = max(temp,j);
                    sum+=(a+j);
                } 
            }
    }
    cout << sum-temp;
    return 0;
}

Measured memory_bytes: 256
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
s = gets.chomp
q = gets.chomp.to_i

normal = true
head = Array.new(q)
tail = Array.new(q)
h=0
t=0
q.times do
  query = gets.chomp
  if query[0] == '1'
    normal = !normal
  else
    if query[2] == '1'
      if normal
        head[h] = query[4]
        h+=1
      else
        tail[t] = query[4]
        t+=1
      end
    else
      if normal
        tail[t] = query[4]
        t+=1
      else
        head[h] = query[4]
        h+=1
      end
    end
  end
end

#p [s, head, tail, normal]
head.compact!
tail.compact!
ans = head.reverse.join('') + s + tail.join('')

ans.reverse! if !normal

puts ans

Measured memory_bytes: 19308
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int n; cin >> n;
  string s; cin >> s;
  vector<ll> a(n);
  rep(i,0,n){
    if(s[i]=='R') a[i]=0;
    if(s[i]=='G') a[i]=1;
    if(s[i]=='B') a[i]=2;
  }
  vector<ll> cnt(3,0);
  rep(i,0,n)cnt[a[i]]++;
  ll ans = cnt[0]*cnt[1]*cnt[2];
  rep(i,0,n){
    rep(j,0,i){
      int k = i+i-j;
      if(k<n && s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i]) ans--;
    }
  }
   cout << ans << endl;
 }

Measured memory_bytes: 3676
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n;
ll a[100000],b[100000];
int main(){
	cin >> n;
	REP(i,n) {
		cin >> a[i];
	}
	REP(i,n) {
		cin >> b[i];
	}
	ll c = 0;
	REP(i,n) {
		c += max(0ll,a[i] - b[i]);
	}
	ll d = 0;
	REP(i,n) {
		d += max(0ll,(b[i] - a[i]) / 2);
	}
	if(c <= d) 
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;
const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int n;
vector<vector<int>> G(N,vector<int>(N,0));
vector<int> d(N,-1);
vector<int> colors(N,WHITE);

void bfs(){
    queue<int> q;
    q.push(0);
    colors[0] = GRAY;
    d[0] = 0;
    while(!q.empty()){
        int u = q.front();q.pop();
        for(int i = 0;i<n;i++){
            if(colors[i]==WHITE && G[u][i]){
                q.push(i);
                colors[i] = GRAY;
                d[i] = d[u] + 1;
            }
        }
        colors[u] = BLACK;
    }
}

int main()
{
    //freopen("data.txt","r",stdin);
    cin >> n;
    int u,k,v;
    for(int i = 0;i<n;i++){
        cin >> u >> k;
        u--;
        for( int j =0;j<k;j++){
            cin >> v;
            v--;
            G[u][v] = 1;
        }
    }
    bfs();
    for(int i =0;i<n;i++){
        printf("%d %d\n",i+1,d[i]);
    }
    return 0;
}



Measured memory_bytes: 3300
#include<bits/stdc++.h>
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define p push
#define p1 pop
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair<ll,ll>
#define e 1000000007
using namespace std;
ll w[102],v[102],n,memo[100001][2];
void solve(ll w1)
{
   memo[100000][0]=1;
   memo[100000][1]=w1;
   if((w1-w[1])>=0)
   {
        memo[100000-v[1]][0]=1;
        memo[100000-v[1]][1]=w1-w[1];
   }
    for(int i=2;i<=n;++i)
    {
        for(int v1=0;v1<=100000;++v1)
        {
            if(memo[v1][0] && (memo[v1][1]-w[i])>=0)
            {
                if(memo[v1-v[i]][0])
                {
                    ll z=max(memo[v1-v[i]][1],(memo[v1][1]-w[i]));
                    memo[v1-v[i]][1]=z;
                }
                else{
                    memo[v1-v[i]][0]=1;
                    memo[v1-v[i]][1]=memo[v1][1]-w[i];
                }
            }
        }
    }
    for(int v1=0;v1<=100000;++v1)
    {
        if(memo[v1][0])
        {
            cout<<100000-v1;
            break;
        }
    }
}
int main()
{
    ll w1;
    memset(memo,0,sizeof(memo));
    cin>>n>>w1;
    for(int i=1;i<=n;++i)
        cin>>w[i]>>v[i];
    solve(w1);
}

Measured memory_bytes: 1792
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ
int segtree[524288];
int query(int a,int b,int c,int d,int e){
	if(d<a||b<c)return mod;
	if(c<=a&&b<=d)return segtree[e];
	return min(query(a,(a+b)/2,c,d,e*2),query((a+b)/2+1,b,c,d,e*2+1));
}
void update(int  a,int b){
	a+=262144;
	while(a){
		segtree[a]=min(segtree[a],b);
		a/=2;
	}
}
char in[210000];
int dp[210000];
vector<int>g[210000];
int ans[210000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	scanf("%s",in);
	for(int i=0;i<524288;i++)segtree[i]=mod;
	update(a,0);
	for(int i=a-1;i>=0;i--){
		if(in[i]=='1'){
			dp[i]=mod;
			continue;
		}
		int val=query(0,262143,i+1,i+b,1);
		dp[i]=val+1;
		update(i,dp[i]);

	}
	for(int i=0;i<=a;i++){
		// printf("%d: %d\n",i,dp[i]);
		if(dp[i]<mod)g[dp[i]].push_back(i);
	}
	int n=dp[0];
	if(n>=mod){
		printf("-1\n");return 0;
	}
	int at=0;
	for(int i=n-1;i>=0;i--){
		int to=lower_bound(g[i].begin(),g[i].end(),at)-g[i].begin();
		ans[n-1-i]=g[i][to]-at;
		at=g[i][to];
	}
	for(int i=0;i<n;i++){
		if(i)printf(" ");printf("%d",ans[i]);
	}printf("\n");
}


Measured memory_bytes: 11904
#include<iostream>
#include<vector>
using namespace std;
#define MAX 200000

int main() {
    int n;
    cin >> n;
    vector<int> a(MAX+10);
    for (int i = 0; i < n; i++) cin >> a[i];

    if (n % 2 == 0) {
        for(int i = n - 1; i > 0; i -= 2) cout << a[i] << ' ';
        for(int i = 0; i < n; i += 2) cout << a[i] << ' ';
    } else {
        for(int i = n - 1; i >= 0; i -= 2) cout << a[i] << ' ';
        for(int i = 1; i < n; i += 2) cout << a[i] << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 3992
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()

    ans = 0
    sqrt = int(N ** 0.5)

    for m in range(1, sqrt + 1):
        b = N//m
        ans += m * (m + b) * (b + 1 - m)
    ans -= sqrt * (sqrt + 1) * (2 * sqrt + 1) // 6
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9360
import itertools
n,m,q = map(int, input().split())
A,B,C,D = [], [], [], []
for i in range(q):
    a,b,c,d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

def calc_ans(x,A,B,C,D):
    #print(x)
    ans = 0
    for i in range(len(A)):
        if x[B[i]-1] - x[A[i]-1] == C[i]:
            ans += D[i]
    return ans

# x = [1] * n

# for i in range(1, n):
#     for j in range(x[i], m):

answers = {}

l = list(range(m))
for v in itertools.combinations_with_replacement(l, n):
    v = sorted(v)
    vs = ''.join(str(v))
    if vs in answers.keys():
        pass
    else:
        ans = calc_ans(v,A,B,C,D)
        answers[vs] = ans
#print(answers.values())
print(max(answers.values()))

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

using namespace std;

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

    for(int i=0;i<n-1;i++)
    {
        if(v[i]>=v[i+1]) cnt++;
        else cnt=0;
        if(cnt>maxm)
        {
            maxm=cnt;
        }
    }
    cout<<maxm;
    return 0;
}


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

const int VMAX = 80 + 1;
const int XMAX = 80 + 1;

int main(){
    int H,W;
    cin >> H >> W;
    int A[H][W], B[H][W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> A[i][j];
        }
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> B[i][j];
        }
    }

    int dimA = VMAX*XMAX*2;

    bool dp[XMAX][XMAX][dimA]; // at (i,j) k can reached or not
    int nval = VMAX*(H+W);

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            for(int k=0; k<nval; k++){
                dp[i][j][k]=false;
                //cout << "i j k " << i << " " << j << " " << k << endl;                    
            }
        }
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            for(int k=0; k<nval; k++){
                int dp_j1, dp_i1;
                if( i==0 && j==0 ){
                  if(k==0){
                    dp_j1=true;
                    dp_i1=true;
                  }else{
                    dp_j1=false;
                    dp_i1=false;
                  }
                }else if( i==0 ){
                    dp_i1=false;
                    dp_j1=dp[i][j-1][k];
                }else if( j==0 ){
                    dp_i1=dp[i-1][j][k];
                    dp_j1=false;
                }else{
                    dp_i1=dp[i-1][j][k];
                    dp_j1=dp[i][j-1][k];
                }

                int knew1 = abs(k+A[i][j]-B[i][j]);
                int knew2 = abs(k-A[i][j]+B[i][j]);
                if( dp_i1 ){
                    dp[i][j][knew1]=true;
                    dp[i][j][knew2]=true;
                }
                if( dp_j1 ){
                    dp[i][j][knew1]=true;
                    dp[i][j][knew2]=true;
                }
            }
        }
    }

    int ans;

    for(int k=0; k<nval; k++){
        if(dp[H-1][W-1][k]){
            ans=k;
            break;
        }
    }

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

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

using namespace std;

int main()
{
	string s;
	cin >> s;

	int a = s.size();
	int z = 0;

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'A')
		{
			if (i <= a)
			{
				a = i;
			}
		}
		if (s[i] == 'Z')
		{
			if (z <= i)
			{
				z = i;
			}
		}
	}

	printf("%d\n", z-a+1);
	return 0;
}

Measured memory_bytes: 640