akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void){
	int n=0,a_sum=0,b_sum=0,tem=0,max;
	scanf("%d", &n);
	int a[n];

	for(int i=0;i<n;i++){
		scanf("%d", &a[i]);
	}

	for(int m=0;m<n;m++){
		max=0;
		for(int i=0;i<n;i++){
			if(max<a[i]){
				max=a[i];
				tem=i;
			}
		}
		if(m%2==0){
			a_sum+=max;
		}else{
			b_sum+=max;
		}
		a[tem]=0;
	}
	printf("%d", a_sum-b_sum);

	return 0;

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;



vector <int> Ehurui;
void Etenesu(int y){
  bool f[y+1] = {0};
  for(int i = 2;i <= sqrt(y);i++ ){
    if(f[i] == false){
      Ehurui.push_back(i);
      f[i] = true;
      for(int j = i;j <= y;j = j+i){
	f[j] = true;
      }
    }
  }
  for(int i = 2;i <= y;i++){
    if(!f[i])
      Ehurui.push_back(i);
  }
}



int main(){
  int q;
  cin >> q;
  Etenesu(100000);
  bool f[100001] = {0};
  REP(i,Ehurui.size()){
    f[Ehurui[i]] = true;
  }
  bool ff[100001] = {0};
  REP(i,100001){
    if(f[i] == true && f[(i+1)/2] == true)
      ff[i] = true;
  }
  int w[100001] = {0};
  w[3] = 1;
  for(int i = 4;i <= 100000;i++){
    if(ff[i])
      w[i] = w[i-1]+1;
    else
      w[i] = w[i-1];
  }
  REP(i,q){
    int r,l;
    cin >> r >> l;
    
    
    cout <<w[l]-w[r-1]  << endl;
   
  }
  return 0;
}


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

main(){
  int n; cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  int ans=1000;
  int kabu=0;
  string d;
  bool first=1;
  if(a[0]<a[1]) d="up";
  else if(a[0]>a[1]) d="down";
  else d="even";
  rep(i,n-1){
    if(i!=0){
      if(a[i-1]>a[i]) d="down"; 
      if(a[i-1]<a[i]) d="up";
    }
    if(a[i]<a[i+1] && (d=="down" || first)){
      first=0;
      kabu+=ans/a[i];
      ans=ans%a[i];
    }else if(a[i]>a[i+1] && (d=="up" || first)){
      first=0;
      ans+=kabu*a[i];
      kabu=0;
    }
  }
  ans+=kabu*a[n-1];
  kabu=0;
  cout<<ans<<endl;
}


Measured memory_bytes: 3564
H,W,A,B=map(int,input().split())
for _ in range(B):
  for _ in range(A):
    print(0,end='')
  for _ in range(W-A):
    print(1,end='')
  print()
for _ in range(H-B):
  for _ in range(A): 
    print(1,end='')
  for _ in range(W-A):
    print(0,end='')
  print()
   

Measured memory_bytes: 5364
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5;
int n,m,l,r,pos,ans,a[maxn];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=2*n;i++){scanf("%d",&a[i]);}
	sort(a+1,a+2*n+1);
	l=0,r=n;
	while(l!=r){
		int mid=(l+r)/2;
		bool flag=true;
		for(int i=mid+1;i<=n;i++){
		    if((a[2*n-i+mid+1]+a[mid+i])<m) flag=false;
		}
		if(!flag){l=mid+1;}
		else{r=mid;}
	}
	pos=(l+r)/2;
	ans=0;
	for(int i=1;i<=pos;i++){ans=max(a[i]+a[2*pos+1-i],ans);}
	for(int i=pos+1;i<=n;i++){ans=max(a[2*n-i+pos+1]+a[pos+i]-m,ans);}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);ios::sync_with_stdio(false);

template <typename T>
struct Kruskal
{

    struct edge
    {
        int from, to, used;
        T cost;

        edge(int x, int y, T z) : from(x), to(y), cost(z){}
        //初期化

        bool operator<(const edge &e) const
        {
            return cost < e.cost;
        }
        //sort用
    };

    int V;
    vector<int> Parent;
    vector<edge> es;

    Kruskal(){}
    Kruskal(int V_):V(V_), Parent(V_) {
        for(auto &i:Parent){
            i=-1;
        }
    }
    //1.宣言する

    void add_edge(T u, T v, T c)
    {
        es.emplace_back(u, v, c);
    }
    //2.辺を入れる

    int root(int A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = root(Parent[A]);
    }

