akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
  -- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Applicative
import           Debug.Trace


readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons


frac 0 = 1
frac n = n * frac (n-1)

-- dist :: (Integer,Integer) -> (Integer,Integer) -> Double
dist (x1,y1) (x2,y2) = sqrt $ fromInteger $ (x1 - x2)^2 + (y1 - y2)^2

test = [(0,0),(1,0),(0,1)]

allRoute xy =  permutations xy

-- sumDist :: ((Integer, Integer) -> (Integer, Integer) -> Double) -> [(Integer,Integer)] -> Double
sumDist f [x] = 0
sumDist f (xy1:xy2:xys) = (f xy1 xy2) + (sumDist f (xy2:xys))

solve n xy = (/ (toDouble $ frac n)) . sum $ map (sumDist dist) $ allRoute xy


main = do
  n <- readLn
  xys <- replicateM n $ (\vec -> (toInteger $ vec VU.! 0, toInteger $ vec VU.! 1)) <$> getIntVector
  let n' = toInteger n
  print $ solve n' xys

toDouble :: Integer -> Double
toDouble n = fromInteger n


Measured memory_bytes: 2172
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <climits>
#include <bitset>

using namespace std;
using ll = long long int;
const ll MOD = 1e9;

ll count(ll n) {
	ll ans = 0;
	ll beat = 1;

	for (ll i = n; i >= 1; i /= 2) {
		ans += beat;
		beat *= 2;
	}
	return ans;
}

int main()
{
	ll h;
	cin >> h;
	cout << count(h) << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Deque<String> deque = new ArrayDeque<>();
        while(sc.hasNext()){
            String data = sc.next();
            if(data.matches(".*[0-9].*"))
                deque.push(data);
            else{
                int num1 = Integer.parseInt(deque.pop());
                int num2 = Integer.parseInt(deque.pop());
                switch(data.charAt(0)){
                    case '+' : deque.push(String.valueOf(num2 + num1)); break;
                    case '-' : deque.push(String.valueOf(num2 - num1)); break;
                    case '*' : deque.push(String.valueOf(num2 * num1)); break;
                }
            }
        }
        System.out.println(Integer.parseInt(deque.pop()));
    }
}


Measured memory_bytes: 27100
s=input()
l1=len(s)
t=input()
l2=len(t)
arr=[[0]*(l2+1) for _ in range(l1+1)]
for i in range(l1):
  for j in range(l2):
    if s[i]==t[j]:
      arr[i+1][j+1]=1
for i in range(1,l1+1):
  for j in range(1,l2+1):
    if arr[i][j]==1:
      arr[i][j]+=arr[i-1][j-1]
    else:
      arr[i][j]=max(arr[i-1][j],arr[i][j-1])
check=arr[l1][l2]
pos=0
ans=''
for i in range(l1,-1,-1):
  for j in range(l2-pos,-1,-1):
    if j==0:
      continue
    if arr[i][j]==check and arr[i][j-1]==check-1 and arr[i-1][j]==check-1:
      ans+=t[j-1]
      pos=l2-j+1
      check-=1
      break
print(ans[::-1])

Measured memory_bytes: 113756
# https://atcoder.jp/contests/abc052/tasks/abc052_b
n = int(input())
s = input()

ans = 0
x = 0
for i in range(n):
    if s[i] == 'I':
        x += 1
    elif s[i] == 'D':
        x -= 1
    ans = max(ans, x)
print(ans)

Measured memory_bytes: 38384
N, M = map(int,input().split())
H = list(map(int,input().split()))
pairs = [list(map(int,input().split())) for i in range(M)]

connection = {}
for pair in pairs:
    if not pair[0] in connection:
        connection[pair[0]] = set()
    if not pair[1] in connection:
        connection[pair[1]] = set()
    connection[pair[0]].add(pair[1])
    connection[pair[1]].add(pair[0])

#print(connection)

ans = 0
for i, h in enumerate(H):
    candidates = []
    for c in list(connection.get(i+1,set())):
        candidates.append(H[c-1])
    #print(i, h, candidates)
    if len(candidates) == 0 or h > max(candidates):
        ans += 1
print(ans)

Measured memory_bytes: 57020
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var a = Number(lines[0].split(' ')[0]);
 var v = Number(lines[0].split(' ')[1]);
 var b = Number(lines[1].split(' ')[0]);
 var w = Number(lines[1].split(' ')[1]);
 var t = Number(lines[2]);

 var ichisa = a - b;
 var hayasa = v - w;
 var ans = '';
 
 if(hayasa <= 0){
   ans = 'NO';
 }else{
   if(Math.abs(ichisa) / hayasa <= t){
     ans = "YES";
   }else{
     ans = "NO";
   }   
 }

 console.log(ans);

});

