akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
string s;
int w;
int main(void){
    cin>>s>>w;
    for(int i=0;i<s.size();i=i+w){
        cout<<s[i];
    }
    cout<<endl;
    
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define mit(a,b) map<a,b>::iterator
#define sit(a) set<a>::iterator
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define printf __mingw_printf
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
const ll oo=(1ll<<60);
const ll mx=1e5+5;
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
ll abs(ll a,ll b)
{
    if(a<b)return b-a;
    return a-b;
}
ll v[mx],n,dp[mx],i,j,k;
int main()
{
     io;
    //string hudai(1000000,'a');
    int T=1;
    //T=gi();
     for(int cas=1;cas<=T;cas++)
    {
        n=gi();
        for(i=1;i<=n;i++)
        {
            v[i]=gi();
        }
        dp[n]=0,dp[n-1]=abs(v[n],v[n-1]),dp[n-2]=abs(v[n],v[n-2]);
        for(i=n-3;i>0;i--)
            dp[i]=min(dp[i+1]+abs(v[i],v[i+1]),dp[i+2]+abs(v[i],v[i+2]));
        cout<<dp[1];
    }
    return 0;
}


Measured memory_bytes: 5144
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>

#define for0(i, N)    for (ll i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (ll i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (ll i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (ll i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (ll i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (ll i = (x), a = 0; a < (N);   \
                              i = (i + 1) % (N), ++a)