    int size(int A)
    {
        return -Parent[root(A)];
    }

    bool connect(int A, int B)
    {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B)
        {
            //すでにくっついてるからくっ付けない
            return false;
        }

        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらひっくり返しちゃう。
        if (size(A) < size(B))
            swap(A, B);

        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;

        return true;
    }

    bool same(int A, int B)
    {
        return root(A) == root(B);
    }

    //3.回す
    T build()
    {
        sort(es.begin(), es.end());

        T res = 0;

        for (int i = 0; i < (ll)es.size(); i++)
        {
            edge e = es[i];
            if (!same(e.from, e.to))
            {
                connect(e.from, e.to);
                res += e.cost;
            }
        }

        return res;
    }
};

signed main()
{
    int n;cin>>n;
    vector<PL> v(n),u(n);
    rep(i,n){
        ll x,y;cin>>x>>y;
        v.at(i)={x,i};
        u.at(i)={y,i};
    }

    sort(all(v));
    sort(all(u));

    Kruskal<ll> kr(n);
    rep(i,n-1){
        kr.add_edge(v[i].se,v[i+1].se,v[i+1].fi-v[i].fi);
        kr.add_edge(u[i].se,u[i+1].se,u[i+1].fi-u[i].fi);
    }

    cout<<kr.build()<<endl;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

ll mp[222222];
ll ans[222222];
vector<vector<ll>> v(222222);

void dfs(ll now, ll sum, ll pre){
	sum += mp[now];
	ans[now] = sum;
	REP(i, v[now].size()){
		if(v[now][i] == pre)continue;
		dfs(v[now][i], sum, now);
	}
}

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	ll n, q;cin >> n >> q;
	REP(i, n - 1){
		ll a, b;cin >> a >> b;
		a--;b--;
		v[a].PB(b);
		v[b].PB(a);
	}

	REP(i, q){
		ll p, x;cin >> p >> x;
		p--;
		mp[p] += x;
	}

	dfs(0, 0, -1);
	REP(i, n)cout << ans[i] << " ";cout << endl;
	return 0;
}


Measured memory_bytes: 26112
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n;
    cin>>n;
    V vec(n);
    rep(i,n)cin>>vec[i];
    rep(i,n)vec[i]-=i;
    map<ll,ll> mp;
    rep(i,n){
        mp[vec[i]]++;
    }
    ll res=0;
    rep(i,n){
        ll sum=-2*i;
        sum-=vec[i];
        res+=mp[sum];
    }
    cout<<res<<endl;
}


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

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define deb(x)     cout << #x << " = "<<x<<endl

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)

int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 200005;


ll gcd(ll  a , ll b) {
	return (b == 0) ? a : gcd(b, a % b);
}
ll binpow(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}
ll powmod(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinv(ll n, ll p)
{
	return powmod(n, MOD - 2, MOD);
}

int dp[MX];
int main(int argc, char const *argv[])
{
	// two magical lines to speed up IO
	cin.tie(0);
	ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int N, K;
	int dp[100000], h[100000];
	cin >> N >> K;
	for (int i = 0; i < N; i++)
		cin >> h[i];

	for (int i = 0; i < N; i++)
		dp[i] = INT_MAX;

	dp[0] = 0;
	for (int i = 1; i < N; i++)
		for (int j = 1; j <= min(i, K); j++)
			dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]));
	cout << dp[N - 1];



}










Measured memory_bytes: 4428
use proconio::{input, fastout};

fn gcd(mut a: usize, mut b: usize) -> usize {
    if a<b {
        let mut tmp = a;
        a = b;
        b = tmp;
    } 
    let mut r = a % b;
    while r!=0 {
        a = b;
        b = r;
        r = a % b;
    }
    b
}

#[fastout]
fn main() {
    input!{
        n: usize,
        mut a: [usize;n],
    }

    a.sort();
    let mut mins: Vec<usize> = Vec::new();
    let mut flag = false;
    for i in 0..n {
        if a[i]%a[0]!=0 {
            mins.push(gcd(a[0], a[i]%a[0]));
            flag = true;
        } 
    }
    mins.sort();
    if flag==true{
        println!("{}", mins[0]);
    } else {
        println!("{}", a[0]);
    }
}