Measured memory_bytes: 30496
#include <bits/stdc++.h>
#include "atcoder/all"
using namespace std;
using namespace atcoder;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
const long long int sMod = 998244353;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll pow(ll x,ll y,ll mod){
    if(y==0) return 1;
    if(y&1) return x*pow(x,y-1,mod)%mod;
    ll p=pow(x,y/2,mod);
    return p*p%mod;
}

using mint=modint998244353;

vector<mint> ones(300000);


struct S{
    mint num;
    ll size;
};

S op(S a,S b){
    return S{a.num*(mint)pow(10,b.size,sMod)+b.num,a.size+b.size};
}

S e(){
    return S{0,0};
}

using F = ll;

S mapping(F d,S x){
    if(d==0) return x;
    mint nxt=d;
    nxt*=ones[x.size-1];
    return S{nxt,x.size};
}

F composition(F f,F g){
    if(f==0) return g;
    else return f;
}

F id(){
    return 0;
}

void solve(){
    mint m=1;
    rp(i,290000){
        ones[i]=m;
        m*=10;
        m+=1;
    }
    ll n,q;
    cin >> n >> q;
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(n);
    rp(i,n){
        seg.set(i,S{1,1});
    }
    rp(i,q){
        ll l,r,d;
        cin >> l >> r >> d;
        seg.apply(l-1,r,d);
        print(seg.all_prod().num.val());
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 17736
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
  ll N,A,B;
  cin >> N >> A >> B;
  cout << min(A,B) << ' ' << max(A + B - N,0LL) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  lint N,A,B;
  cin>>N>>A>>B;
  lint h[N];
  REP(i,N)cin>>h[i];
  sort(h,h+N);
  if(A==B){
    cout<<(h[N-1]+B-1)/B<<endl;
    return 0;
  }
  int NG=0,OK=1e9+1;
  while(OK-NG>1){
    lint c=(OK+NG)/2;
    lint temp=0;
    REP(i,N){
      temp+=(max(0LL,h[i]-B*c)+(A-B)-1)/(A-B);
    }
    if(temp>c)NG=c;
    else OK=c;
  }
  cout<<OK<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

ll a[100010][3];
ll dp[100010][3];

int main() {
    int N;
    cin >> N;
    rep(i, N) {
        rep(j, 3) { cin >> a[i][j]; }
    }
    rep(i, N) {
        rep(j, 3) {
            rep(k, 3) {
                if (j == k)
                    continue;
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    ll res = 0;
    rep(j, 3) { res = max(res, dp[N][j]); }
    cout << res << endl;
}

Measured memory_bytes: 4992
import sys
readline = sys.stdin.buffer.readline

N = int(readline())
XY = []
for _ in range(N):
    XY.append(list(map(int, readline().split())))

import math
def dist(coord1, coord2):
    return math.sqrt((coord1[0] - coord2[0]) ** 2 + (coord1[1] - coord2[1]) ** 2)

from itertools import permutations

sum = 0
count = 0
for p in permutations(XY):
    for i in range(N-1):
        sum += dist(p[i], p[i+1])

    count += 1

print(sum / count)


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

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

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))
#define INF (1<<28)
#define pb push_back
#define fs first
#define sc second

const char dx[]={0,1,0,-1},dy[]={1,0,-1,0};
template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", " ;
	return out << "}" << endl;
}
template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}
int main(){
	int k,t;
	cin >> k >> t;
	vi a(t);
	int ma = 0,sum = 0;
	rep(i,t){
		cin >> a[i];
		ma = max(a[i],ma);
		sum += a[i];
	}
	sum -= ma;
	if(sum >= ma -1) cout << 0 << endl;
	else cout << (ma-1-sum) << endl;
	

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    string s;
    ll k;
    cin>>s>>k;
    ll cnt=  0;
    string ss = s;

    rep(i,s.size()) {
        if(s[cnt]==s[i]) continue;
        else {
            cnt = -1;
            break;
        }
    }
    if(cnt==0){
        cout<<s.size()*k/2<<endl;
        return 0;
    }
    cnt = 0;
    rep(i,s.size()-1) if(s[i]==s[i+1]) {
        ll p = 2;
        ll j = i+2;
        while(s[i]==s[j] and j < s.size()) {
            j++;
            p++;
        }
        i=j-1;
        cnt += p/2;
    }
    ll a = cnt;
    cnt = 0;
    s = s+s;
    rep(i,s.size()-1) if(s[i]==s[i+1]) {
        ll p = 2;
        ll j = i+2;
        while(s[i]==s[j] and j < s.size()) {
            j++;
            p++;
        }
        i = j-1;
        cnt += p/2;
    }
    // cout<<cnt<<endl;
    // cout<<a<<" "<<cnt<<endl;
    if(s.size()==1) cout<<k/2<<endl;
    else if(k==1) cout<<a<<endl;
    else cout<<(ll)a+(ll)(cnt-a)*(k-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
n, m  = gets.strip.split.map(&:to_i)
as = gets.strip.split.map(&:to_i)

candidates = [2,5,5,4,5,6,3,7,6].map.with_index {|e, i| [e, i+1] }.select {|e, i| as.include?(i) }.to_h

dp = Array.new(n+1)

(n+1).times do |i|
  tmp = candidates[i].to_i.to_s
  candidates.each do |cost, num|
    next if i-cost<0 || dp[i-cost].to_i.zero?

    exists = dp[i-cost]

    c_num = tmp > num.to_s ? exists + num.to_s : num.to_s + exists
    tmp = c_num if c_num.length > tmp.length || (c_num.length== tmp.length && c_num > tmp )
  end
  dp[i] = tmp
end

#p dp
p dp[n].to_i



Measured memory_bytes: 52348
import bisect

def main():
    n = int(input())
    L = list(map(int,input().split()))
    L = sorted(L)
    ans = 0
    for i in range(2,n):
        for j in range(1,i):
            left = bisect.bisect_left(L,L[i]-L[j]+1)
            if j-left > 0:
                ans += j-left
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
  int v, e;
  cin >> v >> e;
  vector<int> g[v];
  vector<int> h(v);
  rep(i,e){
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    h[b]++;
  }
  queue<int> que;
  rep(i,v) if(h[i] == 0) que.push(i);
  vector<int> ans;
  while(!que.empty()) {
    int p = que.front(); que.pop();
    ans.push_back(p);
    for(auto i : g[p]) {
      h[i]--;
      if(h[i] == 0) que.push(i);
    }
  }
  cout << (ans.size() == v ? 0 : 1) << endl;
  return 0;
}


Measured memory_bytes: 3160
def main():
    N, K = map(int, input().split())
    R, S, P = map(int, input().split())
    T = input()

    ans = 0
    U = []
    for i, t in enumerate(T):
        if t == 'r':
            if i-K >= 0:
                if U[i-K] == 'p':
                    U.append('rs')
                    continue
            U.append('p')
            ans += P
        elif t == 's':
            if i-K >= 0:
                if U[i-K] == 'r':
                    U.append('sp')
                    continue
            U.append('r')
            ans += R
        else:
            if i-K >= 0:
                if U[i-K] == 's':
                    U.append('rp')
                    continue
            U.append('s')
            ans += S
    print(ans)

if __name__ == "__main__":
    main()


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}

VI np;
VL v;

pair<VL, VL> fnc(int p){
	int n=np[p];
	VL zsm(55), zct(55);
	VI gt ={ 0, np[0], np[0]+np[1]};
	rep(i, 1<<n){
		int ct = __builtin_popcount(i);
		ll sm = 0;
		rep(j, n) if(i>>j & 1){
			sm += v[gt[p] + j];
		}
		if(zsm[ct] < sm){ zsm[ct] = sm; zct[ct] = 1;}
		else if(zsm[ct] == sm) zct[ct]++;
	}
	return make_pair(zsm, zct);
}



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, a, b;
	cin >>n >>a >>b;
	v.resize(n);
	rep(i, n) cin >>v[i];
	
	np = {n/3 , n/3 ,n/3}; np[2]= n-np[0]-np[1];
	//for(auto x :np) cerr<<x<<" "; dbg("");
	vector<VL> zsm(3), zct(3);
	rep(i, 3){
		tie(zsm[i], zct[i]) = fnc(i);
	}
	VL qsm(55), qct(55);
	rep(i, np[0]+1) rep(j, np[1]+1) rep(k, np[2]+1){
		int zz = i+j+k;
		if( zz >=a && zz <=b ){
			ll psm = zsm[0][i] +zsm[1][j] +zsm[2][k];
			ll pct = zct[0][i] *zct[1][j] *zct[2][k];
			
			if(qsm[zz] < psm && pct > 0){
				qsm[zz] = psm; qct[zz] = pct;
			}else if(qsm[zz] == psm) qct[zz] += pct;
		}
	}
	double mx=0; int svi=-1;
	rep2(i, a, b+1) if(mx < (double)qsm[i] / i){
		mx = (double)qsm[i] / i; svi =i;
	}
	ll ans = 0;
	rep2(i, a, b+1){
		if(qsm[svi] * i == qsm[i] * svi) ans += qct[i];
	}
	printf("%.12f\n%lld\n", mx, ans);

	return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> B(N-1);
  for(int i = 0; i < N - 1; ++i)
  {
    cin >> B[i];
  }
  
  vector<int> A(N);
  int temp = 0;
  for(int i = 0; i < N - 1; ++i)
  {
    if(i == 0)
    {
      A[i] = B[i];
      continue;
    }
    else
    {
      A[i] = B[i-1];
      if(A[i] > B[i])
      {
        A[i] = B[i];
      }
    }
  }
  A[N-1] = B[N-2];
  
  cout << accumulate(A.begin(), A.end(), 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
int n, m;
int par[100010];
int r(int x){ return (x==par[x])?x:(par[x]=r(par[x])); }
priority_queue<int> pq[100010];
bool join(int a, int b){
	a=r(a); b=r(b);
	if(a==b) return 0;
	par[a]=b;
	if(pq[a].size()>pq[b].size()) swap(pq[a], pq[b]);
	while(pq[a].size()){
		pq[b].push(pq[a].top()); pq[a].pop();
	}
	return 1;
}
int pc[100010];
inline void dame(){ puts("Impossible"); exit(0); }
int main()
{
	read(n, m);
	for(int i=0; i<n; ++i){
		par[i]=i;
		int x; read(x);
		pq[i].push(-x);
	}
	for(int i=1; i<=m; ++i){
		int a, b; read(a, b); join(a, b);
	}
	priority_queue<pp> qb;
	int ones = 0;
	int bigs = 0;
	ll ans = 0;
	for(int i=0; i<n; ++i) if(par[i] == i){
		int s = pq[i].size();
		if(s > 1){
			ans += pq[i].top(); pq[i].pop(); ++pc[i];
			if(pq[i].size()){
				qb.emplace(pq[i].top(), i);
			}
			++bigs;
		} else {
			ans += pq[i].top();
			++ones;
		}
	}
	
	if(ones + bigs == 1){ puts("0"); return 0; }
	
	if(bigs == 0){
		if(ones > 2) dame();
		printf("%lld\n", -ans);
		return 0;
	}

	for(int i=0; i<bigs-2+ones; ++i){
		if(qb.empty()) dame();
		int a = qb.top().second; qb.pop();
		ans += pq[a].top(); pq[a].pop();
		++pc[a];
		if(pq[a].size()){
			qb.emplace(pq[a].top(), a);
		}
	}

	if(ones > (n-ones-2*(bigs-1))) dame();

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


Measured memory_bytes: 8188
#include<cstdio>
#include<cstring>
#define LL long long
#define INF (LL)1e16
#define maxn 2005
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
int n,x,a[maxn],minx[maxn][maxn];
LL ans=INF;
int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d",&a[i]);
		minx[i][1]=a[i];
	}
	for(int j=2;j<=n;j++)
		for(int i=1;i<=n;i++)
			minx[i][j]=min(minx[(i==1)?n:(i-1)][j-1],a[i]);
	for(int j=1;j<=n;j++)
	{
		LL tmp=0;
		for(int i=1;i<=n;i++) tmp+=1ll*minx[i][j];
		ans=min(ans,tmp+1ll*x*(j-1));
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 15872
import math

# UnionFind、0-indexであることに注意
#############################################################
class UnionFind:

    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, v):  # vが属する集合の根を返す
        if self.parents[v] < 0:
            return v
        else:
            self.parents[v] = self.find(self.parents[v])
            return self.parents[v]

    def unite(self, u, v):  # 「uが属する集合」と「vが属する集合」を併合（根同士を結ぶ）
        u = self.find(u)
        v = self.find(v)
        if u == v:
            return
        if self.parents[u] > self.parents[v]:  # u < v に統一する
            u, v = v, u
        self.parents[u] += self.parents[v]
        self.parents[v] = u

    def size(self, v):  # vが属する集合の要素数
        return -self.parents[self.find(v)]

    def same(self, u, v):  # uとvが同じ集合に属するか否か
        return self.find(u) == self.find(v)
#############################################################

# 普通のcombination
#############################################################


def comb(n, r):  # 普通のcombination計算
    if r < 0 or r > n:
        return 0
    else:
        n1 = math.factorial(n)
        n21 = math.factorial(n - r)
        n22 = math.factorial(r)
        ans = n1 // (n21 * n22)
        return ans
#############################################################

N, M = map(int, input().split())
uf = UnionFind(N)

for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)

root_list = []
for i in range(N):
    r = uf.find(i)
    root_list.append(r)

root_list = list(set(root_list))
num = len(root_list)

ans = num - 1
print(ans)


Measured memory_bytes: 82920
INF = 10 ** 5

A = [0] * 3
N,A[0],A[1],A[2] = map(int,input().split())

l = [0] * N
for i in range(N):
    l[i] = int(input())

can = [0] * (4 ** N)

for x in range(4 ** N):
    union = [-1] * 4
    bef = [0] * 4 #4番めはどこにも入れない
    xx = x
    for i in range(N):
        where = xx % 4
        xx //= 4
        bef[where] += l[i]
        union[where] += 1
    #print(x,bef)
    if -1 in union[:3]:
        can[x] = INF
        continue
    deffer = 0
    for j in range(3):
        deffer += abs(bef[j]-A[j])
    can[x] = deffer + sum(union[:3]) * 10

print(min(can))
    

Measured memory_bytes: 5032
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll h,w; cin >> w >> h;
	ll ans=0;
	vector<pair<ll,int> > v;
	for(int i=0;i<w;i++){
		ll a; cin >> a;
		v.push_back(make_pair(a,0));
	}
	for(int i=0;i<h;i++){
		ll a; cin >> a;
		v.push_back(make_pair(a,1));
	}
	sort(v.begin(),v.end());
	w++;
	h++;
	for(int i=0;i<v.size();i++){
		if(v[i].second){
			ans+=w*v[i].first; h--;
		}
		else{
			ans+=h*v[i].first; w--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
constexpr int NIL = -1;

struct Node { int parent, left, right; };
Node T[100];

void preorder(int id){
    cout << ' ' << id;
    if(T[id].left != NIL) preorder(T[id].left);
    if(T[id].right != NIL) preorder(T[id].right);
    return;
}

void inorder(int id){
    if(T[id].left != NIL) inorder(T[id].left);
    cout << ' ' << id;
    if(T[id].right != NIL) inorder(T[id].right);
    return;
}

void postorder(int id){
    if(T[id].left != NIL) postorder(T[id].left);
    if(T[id].right != NIL) postorder(T[id].right);
    cout << ' ' << id;
    return;
}

int main(){
    int n; cin >> n;
    memset(T, -1, 100*sizeof(Node));

    rep(i, 0, n){
        int id, left, right;
        cin >> id >> left >> right;
        T[id].left = left;
        T[id].right = right;
        T[left].parent = id;
        T[right].parent = id;
    }

    int root;
    rep(i, 0, n) if(T[i].parent == NIL) root = i;

    cout << "Preorder" << endl;
    preorder(root);
    cout << "\nInorder" << endl;
    inorder(root);
    cout << "\nPostorder" << endl;
    postorder(root);
    cout << endl;
    return 0;
}


Measured memory_bytes: 3092
require "prime"
n=gets.to_i
h={}
(n-1).times do |i|
  b=Prime.prime_division(i+2)
  b.each do |bi|
    h[bi[0]]=0 if !h.has_key?(bi[0])
    h[bi[0]]+=bi[1]
  end
end
c=1
h.each do |p,q|
  c*=(q+1)
  c%=1000000007
end
puts c

Measured memory_bytes: 2300
import sys
MAX_INT = int(10e9)
MIN_NUM = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

# Union-Find #
def init(n):
    for i in range(N):
        par[i]=i
        rnk[i]=0
def find(x):
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
def unite(x,y):
    x=find(x)
    y=find(y)
    if x==y:
        return
    if (rnk[x]<rnk[y]):
        par[x]=y
        num[y]=num[x]+num[y]
    else:
        par[y]=x
        if(rnk[x]==rnk[y]):
            rnk[x]+=1
        num[x]=num[x]+num[y]
def same(x,y):
    return find(x)==find(y)

N,M = IL()
ab = [IL() for i in range(M)]
ans = N*(N-1)//2
data = []
par=[0 for i in range(N+1)]
rnk=[0 for i in range(N+1)]
num=[1 for i in range(N+1)]
init(N)

data.append(ans)
for i in range(M-1,-1,-1):
  a,b = ab[i]
  if same(a, b):
    data.append(ans)
  else:
    ans -= num[find(a)]*num[find(b)]
    unite(a, b)
    data.append(ans)

for i in range(M-1,-1,-1):
  print(data[i])

Measured memory_bytes: 110424
n = gets.to_i

s = [*1..13]
h = [*1..13]
c = [*1..13]
d = [*1..13]

while input = gets
    input = input.chomp.split(" ")
    
    case input[0]
    when "S"
        s.delete(input[1].to_i)
    when "H"
        h.delete(input[1].to_i)
    when "C"
        c.delete(input[1].to_i)
    when "D"
        d.delete(input[1].to_i)
    end
end

s.each do |x|
    puts "S #{x}"
end
h.each do |x|
    puts "H #{x}"
end
c.each do |x|
    puts "C #{x}"
end
d.each do |x|
    puts "D #{x}"
end



Measured memory_bytes: 6876
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >>n;
  while(n--){
    string a,b,solve = "";
    cin >>a>>b;
    int as = a.size(),bs = b.size(),ms;
    int j=0,k;
    ms = (as<bs)?bs:as;
    for(int i=0; i<ms; i++){
      if(i<as && i<bs) k = a[as-i-1]+b[bs-i-1]-'0'*2+j;
      else if(i<as) k = a[as-i-1]-'0'+j;
      else if(i<bs) k = b[bs-i-1]-'0'+j;
      j = k/10;
      solve+='0'+k%10;
    }
    if(j!=0) solve+='1';
    if(solve.size()>80) cout <<"overflow"<<endl;
    else{
      for(int i=solve.size()-1; i>=0; i--)
	cout <<solve[i];
      cout <<endl;
    }
  }
  return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}

void pre(){


}


void solve(){

    ll n,k;
    cin >> n >> k;
    ll a[n+1];
    for(ll i=1;i<n+1;i++){
        cin >> a[i];
    }
    for(ll i=0;i<k;i++){
        vll pre(n+1,0);
        for(ll i=1;i<=n;i++){
            ll r = i + a[i] + 1;
            ll l = i - a[i];
            l = max(1ll,l);
            pre[l]++;
            if(r <= n)
                pre[r]--;
        }
        ll sum=0;
        ll flg=1;
        for(ll i=1;i<=n;i++){
            sum += pre[i];
            a[i] = sum;
            if(a[i] < n){
                flg=0;
            }
        }
        if(flg)
            break;
    }
    
    for(ll i=1;i<n+1;i++)
        cout << a[i] << " ";

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 6788
import java.util.*;
public class Main {
  public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
		String s2 = sc.next();
		if (s1.length()+1 == s2.length()){
			if (s2.startsWith(s1)) {
// 出力
			System.out.println("Yes");
        
			} else {
			// 出力
			System.out.println("No");
        
			}
		}else{
			// 出力
			System.out.println("No");
        }
	}
}



Measured memory_bytes: 26948
#include<stdio.h>
#include<iostream>

using namespace std;
long long int Q,H,S,D,N;
int main(){
    cin >> Q >> H >> S >> D >> N;
    long long int x = min( S, 2 * min( 2 * Q, H));
    cout << min( N * x ,N % 2 * x + N / 2 * D ) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,x[55],y[55],ans = INF;
	cin >> n;
	set<P> st;
	for(int i = 0;i < n;i++){
		cin >> x[i] >> y[i];
		st.emplace(x[i],y[i]);
	}
	if(n == 1){
		cout << 1 << endl;
		return 0;
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			if(i == j) continue;
			int p = x[i] - x[j],q = y[i] - y[j],cnt = 0;
			for(int k = 0;k < n;k++){
				if(!st.count(P(x[k] - p,y[k] - q))) cnt++;
			}
			chmin(ans,cnt);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.StringTokenizer;

public class Main {
  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> out.close()));
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));
    int a = sc.nextInt();
    int b = sc.nextInt();

    int ans = a + b/2;
    out.println(ans);
    out.close();
  }

  /*          
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {
    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


Measured memory_bytes: 29524
#include <iostream>
#include <vector>
#define MAX 55556

using namespace std;

int main(void) {
	int num, i, j;
	vector<int> d(MAX, true);
	cin >> num;
	for (i = 2; i < MAX - 1; i++) {
		if (d[i]) {
			for (j = i << 1; j < MAX; j += i) {
				d[j] = false;
			}
		}
	}
	printf("2 ");
	j = 1;
	for (i = 3; i < MAX; i++) {
		if (j == num)
			break;
		if (d[i] && i % 5 == 1) {
			printf("%d ", i);
			j++;
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int S;
    cin >> S;
    int s1 = S / 100;
    int s2 = S % 100;
    if (1 <= s1 && s1 <= 12) {
        cout << (1 <= s2 && s2 <= 12 ? "AMBIGUOUS" : "MMYY") << endl;
    } else {
        cout << (1 <= s2 && s2 <= 12 ? "YYMM" : "NA") << endl;
    }
    return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  vll num(2);
  char c;
  cin >> num[0] >> c >> num[1];
  
  ll ans;
  if(c == '+')
    ans = num[0]+num[1];
  else
    ans = num[0]-num[1];
  
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program {
    static void Main(string[] args) {
        string[] AB = Console.ReadLine().Split(' ');

        long result=1;

        int a = int.Parse(AB[0]);
        int b = int.Parse(AB[1]);


        int s = 2;

        while (a!=1||b!=1) {
            bool waru = false;

            if (a % s == 0) {
                waru = true;
                a /= s;
            }
            if (b % s == 0) {
                waru = true;
                b /= s;
            }

            if (!waru) {
                s++;
            } else {
                result *= s;
            }

        }



        Console.WriteLine(result);
    }
}

Measured memory_bytes: 13140
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s, fr, ba;
char c[ohara];
ll n, cnt, ans, a, b, d, tmp, m, h, w, x, y, sum, k, q;
ll t[ohara], f[ohara];
ll fl;
char before;

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

  cin >> s >> q;
  rep(i, q) {
    cin >> t[i];
    if (t[i] == 2)
      cin >> f[i] >> c[i];
    else
      cnt++;
  }
  if (cnt % 2 == 1) reverse(all(s));
  rep(i, q) {
    if (t[i] == 2) {
      if (cnt % 2 == 1) {
        if (f[i] == 1)
          f[i] = 2;
        else
          f[i] = 1;
      }
      if (f[i] == 1) {
        fr += c[i];
      } else {
        ba += c[i];
      }
    } else
      cnt--;
  }
  reverse(all(fr));
  cout << fr << s << ba << "\n";
  return 0;
}

Measured memory_bytes: 8784
#include <iostream>
#include <math.h>
using namespace std;
long long n;
int main(void){
    // Your code here!
    cin >> n;
    int res;
    for (int i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) res = i;
    }
    int num = n / res, cou = 0;
    while (num > 0) {
        num /= 10;
        cou++;
    }
    cout << cou << endl;
}


Measured memory_bytes: 256
import math
import itertools

n = int(input())
xys = [list(map(int, input().split(" "))) for _ in range(n)]

sums = []
for li in list(itertools.permutations(range(n))):
    _sum = 0
    for i in range(n):
        if i == n - 1: continue
        dx = abs(xys[li[i]][0] - xys[li[i + 1]][0])
        dy = abs(xys[li[i]][1] - xys[li[i + 1]][1])
        _sum += math.sqrt(dx**2 + dy**2)
    sums.append(_sum)

print(sum(sums) / len(sums))


Measured memory_bytes: 9332
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
    ll a,b;cin>>a>>b;
    ll k=(a+b)/2; 
	if((a+b)%2==0) cout<<k;
	else cout<<"IMPOSSIBLE";
	
	
	
	
 return 0;
}

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

#define INF 1e9;
int main(){
    int n;
    while(1){
        scanf("%d",&n);
        if(!n){break;}
        int tb[n][n+1];
        for(int i=0;i<n;i++){
            for(int j=0;j<n+1;j++){
                scanf("%d",&tb[i][j]);
            }
        }
        int dp[1<<n];
        for(int i=0;i<(1<<n);i++){
            dp[i]=INF;
        }
        dp[0]=0;
        for(int i=0;i<(1<<n);i++){
            for(int j=0;j<n;j++){
                if((i&(1<<j))!=0){continue;}
                int c=tb[j][0];
                for(int k=0;k<n;k++){
                    if((i&(1<<k))==0){continue;}
                    c=min(tb[j][k+1],c);
                }
                int nw = i|(1<<j);
                dp[nw]=min(dp[nw],dp[i]+c);
            }
        }
        printf("%d\n",dp[(1<<n)-1]);
    }
    return 0;
}    



Measured memory_bytes: 2980
<?php
fscanf(STDIN, "%d %d", $N, $K);
fscanf(STDIN, "%s", $S);

$change_place = substr($S, $K - 1, 1);
$little_str = strtolower($change_place);

echo substr_replace($S, $little_str, $K - 1, 1);
return;


Measured memory_bytes: 16056
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using ll = int64_t;

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int w=0;
  REP(i,n) {
    if(s[i] == '.') {
      ++w;
    }
  }
  int mn = w;
  int b=0;
  REP(i,n) {
    if (s[i] == '.') {
      --w;
    } else {
      ++b;
    }
    mn = min(mn, b+w);
  }
  cout<<mn<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S;
    cin >> S;
    rep(0, i, 3)
    {
        if (S[i] == '7')
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3628
"use strict";
function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");
  const s = inputs[0];

  const result = s
    .split("")
    .map((input, index) => (input === "W" ? index : -1))
    .filter(x => x !== -1)
    .reduce((acc, cur, index) => acc + cur - index, 0);

  console.log(result);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

long long N, M;
long long a[50], b[50];
long long g[8][8] = {0};

long long cnt = 0;

void solve(int now, vector<bool> is_visited) {
    for (int i = 0; i < N; i++) {
        if (!is_visited[i]) {
            break;
        } else if (i == N-1) {
            cnt++;
            return;
        }
    }
    for (int i = 0; i < N; i++) {
        if (g[now][i] == 1 && is_visited[i] == false) {
            is_visited[i] = true;
            solve(i, is_visited);
            is_visited[i] = false;
        }
    }
    return;
}


int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < M; i++) {
        g[a[i]-1][b[i]-1] = 1;
        g[b[i]-1][a[i]-1] = 1;
    }
    vector<bool> is_v(N, false);
    is_v[0] = true;
    solve(0, is_v);
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------
int N;
int A[201010];

int main() {
  cin >> N;
  int sum = 0;
  repe(i, 1, N) {
    cin >> A[i];
    sum += abs(A[i] - A[i - 1]);
  }
  sum += abs(0 - A[N]);

  repe(i, 1, N) {
    int ans = sum;
    ans -= abs(A[i] - A[i - 1]);
    ans -= abs(A[i + 1] - A[i]);
    ans += abs(A[i + 1] - A[i - 1]);
    cout << ans << "\n";
  }
}


Measured memory_bytes: 1664
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>

using namespace std;

const int N = 400;
bool dp[N][N];
char a[N][N];
int n;
int ans = 0;

int main() 
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int b = 0; b < n; b++)
	{
		dp[b][0] = true;	
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (a[(j + b) % n][i] != a[(i + b) % n][j])
				{
					dp[b][0] = false;
				}
			}
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (dp[i][j])
			{
				ans++;
			}
		}
	} 
	cout << ans * n<< endl;


	

}


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

int main() {
    int i, q;
    string str;
    cin >> str;
    cin >> q;
    int arg1[q] = {}, arg2[q] = {};
    string state[q] = {}, arg3[q] = {};

    for(i=0; i<q; ++i) {
        cin >> state[i];
        if(!(state[i].compare("print"))) {
            cin >> arg1[i] >> arg2[i];
        }
        else if(!(state[i].compare("reverse"))) {
            cin >> arg1[i] >> arg2[i];
        }
        else if(!(state[i].compare("replace"))) {
            cin >> arg1[i] >> arg2[i] >> arg3[i];
        }
    }

    for(i=0; i<q; ++i) {
        if(!(state[i].compare("print"))) {
            cout << str.substr(arg1[i], arg2[i]+1-arg1[i]) << endl;
        }
        else if(!(state[i].compare("reverse"))) {
            reverse(str.begin()+arg1[i], str.begin()+arg2[i]+1);
        }
        else if(!(state[i].compare("replace"))) {
            str.replace(arg1[i], arg2[i]+1-arg1[i], arg3[i]);
        }
    }

    return 0;
}

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

using namespace std;

int main()
{
        int n,r=0,s=0,k=0;
        cin>>n;
        k=n;
        while(n>0)
        {
            r=n%10;
            s=s+r;
            n=n/10;
        }
        //cout<<s<<endl;
        if(k%s==0)
                cout<<"Yes"<<endl;
        else
                cout<<"No"<<endl;
        return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    string s,t; cin >> s >> t;
    i32 a,b; cin >> a >> b;
    string u; cin >> u;
    if(s == u) {
        cout << a-1 << ' ' << b << '\n';
    }
    else {
        cout << a << ' ' << b-1 << '\n';
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

ll dp[51][51][2501];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, a;
  cin >> n >> a;
  vector<ll> x(n);
  rep(i, 0, n) cin >> x[i];


  dp[0][0][0] = 1;
  rep(j, 0, n) {
    rep(k, 0, n) {
      rep(s, 0, 2501) {
        if (dp[j][k][s] == 0)
          continue;
        dp[j + 1][k][s] += dp[j][k][s];
        dp[j + 1][k + 1][s + x[j]] += dp[j][k][s];
      }
    }
  }

  ll ans = 0;
  rep(k, 1, n + 1) ans += dp[n][k][k * a];
  cout << ans << endl;
}


Measured memory_bytes: 48128
#include <stdio.h>
#include <iostream>

using namespace std;

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

int main() {
    int A, B;
    cin >> A >> B;

    if (A + B > 9) {
        cout << "error" << endl;
    } else {
        cout << A + B << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[2005],n,k;
const int mod=1e9+7;
int calc(int K){
	return (1ll*K*(K+1)/2)%mod;
}
signed main(){
	cin>>n>>k;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	int ans=0;
	for(int i=1;i<=n;++i){
		for(int j=1;j<i;++j)
			if(a[j]>a[i]) ans=(ans+calc(k))%mod;
			else if(a[j]<a[i]) ans=(ans+calc(k-1))%mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3620