#define int long long

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, int){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


signed main(void){
    cin.tie(0); ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);
    int n, r;
    cin >> n >> r;

    if (n >= 10) {
        cout << r;
    } else {
        cout << r+100 * (10 - n);
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<pii> v;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        v.emplace_back(b,a);
    }
    sort(v.begin(), v.end());
    rep(i,m)swap(v[i].first, v[i].second);
    int now = -1;
    int ans = 0;
    rep(i,m){
        if(v[i].first >= now){
            now = v[i].second;
            ans++;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

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

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

int dp[111111];

int main(){
	
	int n,k;cin >> n >> k;
	vector<int> v(n);
	REP(i,n)cin >> v[i];
	
	for(int i = 1;i <= k;i++){
		bool flag = false;
		REP(j,n){
			if(i - v[j] >= 0){
				if(dp[i - v[j]] == 0)flag = true;
			}
		}
		if(flag)dp[i] = 1;
	}
	
	if(dp[k]){
		cout << "First" << endl;
	}
	else {
		cout << "Second" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 640
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld long double
#define   pb push_back
#define  sz(x)  (int)x.size()
#define  ff first
#define  ss second
#define  pii  pair<int,int>
using namespace std;

inline void solve(){ 
    int s,k,ans=0; cin>>k>>s; 
    for (int i=0;i<=k ;i++) { 
        for (int j=0;j<=k;j++){ 
            int ss= s-i-j; 
            if (ss>=0 and ss<=k) ans++; 
        } 
    } 
    cout << (ans) << endl; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
    ll a=read(),b=read(),c=read(),k=readll();
    if (k&1) cout << b-a;
    else cout << a-b;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 50

int main (void){

    int i, j, tmp;
    float ans;
    int n;
    int v[N];

    if( scanf("%d",&n)==1);
    for (i = 0; i < n;i++) if(scanf("%d",&v[i])==1);

    
    for (i = 0; i < n; i++)
        for (j = i; j <n ; j++){
            if (v[i] > v[j]){
                tmp = v[i];
                v[i] = v[j];
                v[j] = tmp;
            }
        }

    ans = v[0];
    for (i = 1; i < n;i++){
        ans += v[i];
        ans /= 2;
    }

    printf("%f", ans);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 1e5+5;
vector<pii> adj[N];
bitset<N> ans;

void dfs(int u, int p, int d) {
  ans[u] = d;
  for (pii e : adj[u]) {
    int v = e.ff;
    int l = e.ss;
    if (v == p) continue;
    dfs(v, u, d^l);
  }
}

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n; cin >> n;
  for (int i = 0; i < n-1; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    w &= 1;
    u--,v--;
    adj[u].emplace_back(v, w);
    adj[v].emplace_back(u, w);
  }
  dfs(0, -1, 0);
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << nl;
  }
  return 0;
}



Measured memory_bytes: 8064
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

vector<int> a(0);
int n,k;

bool jud(int x){
    if(x==0) return false;
    int cnt=0;
    rep(i,n){
        if(a[i]<=x) continue;
        if(a[i]%x==0) cnt +=a[i]/x-1;
        else cnt +=a[i]/x;
        if(k<cnt) break;
    }
    return (k>=cnt);
}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    cin>>n>>k;
    a.resize(n);
        rep(i,n) cin>>a.at(i);
    int mini=0,maxi=1000000000;
    int half=maxi/2;
    while(maxi-mini>1){
        if(jud(half)){
            maxi=half;
        }
        else{
            mini=half;
        }
        half=(maxi+mini)/2;
    }
    if(jud(mini)) cout<<mini<<endl;
    else cout<<maxi<<endl;
}/*
./problem.exe
*/

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

typedef long long ll;

int N;
vector<int> G[50010];
int sub[50010];
ll F[50010] = {1};
ll R[50010];
ll mod = 1000000007;
ll dp[5010][5010];

int sub_size(int v,int p)
{
    int res = 1;
    for(int i = 0; i < G[v].size(); i++)if(p != G[v][i])res += sub_size(G[v][i],v);
    return sub[v] = res;
}

ll con(int a,int b)
{
    return F[a] * R[a - b] % mod * R[b] % mod;
}

ll pow_mod(ll a,ll b)
{
    if(b == 0)return 1;
    ll res = pow_mod(a * a % mod, b / 2);
    if(b & 1)res = res * a % mod;
    return res;
}

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N - 1; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for(int i = 1; i < 50010; i++)F[i] = F[i - 1] * i % mod;
    for(int i = 0; i < 50010; i++)R[i] = pow_mod(F[i],mod - 2);

    for(int i = 1; i <= N; i++)
    {
        for(int j = 0; j < G[i].size(); j++)
        {
            if(sub_size(i,G[i][j]) == sub_size(G[i][j],i))
            {
                printf("%lld\n",F[N / 2] * F[N / 2] % mod);
                return 0;
            }
        }
    }

    int c = 0,MIN = 1001001001;
    for(int i = 1; i <= N; i++)
    {
        int MAX = 0;
        for(int j = 0; j < G[i].size(); j++)MAX = max(MAX,sub_size(G[i][j],i));
        if(MIN > MAX)
        {
            c = i;
            MIN = MAX;
        }
    }

    dp[0][0] = 1;
    for(int i = 0; i < G[c].size(); i++)
    {
        for(int j = 0; j <= N; j++)
        {
            int m = sub_size(G[c][i],c);
            for(int k = 0; k <= m; k++)
            {
                if(j + k > N)continue;
                dp[i + 1][j + k] += dp[i][j] * con(m,k) % mod * con(m,k) % mod * F[k] % mod;
                dp[i + 1][j + k] %= mod;
            }
        }
    }

    ll ans = 0;
    for(int i = 0; i <= N; i++)
    {
        ll tmp = dp[G[c].size()][i] * F[N - i] % mod;
        if(i % 2)ans -= tmp;
        else ans += tmp;
        ans = (ans + mod) % mod;
    }

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 198400
import java.util.*

enum class Directions(val dir: Pair<Int,Int>) {
    Up(-1 to 0),
    Down(1 to 0),
    Left(0 to -1),
    Right(0 to 1),
}

fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map{ it.toInt() }
    val s = Array(h+2){""}

    var map = Array(h+2){ IntArray(w+2){-1} }

    fun mark(r:Int, c:Int): Int {
        val queue = ArrayDeque<Pair<Pair<Int,Int>, Int>>()
        queue.add((r to c) to 0)

        var max = 0
        while (queue.isNotEmpty()) {
            val q = queue.poll()
            val pos = q.first
            val d = q.second
            if (map[pos.first][pos.second] == -1) {
                max = Math.max(d, max)
                map[pos.first][pos.second] = d
                Directions.values().forEach {
                    val row = pos.first + it.dir.first
                    val col = pos.second + it.dir.second
                    if (s[row][col] != '#' && map[row][col] == -1) {
                        queue.add((row to col) to d + 1)
                    }
                }
            }
        }
        return max
    }

    s[0] = Array(w+2) {'#'}.joinToString("")
    repeat(h) {
        s[it+1] = "#" + readLine()!! + "#"
    }
    s[h+1] = Array(w+2) {'#'}.joinToString("")

    var max = 0
    repeat(h) {r ->
        repeat(w) {c ->
            if (s[r+1][c+1] != '#') {
                map = Array(h + 2) { IntArray(w + 2) { -1 } }
                val ret = mark(r + 1, c + 1)
                max = Math.max(max, ret)
            }
        }
    }
    println(max)
}


Measured memory_bytes: 42460
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
#include <algorithm>
using namespace std;

void trace(int* intArray, int arraySize){
	cout << intArray[0];
	for (int i = 1; i < arraySize; ++i){
		cout << " " << intArray[i];
	}
	cout << "\n";
}

int main(){
	int n;
	cin >> n;
	int *a = new int[n];

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

	int v, j;
	trace(a, n);
	for (int i=1; i<n; ++i){
		v = a[i];
		j = i - 1;
		while ((j >= 0) && (a[j] > v)){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
		trace(a, n);
	}

	return 0;
}



Measured memory_bytes: 3076
import sys
import os
import math
import string
import collections

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A = il()
    print('bust' if sum(A) > 21 else 'win')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3896
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>
#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.bigin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>

using namespace std;

int sum_digit(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int digit(int n){
    while( n >= 10 ) n = sum_digit(n);
    return n;
}


int gcd(int x, int y){
    return x % y == 0 ? y : gcd(y, x % y);
}

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

bool prime_judge(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;
    double sqrtN = sqrt(n);
    for (int i = 3; i <= sqrtN; i += 2) if (n % i == 0) return false;
    return true;
}

int binary_search(vi a,int key){
    int n = a.size();
    int left = 0, right = n;
    while(left < right){
        int mid = (left + right) / 2;
        if(a[mid] == key) return mid;
        else if(a[mid] > key) right = mid;
        else left = mid + 1;
    }
    return -1;
}

vi ITV(int bit, int n){
   vi S;
   Srep(n){
       if(bit & (1<<i)){
           S.push_back(i);
       }
   }
   return S;
}

int main(){
	int a,b,ans;
	cin>>a>>b;

	if(a>=13){
		ans=b;
	}else if(a>=6 && a<=12){
    	ans=b/2;
    }else if(a<=5){
    	ans=0;
    }
  	cout<<ans<<endl;
}

Measured memory_bytes: 3696
import sys
N,A,B,C,D=map(int,input().split())
S=str(input())
stone=[]
A=A-1
B=B-1
C=C-1
D=D-1
#2つ連続があるか
double=[]
for i in range(0,N-1):
    if(S[i]=='#' and S[i+1]=='#'):
        double.append(i)
#２つ連続判定
for i in range(0,len(double)):
    if(A<double[i] and double[i]<C):
        print("No")
        sys.exit()
    elif(B<double[i] and double[i]<D):
        print("No")
        sys.exit()

#追い越しがいらないならこれでもうOK
if((B-A)*(D-C)>0):
    print("Yes")
    sys.exit()

#追い越しがいるのならB-Dの範囲を中心とした連続した3ますの空白が必要
tri=False
for i in range(B,D+1):
    if(S[i-1]=='.' and S[i]=='.' and S[i+1]=='.'):
        tri=True

if(tri):
    print("Yes")
    sys.exit()
else:
    print("No")
    sys.exit()

Measured memory_bytes: 3516
#include <iostream>

int main (void) {
	std::string S;
	std::getline(std::cin, S);
	
	int cnt_f = 0, cnt_b = 0;
	char prev = S[0] == '0' ? '1' : '0';
	for (char c : S) {
		if (c == prev) {
			prev = c == '0' ? '1' : '0';
			++cnt_f;
		} else {
			prev = c;
		}
	}
	
	prev = S[S.size() - 1] == '0' ? '1' : '0';
	for (int i = S.size() - 1; i >= 0; --i) {
		char c = S[i];
		
		if (c == prev) {
			prev = c == '0' ? '1' : '0';
			++cnt_b;
		} else {
			prev = c;
		}
	}
	
	int cnt = cnt_f > cnt_b ? cnt_b : cnt_f;
	
	std::cout << cnt << std::endl;
	
	return 0;
}

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

int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;

  for(int i = 0; flag; i++) {
    flag = 0;

    for(int j = N - 1; j > i; j--) {
      if (A[j - 1] > A[j]) {
        swap(A[j - 1], A[j]);
        flag = 1;
        sw++;
      }
    }
  }

  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;

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

  sw = bubbleSort(A, N);

  for(int i = 0; i < N; i++) {
    if (i) cout << " ";
    cout << A[i];
  }

  cout << endl;
  cout << sw << endl;

  return 0;
}


Measured memory_bytes: 3084
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N = in_n()
    A = in_nl()

    ans = []
    if abs(min(A)) < abs(max(A)):
        ma = max(A)
        ind = A.index(ma)
        for i in range(N):
            if i != ind:
                ans.append((ind + 1, i + 1))
                A[i] += A[ind]
    else:
        ma = min(A)
        ind = A.index(ma)
        for i in range(N):
            if i != ind:
                ans.append((ind + 1, i + 1))
                A[i] += A[ind]

    if min(A) >= 0:
        for i in range(N - 1):
            if A[i] > A[i + 1]:
                max_a = max(A)
                ind = A.index(max_a)
                A[i + 1] += max_a
                ans.append((ind + 1, i + 2))
    else:
        for i in range(N - 1, 0, -1):
            if A[i - 1] > A[i]:
                min_a = min(A)
                ind = A.index(min_a)
                A[i - 1] += min_a
                ans.append((ind + 1, i))

    print(len(ans))
    for x, y in ans:
        print(x, y)

    # print(A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63952
#include <bits/stdc++.h>                                                                              
using namespace std;                                                                                  
using ll = long long;                                                                                 
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }               
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }               
                                                                                                      
int main() {                                                                                          
  int n;                                                                                              
  int r;                                                                                              
  cin >> n >> r;                                                                                      
  if (n < 10) {                                                                                       
    cout << r + 100 * (10 - n) << endl;                                                               
  } else {                                                                                            
    cout << r << endl;                                                                                
  }                                                                                                   
  return 0;                                                                                           
}  

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  string s;
  cin >> s;
  cout << s.substr(0,3) << endl;



  return 0;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int r = scanner.nextInt();
    int d = scanner.nextInt();
    int x = scanner.nextInt();
    
    for (int i = 0; i < 10; i++) {
      x = x * r - d;
      System.out.println(x + "\n");
    }
  }
}

