akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	int arr[t];
	for(int i =0;i<t;i++){
		cin>>arr[i];
		if(arr[i]%2==0){
			if(arr[i]%3==0 || arr[i]%5==0){
				continue;
			}
			else{
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
				cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n,x, ans = 0; sc(n)
    set <int> s;
    for (int i = 0; i < n; i++){
        sc(x)
        if (s.find(x) == s.end()) s.insert(x);
        else s.erase(x);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 4864
## ABC 088
n = int(input())
cl = [int(_) for _ in input().split()]

cl.sort(reverse=True)

alice = 0
bob = 0

for i in range(len(cl)):
    if(i%2 == 0):
        alice += cl[i]
    else:
        bob += cl[i]
        
print(alice-bob)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
//#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}
int a[66];
int b[66];


int main(void) {
    FAST_IO;
    int n;
    cin >> n;
    int t = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    memcpy(b, a, sizeof(b));
    sort(b + 1, b + 1 + n);
    for (int i = 1; i <= n; i++) {
        if (a[i] != b[i]) {
            t++;
        }
    }
    if (t > 2) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long

int main(){

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif

	ll x,n;
	cin>>x>>n;

	vector<ll> v(n);
	for(ll i=0; i<n; i++)
		cin>>v[i];

	ll l=x, r=x;
	while(1){

		if(count(v.begin(), v.end(), l)==0){

			cout<<l;
			break;
		}
		else if(count(v.begin(), v.end(), r)==0){

			cout<<r;
			break;
		}
		l--;
		r++;
	}
	// fclose(stdin);
	// fclose(stdout);
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll H,A;
    cin >> H >> A;
    cout << H/A+(H%A != 0) << endl;
}

Measured memory_bytes: 3568
N,A,B=map(int,input().split())
ans=0
for i in range(1,N+1):
    if i<=9:
        if A<=i<=B:
            ans+=i
    elif 10<=i<=99:
        I=str(i)
        a=int(I[0])
        b=int(I[1])
        if A<=a+b<=B:
            ans+=i
    elif 100<=i<=999:
        K=str(i)
        c=int(K[0])
        d=int(K[1])
        e=int(K[2])
        if A<=c+d+e<=B:
            ans+=i
    elif 1000<=i<=9999:
        K=str(i)
        c=int(K[0])
        d=int(K[1])
        e=int(K[2])
        f=int(K[3])
        if A<=c+d+e+f<=B:
            ans+=i
    elif i==10000:
        if A<=1<=b:
            ans+=10000
            
print(ans)

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

using namespace std;

map <int,int> d;

int main() 
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,m,t;

	cin >> n;
	
	for(int i=0;i<n;i++)
	{
		cin >> t;
		d[t] += 1;
	}
	cin >> m;
	for(int i=0;i<m;i++)
	{
		cin >> t;
		d[t] -= 1;
		if(d[t] < 0)
		{
			cout << "NO" << '\n';
			return 0;
		}
	}

	cout << "YES" << '\n';
	return 0;
}

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
	fast;
	int n,p;
	cin >> n >> p;
	
	string s;
	cin >> s;
	
	// special case :(
	if(p == 2 || p== 5){
		int ans = 0;
		map<int,int>m;
		for(int i=0 ; i<n ; i++){
			int a = s[i] - '0';
			if(a%p==0){
				ans += i + 1;
			}
		}
		cout << ans;
		return 0;
	}

	reverse(all(s));
	map<int,int>m;
	
	int ten = 1;
	int rem = 0;
	int ans = 0;
	m[0]++;
	
	for(int i=0 ; i<n ; i++)
	{
		int a = s[i] -'0';
		
		int num = (rem + ten*a)%p;
		rem = num;
		m[num]++;
		
		ten = (ten * 10)%p;
	}
	
	for(auto it : m)
	{
		ans += (it.S - 1) *it.S/2;
	}
	cout << ans ;
}


Measured memory_bytes: 1044
# string
# a, b, c = input().split()
# str_list = list(input().split())

# number
# a, b, c = map(int, input().split())
# num_list = list(map(int, input().split()))

# lows
# str_list = [input() for _ in range(n)]

# many inputs
# num_list = []
# for i in range(n): num_list.append(list(map(int, input().split())))

s = input()
if s[0] == "R":
    if s[1] == "R":
        if s[2] == "R":
            print(3)
        else:
            print(2)
    else:
        print(1)
else:
    if s[1] == "R":
        if s[2] == "R":
            print(2)
        else:
            print(1)
    else:
        if s[2] == "R":
            print(1)
        else:
            print(0)

Measured memory_bytes: 9064
def can_match(x1, y1, x2, y2):
    return x1 < x2 and y1 < y2

N = int(input())
red = []
blue = []
for i in range(N):
    x, y = map(int, input().split())
    red.append((x, y))

for i in range(N):
    x, y = map(int, input().split())
    blue.append((x, y))
    
red.sort()
ans = 0
for i in range(N - 1, -1, - 1):
    xr, yr = red[i]
    yb_min = 2 * N
    arg_yb_min = 0
    matched = False
    for xb, yb in blue:
        if can_match(xr, yr, xb, yb) and yb < yb_min:
            matched = True
            arg_yb_min = xb
            yb_min = yb
    
    if matched:
        ans += 1
        blue.remove((arg_yb_min, yb_min))

print(ans)

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    ll n; cin >> n;

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

    int ans = 0;
    int current = 1;

    for (int i = 0; i < n; ++i) {
        if (a[i] != current) {
            ++ans;
        } else {
            ++current;
        }
    }

    if (ans == n) {
        puts("-1");
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			cout << v[i][j] << "   ";
		}
		cout << endl;
	}
}


int main(){//

    int N;
    cin >> N;
    vector<int> A(N);
    int MAX = 0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        MAX = max(MAX, A[i]);
    }
    
    //divisor[i]: A[0]~A[N-1]の中でiを倍数に持つ個数
    vector<int> divisor(MAX+5, 0);
    for(int i=0; i<N; i++){
        for(int j=0; j*A[i]<divisor.size(); j++){
            divisor[j*A[i]]++;
        }
    }

    int ans = 0;
    for(int i=0; i<N; i++){
        if(divisor[A[i]]  == 1) ans++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 7952
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, i;
    scanf("%d", &n);
    vector<int> a(n);
    for(i = 0; i < n;i++) scanf("%d", &a.at(i));
    for(i = n - 1;i > 0; i--) cout << a.at(i) << " ";
    cout << a.at(0) << endl;
}


Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


int N, K;
string S;

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

  cin >> N >> K;
  cin >> S;

  if (S[K-1] == 'A') {
      S[K-1] = 'a';
  } else if (S[K-1] == 'B') {
      S[K-1] = 'b';
  } else {
      S[K-1] = 'c';
  }

  cout << S << endl;

  return 0;
}