Measured memory_bytes: 4832
#include<iostream>
#include<string>
using namespace std;
int main() {
	string S;
	cin >> S;
	for (int i = 1; i < S.size()+1; i++) {
		if (i % 2 == 1) {
			if (S[i-1] == 'L') {
				cout << "No" << endl;
				return 0;
			}
		}
		if (i % 2 == 0) {
			if (S[i-1] == 'R') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';
using namespace std;

#define NODE_NUM 100
struct Node{
    ll ord;
    ll low;
    ll depth;
    bool visited;
    vector<ll> par;
};

Node node[NODE_NUM];
bool edges[NODE_NUM][NODE_NUM];
ll ORD;
void dfs(ll index){
    node[index].ord=ORD;
    ORD++;
    node[index].low=node[index].ord;
    node[index].visited=true;
    rep(i, node[index].par.size()){
        if(node[node[index].par[i]].visited==false){
            edges[node[index].par[i]][index]=true;
            edges[index][node[index].par[i]]=true;
            //cout<<node[index].par[i]<<"%"<<index<<endl;
            dfs(node[index].par[i]);
            node[index].low=min(node[index].low, node[node[index].par[i]].low);
        }
        else if(edges[index][node[index].par[i]]==false){
            //cout<<node[index].par[i]<<"#"<<index<<endl;
            node[index].low=min(node[index].low, node[node[index].par[i]].ord);
            edges[index][node[index].par[i]]=true;
            edges[node[index].par[i]][index]=true;
        }
    }
    //cout<<index<<sp<<node[index].ord<<sp<<node[index].low<<endl;
}
void dfs_refresh(void){
    rep(i, NODE_NUM) rep(j, NODE_NUM) edges[i][j]=false;
    ORD=0;
    rep(i, NODE_NUM){
        node[i].visited=false;
    }
}

int main(void){
    ll N, M;
    cin>>N>>M;
    ll A[100], B[100];
    rep(i, M){
        cin>>A[i]>>B[i];
        node[A[i]-1].par.push_back(B[i]-1);
        node[B[i]-1].par.push_back(A[i]-1);
    }
    dfs_refresh();
    dfs(0);
    ll count=0;
    rep(i, M){
        if(node[A[i]-1].ord<node[B[i]-1].low || node[B[i]-1].ord<node[A[i]-1].low) count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
#define PI             acos(-1.0)
#define IOS            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(a,b)         memset(a, b, sizeof(a))
#define filein      freopen("input.txt", "r", stdin);
#define fileout     freopen("output.txt", "w", stdout);
#define debug       cout<<"Hello, i am in here."<<endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
using namespace std;
const int MOD = (int)1e9+7;
/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N | (1<<pos);}
//int reset(int N,int pos){return N= N & ~(1<<pos);}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/
void solve()
{
  ll d,t,s;
  cin>>d>>t>>s;
  if(t*s>=d)
    cout<<"Yes"<<endl;
  else 
    cout<<"No"<<endl;
}
int  main()
{
    IOS
        solve();
    return 0;
}

Measured memory_bytes: 3644
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()

    if S[0] == 'A' and 'C' in S[2:-1] and len([i for i in S if i in string.ascii_uppercase]) == 2:
        print('AC')
    else:
        print('WA')

if __name__ == '__main__':
    resolve()


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

using namespace std;

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

    bool res = true;

    if (s[0]!='A') {
        res = false;
    }

    if (s[1]<'a' || s[1]>'z' || s[s.size()-1]<'a' || s[s.size()-1]>'z') {
        res = false;
    }

    int cnt = 0;
    for (int i=2; i<s.size()-1; ++i) {
        if (s[i]>='a' && s[i]<='z') {
            continue;
        } else if (s[i]=='C') {
            cnt += 1;
        } else {
            res = false;
        }
    }

    if (!cnt || cnt>1) {
        res = false;
    }

    cout << (res?"AC":"WA") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const lol MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;


//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  return ((x * y) / gcd(x, y));
}

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

  lol n, k;
  cin >> n >> k;
  lol a[n + 5], ans = k * (k - 1) / 2;
  ans %= MOD;
  rep(i, n){
    cin >> a[i];
  }
  lol sum = 0, nasu = 0;
  rep(i, n){
    rep(j, n){
      if(a[i] > a[j] && i < j){
	sum ++;
      } else if(a[i] > a[j] && i > j){
	nasu ++;
      }
    }
  }
  cout << ((sum * k) % MOD + ((sum + nasu) % MOD) * ans) % MOD << '\n';
  return 0;
}


Measured memory_bytes: 256
from collections import deque

K = int(input())
q = deque([i for i in range(1, 10)])

cnt = 0
while cnt < K-1:
    n = q.popleft()
    d = int(str(n)[-1])
    cnt += 1
    for i in [d-1, d, d+1]:
        if i < 0 or 10 <= i:
            continue
        q.append(10*n+i)
print(q.popleft())


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

typedef long long ll;

int main() {
    int N, M;
    int ans = 0;
    cin >> N >> M;
    vector<int>v(N);
    vector<vector<int>>p(N);

    for (int i = 0; i < N; i++) {
        v[i] = i+1;
    }
    
    for (int i = 0; i < N; i++) {
        vector<int>x;
        p[i] = x;
    }

    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        p[a-1].push_back(b);
        p[b-1].push_back(a);
    }

    do {
        if (v[0] != 1) {
            continue;
        }
        int cnt = 0;
        for (int i = 0; i < N-1; i++) {
            for (int j = 0; j < p[v[i]-1].size(); j++) {
                if (p[v[i]-1][j] == v[i+1]) {
                    cnt++; 
                    break;
                }
            }
        }
        if (cnt == N-1) {
            ans++;
        }
    } while (next_permutation(v.begin(), v.end()));

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    int result = 0;
    bool flag = true;

    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    while(true){
        for (int i = 0; i < N; ++i) {
            if (a[i] % 2 == 0) {
                a[i] = a[i] / 2;
                flag = true;
            } else {
                flag = false;
                break;
            }
        }
        if(flag){
            result++;
        }else{
            break;
        }
    }
    
    cout << result << endl;
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int n;
    string st;
    while(cin >> n,n){
        vector<int> tab(n);
        REP(i,n){
            cin >> st;
            if(st[1]=='u')tab[i]=1;
            else tab[i]=-1;
        }

        bool flg=false;
        int cou=0,sum=0;
        REP(i,n){
            sum+=tab[i];
            if(sum==2){
                if(!flg){
                    cou++;
                    flg=true;
                }
            }else if(sum==0){
                if(flg){
                    cou++;
                    flg=false;
                }
            }
        }
        cout << cou << endl;
    }
}



Measured memory_bytes: 3212
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }

fn main() {
    input! {
        n: usize,
        mut x: usize,
        mut a: [usize; n],
    }
    a.sort();
    let mut ans = 0;
    for i in a {
        if x < i {
            break;
        }
        x -= i;
        ans += 1;
    }
    if ans == n && x > 0 {
        ans -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
N = int(input())
a = list(map(int, input().split()))
ans = 0
while True:
	odd = 0
	for i in range(N):
		if a[i] % 2 != 0:
			odd += 1
		else:
			a[i] /= 2
			ans += 1
	if odd == len(a):
		break
print(ans)

Measured memory_bytes: 4140
#define rep(i,n) for(int i=0;i<(n);++i)

#include<iostream>
#include<fstream>
#include<iomanip>

#include<vector>
#include<array>
#include<string>
#include<bitset>
#include<queue>

#include<utility>

#include<algorithm>
#include<cmath>
using ll = long long;
using namespace std;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int src(){
    int n,m;
    cin>>n>>m;
    int s,t;
    vector<int> paths[650];
    vector<long double> dp(650,0.0);
    rep(i,m){
        cin>>s>>t;
        paths[s].push_back(t);
    }
    long double ans=1e18;

    rep(j,n){
        int block=j;
        dp[n]=0;
        for(int i=n-1;i>=1;--i){
            long double sum=0;
            long double maxi=0.0;
            int num=paths[i].size();
            for(auto to:paths[i]){
                sum+=dp[to];
                chmax(maxi,dp[to]);
            }
            if(i==block and num>=2){
                num--;
                sum-=maxi;
            }
            dp[i] = sum/num+1;
        }
        chmin(ans,dp[1]);
    }
    cout<< setprecision(10) << fixed << ans << endl;
    return 0;
}


int main(int argc,char* argv[]){
    //ifstream in( argv[1] );
    //cin.rdbuf(in.rdbuf());
    src();    
    return 0;
}

Measured memory_bytes: 1408
from heapq import heappush, heappop
from collections import defaultdict, deque
n, m = map(int, input().split())
G = defaultdict(list)
E = []
for i in range(m):
    a, b, c = map(int, input().split())
    G[a - 1].append((b - 1, c))
    G[b - 1].append((a - 1, c))
    E.append((a - 1, b - 1, c))

INF = float("inf")
d = [[INF] * n for i in range(n)]
for i in range(n):
    d[i][i] = 0
    que = [(0, i)]
    while que:
        cost, v = heappop(que)
        if d[i][v] < cost:
            continue
        for w, c in G[v]:
            if cost + c < d[i][w]:
                d[i][w] = cost + c
                heappush(que, (cost + c, w))

num = m
for x, y, c in E:
    flag = False
    for i in range(n):
        if d[i][x] + c == d[i][y]:
            flag = True
    if flag:
        num -= 1

print(num)

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vin(v) rep(i,v.size()) {cin >> v[i];}

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//(lambda (x y) (< x y)) => [](int x, int y) -> int { return x<y; }

#define int ll

signed main(void){
  int n,m,ans=0,l,r;cin >> n >> m;
  l=0;r=10e5;
  int a,b;
  rep(i,m){
    cin >> a >> b;
    chmax(l,a);chmin(r,b);
  }
  if(r-l<0) ans=0;
  else ans=r-l+1;
  printf("%lld\n",ans);

  return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		string dat;
		int ou=0,hi=0,ans=0;
		for(;;){
			cin>>dat;
			if(dat[0]=='O' && dat[1]=='U'){
			ou++;
			}
			else if(dat[0]=='H' && dat[1]=='I'){
			hi++;}
			else if(dat[0]=='H' && dat[1]=='O'){
			ans=ans+hi+1;
			hi=0;
			}
			if(ou==3){
				cout<<ans<<endl;
				break;
			}
			if(hi==4){
				ans++;
				hi--;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <chrono> 
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fr(i,a,b) for (ll i=(a); i<(b);++i)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);--i)
#define vi vector<ll>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<ll,ll> 
#define rev(a) reverse(a.begin(),a.end())
#define srt(a,k) sort(a,a+k,greater<ll>())
#define rsrt(a) sort(a.begin(),a.end(),greater<ll>())
#define sz(a) (ll)a.size()
//#define endl "\n"
#define po(a,b) (ll)(pow(a,b)+0.5)
#define double long double
#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define setbits(a) __builtin_popcount(a)
const ll M=1e9+7;
const ll mxx=3001;

int main()
{  


     ll n,m;
     cin>>n>>m;
     ll a[n];

     fr(i,0,n){cin>>a[i];}
     ll lc=a[0]/2;
     fr(i,1,n)lc=(lc*(a[i]/2))/__gcd(lc,a[i]/2);

     
     fr(i,0,n)if((lc/(a[i]/2))%2==0){cout<<0;return 0;}

     cout<<m/lc-m/(2ll*lc);

}



Measured memory_bytes: 4412
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
    int N;
    int cnt;

    cin >> N;

    vector<int> array(N);

    for(int i = 0; i < N; i++)
    {
        cin >> array[i];
    }

    cnt = 0;
    for(int i = 1; i <= N; i++)
    {
        bool is_i_odd = (i % 2 != 0);
        bool is_val_odd = (array[i-1] % 2 != 0);

        if(is_i_odd && is_val_odd)
        {
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
 using namespace std;
#define ll long long
int main(){
    string s1,s2;
    cin>>s1>>s2;
    int n=s1.size(),m=s2.size();
    int dp[n+1][m+1];
    
    for(int i=0;i<=n;i++)
    {  
        for(int j=0;j<=m;j++){
            if(i==0 || j==0){ dp[i][j]=0; continue; }
            if(s1[i-1]==s2[j-1] ) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string s="";
    int j=m,i=n;
    while(i>0 && j>0 ){
        if(dp[i-1][j-1]+1==dp[i][j] && (s1[i-1]==s2[j-1]) ){ s+=s1[i-1]; i--; j--; }
        else if(dp[i-1][j]>dp[i][j-1] ) i--;
        else j--;    
    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;
    
    return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, x, y, a[N], b[N] = {1}, c[N], v[N];
ll M = 1e9 + 7;
int main()
{
	ll i, j;
	cin >> n;
	n++;
	for (i = 1; i <= n; i++) b[i] = b[i - 1] * i % M;
	for (c[n] = 1, i = b[n], j = M - 2; j; i = i * i % M, j >>= 1)
		if (j & 1) c[n] = c[n] * i % M;
	for (i = n - 1; i >= 0; i--) c[i] = c[i + 1] * (i + 1) % M;
	for (i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		if (v[a[i]]) x = v[a[i]] - 1, y = n - i;
		v[a[i]] = i;
	}
	for (i = 1; i <= n; i++) {
		printf("%lld\n", (b[n] * c[i] % M * c[n - i] % M + M - b[x + y] * c[i - 1] % M * c[x + y - i + 1] % M * (x + y >= i - 1)) % M);
	}
    return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<string,int> P;
typedef pair<int,P> PP;

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

int n,m,cnt,ma,sum;

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

	cin>>n>>m;
	REP(i,m) {
		int a,b;cin>>a>>b;
		if(a<n) ma=max(ma,(n-a)),sum+=(n-a);
	}
	cout<<sum-ma<<endl;

	return 0;
}



Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
#define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  vector<int> b(n);
  rep(i,n) cin>>b[i];
  vector<int> ans;
  while(b.size() > 0) {
    bool f = false;
    repr(i,b.size() - 1) {
      // debug(i);
      if(b[i] == i + 1) {
        ans.push_back(b[i]);
        b.erase(b.begin() + i);
        // debug(b[i]);debug(i);
        f = true;
        break;
      }
    }
    if(f) {
      continue;
    }
    cout << -1 << endl;
    return 0;
  }

  reverse(ans.begin(), ans.end()); 
  rep(i,n) {
    cout << ans[i] << endl;
  }
  

  return 0;
}


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

using namespace std;

int main(){
	char N[3];
	char ans[4];
	
	cin >> N;
	
	if(N[0]==N[1]){
		if(N[1]>=N[2]){
			ans[0]=ans[1]=ans[2]=N[0];
		}else{
			ans[0]=ans[1]=ans[2]=N[0]+1;
		}
	}else{
		if(N[0]>N[1]){
			ans[0]=ans[1]=ans[2]=N[0];
		}else{
			ans[0]=ans[1]=ans[2]=N[0]+1;
		}
	}
	
	ans[3]='\0';
	
	cout << ans << endl;
	
	return 0;
}

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

int main() {
  char b, c;
  cin >> b;
  if(b == 'A') c = 'T';
  else if(b == 'T') c = 'A';
  else if(b == 'C') c = 'G';
  else c = 'C';
  cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (ll i = 0; i < ll(n); i++)

const ll mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vl c(n);
    rep(i, n) cin >> c[i];
    sort(c.begin(), c.end());

    mint ans;
    for (int i = 0; i < n; i++) {
        ans += mint(c[i]) * mint(n - i + 1);
    }
    ans *= mint(4).pow(n - 1);
    cout << ans.x << endl;
}


Measured memory_bytes: 4756
n,w = map(int,input().split())
weight = [0] * n
value = [0] * n
dp = [ [0 for i in range(w + 1)] for j in range(n + 1)]
for i in range(n):
    weight[i], value[i] = map(int, input().split())

for i in range(n):
    for w in range(w + 1):
        if weight[i] <= w:
            dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w])
        else:
            dp[i + 1][w] = dp[i][w]
print(dp[n][w])


Measured memory_bytes: 171400
#include<iostream>

using namespace std;


int main() {
	int n;
	char Taro[1001][101], Hanako[1001][101];
	int TaroPoint = 0, HanakoPoint = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> Taro[i] >> Hanako[i];

		for (int j = 0; j < 101; j++) {
			if (Taro[i][j] > Hanako[i][j]) {
				TaroPoint += 3;
				break;
			}
			else if (Taro[i][j] < Hanako[i][j]) {
				HanakoPoint += 3;
				break;
			}
			if (Taro[i][j] == '\0'&&Hanako[i][j] == '\0') {
				TaroPoint++;
				HanakoPoint++;
				break;
			}
		}
	}

	cout << TaroPoint << " " << HanakoPoint << endl;

	return 0;
}

Measured memory_bytes: 1364
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut a: u64 = read();
    let mut b: u64 = read();
    let mut k: u64 = read();

    if a >= k {
        a = a - k;
        k = 0;
    }else if a < k {
        k = k - a;
        a = 0;
    }

    if b >= k {
        b = b - k;
    }else if b < k {
        b = 0;
    }

    println!("{} {}",a , b );
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int[] t = new int[n + 1];
		int[] x = new int[n + 1];
		int[] y = new int[n + 1];
		
		for (int i = 1; i <= n; i++) {
			t[i] = sc.nextInt();
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		
		for (int i = 1; i <= n; i++) {
			int dt = t[i] - t[i - 1];
			int dx = Math.abs(x[i] - x[i - 1]);
			int dy = Math.abs(y[i] - y[i - 1]);
			
			// System.out.printf("dt=%d, dx=%d, dy=%d\n", dt, dx, dy);
			
			int dif = dt - (dx + dy);
			
			if (dif < 0 || dif % 2 != 0) {
				System.out.println("No");
				return;
			}
		}
		
		System.out.println("Yes");

	}
}


Measured memory_bytes: 94148
#include <cstdio>

using namespace std;

using i64=long long;

int main() {
    size_t n;
    scanf("%zu", &n);

    int min_=1000000, max_=-1000000;
    i64 sum=0;
    for (size_t i=0; i<n; ++i) {
        int a;
        scanf("%d", &a);

        if (min_ > a)
            min_ = a;

        if (max_ < a)
            max_ = a;

        sum += a;
    }

    printf("%d %d %lld\n", min_, max_, sum);
    return 0;
}

Measured memory_bytes: 2752
#include <bits/stdc++.h>
        //#define m ((long long)1e9+7)
        #define f first
        #define s second
        typedef long long ll;
        using namespace std;
         
        int main() {
            ios_base::sync_with_stdio(false);cin.tie(NULL);
        	string s,t;
        	cin>>s>>t;
        	int i,j,ma,ss=s.size(),st=t.size();
        	int h[st+1][ss+1];
        	for(i=0;i<=st;i++)
        	{
        	    for(j=0;j<=ss;j++)
        	    {
        	        if(i==0||j==0)
        	        h[i][j]=0;
        	        else if(t[i-1]==s[j-1])
        	        h[i][j]=1+h[i-1][j-1];
        	        else
        	        h[i][j]=max(h[i-1][j],h[i][j-1]);
        	    }
        	}
        	
        	string s1="";
        	for(i=st,j=ss;i>0&&j>0;){
        	    if(s[j-1]==t[i-1])
        	    {
        	        s1=t[i-1]+s1;
        	        i--;
        	        j--;
        	    }
        	    else if(h[i-1][j]>h[i][j-1])
        	    i--;
        	    else
        	    j--;
        	}            cout<<s1<<endl;
        	return 0;
        }

Measured memory_bytes: 35456
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	string str;
	int l, s, t;
	
	while(cin >> str){
		vector<int> vec;
		l = str.size();
		
		for(int i = 0; i < l; i++){
			if(str[i] == 'M'){
				vec.push_back(1000);
			} else if(str[i] == 'D'){
				vec.push_back(500);
			} else if(str[i] == 'C'){
				vec.push_back(100);
			} else if(str[i] == 'X'){
				if(str[i+1] == 'C'){
					vec.push_back(90);
					i++;
				} else if(str[i+1] == 'L'){
					vec.push_back(40);
					i++;
				} else if(str[i+1] == 'V'){
					t = 15;
					i++;
					s = 1;
					while(str[i+s] == 'I' && s <= 3 && i+s < l){
						t += 1;
						s++;
					}
					i += (s-1);
					vec.push_back(t);
				} else if(str[i+1] == 'I'){
					i++;
					if(str[i+1] == 'V'){
						i++;
						vec.push_back(14);
					} else if(str[i+1] == 'X'){
						i++;
						vec.push_back(19);
					} else {
						t = 11;
						s = 1;
						while(str[i+s] == 'I' && s <= 2 && i+s < l){
							s++;
							t++;
						}
						i += (s-1);
						vec.push_back(t);
					}
				} else {
					t = 10;
					s = 1;
					while(str[i+s] == 'X' && s <= 2 && i+s < l){
						t += 10;
						s++;
					}
					i += (s-1);
					vec.push_back(t);
				}
			} else if(str[i] == 'L'){
				t = 50;
				s = 1;
				while(str[i+s] == 'X' && s <= 3 && i+s < l){
					t += 10;
					s++;
				}
				i += (s-1);
				vec.push_back(t);
			} else if(str[i] == 'V'){
				t = 5;
				s = 1;
				while(str[i+s] == 'I' && s <= 3 && i+s < l){
					t += 1;
					s++;
				}
				i += (s-1);
				vec.push_back(t);
			} else {
				if(str[i+1] == 'V'){
					i++;
					vec.push_back(4);
				} else if(str[i+1] == 'X'){
					i++;
					vec.push_back(9);
				} else {
					t = 1;
					while(str[i+t] == 'I' && t < 3 && i+t < l){
						t++;
					}
					i += (t-1);
					vec.push_back(t);
				}
			}
		}
		
		t = 0;
		for(int i = 0; i < vec.size(); i++){
			t += vec[i];
		}
		
		for(int i = 0; i < vec.size()-1; i++){
			if(vec[i] < vec[i+1]){
				t -= 2*vec[i];
			}
		}
		
		cout << t << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    vll x(n);
    cin>>x[0];
    ll count=0;
    repi(i,1,n){
        cin>>x[i];
        if((x[i]-x[i-1])*a>b){
            count+=b;
        }else count+=a*(x[i]-x[i-1]);
    }
    cout<<count<<endl;
}

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


template<typename T>
struct Pt {
  T x, y;
  Pt() : x(T()), y(T()) {
  }
  Pt(T x_, T y_) : x(x_), y(y_) {
  }
  bool operator<(const Pt& other) const {
    if(x == other.x) {
      return y < other.y;
    }
    return x < other.x;
  }
  bool operator==(const Pt& other) const {
    return x == other.x && y == other.y;
  }
  bool operator<=(const Pt& other) const {
    return *this < other || *this == other;
  }
  bool operator>(const Pt& other) const {
    return !(*this <= other);
  }
  bool operator>=(const Pt& other) const {
    return !(*this < other);
  }
  Pt operator-(const Pt& other) const {
    return {x - other.x, y - other.y};
  }
  Pt operator+(const Pt& other) const {
    return {x + other.x, y + other.y};
  }
};

template<typename T>
Pt<T> operator+(Pt<T> a, Pt<T> b) {
  return {a.x + b.x, a.y + b.y};
}

template<typename T> typename common_type<long long, T>::type
cross_z(Pt<T> const& v1, Pt<T> const& v2) {
  using R = typename common_type<long long, T>::type;
  return (R) v1.x * v2.y - (R) v1.y * v2.x;
}

template<typename T> typename common_type<long long, T>::type
dot(Pt<T> const& v1, Pt<T> const& v2) {
  using R = typename common_type<long long, T>::type;
  return (R) v1.x * v2.x + (R) v1.y + v2.y;
}

template<typename T>
auto spin(Pt<T> const& a, Pt<T> const& b, Pt<T> const& c) {
  // spin of a -> b -> c
  // return > 0 : counterclockwise
  // return = 0 : collinear
  // return < 0 : clockwise
  return cross_z(b - a, c - a);
}

template<typename T>
vector<Pt<T>> convex_hull(vector<Pt<T>> a) {
  if(a.size() == 1) {
    return a;
  }
  sort(a.begin(), a.end());
  vector<Pt<T>> up {a[0]}, dw {a[0]};
  for(int i = 1; i < a.size(); ++i) {
    while(up.size() >= 2 && spin(up[up.size() - 2], up[up.size() - 1], a[i]) >= 0) {
      up.pop_back();
    }
    while(dw.size() >= 2 && spin(dw[dw.size() - 2], dw[dw.size() - 1], a[i]) <= 0) {
      dw.pop_back();
    }
    up.push_back(a[i]);
    dw.push_back(a[i]);
  }
  auto hull = move(dw);
  for(int i = (int) up.size() - 2; i >= 1; --i) {
    hull.push_back(up[i]);
  }
  return hull;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<Pt<long long>> a(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i].x >> a[i].y;
  }
  long long ans = 0;
  auto cv = convex_hull(a); 
  int m = cv.size();
  for(int i = 0; i < m; ++i) {
    for(int j = (i + (m / 2 - 5) + 5 * m) % m, T = 10; T--; j = (j + 1) % m) {
      ans = max(ans, abs(cv[i].x - cv[j].x) + abs(cv[i].y - cv[j].y));
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 9536
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
const int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const string dir8[8] = {"U", "RU", "R", "RD", "D", "LD", "L", "LU"};

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> K >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  A.push_back(K + A[0]);

  ll d = 0;
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    sum += (A[i + 1] - A[i]);
    d = max<int>(d, A[i + 1] - A[i]);
  }
  sum -= d;
  cout << sum << endl;

  return 0;
}


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

int main(void){
    
    string s;
    cin >> s;
    int sum = 0;
    
    for(int i=0;i<4;i++){
        if(s[i] == '+'){
            sum++;
        }
        else{
            sum--;
        }
    }
    cout << sum <<endl;
    
}

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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

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

	ll ans = 0;
	ans += (a / 500) * 1000;
	ll tmp = a % 500;
	ans += (tmp / 5) * 5;

	cout <<  ans << endl;
	return 0;

}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner=new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int c=scanner.nextInt();
        int x=scanner.nextInt();
        int total=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){
                        total++;
                    }
                }
            }
        }
        System.out.println(total);
    }
}


Measured memory_bytes: 21844