akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  string N; cin >> N;
  cout << (N[0] == '7' || N[1] == '7' || N[2] == '7' ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3628
function Main(input){
    const N = input.trim();
    let answer = 0;
    const DFS = (N, num753) => {

        const contains7 = num753.includes('7');
        const contains5 = num753.includes('5');
        const contains3 = num753.includes('3');
        const contains = contains7 && contains5 && contains3;

        // 753数値が完成
        if(N.length == num753.length){
            if(contains && Number(num753) <= Number(N))  {
                answer++;
            }
            return; 
        }
        // 今の桁をチェック
        if(contains && Number(num753) <= Number(N)) {
            answer++;
        }
        // 3を入れるパターン
        DFS(N, num753 + '3');    
        // 5を入れるパターン
        DFS(N, num753 + '5');
        // 7を入れるパターン
        DFS(N, num753 + '7');
    }
    // 一桁目を作る
    DFS(N, '3');
    DFS(N, '7');
    DFS(N, '5');
    console.log(answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 32436
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define LL long long
#define NUM 1000000007

using namespace std;

int main()
{
    int x, y;
    cin >> x >> y;
    if (x % y == 0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << x << endl;
    }

}

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

int main(){
  int n;
  cin >> n;
  if(n >= 64) cout << "64" << endl;
  else if(n >= 32) cout << "32" << endl;
  else if(n >= 16) cout << "16" << endl;
  else if(n >= 8) cout << "8" << endl;
  else if(n >= 4) cout << "4" << endl;
  else if(n >= 2) cout << "2" << endl;
  else cout << "1" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, n);
  Cin(string, s, t);

  for (int i = 0; i < n; ++i) {
    cout << s[i];
    cout << t[i];
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <string>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char str[10];

int main()
{
	scanf("%s",&str);
	int n=strlen(str);
	for(int i=0;i+1<n;i++)
	{
		if(str[i]=='A'&&str[i+1]=='C')
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

const vector<int> cost = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

vector<int> as;

// can_create[i][j] means j consisting of i numbers can create
vector<vector<bool>> can_create;
// vector<vector<ll>> dp;

int calc_expected_digits(const int N, const int M) {
    vector<int> memo(N + 1, -1);
    memo[0] = 0;
    for (int i = 0; i < M; i++) {
        const int a = as[i];
        for (int j = 0; j < N; j++) {
            if (j + cost[a]  > N) {
                continue;
            }
            if (memo[j] >= 0) {
                chmax(memo[j + cost[a]], memo[j] + 1);
            }
        }
    }

    return memo[N];
}

void calc_can_create(const int expected_digits, const int N) {
    can_create.resize(expected_digits + 1, vector<bool>(N + 1, false));
    can_create[0][0] = true;
    for (int i = 0; i < expected_digits; i++) {
        for (auto a : as) {
            for (int j = 0; j < N; j++) {
                if (j + cost[a] > N) {
                    continue;
                }
                if (can_create[i][j]) {
                    can_create[i + 1][j + cost[a]] = true;
                }
            }
        }
    }
}

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

    as.resize(M);
    for (int i = 0; i < M; i++) {
        cin >> as[i];
    }
    // sort by descending order
    sort(as.begin(), as.end());
    reverse(as.begin(), as.end());

    const int expected_digits = calc_expected_digits(N, M);
    calc_can_create(expected_digits, N);

#ifdef DEBUG
    printf("can_create: \n");
    for (auto row : can_create) {
        for (auto x : row) {
            cout << x << " ";
        }
        cout << endl;
    }
#endif

    vector<int> ans;
    int n = N;
    for (int i = expected_digits; i > 0; i--) {
        for (auto a : as) {
            if (i > 1) {
                if (n - cost[a] > 0) {
                    if (can_create[i - 1][n - cost[a]]) {
                        ans.push_back(a);
                        n -= cost[a];
                        break;
                    }
                }
            } else {
                if (n - cost[a] == 0) {
                    if (can_create[i - 1][n - cost[a]]) {
                        ans.push_back(a);
                        n -= cost[a];
                        break;
                    }
                }
            }
        }
    }

    for (auto x : ans) {
        cout << x;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 9652
#include <iostream>
#include <cstdlib>
#include <cmath>

using namespace std;

int main()
{
	long long A, B;
	int i, j, K;

	cin >> A; cin >> B; cin >> K;

	if ((B - A) / 2 < K) {
		for (i = 0; i < B - A + 1; i++)
			cout << A + i << endl;
	}
	else {
		for (i = 0; i < K; i++)
			cout << A + i << endl;

		for (i = K - 1; i >= 0; i--)
			cout << B - i << endl;
	}

	return 0;
}

Measured memory_bytes: 256
using System;

class D
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());

		var c = new int[10, 10];
		for (int i = 1; i <= n; i++)
		{
			if (i % 10 == 0) continue;
			var s = i.ToString();
			c[s[0] - '0', s[s.Length - 1] - '0']++;
		}

		var r = 0L;
		for (int i = 1; i <= n; i++)
		{
			if (i % 10 == 0) continue;
			var s = i.ToString();
			r += c[s[s.Length - 1] - '0', s[0] - '0'];
		}
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 15304
fn main() {
    let mut n: Vec<usize> = Vec::new();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    n.push(buf.trim().parse().unwrap());

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    n.push(buf.trim().parse().unwrap());

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    n.push(buf.trim().parse().unwrap());

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    n.push(buf.trim().parse().unwrap());

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    n.push(buf.trim().parse().unwrap());

    if n[0] % 10 == 0 && n[1] % 10 == 0 && n[2] % 10 == 0 && n[3] % 10 == 0 && n[4] % 10 == 0 {
        println!("{}", n[0] + n[1] + n[2] + n[3] + n[4]);
        return;
    }

    let mut min_1_idx = 0;
    for i in 1..5 {
        if n[min_1_idx] % 10 == 0 {
            min_1_idx = i;
        } else if n[i] % 10 != 0 && n[min_1_idx] % 10 > n[i] % 10 {
            min_1_idx = i;
        }
    }

    let mut result: usize = 0;
    for i in 0..5 {
        if i == min_1_idx || n[i] % 10 == 0 {
            result += n[i];
        } else {
            result += n[i] + (10 - n[i] % 10);
        }
    }

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

Measured memory_bytes: 4352
#include <cstdio>
#include <stdlib.h>
#include <vector>
using namespace std;

int main() {
	int N;
	scanf("%d", &N);
    int x[200001] = {0};
    int a = 0;
    for (int i=0; i < N-1; i++) {
        int A;
        scanf("%d", &A);
        if (a == A) {
            x[a]++;
        } else {
            x[a]++;
            a = A;
        }
    }
    x[a]++;
    for (int i=1; i <= N; i++) {
        printf("%d\n", x[i]);
    }
    
    
}



Measured memory_bytes: 2512
#define George_Plover
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#define MAXN 400021
using namespace std;
struct DB{
    int key,atc;
}b[MAXN];
bool cmp(DB x,DB y)
{
    return x.key<y.key;
}
int n,m;
int find(int x)
{
    int L=0,R=n;
    while(L!=R)
    {
        int mid=(L+R+1)/2;
        if(b[mid].key<=x)
        {
            L=mid;
        }
        else
        {
            R=mid-1;
        }
    }
    return L;
}
int l[MAXN],r[MAXN],tot,pre[MAXN],to[MAXN],lin[MAXN],d[MAXN];
bool vis[MAXN],cut[MAXN];
void add(int x,int y)
{
    tot++;
    lin[tot]=pre[x];
    pre[x]=tot;
    to[tot]=y;
}
void dfs(int x)
{
    vis[x]=1;
    if(!x)
        d[x]=0;
    else
        d[x]=b[x].atc^b[x-1].atc;
    
    for(int i=pre[x];i;i=lin[i])
    {
        int v=to[i];
        if(!vis[v])
        {
            dfs(v);
            if(d[v]&1)
            {
                cut[(i+1)/2]=1;
            }
            d[x]^=d[v];
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&b[i].key,&b[i].atc);
    }
    
    sort(b+1,b+n+1,cmp);
    b[0].key=0;
    
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&l[i],&r[i]);
        l[i]=find(l[i]-1)+1;
        r[i]=find(r[i])+1;
        add(l[i],r[i]);
        add(r[i],l[i]);
    }
    
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            dfs(i);
            if(d[i]&1)
            {
                printf("-1\n");
                return 0;
            }
        }
    }
    
    int sum=0;
    for(int i=1;i<=m;i++)
    {
        if(cut[i])
            sum++;
    }
    printf("%d\n",sum);
    for(int i=1;i<=m;i++)
    {
        if(cut[i])
        {
            printf("%d ",i);
        }
    }
    
    
    return 0;
}





Measured memory_bytes: 14336
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

void solve() {
    int x;
    cin >> x;
    cout << (x == 0 ? 1 : 0) << "\n";
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases
// multiset erase is does not do what it is supposed to


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
  int n, sum = 0;
  cin >> n;
  vector<int> A(n), B(n), C(n - 1);
  rep(i, n) cin >> A.at(i);
  rep(i, n) cin >> B.at(i);
  rep(i, n - 1) cin >> C.at(i);
  int old_x = -100;
  for (int x : A) {
    sum += B.at(x - 1);
    if (old_x + 1 == x) sum += C.at(old_x - 1);
    old_x = x;
  }
  cout << sum << endl;
}


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

int main() {
  string s,t; cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<char>());
  
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
/*input
3 1
10 20 10



*/ 
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 
    
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5+1;
    

 
int32_t main() {
    IOS;
	int n,k;cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int dp[n] ;
	fill(dp,dp+n,INT_MAX);
	dp[0] = 0;
	for(int i=0;i<n;i++){
		for(int j=1;j<=k;j++){
			if(i+j<n){
			//cout<<dp[i]+abs(arr[i]-arr[i+1])<<" "<<dp[i+1]<<endl;
				dp[i+j] =  min(dp[i+j],dp[i]+abs(arr[i]-arr[i+j]));
				
			}
			if(i+j<n){
				dp[i+j] = min(dp[i+j],dp[i]+abs(arr[i]-arr[i+j]));
				//cout<<dp[i+2]<<" ";
			}
		}
		
		//cout<<dp[i]<<" ";
	}
	//cout<<endl;
	cout<<dp[n-1]<<endl;
	return 0;
}




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

int main() {
    while (true) {
        string cards; cin >> cards;
        if (cards == "-") {
            break;
        }

        int m; cin >> m;
        for (int i = 0; i < m; i++) {
            int h; cin >> h;
            cards += cards.substr(0, h);
            cards.erase(0, h);
        }

        cout << cards << endl;
    }

    return 0;
}


Measured memory_bytes: 3160
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
LL X,W;char ch;
inline LL read()
{
	X=0,W=1;ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')W=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){X=(X<<1)+(X<<3)+ch-48;ch=getchar();}
	return X*W;
}
struct store{
	LL num;
	LL pri;
}a[100001];
bool cmp(store c,store b)
{
	return c.pri<b.pri;
}
LL ans;
int main()
{
	int n,m;
	n=read(),m=read();
	for(int i=1;i<=n;i++)a[i].pri=read(),a[i].num=read();
	sort(a+1,a+n+1,cmp);
	int i=1;
	while(true){
		if(a[i].num<m)ans+=a[i].num*a[i].pri;
		else {ans+=m*a[i].pri;break;}
		m-=a[i].num;
		i++;
	}
	printf("%lld",ans);
}

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

using namespace std;

int N;
vector< vector<int> > G;
vector<bool> used;

void remove_edge(int v1, int v2) {
	for (int i = 0; i < G[v1].size(); ++i) {
		if (G[v1][i] == v2) {
			G[v1].erase(G[v1].begin()+i);
			break;
		}
	}
	for (int i = 0; i < G[v2].size(); ++i) {
		if (G[v2][i] == v1) {
			G[v2].erase(G[v2].begin()+i);
			break;
		}
	}
}
void add_edge(int v1, int v2) {
	G[v1].push_back(v2);
	G[v2].push_back(v1);
}
int dfs(int v, int prev) {
	for (int i = 0; i < G[v].size(); ++i) {
		int to = G[v][i];
		if (to != prev) {
			return dfs(to, v)+1;
		}
	}
	return 1;
}
int getlen(int s) {
	return dfs(s, -1);
}
bool isConnected(int s, int t) {
	vector<bool> reached(N, false); reached[s] = true;
	queue<int> Q; Q.push(s);
	while ( !Q.empty() ) {
		int v = Q.front(); Q.pop();
		for (int i = 0; i < G[v].size(); ++i) {
			int to = G[v][i];
			if (!reached[to]) {
				reached[to] = true;
				Q.push(to);
			}
		}
	}
	return reached[t];
}
bool check(int v1, int v2) {
	if ( N % 2 == 1 ) return false;
	if ( isConnected(v1, v2) ) return false;
	if ( getlen(v1) == N/2 && getlen(v2) == N/2 ) return true;
	return false;
}
bool check2(int v, int v1, int v2) {
	vector<int> kh = G[v];
	for (int i = 0; i < kh.size(); ++i) {
		remove_edge(v, kh[i]);
		if (check(v1, v2)) return true;
		add_edge(v, kh[i]);
	}
	return false;
}
bool solve(int v1, int v2) {
	bool f = false;
	if (N % 2 == 1) return false;
	for (int i = 0; i < N; ++i) {
		if (G[i].size() == 3) {
			f = true;
		}
		else if (G[i].size() >= 4) {
			return false;
		}
	}
	if (f) { // delta G == 3
		vector<int> v;
		for (int i = 0; i < N; ++i) {
			if (G[i].size() == 3) {
				v.push_back(i);
			}
		}
		if (v.size() >= 3) return false;
		if (v.size() == 1) {
			return check2(v[0], v1, v2);
		}
		else {
			assert(v.size() == 2);
			bool isFind = false;
			for (int i = 0; i < G[v[0]].size(); ++i) {
				if (G[v[0]][i] == v[1]) {
					isFind = true;
				}
			}
			if (isFind) {
				remove_edge(v[0], v[1]);
				return check(v1, v2);
			}
			else {
				return false;
			}
		}
	}
	else { // delta G <= 2
		if ( check2(v1, v1, v2) ) return true;
		if ( check2(v2, v1, v2) ) return true;
		if (G[v1].size() == 1 && G[v2].size() == 1) {
			return true;
		}
		else {
			bool isFind = false;
			for (int i = 0; i < G[v1].size(); ++i) {
				if (G[v1][i] == v2) {
					isFind = true;
				}
			}
			remove_edge(v1, v2);
			return check(v1, v2);
		}
	}
}

int main() {
	cin >> N;
	G.resize(N);
	int v1, v2; cin >> v1 >> v2; --v1, --v2;
	for (int i = 0; i < N-1; ++i) {
		int u, v; cin >> u >> v; --u, --v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	if ( solve(v1, v2) ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 8420
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

const int N=100005;
const int P=998244353;
const long long INF=0x3f3f3f3f3f3f3f3fll;

int n;
long long C,x[N],v[N];
long long cur,ans;
long long s_p[N],s_n[N];
long long f_p[N],f_n[N];

void init(){
	scanf("%d%lld",&n,&C);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&x[i],&v[i]);
	}
	f_p[0]=f_n[n+1]=-INF;
	for(int i=1;i<=n;i++){
		cur+=v[i];
		s_p[i]=cur-x[i];
		f_p[i]=max(f_p[i-1],cur-x[i]);
	}
	cur=0;
	for(int i=n;i>=1;i--){
		cur+=v[i];
		s_n[i]=cur-(C-x[i]);
		f_n[i]=max(f_n[i+1],cur-(C-x[i]));
	}
	for(int i=1;i<=n;i++){
		ans=max(ans,s_p[i]);
		ans=max(ans,s_p[i]-x[i]+f_n[i+1]);
		ans=max(ans,s_n[i]);
		ans=max(ans,s_n[i]-(C-x[i])+f_p[i-1]);
	}
	printf("%lld\n",ans);
}

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

Measured memory_bytes: 4992
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
#１行に数値一つならparseInt(readline())
#１行に数値複数ならparseMap(split(readline()))を行数分。
# 例：n,k = readline() |> split |> parseMap
#      a = readline() |> split |> parseMap
function main()
  #a = parseInt(readline())
  N,K = parseMap(split(readline()))
  p = parseMap(split(readline()))
  #println("$N,$K")
  #println("$p")
  p=sort!(p)
  #println("$p")
  println(sum(p[1:K]))
end
main()


Measured memory_bytes: 164564
a = list(input())

flag = 0
for i in range(len(a)):
  if (i + 1) % 2 == 1:
    if a[i] not in ("R", "U", "D"):
      flag = 1
      break
  else:
    if a[i] not in ("L", "U", "D"):
      flag = 1
      break 
if flag == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int price;
		int n;
		int all = 0;
		int allN = 0;
		int rCount = 0;
		for (Scanner in = new Scanner(System.in); in.hasNext();) {
			String[] r = in.next().split(",");
			price = Integer.parseInt(r[0]);
			n = Integer.parseInt(r[1]);
			all += price * n;
			allN += n;
			rCount++;
		}
		System.out.println(all);
		System.out.println(Math.round((float) allN / rCount));
	}
}

Measured memory_bytes: 11000
N = int(input())
a = list(map(int, input().split()))
up = -1
ans = 1
for i in range(1, N):
    if up == 0 and a[i] - a[i-1] > 0:
        up = -1
        ans += 1
    elif up == 1 and a[i] - a[i-1] < 0:
        up = -1
        ans += 1
    elif up == -1 and a[i] - a[i-1] > 0:
        up = 1
    elif up == -1 and a[i] - a[i-1] < 0:
        up = 0
print(ans)

Measured memory_bytes: 14252
#include "bits/stdc++.h"

using namespace std;

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

int main()
{
	int dx[6] = {0, 1, 1, 0, -1, -1};
	int dy[6] = {1, 1, 0, -1, -1, 0};
	while (1)
	{
		int n, t;
		int ans = 0;
		cin >> t >> n;
		if (t == 0 && n == 0)
			break;

		int ban[150][150];
		fill(ban[0], ban[150], 1e8 - 1);
		//(75,75)が(0,0)に相当

		for (int i = 0; i < n; i++)
		{
			int x, y;
			cin >> x >> y;
			ban[x + 75][y + 75] = -1; //到達不可
		}
		int x, y;
		cin >> x >> y;
		x += 75;
		y += 75;
		ban[x][y] = 0; //スタート
		deque<P> que;
		que.push_back(P(make_pair(x, y), 0));
		while (!que.empty())
		{
			P p = que.back();
			pair<int, int> za = p.first;
			que.pop_back();
			if (p.second > ban[za.first][za.second])
				continue;
			//隣接マスを探す
			for (int i = 0; i < 6; i++)
			{
				if (ban[za.first + dx[i]][za.second + dy[i]] == -1)
					continue;

				if (p.second + 1 < ban[za.first + dx[i]][za.second + dy[i]])
				{
					ban[za.first + dx[i]][za.second + dy[i]] = p.second + 1;
					if (p.second + 1 < t)
						que.push_back(P(make_pair(za.first + dx[i], za.second + dy[i]), p.second + 1));
				}
			}
		}

		for (int i = 0; i < 150; i++)
		{
			for (int j = 0; j < 150; j++)
			{
				if (ban[i][j] != 1e8 - 1 && ban[i][j] > -1)
					ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


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

typedef long long ll;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

char getDif(char a,char b){
    if('R'!=a && 'R'!=b)return 'R';
    if('G'!=a && 'G'!=b)return 'G';
    return 'B';
}

ll getInd(char c){
    if(c=='R')return 0;
    if(c=='G')return 1;
    return 2;
}

void solve(){
    ll n;
    string s;
    cin>>n>>s;
    unordered_map<char,set<int>> m;
    for(int i=0;i<n;i++){
        m[s[i]].insert(i);
    }
    vector<vector<ll>> v(n,vector<ll>(3));
    for(int i=n-2;i>=0;i--){
        for(int j=0;j<3;j++)v[i][j]+=v[i+1][j];
        v[i][getInd(s[i+1])]++;
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i]!=s[j]){
                char c=getDif(s[i],s[j]);
                int di=j-i;
                ans+=v[j][getInd(c)];
                if(m[c].count(j+di))ans--;
            }
        }
    }
    cout<<ans;
}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3992
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n,m,x;
  cin >> n >> m >> x;
  vector<ll> c(n);
  vector<vector<ll>> a(n, vector<ll>(m));
  rep(i,n) {
    cin >> c[i];
    rep(j,m) {
      cin >> a[i][j];
    }
  }

  ll ans = INF;
  rep(i,1ll<<n) {
    ll now = 0;
    vector<ll> b(m);
    rep(j,n) {
      if (i&(1ll<<j)) { // j is in i
        now += c[j];
        rep(k,m) {
          b[k] += a[j][k];
        }
      }
    }
    // Here, check b.
    bool ok = true;
    rep(j,m) {
      if (b[j] < x) {
        ok = false;
        break;
      }
    }
    if (ok) {
      chmin(ans, now);
    }
  }

  if (ans == INF) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 3664
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>

using namespace std;

#define ABS(a) ((a>0)?a:-(a))
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a<b)?(b):(a))
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define pnt pair <int, int>
#define mp make_pair
#define PI 3.1415926535897
#define MEMS(a,b) memset(a,b,sizeof(a))
#define LL long long
#define U unsigned

vector<vector<int>> g;
int ans[100100];
int v[100100];
int d[100100];
int c[100100];
int watched[100100];
int p[100100];
int curD[100100];

int main()
{
#ifdef Fcdkbear
	freopen("in.txt", "r", stdin);
	double beg = clock();
	//freopen("out.txt", "w", stdout);
#endif

	int n, m;
	scanf("%d%d", &n, &m);
	g.resize(n);
	FOR(i, 0, m) {
		int v1, v2;
		scanf("%d%d", &v1, &v2);
		v1--;
		v2--;
		g[v1].push_back(v2);
		g[v2].push_back(v1);
	}
	int q;
	scanf("%d", &q);
	FOR(i, 0, q) {
		scanf("%d%d%d", &v[i], &d[i], &c[i]);
		v[i]--;
	}
	MEMS(watched, -1);
	for (int i = q - 1; i >= 0; --i) {
		int l = 0;
		int r = 0;
		p[0] = v[i];
		if (ans[v[i]] == 0) {
			ans[v[i]] = c[i];
		}
		if (watched[v[i]] >= d[i]) {
			continue;
		}
		watched[v[i]] = d[i];
		curD[v[i]] = d[i];
		while (l <= r) {
			int ver = p[l++];
			if (ans[ver] == 0) {
				ans[ver] = c[i];
			}
			if (curD[ver]) {
				FOR(i, 0, g[ver].size()) {
					int to = g[ver][i];
					int nextD = curD[ver] - 1;
					if (nextD > watched[to]) {
						watched[to] = nextD;
						curD[to] = nextD;
						p[++r] = to;
					}
				}
			}
		}
	}
	FOR(i, 0, n) {
		printf("%d\n", ans[i]);
	}


#ifdef Fcdkbear
	double end = clock();
	fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>bool chmax(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    cout<<fixed<<setprecision(10);
    int n;
    cin>>n;
    vector<double> t(n+1),v(n+2);
    rep(i,n) cin>>t[i+1];
    rep(i,n) cin>>v[i+1];
    
    rep(k,n) FOR(i,1,n) {
        chmin(v[i],v[i+1]+t[i]);
        chmin(v[i],v[i-1]+t[i]);
    }

    double ans=0;
    FOR(i,1,n) {
        if(v[i-1]<=v[i] && v[i]<=v[i+1]) {
            ans+=v[i]*t[i]-pow((v[i]-v[i-1]),2)/2;
        }
        else if(v[i-1]>=v[i] && v[i]>=v[i+1]) {
            ans+=v[i]*t[i]-pow((v[i]-v[i+1]),2)/2;
        }
        else if(v[i-1]<v[i] && v[i]>v[i+1]) {
            double d=v[i+1]-v[i-1];
            ans+=t[i]*(v[i-1]+t[i]/2+d/2)-(pow(t[i]/2+d/2,2)+pow(t[i]/2-d/2,2))/2-pow(max(0.0,v[i-1]+t[i]/2+d/2-v[i]),2);
        }
        else {
            ans+=v[i]*t[i];
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a,b,c;
    scanf(" %d%d%d",&a,&b,&c);
    if((1<=a&&a<=1E9)&&(1<=b&&b<=1E9)&&(1<=c&&c<=1E9)){

        if(c<=b){printf("delicious");}
        if(b<c&&c<=(a+b)) {printf("safe");}
        if(c>(a+b)){printf("dangerous");}
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <random>
#include <sstream>
#include <stack>
#include <deque>

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
    int H, W;
    cin >> H >> W;
    string S[H];
    rep(i,H) cin >> S[i];
    bool flag = true;
    int dy[] = {1, 0, -1, 0};
    int dx[] = {0, -1, 0, 1};
    rep(i,H) rep(j,W) {
        if (S[i][j] == '#') {
            bool can = false;
            rep(k,4) {
                if (i + dy[k] >= 0 && i + dy[k] < H && j + dx[k] >= 0 && j + dx[k] < W) {
                    if (S[i+dy[k]][j+dx[k]] == '#') can = true;
                }
            }
            if (!can) {
                flag = false;
                break;
            }
        }
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    // cout << ans << endl;
    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


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

    i64 cnt = 0;
    REP(i, S.length()) {
        if (S[i] == 'x') cnt++;
    }
    cout << (cnt >= 8 ? "NO" : "YES") << endl;

    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int X; cin >> X;
	int i = 1;
	for (;i * (i + 1) / 2 < X; ++i);
	cout << i << endl;

	return 0;
}

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


// int brute(vector<int> &a, vector<int> &b, vector<int> &c, int p, int i)
// {
//     int ret = 0;
//     if(i >= a.size())
//     {
//         return ret;
//     }
//     if(p == 0)
//     {
//         ret += a[i];
//         int y = brute(a, b, c, 1, i+1);
//         int z = brute(a, b, c, 2, i+1);
//         ret += max(y, z);
//     }
//     else if(p == 1)
//     {
//         ret += b[i];
//         int x = brute(a, b, c, 0, i+1);
//         int z = brute(a, b, c, 2, i+1);
//         ret += max(x, z);
//     }
//     else
//     {
//         ret += c[i];
//         int x = brute(a, b, c, 0, i+1);
//         int y = brute(a, b, c, 1, i+1);
//         ret += max(x, y);
//     }
//     return ret;
// }

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    vector<int> a(n), b(n), c(n);
    for(int i = 0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    
    vector<vector<int>> dp(3, vector<int> (n));
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    
    for(int i = 1;i<n;i++)
    {
        dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
    }
    
    int ans = max({dp[0][n-1], dp[1][n-1], dp[2][n-1]});
    // int x = brute(a, b, c, 0, 0);
    // int y = brute(a, b, c, 1, 0);
    // int z = brute(a, b, c, 2, 0);
    // int ans = max(x, max(y, z));
    cout<<ans<<"\n";
    
    return 0;
}

Measured memory_bytes: 6100
# -*- coding: utf-8 -*-

import sys

n = raw_input().split()[0]
al = [int(e) for e in raw_input().split()]

p = 0
for ai in al:
    p |= ai

n = 0
while True:
    if p & 1:
        break
    p >>= 1
    n += 1

sys.stdout.write('%d\n' % n)
sys.stdout.flush()


Measured memory_bytes: 2568
n = gets.to_i
red = n.times.map { gets.split.map(&:to_i) }.sort_by { |a| a[0] }
blue = n.times.map { gets.split.map(&:to_i) }.sort_by { |a| a[0] }

pair = 0
blue.each do |b|
  candidate = red.select { |rs| rs[0] < b[0] }.sort_by { |r| r[1] }.reverse
  candidate.each do |c|
    next unless c[1] < b[1]
    pair += 1
    red.delete c
    break
  end
end

puts pair


Measured memory_bytes: 1912
n = int(input())
array = list(map(int,input().split(" ")))
for i in range(0, n):
    v = array[i]
    j = i - 1
    while j >= 0 and array[j] > v:
        array[j+1] = array[j]
        j -= 1
    array[j+1] = v
    print(" ".join(list(map(str, array))))


Measured memory_bytes: 5600
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF 1000000000

// count past days from 1/1/1
int days(int y,int m,int d){
  int res=0;
  res += (y-1)*195 + ((y-1)/3)*5;
  if(y%3==0) res += (m-1)*20;
  else res += (m-1)*20 - ((m-1)/2);
  res += d-1;
  return res;
}

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

  int mill = days(1000,1,1);

  rep(i,n){
    int y,m,d;
    scanf("%d %d %d", &y, &m, &d);
    printf("%d\n", mill - days(y,m,d));
  }

}

Measured memory_bytes: 1224
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 7223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, K;
	cin >> N >> K;
	VI H(N + 1, 0);
	REP(i, N)cin >> H[i + 1];

	int dp[310][310];
	REP(i, 310) {
		REP(j, 310)dp[i][j] = LLINF;
	}
	//x番目まで見た時にy個選んだ時
	dp[0][0] = 0;
	
	eFOR(i, 1, N) {
		dp[i][0] = dp[i - 1][0] + max(0LL, H[i] - H[i - 1]);
		//cout << dp[i][0] << " ";
	}
	eFOR(i,1, N) {
		eFOR(j, 1, N - K) {

			int next = LLINF;

			FOR(k, 0, i) {
				next = min(next, dp[k][j - 1] + max(0LL, H[i] - H[k]));
			}

			dp[i][j] = min(dp[i][j], next);
		}
	}



	int ans = LLINF;
	eREP(i, N) {
		ans = min(ans, dp[i][N - K]);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  int N=S.size();
  int ans=0;
  vi A;
  rep(i,0,N){
    if(S[i]=='B') A.pb(i+1);
  }
  int M=A.size();
  rep(i,0,M){
    ans+=N-i-A[i];
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 2552
#include<stdio.h>
#define N 40
#define O 0
#define I 1

int n,p,a[N],b[N];

void solve(int l,int r){
  int i,x;

  x=a[p];
  if(l>r){
    return;
  }
  if(l==r){
    if(b[l]==a[O]){
      printf("%d",b[l]);
    }
    else{
      printf("%d ",b[l]);
    }
    p++;
    return;
  }
  p++;
  for(i=l;i<=r;i++){
    if(b[i]==x){
      break;
    }
  }
  solve(l,i-I);
  solve(i+I,r);
  if(x==a[O]){
    printf("%d",x);
  }
  else{
    printf("%d ",x);
  }
}


int main(){
  int i;

  scanf("%d",&n);
  for(i=O;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=O;i<n;i++){
    scanf("%d",&b[i]);
  }
  p=O;
  solve(O,n-I);
  printf("\n");
  return O;
}



Measured memory_bytes: 2092
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

int dp[201][201][6];
bool kag[201][201] = {};

int dir_x[7] = {0,1,1,0,-1,-1,0};
int dir_y1[7] = {1,0,-1,-1,-1,0,0};
int dir_y2[7] = {1,1,0,-1,0,1,0};

int get_state(int x, int y, int t) {
	return ((x+100)<<20)|((y+100)<<10)|(t%6);
}

void set_state(int state, int *x, int *y, int *t) {
	*x = ((state>>20)&0b1111111111)-100;
	*y = ((state>>10)&0b1111111111)-100;
	*t = ((state>> 0)&0b1111111111);
}

int main() {
	int sx,sy,gx,gy,n,lx,ly;
	cin>>sx>>sy>>gx>>gy>>n;
	for(int i = 0; i < n; i++) {
		int x,y;
		cin>>x>>y;
		kag[x+100][y+100] = true;
	}
	cin>>lx>>ly;
	for(int i = 0; i < 201; i++) {
		for(int j = 0; j < 201; j++) {
			for(int k = 0; k < 6; k++) {
				dp[i][j][k] = 1<<30;
			}
		}
	}
	//memset(dp,0b01111111,201*201*6*sizeof(int));

	queue<int> q1,q2;
	dp[sx+100][sy+100][0] = 0;
	q1.push(get_state(sx,sy,0));
	while(!q1.empty()) {
		//cout << q1.size() << endl;
		while(!q1.empty()) {
			int state = q1.front(); q1.pop();
			int x,y,t;
			set_state(state,&x,&y,&t);
			//cout << " " << x << "," << y << "," << t << "," << dp[x+100][y+100][t] << endl;
			int pre_count = dp[x+100][y+100][t];
			int honest = abs(x*y*t)%6;
			for(int d = 0; d < 7; d++) {
				int dx = x+dir_x[d];
				int dy = y+(((x+100)%2==0)?dir_y1[d]:dir_y2[d]);
				int dt = (t+1)%6;
				//cout << "  " << dx << "," << dy << "," << dt << endl;
				if(abs(dx)>lx||abs(dy)>ly) continue;
				if(kag[dx+100][dy+100]) continue;
				int new_state = get_state(dx,dy,dt);
				int *dpt = &dp[dx+100][dy+100][dt];
				int new_count = pre_count+((d==honest)?0:1);
				if(*dpt>new_count) {
					*dpt = new_count;
					if(d==honest) {
						q1.push(new_state);
					}else {
						q2.push(new_state);
					}
				}
			}
		}
		swap(q1,q2);
	}
	int ans = 1<<30;
	for(int t = 0; t < 6; t++) {
		int *dpt = &dp[gx+100][gy+100][t];
		ans = min(ans,*dpt);
		/*
		for(int y = ly; y >= -ly; y--) {
			for(int x = -lx; x <= lx; x++) {
				cout << dp[x+100][y+100][t] << " ";
			}
			cout << endl;
		}
		cout << endl;
		*/
	}
	if(ans==(1<<30)) ans = -1;
	cout << ans << endl;
}



Measured memory_bytes: 4184
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string S, Sl, Sr; int Q;
int main() {
  cin >> S >> Q;
  int T, F; string C; bool l2r = true;
  for(int i = 0; i < Q; ++i) {
    cin >> T;
    if(T == 1) {
      l2r = !l2r;
    } else {
      cin >> F >> C;
      if((l2r && F == 1) || (!l2r && F == 2)) Sl.append(C);
      else Sr.append(C);
    }
  }
  if(l2r) {
    reverse(Sl.begin(), Sl.end());
    cout << Sl << S << Sr << endl;
  } else {
    reverse(S.begin(), S.end());
    reverse(Sr.begin(), Sr.end());
    cout << Sr << S << Sl << endl;
  }
}

Measured memory_bytes: 1088
#include <bits/stdc++.h>
using namespace std;
vector<int> g[100005];
int a,b,n,ans=0;
int Fennec[100005];
int Sunuke[100005];
void dfs(int r,int d,int f,int dist[])
{
  dist[r]=d;
  for(int i=0;i<g[r].size();i++){
    if(g[r][i] != f) dfs(g[r][i],d+1,r,dist); 
  }
}
int main()
{
  cin>>n;
  for(int i=0;i<n-1;i++){
    cin>>a>>b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0,0,-1,Fennec);
  dfs(n-1,0,-1,Sunuke);
  for(int i=0;i<n;i++) if(Fennec[i]<=Sunuke[i]) ans++;
    else ans--;
  printf("%s\n",(ans>0)?"Fennec":"Snuke");
  return 0;
}


Measured memory_bytes: 14336
def make_digit x
    digit, sum = nil, nil
    if x.positive?
        digit, sum = 0, 1
        while x > sum
            digit += 2
            sum += 2 ** digit
        end
    elsif x.negative?
        digit, sum = 1, -2
        while x < sum
            digit += 2
            sum += (-2) ** digit
        end
    end
    return digit
end

n = gets.to_i
if n == 0
    puts 0
else
    arr = []
    x = n
    while x != 0
        arr << make_digit(x)
        x = x - (-2) ** arr.last
    end
    
    answer = Array.new(arr.max, "0")
    arr.each{|i| answer[i] = "1"}
    puts answer.join.reverse
end

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

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

    std::string t;
    std::string p;
    std::cin >> t;
    std::cin >> p;
    int tl = t.length();
    int pl = p.length();
    //create table                                                                                                                                                                                                                     
    std::vector<int> table(pl + 1, 0);
    table[0] = -1;
    table[1] = 0;
    int i = 2; int j = 0;
    while(i <= pl){
        if(p[i-1] == p[j]){
            table[i] = j + 1;
            ++i;
            ++j;
        } else if(j > 0) j = table[j];
        else table[i++] = 0;
    }

    i = 0; j = 0;
    while(i < tl){
        if(t[i] == p[j]){
            ++i;
            ++j;
            if(j == pl){
                std::cout << i - pl << "\n";
                j = table[j];
            }
        } else if(j == 0){
            ++i;
        } else {
            j = table[j];
        }
    }
    return 0;
}


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

int main()
{
ll n ;
cin >> n ;
string s ;
cin >> s ;
vector<vector<ll>> v(n+1, vector<ll>(3,0) );
rep(i,n){
  v[i+1][0]=v[i][0];
  v[i+1][1]=v[i][1];
  v[i+1][2]=v[i][2];
  if(s[i]=='R')v[i+1][0]++;
  if(s[i]=='G')v[i+1][1]++;
  if(s[i]=='B')v[i+1][2]++;
}
char p[3]={'R','G','B'};
for (ll i = 0; i < n-1; i++)
{
  for (ll j = i+1; j < n; j++)
  {
    if(s[i]==s[j])continue;
    bool a[3]={};
    if(s[i]=='R')a[0]=1;
    if(s[j]=='R')a[0]=1;
    if(s[i]=='G')a[1]=1;
    if(s[j]=='G')a[1]=1;
    if(s[i]=='B')a[2]=1;
    if(s[j]=='B')a[2]=1;
    ll b;
    rep(u,3)if(!a[u]){b=u;break;}
    ans+=v[n][b]-v[j][b];
    if(j+j-i<n&&s[j+j-i]==p[b])ans--;
  }
  
}


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

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

ll f[2000002];

ll p(ll x, ll n) {
	ll res = 1;
	while(n) {
		if(n&1) {
			res=(res*x)%MOD;
		}
		x=(x*x)%MOD;
		n/=2;
	}
	return res;
}

ll nCr(ll n, ll r) {
	ll ans=1;
	ans=(ans*f[n])%MOD;
	ans=(ans*p(f[r],MOD-2))%MOD;
	ans=(ans*p(f[n-r],MOD-2))%MOD;
	return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll r1,c1,r2,c2,sum=0,i;
    f[0]=1; 
    for(i=1;i<2000002;i++) f[i]=(f[i-1]*i)%MOD;
    
	cin >> r1 >> c1 >> r2 >> c2;
	for(i=c1;i<=c2;i++) {
		ll temp=nCr(r2+1+i,r2)-nCr(r1+i,r1-1);
		temp = (temp+MOD)%MOD;
		sum=(sum+temp)%MOD;
	}
    cout << sum << "\n";
    return 0;
}



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

int main(void)
{
	string S;
	cin >> S;
	int *flg = new int[26]();
	int aaa = -1;
	for (int i = 0; i < S.length(); ++i) {
		++flg[S[i] - 97];
		if (i != 0 && S[i - 1] < S[i]) {
			aaa = i - 1;
		}
	}

	if (S.length() < 26) {
		int ind = 0;
		for (int i = 0; i < 26; ++i) {
			if (flg[i] == 0) {
				ind = i;
				break;
			}
		}
		cout << S << char(ind + 97) << endl;
	} else {
		if (aaa == -1) {
			cout << -1 << endl;
			return 0;
		}
		int min = aaa + 1;
		for (int i = min; i < S.length(); ++i) {
			if (S[i] > S[aaa] && S[min] > S[i])	min = i;
		}
		S = S.substr(0, aaa) + S[min];
		cout << S << endl;
	}

	return 0;
}

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

using namespace std;

int h[100005], dp[100005];

int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 1;i <= n; ++i)
        cin >> h[i];
    dp[0]=1000000002 ;
  dp[1] = 0;
    for(int i = 2;i <=n; ++i){ 
      dp[i] = 1000000002 ;
       for(int j = 1; j <= k; ++j)
         if(i - j >= 0)
            dp[i] = min(dp[i-j] + abs(h[i-j]-h[i]), dp[i] );
    } 
      cout << dp[n];
    return 0;
}


Measured memory_bytes: 4368