Measured memory_bytes: 384
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        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>().expect("Parse error")
    };
}

fn main() -> () {
    input!{
        a: u8,
        b: u8,
    }
    for c in 1..3 {
        if a * b * c % 2 == 1 {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 4352
def check(s):
    h = 0
    for p in s:
        b = h + p[0]
        if b < 0:
            return False
        h += p[1]
    return True


N = int(input())
S = []
left = []
right = []
total = 0
for i in range(N):
    last = 0
    bottom = 0
    s = input().strip()
    for c in s:
        if c == "(":
            last += 1
        else:
            last -= 1
        bottom = min(bottom, last)
    if last > 0:
        left.append((bottom, last))
    else:
        right.append((bottom-last, -last))
    total += last

left.sort(key=lambda x: -x[0])
right.sort(key=lambda x: -x[0])

if check(left) and check(right) and total == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 175004
#include <stdio.h>
#include <math.h>

int main(void){

	int i,w,f;
	while(scanf("%d",&w)!=EOF){
		i=1;f=0;
		while(w>0){
			if(w%2==1){
				if(f==0)f++; else printf(" ");
				printf("%d",i);
			}
			w/=2;i*=2;
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 600
from collections import defaultdict
def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
a = readInts()

ma = max(a)
ans = 0
seki = 1
for i in a:
  seki*=i

for i in a:
  ans += (seki-1)%i

print(ans)

Measured memory_bytes: 9516
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int N, M;
    cin >> N >> M;

    vector<int> ks(M);
    int sw[10][10];
    for (int i = 0; i < M; i++) {
        int k;
        cin >> k;
        ks[i] = k;
        for (int j = 0; j < k; j++) {
            cin >> sw[i][j];
            sw[i][j]--;
        }
    }

    int p[10];
    for (int i = 0; i < M; i++) {
        cin >> p[i];
    }

    ll ans = 0;
    for (int itr = 0; itr < (1 << N); itr++) {
        vector<int> S(N); // switch の on, off
        for (int j = 0; j < N; j++) {
            if ((itr >> j) & 1) {
                S[j] = 1;
            } else {
                S[j] = 0;
            }
        }

        // for (int i = 0; i < N; i++) {
        //     cout << S[i];
        // }
        // cout << endl;

        int state = 1;
        for (int j = 0; j < M; j++) {
            int cnt = 0;
            for (int k = 0; k < ks[j]; k++) {
                cnt += S[sw[j][k]];
            }
            state *= ( (cnt & 1) == p[j] );
        }

        if (state) ans++;
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359
vector<LL> A;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	cin >> N;
	for(int i=0; i<3*N; i++){
		int a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end(), greater<int>());
	LL ans = 0;
	for(int i=0; i<N; i++) ans += A[i*2+1];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a / gcd(a, b) * b; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


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

    string s;
    cin>>s;
    bool flag = false;
    rep(i,s.size())if(s[0] != s[i])flag = true;
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

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

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n,q;
	cin >> n >> q;
	string s;
	cin >> s;
	int cnt[n+1];
	cnt[0] = 0;
	char last = '#';
	FOR(i,0,n){
		cnt[i+1] = cnt[i];
		if(last == 'A' && s[i] == 'C'){
			cnt[i+1]++;
		}
		last = s[i];
	}
	FOR(i,0,q){
		int l,r;
		cin >> l >> r;
		ANS(cnt[r] - cnt[l]);
	}
	return 0;
}


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


bool check(char data[4]){
  for(int i = 1 ; i < 4 ; i++){
    if(data[0] != data[i])return false;
  }
  return true;
}

int toInt(char data[4]){
  int ret = 0;
  for(int i = 0 ; i < 4 ; i++){
    ret += (data[i]-'0');
    ret *= 10;
  }  
  return ret/10;
}

void getNext(int a,char data[4]){
  for(int i = 0 ; i < 4 ; i++){
    data[3 - i] = a%10 + '0';
    a /= 10;
  }
}

void solve(char data[4]){

  if(check(data)){
    cout << "NA" << endl;
    return;
  }

  if(toInt(data) == 6174){
    cout << 0 << endl;
    return;
  }

  int res;
  for(res = 1 ; ; res++){
    int L,S;
    sort(data,data + 4);
    S = toInt(data);
    reverse(data,data + 4);
    L = toInt(data);
    if(L - S == 6174)break;
    getNext(L - S,data);
  }
  cout << res << endl;
}

int main(){

  char data[4];
  while(1){
    bool f = true;
    for(int i = 0 ; i < 4 ; i++){
      cin >> data[i];
      if(data[i] != '0')f = false;
    }
    if(f)break;
    solve(data);
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <cmath>
#include <tuple>
#include <algorithm>
#include <ctime>
#include <map>
using namespace std;


const long long MOD = static_cast<long long>(1e9+7);
const long long INFINITE = static_cast<long long>(1e16);
const bool IS_DEBUG = false;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    int res = 0;
    int compte = 0;
    for(int c=0;c<s.size();c++) {
        if(s[c]=='R') compte++;
        else compte=0;
        res=max(res,compte);
    }
    cout<<res;
}


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

using namespace std;

const int MOD=1000000007;
typedef long long int ll;

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

ll mult(ll a,ll b)
{
	return (a*b)%MOD;
}

ll pot(ll n,ll k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

ll divide(ll a,ll b)
{
	return mult(a,pot(b,MOD-2));
}

ll sub(ll a,ll b)
{
	return (a-b+MOD)%MOD;
}

ll add(ll a,ll b)
{
	return (a+b)%MOD;
}

int n,x,y,t,a,b,w;

int main()
{
	std::ios_base::sync_with_stdio(false);
	cin>>n;
	for (int i=0;i<n;++i)
	{
		cin>>w>>a>>b;
		int k=abs(x-a)+abs(y-b);
		if (k>w-t)
		{
			cout<<"No"<<endl;
			return 0;
		}
		if ((k-(w-t))%2==-1)
		{
			cout<<"No"<<endl;
			return 0;
		}
		t=w;
		x=a;
		y=b;
	}
	cout<<"Yes"<<endl;
}



Measured memory_bytes: 256
import math

while True:
    n = int(input())
    if n == 0:break
    c = 0
    for x in reversed(range(1,math.ceil(n/2)+1)):
        sumx = 0
        add_c = 0
        for y in reversed(range(1,x+1)):
            sumx += y
            add_c += 1
            if sumx >= n:
                break
        if sumx == n and add_c > 1:
            c += 1
    print(c)


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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  ll A, B;

  CIN(A >> B);

  ll lcm = (A * B) / __gcd(A, B);
  COUT(lcm);

  return 0;
}


Measured memory_bytes: 256
import java.util.*;import java.io.*;import java.math.*;
public class Main
{
    public static void process()throws IOException
    {
        int n=ni();
        int[]A=nai(n);
        int min=A[0];
        int ans=1;
        for(int i=1;i<n;i++)
        {
            min=Math.min(A[i],min);
            if(min==A[i])
                ans++;
        }
        pn(ans);
    }
 
    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        boolean oj = true;
        if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
        else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
        int t=1;
        // t=ni();
        while(t-->0) {process();}
        out.flush();out.close();  
    }
 
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
    static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
 
/////////////////////////////////////////////////////////////////////////////////////////////////////////
 
    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
   
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

Measured memory_bytes: 47828
import math
N=int(input())
def confirm(n):
    for i in range(int(math.sqrt(n)-1)):
        if n%(i+2)==0:
            return False
    else:
        return True


if confirm(N):
    i=N
else:
    i=N+1
    while True:
        if confirm(i):
            break
        else:
            i+=1

print(i)


Measured memory_bytes: 3060
#include <stdio.h>

int a,b,c;
int d;
int main(void)
{
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		d=a;
		a=b;
		b=d;
	}
	if(b>c){
		d=b;
		b=c;
		c=d;
	}
	if(a>b){
		d=a;
		a=b;
		b=d;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

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































int main () {
double t1 = clock();

    int N;
    cin >> N;
    
    vector<int64_t> A(N), B(N), C(N);

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }
    
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    int64_t count = 0;

    for (int i = 0; i < N; i++) {
        auto C_low = lower_bound(C.begin(), C.end(), B[i] + 1); // >= B[i] + 1 になる最小のインデックス
        auto A_upp = upper_bound(A.begin(), A.end(), B[i] - 1); // > B[i] - 1 になる最小のインデックス
        count += distance(C_low, C.end()) * distance(A.begin(), A_upp);
        // cout << distance(A.begin(), A_upp) << " ";
        // cout << distance(C_low, C.end()) << " ";
        // cout << count << endl;
    }

    cout << count << endl;
    double t2 = clock();
    // cout << ((t2 - t1) / CLOCKS_PER_SEC) << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

signed main(){
    int N; cin >> N;
    vector<int> A(N+1), B(N);
    rep(i,N+1) cin >> A[i];
    rep(i,N) cin >> B[i];
    
    reverse(ALL(A));
    reverse(ALL(B));
    
    int ans = 0;
    rep(i,N){
        ans += min(B[i], A[i]+A[i+1]);
        A[i+1] = max(0ll, A[i+1] - max(0ll,B[i]-A[i]));
    }
    
    cout << ans << endl;
}

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

int main()
{

        int H, W;
        cin >> H >> W;

        string S[H];
        for (int i = 0; i < H; ++i) {

                cin >> S[i];

        }

        int res[H][W];

        for (int i = 0; i < H; ++i) {

                for (int j = 0; j < W; ++j) {
                        int cnt = 0;

                        if (S[i][j] == '#') {
                                res[i][j] = -1;
                                continue;

                        }
                        for (int l = i-1; l < i+2; l++) {

                                for (int m = j-1; m < j+2; m++) {

                                        if (l < 0 || m < 0) {
                                                continue;
                                        }
                                        else if (l >= H || m >= W) {
                                                continue;
                                        }
                                        else if (S[l][m] == '#') {
                                                cnt++;
                                        }

                                }
                                res[i][j] = cnt;

                        }
                }
        }

        for (int i = 0; i < H; ++i) {

                for (int j = 0; j < W; ++j) {
                        if (res[i][j] == -1) {
                                cout << '#';
                        }
                        else {
                                cout << res[i][j];
                        }
                }
                cout << endl;
        }












}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll a,b,c,d; cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //昇順
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順

int main(){
  int n; cin >> n;
  vector<int> flower(n);
  rep_i(i, n){
    cin >> flower[i];
  }

  int count = 0;
  int f;
  vector<vector<int>> st;
  vector<int> sub_st;
  while (1){
    for (int i = 0; i < n; i++){
      f = flower[i];
      if (f != 0){
        sub_st.push_back(i);
        if(i == n - 1){
          st.push_back(sub_st);
          sub_st.clear();
        }
      }else{
        if (!sub_st.empty()){
          st.push_back(sub_st);
        }
        sub_st.clear();
      }
    }
    // for (int i = 0; i < st.size(); i++){
    //   for (int v = 0; v < st[i].size(); v++){
    //     cout << st[i][v] << endl;
    //   }
    // }
    
    if (st.empty()){
      // cout << "hoge" << endl;
      break;
    }

    for (int i = 0; i < st.size(); i++){
      for (int v = 0; v < st[i].size(); v++){
        flower[st[i][v]] -= 1;
      }
      count += 1;
    }
    st.clear();
  }
  cout << count << endl;
}

Measured memory_bytes: 256
from itertools import combinations

n = int(input())
s = [input() for _ in range(n)]

num = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0,
}
for s_i in s:
    for x in 'MARCH':
        if s_i[0] == x:
            num[x] += 1
            break

ans = 0
for x1, x2, x3 in combinations('MARCH', 3):
    ans += num[x1] * num[x2] * num[x3]
print(ans)


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

int main()
{
  int a,b;
  char op;

  while(1)
  {
    cin >> a >> op >> b;
    if(op == '?') break;

    if(op == '+') cout << a + b << endl;
    else if(op == '-') cout << a - b << endl;
    else if(op == '*') cout << a * b << endl;
    else if(op == '/') cout << a / b << endl;
  }

  return 0;
}

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

int main() {
  int n,a,b,c;
  cin >> n >> a >> b >> c;
  vector<int> l(n);
  for (int i=0; i<n; i++)
    cin >> l.at(i);
  int ans=1e9;
  for (int i=0; i<(1<<2*n); i++) {
    int cost = 0;
    int long_a=0,long_b=0,long_c=0;
    int A=0,B=0,C=0;
    for (int j=0; j<n; j++) {
      if (i&(1<<j*2) && !(i&(1<<j*2+1))) {
	A++;
	if(A>=2)
	  cost += 10;
	long_a += l.at(j);
      }
      else if (!(i&(1<<j*2)) && i&(1<<j*2+1)) {
	B++;
	if(B>=2)
	  cost += 10;
	long_b += l.at(j);
      }
      else if (i&(1<<j*2) && i&(1<<j*2+1)) {
	C++;
	if(C>=2)
	  cost += 10;
	long_c += l.at(j);
      }
    }
    if(!A || !B || !C)
      continue;
    cost += abs(long_a - a) + abs(long_b - b) + abs(long_c - c);
    ans = min(cost,ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())

int c[305000],b[305000];
int main()
{
    _SAD()
    int n,m;
    cin>>n>>m;
    ll cnt=0,ans=0;
    for(int i=0;i<m;i++)
    {
        string s;
        int x;
        cin>>x>>s;
        if(s=="WA"&&c[x]==0)
        {
              b[x]++;
        }
        else if(s=="AC"&&c[x]==0)
        {
                c[x]=1;
                cnt+=b[x];
                ans++;
        }
    }
    cout<<ans<<" "<<cnt<<nl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
 
int main(){
    vector<ll> n(3);
    REP(i, 3) cin >> n[i];
    DESC(n);
    ll res = n[0]*10 + n[1] + n[2];
    cout << res << "\n";
}


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

int main() {
    int n, k;
    vector<long double> ep, ek;
    cin >> n >> k;
    long double buf;
    for (int i = 0; i < n; i++) {
        cin >> buf;
        ep.push_back((buf + 1) / 2);
        if (i == 0) {
            ek.push_back(ep[0]);
        } else if (i < k) {
            ek.push_back(ek[i - 1] + ep[i]);
        } else {
            ek.push_back(ek[i - 1] + ep[i] - ep[i - k]);
        }
    }
    auto max_iter = max_element(ek.begin() + k - 1, ek.end());
    auto idx = distance(ek.begin(), max_iter);
    cout << fixed << ek[idx] << endl;
}



Measured memory_bytes: 10080
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h=0;
	int a=0;
	int ans=0;
	cin>>h>>a;
	for(int i=0;i<h;i=0)
	{
		h-=a;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
x=[]
y=[]
t=float(0)
m=int(0)
for i in range(n):
    a, b = map(int, input().split())
    x.append(a)
    y.append(b)

for i in range(n-1):

    for k in range(i+1, n):
        t += (((x[i]-x[k])**2) + ((y[i]-y[k])**2))**(1/2)
        m +=1


ave=float(t/m*(n-1))

print('{:.9g}'.format(ave))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>

using namespace std;

int main(int argc, char *argv[]) {
  string table = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

  while (true) {
    int num, *keys;
    string s;

    if (cin >> num, num == 0) {
      break;
    }
    keys = new int[num];
    for (int i = 0; i < num; i++) {
      cin >> keys[i];
    }
    cin >> s;

    for (int i = 0, len = s.length(); i < len; i++) {
      int index;
      if ('a' <= s[i] && s[i] <= 'z') {
        index = s[i] - 'a' - keys[i % num];
      } else {
        index = s[i] - 'A' + 26 - keys[i % num];
      }
      index = (index < 0 ? index + table.length() : index);
      s[i] = table[index];
    }
    cout << s << endl;
    delete keys;
  }
  return 0;
}

Measured memory_bytes: 1216
import sys

#+++++
	



def main():
	n, c = map(int, input().split())
	
	ll=[]
	for i in range(n):
		x,v=map(int, input().split())
		ll.append([x,v])
		
	ll.sort(key=lambda x:x[0])
	for i,v in enumerate(ll):
		ll[i].append(c - v[0])
	all_cal=sum([v[1] for v in ll])
	
	tw=0
	tc=0
	max_c=0
	max_cr=0
	for i,v in enumerate(ll):
		ptw=tw
		tw=v[0]
		tc+=v[1]
		
		#ll[i].append(v[1]-v[0]+ptw)
		cc=tc-tw
		max_c=max(cc,max_c)
		crc=tc-2*tw
		max_cr=max(crc, max_cr)
		#ll[i].append(cc)
		ll[i].append(max_c)
		#ll[i].append(crc)
		ll[i].append(max_cr)

	ll.sort(key=lambda x:-x[0])
	tw=0
	tc=0
	max_c=0
	max_cr=0
	for i,v in enumerate(ll):
		ptw=tw
		tw=v[2]
		tc+=v[1]
		
		#ll[i].append(v[1]-v[0]+ptw)
		cc=tc-tw
		max_c=max(cc,max_c)
		crc=tc-2*tw
		max_cr=max(crc, max_cr)
		#ll[i].append(cc)
		ll[i].append(max_c)
		#ll[i].append(crc)
		ll[i].append(max_cr)
		
	ll.sort(key=lambda x:x[0])
	ret_max=0
	for l in ll:
		#print(l)
		pass
	
	for l,lp in zip(ll,ll[1:]):
		r=l[3]+lp[6]
		ret_max=max(r,ret_max)
		
	for l,lp in zip(ll[-1::-1],ll[-2::-1]):
		r=l[5]+lp[4]
		ret_max=max(r,ret_max)
		
	ret_max=max(ret_max, ll[-1][3])
	ret_max=max(ret_max, ll[0][5])
				
	print(ret_max)
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		input = sys.stdin.readline
		
	ret = main()
	if ret is not None:
		print(ret)
		
	if sys.platform =='ios':
		sys.stdin.close()

Measured memory_bytes: 40132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
//#define mod 1000000007 
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

ll p;
ll mod;
int t;
vector<pair<ll,int> >dv;

ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}

int main(){
	cin>>p>>t; mod = p;
	p--;
	for(ll i=2;i*i<=p;i++){
		if(p%i != 0) continue;
		int C = 0;
		while(p%i==0){
			p/=i;
			C++;
		}
		dv.pb(mp(i,C));
	}
	if(p > 1) dv.pb(mp(p,1));
	while(t--){
		int g; scanf("%d",&g);
		ll cur = 0;
		for(int i=0;i<g;i++){
			ll a; scanf("%lld",&a);
			ll gcd = 1;
			for(int i=0;i<dv.size();i++){
				ll up = mod-1;
				for(int j=0;j<dv[i].sc;j++){
					up /= dv[i].fi;
					if(modpow(a,up) == 1){
						gcd *= dv[i].fi;
					}
					else{
						break;
					}
				}
			}
			cur = __gcd(cur,gcd); //if(t == 0) cout << gcd << "N"<< endl;
		}
		ll cur2 = 0;
		{
			ll a; scanf("%lld",&a);
			ll gcd = 1;
			for(int i=0;i<dv.size();i++){
				ll up = mod-1;
				for(int j=0;j<dv[i].sc;j++){
					up /= dv[i].fi;
					if(modpow(a,up) == 1){
						gcd *= dv[i].fi;
					}
					else{
						break;
					}
				}
			}
			cur2 = __gcd(cur2,gcd);
		}
		assert(cur && cur2);
		if(cur2 % cur == 0){
			puts("1");
		}
		else{
			puts("0");
		}
	}
}


Measured memory_bytes: 3144
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
const int maxn = 1<<21, mod = 1e9 + 7;
struct segtree {
	vi tree;
	int n;
	ll bias = 0;
	void init(int _n) {
		n = _n;
		tree.resize(2*n, 1ll<<56);
	}
	void addall(ll x) {
		bias += x;
	}
	void upd(int p, ll v) {
		for(p += n, tree[p] = min(tree[p], v-bias); p>>=1;) tree[p] = min(tree[p<<1], tree[p<<1|1]);
	}
	ll get(int l, int r) {
		ll ans = 1ll<<56;
		for(l += n, r += n+1; l < r; l>>=1, r>>=1) {
			if(l&1) ans = min(ans, tree[l++]);
			if(r&1) ans = min(ans, tree[--r]);
		}
		return ans + bias;
	}
};
//(first, second)
segtree xi, xip,//(x, i) - a_x, (x, i) + a_x DP for second
		yi, yip;//(i, y) - a_y, (i, y) + a_y Dp for first
int n, q, a, b, x[maxn];
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> q >> a >> b;
	xi.init(n+4);
	xip.init(n+4);
	yi.init(n+4);
	yip.init(n+4);
	
	for(int i = 0; i < q; i++) cin >> x[i];
	xi.upd(a, -a);
	xip.upd(a, a);
	yi.upd(b, -b);
	yip.upd(b, b);
	for(int i = 0; i < q; i++) {
		ll fromstof = min(xip.get(x[i], n) - x[i], x[i] + xi.get(1, x[i])); 
		ll fromftos = min(yip.get(x[i], n) - x[i], x[i] + yi.get(1, x[i])); 
		xi.addall(abs((i ? x[i-1] : b) - x[i]));
		xip.addall(abs((i ? x[i-1] : b) - x[i]));
		yi.addall(abs((i ? x[i-1] : a) - x[i]));
		yip.addall(abs((i ? x[i-1] : a) - x[i]));
		xi.upd(i?x[i-1]:a, fromftos - (i?x[i-1]:a));
		xip.upd(i?x[i-1]:a, fromftos + (i?x[i-1]:a));
		yi.upd(i?x[i-1]:b, fromstof - (i?x[i-1]:b));
		yip.upd(i?x[i-1]:b, fromstof + (i?x[i-1]:b));
	}
	ll ans = 1ll<<56;
	for(int i = 1; i <= n; i++) {
		ans = min(ans, xi.get(i, i) + i);
		ans = min(ans, yi.get(i, i) + i);
	}
	cout << ans;
}


Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
signed main() {
	int N;
	cin >> N;
	int a;
	int res = 0;
	bool f = true;
	for (int i = 0; i < N; i++) {
		cin >> a;
		if (a - 1 == i) {
			if (f) {
				res++;
				f = false;
			}
			else {
				f = true;
			}
		}
		else {
			f = true;
		}
	}
	cout << res << endl;
	return 0;
}

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

void merge_sort(long long x[], int n)
{
	static long long y[200001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N;
	long long A[200001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%lld", &(A[i]));
	
	long long b = 0, ans = 0;
	for (i = 0; i < N; i++) A[i] -= i + 1;
	merge_sort(A, N);
	b = A[N/2];
	for (i = 0; i < N; i++) ans += llabs(A[i] - b);
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <vector>


using namespace std;

int main(){

    char c;

    int i = 0;
    int j, buffer;

    int S = 0;

    stack<int> st;
    stack< pair< int , int > > separated_S;

    //??¢????????????

    while( scanf("%c", &c) > 0 ){

        if( c == '\\' ){  

            st.push(i) ;

        }else if( c == '/' && st.size() > 0){

            j = st.top();
            st.pop();
            S += i - j;
            buffer = i - j;

            while(  separated_S.size() > 0 &&  separated_S.top().first > j   ){

                buffer += separated_S.top().second ;
                separated_S.pop();

            }

            separated_S.push( make_pair( j , buffer) );

        }

        i++;

    } 

    printf("%d\n", S);
    printf("%d", separated_S.size() );

    int size = separated_S.size();

    int a[ size ];
 
    for( i = size - 1 ; i >= 0 ; i-- ){

        a[i] = separated_S.top().second;
        separated_S.pop();

    }

    for( i = 0; i < size ; i++ ){

        printf(" ");

        printf("%d", a[i]);

    }

    printf("\n");

    return 0;

}

Measured memory_bytes: 2800
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 100100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
struct Line{int v,next,w;}e[MAX<<1];
int h[MAX],cnt=1,dg[MAX];
inline void Add(int u,int v,int w){e[cnt]=(Line){v,h[u],w};h[u]=cnt++;}
int n,m;ll ans;
int vis[MAX],f[3],edge,size;bool label;
void dfs(int u,int d)
{
	vis[u]=d;f[d]+=1;++size;
	for(int i=h[u];i;i=e[i].next)
	{
		int v=e[i].v;if(e[i].w==1)++edge;
		if(vis[v]==-1)dfs(v,(d+e[i].w)%3);
		else if(vis[v]!=(vis[u]+e[i].w)%3)label=false;
	}
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;++i)
	{
		int x=read(),y=read();
		Add(x,y,1);Add(y,x,2);
	}
	memset(vis,-1,sizeof(vis));
	for(int i=1;i<=n;++i)
		if(vis[i]==-1)
		{
			label=true;f[0]=f[1]=f[2]=0;size=edge=0;dfs(i,0);
			if(label)ans+=(!min(f[0],min(f[1],f[2])))?(edge):(1ll*f[0]*f[1]+1ll*f[1]*f[2]+1ll*f[2]*f[0]);
			else ans+=1ll*size*size;
		}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <list>
using namespace std;
static const int MAX = 100000;
static const int INFTY = (1<<29);

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s){
    queue<int> q;
    q.push(s);
    V[s] = true;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        out.push_back(u);
        for(int i=0;i<G[u].size();i++){
            int v=G[u][i];
            indeg[v]--;
            if(indeg[v] == 0 && !V[v]) {
                V[v] = true;
                q.push(v);
            }
        }
    }
}

void tsort(){
    for(int i=0;i<N;i++){
        indeg[i] = 0;
    }

    for(int u=0;u<N;u++){
        for(int i=0;i<G[u].size();i++){
            int v = G[u][i];
            indeg[v]++;
        }
    }

    for(int u=0;u<N;u++){
        if(indeg[u] == 0 && !V[u]) bfs(u);
    }

    for(list<int>::iterator it=out.begin();it!=out.end();it++){
        cout << *it << endl;
    }
}

int main(){
    int s, t, M;
    cin >> N >> M;
    
    for(int i=0;i<N;i++) V[i] = false;
    for(int i=0;i<M;i++){
        cin >> s >> t;
        G[s].push_back(t);
    }

    tsort();

    return 0;
}


Measured memory_bytes: 6256
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;

  int x;

  cin >> x;

  cout << (x/500)*1000 + (x%500/5)* 5 << endl;

  return 0;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int n,i,avg,sum,cnt,x[10000];
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		sum=0;
		for(i=0;i<n;i++)	{
			scanf("%d",&x[i]);
			sum+=x[i];
		}
		cnt=0;
		for(i=0;i<n;i++)	{
			if(x[i]*n<=sum)	cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}


Measured memory_bytes: 2708