akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 998244353;
const int N = 5205;
const int K = 25;
int dp[N][N], s[N][N], p[N][N], q[N], f[N], invf[N], t[N][N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   // freopen("input.txt", "r", stdin);
    int n, mod;
    cin >> n >> mod;
    int l = (n - 1) / 2;
    p[0][0] = 1;
    for (int j = 0; j <= n; j++) s[0][j] = 1;
    for (int i = 1; i <= n; i++){
        for (int j = i; j <= n; j++){
            p[i][j] = (p[i - 1][j - 1] + p[i][j - i]) % mod;
        }
        for (int j = 0; j <= n; j++){
            s[i][j] = (s[i][j - 1] + p[i][j]) % mod;
        }
    }
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= n; j++){
            dp[i][j] = p[i][j];
            if (i == 2 && j == n && n % 2 == 0) dp[i][j] = 0; else
            if (j >= l + 1) dp[i][j] = (dp[i][j] - s[i - 1][j - l - 1] + mod) % mod;
        }
    }
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= n; j++){
            dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= n; j++){
            if (j == 0) t[i][j] = dp[i][j]; else
            t[i][j] = (t[i][j - 1] + dp[i][j]) % mod;
        }
    }
    for (int j = 0; j <= n; j++){
        for (int i = j + 1; i <= n; i++){
            ans = (ans + dp[n][j] * t[n - i][i - j - 1]) % mod;
        }
    }
    if (n % 2 == 0){
        for (int j = 0; j <= n; j++){
            for (int i = j + 1 + l; i < n; i++){
                ans = (ans + dp[n][j] * t[n - i - 1][i - j - 1 - l]) % mod;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 821504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    cout << (char)(s[0] + 1);
    return 0;
}

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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n,m;
    cin >> n >> m;
    vector<bool> broken(n+1,true);
    REP(i,m){
        int t;
        cin >> t;
        broken[t]=false;
    }
    vector<ll>dp(n+1);
    dp[0]=1;
    REP(i,n){
        FOR(j,i+1,min(n,i+2)+1){
            if(broken[j]){
                dp[j]+=dp[i];
                if(dp[j]>=MOD) dp[j]%=MOD;
            }
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int power(int a,int b)
{
	int i,ans=1;
	for(i=0;i<b;i++)
		ans*=a;
	return ans;
}
int main()
{
	int i,n;
	scanf("%d",&n);
	for(i=0;;i++)
		if(power(2,i)>n)
		{
			printf("%d\n",power(2,i-1));
			return 0;
		}
}

Measured memory_bytes: 128
//author:emre yazicioglu

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define fori(a,b,c) for(int a = b;a < int(c);a++)
#define ford(a,b,c) for(int a = b;a >= int(c);a--)
#define pb push_back

const int N = 2e6 + 7;
ll n,m,k,cnt,cur,ans;
ll ar[N],sum;
ll a,b,c,d;
string str;
bool flag;
vector <ll> v;

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

	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	
	char last = 'A';
	cin >> str;
	n = str.size();
	fori(i,0,n){
		if(i == n - 2){
			if(str[i] == last){
				ans++;
				break;
			}
			else{
				if(str[i] == str[i + 1]){
					ans++;
					break;
				}
			}
		}
		if(str[i] != last){
			last = str[i];
			ans++;
		}
		else{
			last = 'A';
			ans++;
			i++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 720
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
        q: usize,
        bc: [(usize, usize); q],
    }
    let mut d = vec![0usize; 100001];
    for &ai in &a {
        d[ai] += 1;
    }
    // eprintln!("{:?}", d);
    let mut s = 0;
    for i in 0..d.len() {
        s += i * d[i];
    }
    for &(b, c) in &bc {
        let k = d[b];
        s -= k * b;
        s += k * c;
        d[b] = 0;
        d[c] += k;
        println!("{}", s);
    }
}


Measured memory_bytes: 6924
#include<stdio.h>

int main(){

	int a[10];
	int i, j, temp;

// ??°????????\??????????????????????´?????????????

		for(i = 0; i< 10; i++){
//			printf("?±±?????????%d\n",i+1);
			while(1){
				scanf("%d",&a[i]);
				//0???10000?????°?????\????????????????????¨????????????
				if((a[i] >= 0) && (a[i] <= 10000))	
					break;
				else
					while( getchar() != '\n' );			
			}
		}

//??°????????????????????????????????????
	for(i=0; i<10; i++){
		for(j=i+1 ;j<10; ++j){
			if(a[i]<a[j]){
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}

//??????????????????????????°???????????????????????§????????¢?????????????????????
	for(i = 0; i< 3; i++){
		printf("%d\n", a[i]);		
	}

    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
long long f(long long x){
    return x*x*x*x*x;
}
int main(void){
    int a;
    int b = 0;
    cin >> a;
    for(int i=0;i<10000*4;i++){
        for(int j=-i;j<i;j++){
            if(f(i)-f(j) == a){
                cout << i << " " << j << endl;
                b++;
                break;
            }
            if(b == 1) break;
        }
    }
}

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

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
  int a,b;
  cin >> a >> b;
  cout << (a+b+1)/2 << endl;
}

int main(int argc, char *argv[]){

  // /* Regular */
  // int case_num = 1;
  // if (argc > 1 && stoi(argv[1])) cin >> case_num;
  // REP(case_no, case_num) {
  //   cerr << endl << "case " << case_no + 1 << endl;
  //   solve();
  // }
  
  /* AOJ */
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  string s;
  R s;
  string t="";
  rep(i,s.size()) {
    if(i+1<s.size()&&s[i]=='B'&&s[i+1]=='C') {
      t+='D';
      i++;
    } else t+=s[i];
  }
  ll ans=0;
  ll c=0;
  rrep(i,t.size()) {
    if(t[i]=='D') c++;
    else if(t[i]=='A') ans+=c;
    else c=0;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 916
#include<stdio.h>

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;


int main(){

  int m,d;
  while(cin >> m >> d){
    int ans = 0;

    FORE(i,1,m){
      FORE(j,1,d){
        int d1 = j%10;
        int d10 = j/10;

        if(d1 >= 2 and d10 >= 2 and d1*d10 == i){
          ++ans;
        }
        
      }
    }
    

    cout << ans << endl;
  }
  
  


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3 = x2 - (y2 - y1);
  int y3 = y2 + (x2 - x1);
  int x4 = x3 - (x2 - x1);
  int y4 = y3 - (y2 - y1);
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

const int N = 111111;
vector<int> graph[N];
int da[N], dt[N];
int pa, pt;
int n;

void dfs(int u, int p, bool tak) {
    if(p) {
        if(tak) dt[u] = dt[p] + 1;
        else da[u] = da[p] + 1;
    }
    rall(v, graph[u]) {
        if(v != p) {
            dfs(v, u, tak);
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> pt >> pa;
    rep(i, 1, n - 1) {
        int u, v;
        cin >> u >> v;
        graph[u].pb(v);
        graph[v].pb(u);
    }
    dfs(pa, 0, 0);
    dfs(pt, 0, 1);
    int leaf, md = -1;
    rep(u, 1, n) {
        if(da[u] > dt[u] && da[u] > md) {
            md = da[u];
            leaf = u;
        }
    }
    int ans = da[leaf] - 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10624
#ifdef LOCAL
  #define debug_echo(expr) cout << expr;
#else
  #define debug_echo(expr)
#endif

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

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

template<class T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    bool isfirst = false;
    for (const T& e : v) {
        out << (isfirst ? ", " : "") << e;
        isfirst = true;
    }
    out << "]";
    return out;
}
template<class T>
ostream& operator <<(ostream& out, const set<T>& s) {
    out << "{";
    bool isfirst = false;
    for (const T& e : s) {
        out << (isfirst ? ", " : "") << e;
        isfirst = true;
    }
    out << "}";
    return out;
}
template<class A, class B>
ostream& operator <<(ostream& out, const pair<A, B>& p) {
    out << "(" << p.first << ", " << p.second << ")";
    return out;
}
template<class K, class V>
ostream& operator <<(ostream& out, const map<K, V>& s) {
    out << "{";
    bool isfirst = false;
    for (const auto& e : s) {
        out << (isfirst ? ", " : "") << e;
        isfirst = true;
    }
    out << "}";
    return out;
}

//
// Implementation
//

int N;
int M;
int a[100];

int main() {
    cin >> N >> M;
    rep(i, N) {
        cin >> a[i];
    }

    rep(ki, M) {
        int k = ki+1;
        rep(i, N-1) {
            if ((a[i] % k) > (a[i+1] % k)) {
                int tmp = a[i];
                a[i] = a[i+1];
                a[i+1] = tmp;
            }
        }
    }
    
    rep(i, N) {
        cout << a[i] << endl;
    }
}

Measured memory_bytes: 3092
#include<iostream>
#define _USE_MATH_DEFINES
#include <math.h>
#include<iomanip>
using namespace std;

int main()
{
	int a, b, h, m;
	cin >> a >> b >> h >> m;
	long double rad = M_PI * 2 * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);
	long double rsq = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(rad);
	cout << setprecision(12)<<sqrtl(rsq) << endl;
	return 0;
}

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

using namespace std;

#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main(void){

    string s;
    cin >> s;

    int ans = 0, cnt = 0;
    for(int i = 0; i < s.length(); ++i){
        if(s[i] == 'R'){
            cnt++;
        }else{
            ans = max(ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define EPS 0.000000001 //1e-9
#define pii pair<int,int>
using namespace std;
int32_t main()
{
    IOS;
    int n,s=0,p=1000000000+7;
    cin>>n;
    int a[n+1],b[n+1];
    cin>>a[1];
    b[1]=a[1];
    for(int i=2;i<=n;i++)
    {
        cin>>b[i];
        a[i]=a[i-1]+b[i];
    }
    for(int i=1;i<=n-1;i++)
    {
        s+=((((a[n]-a[i])%p)*b[i])%p);
        s=s%p;
    }
    cout << s << endl;
}

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

//{{{
/********************************************************************/
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

//vector<string> split(const string &s, char delim) {
//  vector<string> elems;
//  string item;
//  for (char ch: s) {
//    if (ch == delim) {
//      if (!item.empty()) elems.push_back(item);
//      item.clear();
//    }
//    else item += ch;
//  }
//  if (!item.empty()) elems.push_back(item);
//  return elems;
//}

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

/****************************************************************/
//}}}

signed main()
{
  int h = in(), w = in();
  string table[h];
  rep(i, h) cin >> table[i];
  rep(i, h) print(table[i] + "\n" + table[i]);

  return (0);
}

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

using namespace std;
typedef long long ll;

bool solve(string S){
    for(int i=0;i<3;i++){
        if(S[i] == S[i+1]) return true;
    }
    return false;
}

int main(){
    string S;
    cin >> S;
    if(solve(S)){
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }
}


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

using namespace std;

long long a, b, c, d;
long long k1,k2,k3,k4;

int main()
{
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    
    k1 = a * c;
    k2 = a * d;
    k3 = b * c;
    k4 = b * d;
    k1 = max(k1, k2);
    k3 = max(k3, k4);
    k1 = max(k1, k3);
    printf("%lld", k1);
    return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h> 
#define ll long long
#define F first
#define FF first.first
#define FS first.second
#define S second
#define pb push_back
using namespace std;
const ll N=1000006, INF=1e16;
 
ll n, q=1, m, a[N], b[N], f[N], o, k, t, x, y, z, u, h, mx, mn, ans, Ans;
pair<ll,ll> p[N];
string s;
vector<pair<pair<ll, ll>, ll> > v[N];
 
main(){ios_base::sync_with_stdio(false), cin.tie(0);
   	
//	cin>>q;
   	
   	while(q--){ans=o=0,u=100;
   		cin>>x>>y>>z;
   		ans=(x*z)/y-x*(z/y);
		z=((z+1)/y)*y-1;
		ans=max((x*z)/y-x*(z/y),ans);
		cout<<ans;
	}
	
}

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

int main(){

    int x;
    int sum=0,diffmax=0;
    for(int i=0;i<5;i++){
        cin>>x;
        diffmax=max(diffmax,(x+9)/10*10-x);
        sum+=(x+9)/10*10;
    }
    cout<<sum-diffmax<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;

string s;
int B, W, N;

signed main()
{
    cin >> s;
    N = s.size();
    for(int i = 0; i < N; i++){
        if(s[i] == 'B'){
            B++;
        }
        else {
            W++;
        }
    }
    if(B == 0 || W == 0){
        cout << 0 << endl;
        return 0;
    }
    int pos = 0, ans = 0;
    bool flag = false;
    for(int i = 0; i < N; i++){
        if(s[i] == 'B' && !flag){
            pos = i;
            flag = true;
        }
        if(s[i] == 'W' && flag){
            ans += i - pos;
            pos++;
        }
    }
    cout << ans << endl;

    return 0;
}

/*

*/


Measured memory_bytes: 640
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	string s;
	cin >> s;
	string ans = (s[2] == s[3] && s[4] == s[5]) ? "Yes" : "No";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
    long long n, c, e, mi = 10000000000000000;
    scanf("%lld %lld", &n, &c);
    vector<vector<long long>> d(c, vector<long long>(c)), f(3, vector<long long>(c, 0));
    for (int i = 0; i < c; ++i)
    {
        for (int j = 0; j < c; ++j)
        {
            scanf("%lld", &d[i][j]);
        }
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            long long l;
            scanf("%lld", &l);
            for (int k = 0; k < c; ++k)
            {
                f[(i + j) % 3][k] += d[l - 1][k];
            }
        }
    }
    
    
    for (int i = 0; i < c; ++i)
    {
        for (int j = 0; j < c; ++j)
        {
            for (int k = 0; k < c; ++k)
            {
                if (i == j || j == k || k == i)
                {
                    continue;
                }
                mi = min(mi, f[0][i] + f[1][j] + f[2][k]);
            }
        }
    }
    
    printf("%lld\n", mi);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), is_sorted(),


signed main(){
    FASTER;
    int k;cin>>k;
    int num=0;
    for(int i=1;i<=1e7;i++){
        num=(num*10+7)%k;
        if(num==0){
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
}



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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a.begin(), a.end());
    int b = a[(n-1)/2];
    long long ans = 0;
    for (int x: a) ans += abs(x - b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3976
n = int(input())
s = list(map(int,input().split()))
su = sum(s)
su2 = 0
ans = 100

for i in range(n):
    su2 += s[n-1-i] 
    su1 = su - su2
    k = abs(su1-su2)
    if k<ans:
        ans = k
        
print(ans)

Measured memory_bytes: 3060
import sys
readline = sys.stdin.readline

n = int(readline())
s = readline().rstrip()

from collections import deque
q = deque([])

for i in range(10):
    q.append(["",0,str(i)])

ans = 0
while q:
    num, ind, target = q.popleft()
    #print(num, ind, target)
    while ind < len(s):
        if s[ind] == target: #s[ind]が０から9の中のどれかを見てる
            break
        ind += 1
    else:
        continue
    num += target
    if len(num) == 3:
        ans += 1
        continue
    for i in range(10):
        q.append([num, ind +1, str(i)]) #出現した数字に関するキューを追加（例：一回目は024）

print(ans)

Measured memory_bytes: 9596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

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


int main(){
  int H, W;
  int a[26];
  cin >> H >> W;

  fill(a, a+26, 0);
  for(int i = 0; i < H*W; i++){
    char c;
    cin >> c;
    a[c - 'a']++;
  }
  int n4, n2, n1;
  if(H % 2 == 1 && W % 2 == 1){
    n4 = (H-1)/2*(W-1)/2;
    n2 = (H + W - 2) / 2;
    n1 = 1;
  }
  else if(H % 2 == 1 && W % 2 == 0){
    n4 = (H-1)/2*W/2;
    n2 = W/2;
    n1 = 0;
  }
  else if(H % 2 == 0 && W % 2 == 1){
    n4 = (W-1)/2*H/2;
    n2 = H/2;
    n1 = 0;
  }
  else{
    n4 = H*W/4;
    n2 = 0;
    n1 = 0;
  }

  int c4 = 0, c2 = 0, c1 = 0;
  for(int i = 0; i < 26; i++){
    c4 += a[i]/4;
    c2 += (a[i]%4)/2;
    c1 += a[i]%2;
  }

  if(c4 >= n4 && (c4-n4)*2+c2 == n2 && c1 == n1){
    cout << "Yes" << endl;
  }
  else  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,count=0,i;
    scanf("%d",&N);
    for(i=1; i<=N; i=i+1)
    {
        if((i>=1 && i<10) || (i>=10*10 && i<10*10*10) || (i>=10*10*10*10 && i<10*10*10*10*10))
        {
            count=count+1;
        }
    }
    printf("%d\n",count);

}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
	int w, h;
	while (true){
		cin >> h >> w;
		if (h == 0 && w == 0){
			break;
		}
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3068
#include <stdio.h>
int main(void){
    int c=0,n,t,i,j,k,a[100],f=1;
    scanf("%d",&n);
    for(i=0;i<n;i++){
    	scanf("%d",&a[i]);
    }
    while(f){
    	f=0;
    	for(i=n-1;i>=1;i--){
    		if(a[i]<a[i-1]){
    			t=a[i];
    			a[i]=a[i-1];
    			a[i-1]=t;
    			f=1;
    			c++;
    		}
    	}
    }
    for(i=0;i<n;i++){
    	if(i!=0) printf(" ");
    	printf("%d",a[i]);
    }
    printf("\n%d\n",c);
    
    return 0;
}


Measured memory_bytes: 2096
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws Exception {
try {
	BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
	String input = buf.readLine();
	
	String[] strAry = input.split(" ");
    double r = Double.parseDouble(strAry[0]);
    double x = r*r*Math.PI;
    double y = 2*r*Math.PI;

System.out.printf("%5f %5f", x, y);

} catch (Exception e) {

	System.out.println("????????????");
	
}
		 }
    }

Measured memory_bytes: 24844
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
inline int read() {
    char ch = getchar(); int x = 0;
    while(ch < '0' || ch > '9') ch = getchar();
    while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
    return x;
}

const int N = 2e5+5;
const int M = 4005;
const int mod = 1e9+7;

int n, m, a[N], b[N];
ll fac[N], inv[N];
struct Map {
    int val[M][M];
    int &operator ()(int x, int y) {
        return val[x+m][y+m];
    }
} dp;

ll quickpow(ll x, int k) {
    ll ret = 1;
    for(; k; k >>= 1, (x *= x) %= mod)
        if(k & 1) (ret *= x) %= mod;
    return ret;
}

void update(int &x, int y) {
    x += y;
    if(x >= mod) x -= mod;
    if(x < 0) x += mod;
}

int combine(int n, int m) {
    ll ret = fac[n];
    (ret *= inv[m]) %= mod;
    (ret *= inv[n-m]) %= mod;
    return ret;
}


int main() {
    n = 1e4;
    fac[0] = 1;
    for(int i = 1; i <= n; ++i) fac[i] = fac[i-1] * i % mod;
    inv[n] = quickpow(fac[n], mod-2);
    for(int i = n-1; ~i; --i) inv[i] = inv[i+1] * (i+1) % mod;

    n = read();
    for(int i = 1; i <= n; ++i) {
        a[i] = read(), b[i] = read();
        m = max(m, a[i]);
        m = max(m, b[i]);
    }

    for(int i = 1; i <= n; ++i) ++dp(-a[i], -b[i]);
    for(int i = -m; i <= m; ++i)
    for(int j = -m; j <= m; ++j)
        update(dp(i+1, j), dp(i, j)),
        update(dp(i, j+1), dp(i, j));

    int ans = 0;
    for(int i = 1; i <= n; ++i)
        update(ans, dp(a[i], b[i]));
    for(int i = 1; i <= n; ++i)
        update(ans, -combine(2*(a[i]+b[i]), a[i]+a[i]));
    ans = 1LL * ans * quickpow(2, mod-2) % mod;
    update(ans, mod);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 67200
package main

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

func main() {
	sc := NewScanner()
	N, T := sc.NextInt(), sc.NextInt()
	t := sc.NextIntArray()

	ans := 0
	for i := 0; i < N-1; i++ {
		d := t[i+1] - (t[i] + T)

		if d > 0 {
			ans += T
		} else {
			ans += T + d
		}
	}
	ans += T
	fmt.Println(ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 11776
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 2000;
int n, z, w;
int a[MAX_N];

int main() {
    fastio();

    cin >> n >> z >> w;
    forn(i, n) cin >> a[i];

    if (n == 1) {
        cout << abs(w - a[0]) << endl;
    } else {
        cout << max(abs(w - a[n - 1]), abs(a[n - 2] - a[n - 1])) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  3
//
//  Created by RISHAV SINGH MEHTA on 09/02/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define ll long long
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    ll int T,i,j,k,l,N,a,b,c;
    map<ll int, bool > mp;
    cin>>N;
    bool yyy=false;
    for (i=0; i<N; i++) {
        cin>>a;
        
        if (mp[a] == false) {
            mp[a] =true;
        }else{
            yyy=true;
        }
    }
    if (yyy == false) {
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	string s; cin >> s;
	rep(i,s.size()) {
		cout << 'x';
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=1e5+5;
int n;
struct data{
	int x,y,t;
	inline void read();
	friend bool reachable(const data &a,const data &b);
};

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	template <class T> inline T cabs(const T x){return x<0?-x:x;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

void data::read(){
	t=nxi(),x=nxi(),y=nxi();
}

bool reachable(const data &a,const data &b){
	assert(a.t<=b.t);
	int dis=cabs(a.x-b.x)+cabs(a.y-b.y);
	return dis<=b.t-a.t&&(dis&1)==((b.t-a.t)&1);
}

int main(){
	n=nxi();
	data a,b;
	a=(data){0,0,0};
	for(int i=1; i<=n; ++i){
		b.read();
		if(!reachable(a,b)){
			puts("No");
			return 0;
		}
		a=b;
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



int main(){
    
    int n,k;
    cin >> n >> k;
    vector<int> snack(n,0);
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int a;
            cin >> a;
            snack[a-1] = 1;
        }
    }
    int ans = 0;
    rep(i,n){
        if (snack[i] == 0) ans ++;
    }
    cout << ans;

}





Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp104 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Array.Sort(A);

            var A_ = A.Reverse().ToList();

            var len = new List<int>();

            for (int i = 0; i < N - 1; i++) {
                if (A_[i + 1] == A_[i]) {
                    len.Add(A_[i]);
                    i++;
                }

                if (len.Count() == 2) {
                    break;
                }
            }
            if (len.Count() != 2) {
                Console.WriteLine(0);
                return;
            }
            Console.WriteLine((long)len[0] * len[1]);

        }
    }
}


Measured memory_bytes: 21088
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{

    int N,K;
    cin>>N>>K;

    if(N%K==0){
        cout<<0<<endl;
    }else{
        cout<<1<<endl;
    }

    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define mp(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << '\n';
    return 0;
}

Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def SI(): return input()

N,A,B,C,D=LI()
st=input()

if C < D:
    if st[A:C].find('##') >= 0 or st[B:D].find('##') >= 0:
        print('No')
    else:
        print('Yes')
else:
    # Cの方がおおきいケース 入れ替わる
    if st.find('##', A-1, C) >= 0:
        print('No')
    else:
        fnd = st.find('...', B-2, D+1)
        if fnd >= 0:
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

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

	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		string t;
		t = to_string(i);

		if( (int)t.size() % 2 == 1 ) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
typedef long long LL;
const int N=1e5+5;

int n;
LL a[N],b[N],sa,sb,ans;

multiset<int> A,B;
LL tot;

int main(){
    scanf("%d",&n);
    FOR(i,1,n)scanf("%lld%lld",&a[i],&b[i]),sa+=a[i],sb+=b[i];
    ans=min(sa,sb);
    FOR(i,2,n)A.insert(a[i]),A.insert(b[i]),tot+=a[i],tot+=b[i];
    FOR(i,1,n){
        int cur=*A.rbegin();
        tot-=cur;
        A.erase(A.find(cur));
        B.insert(cur);
    }
    ans=min(a[1]+b[1]+tot,ans);
    FOR(i,2,n){
        int cur;
        B.insert(a[i-1]);
        B.insert(b[i-1]);
        cur=*B.begin(), B.erase(B.find(cur)),A.insert(cur),tot+=cur;
        cur=*B.begin(), B.erase(B.find(cur)),A.insert(cur),tot+=cur;
        cur=*A.rbegin(), A.erase(A.find(cur)),tot-=cur,B.insert(cur);
        cur=*A.rbegin(), A.erase(A.find(cur)),tot-=cur,B.insert(cur);
        if(A.find(a[i])!=A.end())tot-=a[i],A.erase(A.find(a[i])),cur=*B.begin(),B.erase(B.find(cur)),tot+=cur,A.insert(cur);
        else B.erase(B.find(a[i]));
        if(A.find(b[i])!=A.end())tot-=b[i],A.erase(A.find(b[i])),cur=*B.begin(),B.erase(B.find(cur)),tot+=cur,A.insert(cur);
        else B.erase(B.find(b[i]));
        ans=min(ans,a[i]+b[i]+tot);
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int cnt = 0;
    for(int i=1;i<=N;i++){
        int a;
        cin >> a;
        cnt += (i!=a);
    }
    cout << ((cnt==0 || cnt==2)? "YES":"NO") << endl;
}

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

typedef pair<int,int>pint;
typedef vector<int>vint;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

const int INF=1001001001;
int N;
int A[1000],B[1000];
int dp[1001][1001];

int main(){
    cin>>N;
    vector<pint>vec(N);
    rep(i,N)cin>>vec[i].second>>vec[i].first;
    sort(vec.begin(),vec.end());
    rep(i,N){
        A[i]=vec[i].second;
        B[i]=vec[i].first;
    }

    fill_n(*dp,1001*1001,INF);
    dp[0][0]=0;

    rep(i,N){
        rep(j,N){
            if(dp[i][j]==INF)continue;
            if(dp[i][j]+A[i]<=B[i])chmin(dp[i+1][j+1],dp[i][j]+A[i]);
            chmin(dp[i+1][j],dp[i][j]);
        }
    }

    cout<<lower_bound(dp[N],dp[N]+N+1,INF)-dp[N]-1<<endl;
    return 0;
}

Measured memory_bytes: 5124
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

bool compare(const P& lp, const P& rp){
    if(lp.second == rp.second){
        return lp.first > rp.first;
    }
    return lp.second < rp.second;
}

int main(){
    int N;
    std::cin >> N;

    std::vector<P> V;
    REP(i, N){
        int a, v;
        std::cin >> a >> v;
        V.push_back({a, v});
    }

    std::sort(V.rbegin(), V.rend(), compare);

    std::cout << V[0].first << " " << V[0].second << std::endl;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

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

    int count = 0;
    for (int i = 0; i < N; i++){
        x -= a[i];
        if (x < 0){
            break;
        }
        count++;
    }
    
    if (x > 0){
        count--;
    }
    
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#define int long long
#define SIZE 21
#define VALUE 50001
const int infty = 99999;
//#define _DEBUG
using namespace std;
int N, M, Cs[SIZE], T[SIZE][VALUE];
int solve(){
    for(int i=0; i<=M; i++){
        for(int n=0; n<=N; n++){
            if(n==0){
                T[i][n] = 0;
            }else if(i==0){
                T[i][n] = infty;
            }else if(n<Cs[i-1]){
                T[i][n] = T[i-1][n]; 
            }else{
                T[i][n] = min(T[i-1][n], min(T[i-1][n-Cs[i-1]], T[i][n-Cs[i-1]])+1);
            }
        }
    }
#ifdef _DEBUG
    for(int i=0; i<=M; i++){
        if(i>0)cout << Cs[i-1] << "\t";
        else cout << "i\\n\t";
        for(int n=0; n<=N; n++){
            cout << T[i][n] << "\t";
        }cout << endl;
    }
#endif
    return T[M][N];
}
signed main(){
    while(cin >> N >> M){
        for(int i=0; i<M; i++){
            cin >> Cs[i];
        }
        cout << solve() << endl;
    }
}


Measured memory_bytes: 7196
#include <iostream>
#include <deque>
#include <algorithm>

#define MOD 1000000007

using namespace std;

long long arr[100005] = { 0 }, m = 0;

long long calc(size_t n)
{

    for(size_t i = 0; i < n; i++)
        cin >> arr[i];

    n = n - 1;

    for(size_t i = n; i >= 1; i--)
        arr[i] = arr[i] - arr[i - 1];

    long long sum = 0;
    for(size_t i = 1; i <= n; i++) {
        long long acc = arr[i];
        acc = (acc * i) % MOD;
        acc = (acc * (n - i + 1)) % MOD;
        sum = (sum + acc) % MOD;
    }

    return sum;
}

int main()
{
    size_t n = 0, m = 0;

    cin >> n >> m;

    printf("%lld", (calc(n) * calc(m)) % MOD);
}


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

#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

class Modulo{
public:
    ll val;
    static const ll mod = 1e9+7;
    vector<ll> factable = {1};
    vector<ll> invtable = {1};
    ll pro(ll x,ll y){return ((x%mod)*(y%mod))%mod;}
    ll sum(ll x,ll y){return ((x%mod)+(y%mod))%mod;}
    ll dif(ll x,ll y){ll d =((x%mod)-(y%mod))%mod;if(d>=0){return d;}else{return d+mod;}}
    ll quo(ll x, ll y){return pro(x,pow(y,mod-2));}
    ll pow(ll x,ll y){
        if(y<=0){return 1;}
        if(y%2==0){ll d = pow(x,y/2);return ((d%mod)*(d%mod))%mod;}
        else{return (x*pow(x,y-1))%mod;}
    }
    void operator=(ll n){this->val = n%mod;}
    ll operator+(ll n){return sum(this->val,n);}
    ll operator-(ll n){return dif(this->val,n);}
    ll operator*(ll n){return pro(this->val,n);}
    ll operator/(ll n){return quo(this->val,n);}
    void operator+=(ll n){this->val = sum(this->val,n);}
    void operator-=(ll n){this->val = dif(this->val,n);}
    void operator*=(ll n){this->val = pro(this->val,n);}
    void operator/=(ll n){this->val = quo(this->val,n);}
    ll fac(ll x){
        //x! mod mod
        if(factable.size()<=x){
            ll s = factable.size();
            FOR(i,s,x+1){
                factable.push_back(pro(i,factable.back()));
                invtable.push_back(quo(1,factable.back()));
            }
        }
        if(x<0) return 1;
        else return factable[x];
    }
    ll facinv(ll x){
        if(invtable.size()<=x){
            ll s = invtable.size();
            FOR(i,s,x+1){
                factable.push_back(pro(i,factable.back()));
                invtable.push_back(quo(1,factable.back()));
            }
        }
        if(x<0) return 1;
        else return invtable[x];
    }
    ll com(ll x,ll y){
        //xCy mod mod = x!/((x-y)!*y!) mod mod
        if(x-y<y)return com(x,x-y);
        return pro(fac(x),pro(facinv(x-y),facinv(y)));
    }
};
ll h,w,a,b;
int main(){
    cin >> h >> w >> a >> b;
    Modulo m;
    m.val = 0;
    REP(i,h-a){
        //put(m.com(h-a+b+i-2,b-1));
        //put(b+i-1);
        //put(b-1);
        //put(m.com(w-b+h-i-2,w-b-1));
        m+=m.pro(m.com(b+i-1,b-1),m.com(w-b+h-i-2,w-b-1));
    }
    put(m.val);
}


Measured memory_bytes: 3564