Measured memory_bytes: 21332
n,k = map(int,input().split())
ans = 0
cnt = 0
for i in range(1,n+1):
  if i >= k:
    ans += 1/n
  else:
    cnt = 0
    while i < k:
      i *= 2
      cnt += 1
    ans += 1/n*(1/2)**cnt
print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b; cin >> a >> b;
    if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    
    
    
    
    
}



Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

template <typename T>
bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;}

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,w;
    cin>>n>>w;
    vector<int> v(n),h(n);
    rep(i,n) cin>>v[i]>>h[i];
    vector<vector<int>> dp(n+1,vector<int>(w+1,-1));//dp[i][j]i made,omosa j no kati
    dp[0][0]=0;
    REP(i,1,n+1){
        rep(j,w+1){
            chmax(dp[i][j],dp[i-1][j]);
            if(j-h[i-1]>=0) chmax(dp[i][j],dp[i][j-h[i-1]]+v[i-1]);
        }
    }
    int ans=-1;
    for(int i=w;i>=0;i--) chmax(ans,dp[n][i]);
    cout<<ans<<endl;
}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a+b>c+d){
    cout << "Left" << endl;
  }
  else if (a+b==c+d){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

int main(){
  double x1, y1, x2, y2, out;
  cin >> x1 >> y1 >> x2 >> y2;
  out = sqrt(pow(x2-x1, 2.0)+pow(y2-y1, 2.0));
  cout << fixed << setprecision(10) << out << endl;
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n,d; cin >> n >> d;
	vvi x(n,vi(d));
	rep(i,n)rep(j,d) cin >> x[i][j];
	int ans = 0;
	rep(i,n)rep2(j,i+1,n){
		int r2=0;
		rep(k,d) r2 += (x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
		int r = sqrt(r2);
		if(r*r==r2) ans++;
		}
		cout << ans << endl;
}




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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll h, w;
  cin >> h >> w;
  char a[h][w];
  for(i = 0; i < h; i++)
    for(j = 0; j < w; j++)
      cin >> a[i][j];
  vector<ll> judgeh(h), judgew(w); 
  ll counth = h, countw = w;
  for(i = 0; i < h; i++)
    for(j = 0; j < w && a[i][j] == '.'; j++)
      if(j == w - 1){
        judgeh[i] = 1;
        counth--;
      }
  
  for(i = 0; i < w; i++)
    for(j = 0; j < h && a[j][i] == '.'; j++)
      if(j == h - 1){
        judgew[i] = 1;
        countw--;
      }
  
  //cout << counth spa countw << endl;
  for(i = 0; i < h; i++)
    if(judgeh[i] == 0){
    for(j = 0; j < w; j++)
      if(judgew[j] == 0)
      cout << a[i][j];
    cout << endl;
    }
  
        
        

  return 0;
}

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

int main(){
	long long a, b, c, sum = 0;
	cin >> a >> b >> c;
	if (b == c){
		sum = b + c;
	}
	if (b < c){
		sum = b + b + 1;
		c -= (b + 1);
		if(a){
			sum += min(a,c);
		}
	}
	else {
		sum = a + c;
	}
	cout << sum;
}



Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))

a,b = l()

print(max(a*b,a-b,a+b))

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    float total = 0;
    int counter = 0;
    int[] a = new int[n];
    
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
      total += a[i];
    }
    float p = total / (4 * m);
    
    for(int i = 0; i < n; i++){
      if(a[i] >= p){
        counter++;
      }
    }
    if(counter >= m){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
using namespace std;
typedef long long ll;

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

  map<pair<ll, ll>, ll> m;
  ll ans = 0;
  FOR(x, 1, K)
  {
    FOR(y, 1, K)
    {
      ll a, b;
      if (x < y)
        a = x, b = y;
      else
        a = y, b = x;

      ll d;
      if (m.count({a, b}))
      {
        d = m[{a, b}];
      }
      else
      {
        d = gcd(a, b);
        m[{a, b}] = d;
      }

      FOR(z, 1, K)
      {
        ll e, f;
        if (d < z)
          e = d, f = z;
        else
          e = z, f = d;

        if (m.count({e, f}))
        {
          ans += m[{e, f}];
        }
        else
        {
          ll g = gcd(e, f);
          m[{e, f}] = g;
          ans += g;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4868
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] ps = new int[N];
        for (int i = 0; i < N; i++) {
            ps[i] = sc.nextInt();
        }
        Arrays.sort(ps);
        int total = 0;
        for (int i = 0; i < K; i++) {
            total += ps[i];
        }
        System.out.println(total);
    }
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll A, B, V, W; cin >> A >> V >> B >> W;
    if (A == B) {
        cout << "YES\n";
        return 0;
    }
    if (W >= V) {
        cout << "NO\n";
        return 0;
    }
    ll dist = abs(A-B);
    ll vel = abs(V-W);
    ll T; cin >> T;
    if (dist <= T*vel) {
        cout << "YES\n";
    }
    else {
        cout << "NO\n";
    }
}


Measured memory_bytes: 3656
N = int(input())
s = []
for _ in range(N):
    s.append(input().strip())

ac = 0
wa = 0
tle = 0
re = 0

for c in s:
    if c == 'AC':
        ac += 1
    elif c == 'WA':
        wa += 1
    elif c == 'TLE':
        tle += 1
    elif c == 'RE':
        re += 1

print(f'AC x {ac}')
print(f'WA x {wa}')
print(f'TLE x {tle}')
print(f'RE x {re}')

Measured memory_bytes: 16312
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;
typedef long long ll;

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

  vector<int> queue(n);
  vector<string> label(n);

  rep(i, n) cin >> label[i] >> queue[i];

  int head = 0;
  int tail = n;
  int time = 0;

  while (head < tail) {
    // if queue[0] != 0; then run process
    // if (queue[head] < q) cout << label[head] << ' ' << time + queue[head] << endl;

    if (queue[head] - q > 0) {
      queue.push_back(queue[head] - q);
      label.push_back(label[head]);
      tail++;
      time += q;
    }
    else {
      time += queue[head];
      queue[head] = 0;
      cout << label[head] << ' ' << time << endl;
    }

    head++;
  }
}

Measured memory_bytes: 5524
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
const int N=100005;
const int mod=1e9+7;

int main()
{
    std::ios::sync_with_stdio(false);
    set<int > s;
    int a[3];
    for(int i=0;i<3;i++){
        cin>>a[i];
        s.insert(a[i]);
    }
    int t=s.size();
    cout<<t<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),m=sc.nextInt();
		ArrayList<Integer> array = new ArrayList<Integer>();
		for(int i=0;i<n;i++) array.add(sc.nextInt());
		Collections.sort(array);
		int[][] array2 = new int[m][2];
		for(int i=0;i<m;i++) {
			array2[i][1]=sc.nextInt();
			array2[i][0]=sc.nextInt();
		}
		sc.close();
		Arrays.sort(array2,(a,b)->Integer.compare(a[0],b[0]));
		int temp=0,now1=n-1,now2=m-1;
		long ans=0;
		while(temp<n) {
			if(now2<0 || array.get(now1)>array2[now2][0]) {
				ans+=array.get(now1);
				now1--;
			}else {
				ans+=array2[now2][0];
				array2[now2][1]--;
				if(array2[now2][1]==0)  now2--;
			}
			temp++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 100116
#include<stdio.h>
int main(){
    long long int x;
    scanf("%lld",&x);
    long long int ans;
    if(x%11==0||x%11==6){
        ans=x*2/11;;
    }else{
        ans=(x*2)/11+1;   
    }
    printf("%lld\n",ans);
    return 0;

}


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

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

class modint {
	static constexpr std::int_fast64_t Modulus = 1e9 + 7;
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const ll rhs) const noexcept {
		return modint(*this) *= modint(rhs);
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr operator u64() const { return a; }
};

int main() {
	ll n;
	cin >> n;
	vector<ll> as(n), bs(n), cs(n);
	rep(i, n) cin >> as[i];
	rep(i, n) cin >> bs[i];
	rep(i, n) cin >> cs[i];
	sort(as.begin(), as.end());
	sort(bs.begin(), bs.end());
	sort(cs.begin(), cs.end());
	vector<ll> ab(n);
	ll sum = 0;
	rep(i, n) {
		ll c = cs.end() - upper_bound(cs.begin(), cs.end(), bs[i]);
		ll a = lower_bound(as.begin(), as.end(),bs[i]) - as.begin();
		sum += c * a;
	}
	cout << sum << endl;
	return 0;
}


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

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

  int N, M; cin >> N >> M;
  vector<int> G[N];
  for (int i = 0; i < M; i++)
  {
    int u, v;
    cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
  }
  int S, T; cin >> S >> T;
  S--; T--;

  vector<vector<ll>> d(N, vector<ll>(3, 1e15));
  d[S][0] = 0;
  queue<pair<int, int>> q;
  q.push(make_pair(S, 0));

  while (!q.empty()){
    pair<int, int> p = q.front(); q.pop();
    int c = p.first;
    int step = p.second;
    for (int v : G[c]) {
      int newd = d[c][step] + 1;
      int newStep = (step + 1) % 3;

      if (newd < d[v][newStep]) {
        d[v][newStep] = newd;
        q.push(make_pair(v, newStep));
      }
    }
    if (d[T][0] < 1e15) break;
  }

  ll ans = -1;
  if (d[T][0] < 1e15) ans = d[T][0] / 3;
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 11136
def cycle_getter(N, start):
    """
    :param N: 移動回数
    :param start:　初期条件
    :return front: cycleまでの要素のリスト
            cycle: cycle内の要素のリスト
            end: cycle後の余った部分の要素のリスト
            cnt: cycle回数
    """
    p = start
    front, cycle, end = [], [], []
    cnt = 0
    visit = {p:0}
    L, R = N, -1
    for i in range(1,N):
        p = lift(p)
        if p in visit:
            """
            (L, R) = (サイクルに入るまでに移動した回数, サイクルの終端に着くまでに移動した回数)
            [6,2,3,4,0,1,2] ⇒ (L, R) = (1, 6)
            """
            L, R = visit[p], i
            period = R-L
            break
        visit[p] = i
    p = start
    for _ in range(L):
        front.append(p)
        p = lift(p)
    if L != N:
        for _ in range(L,R):
            cycle.append(p)
            p = lift(p)
        for _ in range(N-(N-L)%period,N):
            end.append(p)
            p = lift(p)
        cnt = (N-L)//period
    return front, cycle, end, cnt

def lift(x): return pow(x,2,M)

################################################################################
import sys
input = sys.stdin.readline

N, X, M = map(int, input().split())
front, cycle, end, cnt = cycle_getter(N,X)
print(sum(front)+sum(cycle)*cnt+sum(end))

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

using namespace std;
int main() {
    int n;
    int a[100001];
    int next = 1;
    int step = -1;

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

    for (int i = 0; i < n; i++) {
        next = a[next-1];

        if (next == 2) {
            step = i+1;
            break;
        }
    }
    cout << step << endl;;
    return 0;
}



Measured memory_bytes: 640
n, s = gets.chomp.split
n = n.to_i
arr = []
s.split("").each_with_index{|c, i| arr << i if c == "B"}

max = 0
if arr.length != 0
    arr2 = []
    prev = arr[0]
    temp = [prev]
    arr[1..-1].each{|x|
        if x == prev + 1
            temp << x
        else
            arr2 << temp
            temp = [x]
        end
        prev = x
    }
    arr2 << temp

    arr2.each{|ar|
        next if ar[0] == 0
        next if ar[-1] == n - 1
    
        dame = false
        (ar[0] - 2).downto(0){|i|
            case s[i]
            when "B"
                dame = true
                break
            when "."
                break
            end
        }
        next if dame
    
        dame = false
        (ar[-1] + 2).upto(n - 1){|i|
            case s[i]
            when "B"
                dame = true
                break
            when "."
                break
            end
        }
        next if dame
    
        next if s[ar[0] - 1] == "." && s[ar[-1] + 1] == "."
        next if s[ar[0] - 1] == "W" && s[ar[-1] + 1] == "W"
        max = ar[-1] - ar[0] + 1 if max < ar[-1] - ar[0] + 1
    }
end
puts max


Measured memory_bytes: 6888
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
//#include <bits/stdc++.h>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007


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

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(int a,int b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 

 
int main() {
    string N;
    cin >> N ;
    ll bc=0;
    ll ans=0;
    FOR(i,0,N.size()-1){
      if(N[i]=='B'){
        bc++;
      }else{
        ans=ans+bc;
      }
    }
    cout<<ans<<endl;

  return 0;
}





Measured memory_bytes: 640
from collections import deque
import sys
INF = 500000000000
sys.setrecursionlimit(2147483647)

def bfs(posit):
    y,x = posit
    n = [(y - 1, x), (y  + 1, x), (y, x - 1), (y, x + 1)]
    for ny, nx in n:
        if 0 <= ny < H and 0 <= nx < W and s[ny][nx] != "#":
            temp = dist[ny][nx]
            dist[ny][nx] = min(temp, dist[y][x] + 1)
            if temp != dist[ny][nx]:
                route.append((ny, nx))
            if (ny, nx) == (H - 1, W - 1):
                return
    if len(route) > 0:
        bfs(route.popleft())

H,W = [int(i) for i in input().split()]
s = []
route = deque()
black = 0
for i in range(H):
    po = list(input())
    black += po.count("#")
    s.append(po)
dist = [[INF for _ in range(W)] for _ in range(H)]
dist[0][0] = 0
bfs((0, 0))
if 0 < dist[H - 1][W - 1] < INF:
    print(H * W - black - dist[H - 1][W - 1] - 1)
else:
    print(-1)

Measured memory_bytes: 6636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;cin>>S;int sum=0;
  for(int X=0;X<S.size()/2-1;X++){
    string A=S.substr(0,X+1);
    string B=S.substr(X+1,X+1);
    if(A==B)sum=A.size()*2;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
string s,ss[3030],now,ans;
int dn=0;
void work(int l,int r)
{
	int p=0,ap=0,bp=0;
	dn++;
	ss[dn]="";
	if(s[l]=='a')
	{
		for(int i=l;i<=r;i++)
		{
			if(s[i]=='a')
			{
				ap++;
				if(p==0)
				{
					p=ap;
					ss[dn]+='a';
				}
			}
			else
			{
				bp++;
				if(p==bp)
				{
					p=0;
					ss[dn]+='b';
				}
			}
		}
	}
	else
	{
		for(int i=1;i<=(r-l+1)/2;i++)
		{
			now="";
			ap=bp=0;
			for(int j=l;j<=r;j++)
			{
				if(s[j]=='a')
				{
					ap++;
					if(ap>=i)
						now+='a';
				}
				else
				{
					bp++;
					if(bp>=i)
						now+='b';
				}
			}
			if(now>ss[dn])
				ss[dn]=now;
		}
	}
}
int main()
{
	int n,cnt=0,l=0;
	cin>>n;
	cin>>s;
	n<<=1;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='a')
			cnt++;
		else
			cnt--;
		if(cnt==0)
		{
			work(l,i);
			l=i+1;
		}
	}
	ans="";
	for(int i=dn;i>=1;i--)
		if(ss[i]+ans>ans)
			ans=ss[i]+ans;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<sstream>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<string>
#include<numeric>
#include<set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using vpii = vector<pii>;

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

  if(N % 2 == 0)
    cout << 0.5 << endl;
  else
    cout << (((double)(N+1)) / 2.0) / (double)N << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int a[210];
int main(void)
{
    cin>>n;
    int cnt=INT_MAX;
    int num=0;
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
        num=0;
        while(a[i]%2==0)
        {
            num++;
            a[i]/=2;
        }
        cnt=min(cnt,num);
    }
    cout <<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256