akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

string solve() {
    string S, T;
    cin >> S >> T;
    int sl = S.size(), tl = T.size();
    if ( sl < tl ) return "UNRESTORABLE";
    int k = -1;
    for ( int i = sl - tl; i >= 0; i-- ) {
        bool ng = false;
        for ( int j = 0; j < tl; j++ ) {
            if ( S[i+j] != '?' && S[i+j] != T[j] ) {
                ng = true;
                break;
            }
        }
        if ( !ng ) {
            k = i;
            break;
        }
    }
    if ( k < 0 ) return "UNRESTORABLE";
    for ( int i = 0; i < sl; i++ ) {
        if ( S[i] == '?' ) S[i] = 'a';
    }
    for ( int j = 0; j < tl; j++ ) {
        S[k+j] = T[j];
    }
    return S;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    char ch;
    int max,i,j,k,n,s,a[105],b[105];
    while(scanf("%d",&n)==1)
    {
        max=0,s=0;
        getchar();
        for(i=0;i<n;i++)
        {
            scanf("%c",&ch);
            a[i]=ch-'a';
            //printf("%d",a[i]);
        }
        for(i=0;i<n;i++)
        {
            b[i]=a[i];
            sort(b,b+i+1);
            for(j=0;j<=i;j++)
            {
                if(j==0||(b[j-1]!=b[j]))
                {
                    for(k=i+1;k<n;k++)
                    {
                        if(a[k]==b[j])
                        {
                            s++;
                            break;
                        }
                    }
                }
            }
            //printf("%d\n",s);
            max=max>s?max:s;
            s=0;
        }
        printf("%d\n",max);
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
void initialize_rc(int n[101][101], int r, int c) //増えた配列を初期化する関数
{
    for (int i = 0; i < r; i++) //ｃ列を初期化
    {
        n[i][c] = 0;
    }
    for (int j = 0; j <= c; j++) //ｒ列を初期化
    {
        n[r][j] = 0;
    }
}
void assign_c(int n[101][101], int r, int c) //増えたｃ列に値を代入する関数
{
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            n[i][c] += n[i][j];
        }
    }
}
void assign_r(int n[101][101], int r, int c) //増えたｒ行に値を代入する関数
{
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            n[r][j] += n[i][j];
        }
    }
}
void assign_rc(int n[101][101], int r, int c) //n[r][c]の値を代入する関数
{
    for (int j = 0; j < c; j++)
    {
        n[r][c] += n[r][j];
    }
}
void print_spreadsheet(int n[101][101], int r, int c) //増えたｒ行ｃ列を追加して表示する関数
{
    int i, j;
    for (i = 0; i <= r; i++)
    {
        for (j = 0; j < c; j++)
        {
            printf("%d ", n[i][j]);
        }
        printf("%d\n", n[i][j]); //ｃ列の右に空白があるとpresentation errorになったのでここだけ分離した。
    }
}

int main(void)
{
    int r, c;
    int n[101][101];

    scanf("%d %d", &r, &c);
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            scanf("%d", &n[i][j]); //入力した値を配列に代入する
        }
    }

    initialize_rc(n, r, c);
    assign_c(n, r, c);
    assign_r(n, r, c);
    assign_rc(n, r, c);

    print_spreadsheet(n, r, c);
    return 0;
}


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

using namespace std;
using ll  = long long;
template <typename T> T In() {
    T t;
    cin >> t;
    return t;
}
template <typename T> vector<vector<T>> Vec2(int i, int j, T ini = 0) {
    vector<vector<T>> vec(i, vector<T>(i, ini));
    return move(vec);
}
template <typename T> vector<vector<vector<T>>> Vec3(int i, int j, int k, T ini = 0) {
    vector<vector<vector<T>>> vec(i, vector<vector<T>>(j, vector<T>(k, ini)));
    return move(vec);
}

int main() {
    int a = In<int>();
    string s = In<string>();
    cout << (a >= 3200 ? s : "red") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    string S ;
    cin >> S;
    int ans=0;
    rep(i,4){
        if(S.at(i)=='+'){
            ans++;
        }else{
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>

using namespace std;

const double EPS=1e-11;

double p,e,t;

double dfs(int k,double l,double r){
	double h=(l+r)/2;

	if(t+EPS<l-e || r+e<t-EPS) return 0;
	if(t-e<l+EPS && r-EPS<t+e) return 1;
	if(k==0) return (abs(h-t)<e+EPS)?1:0;

	if(h<t) return (1-p)*dfs(k-1,h,r)+  p  *dfs(k-1,l,h);
	else    return   p  *dfs(k-1,h,r)+(1-p)*dfs(k-1,l,h);
}

int main(){
	int k,l,r; scanf("%d%d%d%lf%lf%lf",&k,&l,&r,&p,&e,&t);

	printf("%.9f\n",dfs(k,l,r));

	return 0;
}

Measured memory_bytes: 0
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

// https://atcoder.jp/contests/abc141/tasks/abc141_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine(); //Sは Sunny, Cloudy, Rainy のいずれかである
		sc.close();

        List<String> weatherList = new ArrayList<String>();
        weatherList.add("Sunny");
        weatherList.add("Cloudy");
        weatherList.add("Rainy");

        int index = (weatherList.indexOf(S)+1)%3;
        System.out.println(weatherList.get(index));

	}

}


Measured memory_bytes: 20820
l = []
l1 = []
for i in range(5):
  a = int(input())
  l.append((a,a%10))
l.sort(key = lambda x: x[1])

count = 0
for i in range(5):
  if l[i][1] == 0:
    count += l[i][0]
    if i == 4:
      c = 5
  else:
    c = i
    break
for i in range(4,c-1,-1):
  
  if i == c:
    count += l[i][0]
  else:
    count += l[i][0] + 10-l[i][1]
print(count)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
    int x;
    cin>>x;
    int hap=0;
    while(x>4)
    {
        if(x>=500)
        {

       
             hap=hap+1000*(x/500);
             x=x%500;
        }
        else 
        {
            hap=hap+5*(x/5);
            x=x%5;
        }
        
    }
    cout<<hap<<endl;
}

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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 20;
int n;
int cntp[N+1][1 << N];
int* d[N+1][N+1];

int main() {
    ios::sync_with_stdio(false);
    int kk;
    cin >> n >> kk;
    for (int i = 0; i <= n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < 1 << i; ++j) {
            if (s[j] == '1') {
                for (int x = 0; x <= i; ++x)
                    cntp[x][j & ((1 << x) - 1)]++;
            }
        }
    }

    for (int len = n; len >= 0; --len)
        for (int pos = len; pos >= 0; --pos) {
            d[len][pos] = new int[1 << len];
            for (int i = 0; i < 1 << len; ++i) {
                if (pos == len)
                    d[len][pos][i] = cntp[len][i];
                else {
                    d[len][pos][i] = 0;
                    int ni = i;
                    int cur = (!(1 & (i >> pos))) << pos;
                    int nlen = len;
                    int npos = pos + 1;
                    while (1) {
                        d[len][pos][i] += d[nlen][npos][ni];
                        if (nlen == n)
                            break;
                        ++npos;
                        ++nlen;
                        ni ^= (i & ((1 << pos) - 1));
                        ni <<= 1;
                        ni ^= cur;
                        ni ^= (i & ((1 << pos) - 1));
                    }
                }
            }
        }

    for (int len = n; len >= 0; --len) {
        int ans = IINF;
        for (int i = 0; i < 1 << len; ++i) {
            if (d[len][0][i] >= kk) {
                ans = i;
                break;
            }
        }
        if (ans != IINF) {
            for (int i = len - 1; i >= 0; --i)
                cout << (1&(ans >> i));
            cout << "\n";
            return 0;
        }
    }
    assert(false);

    return 0;
}


Measured memory_bytes: 209468
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int k, x;
    cin >> k >> x;
    if (500 * k >= x){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define fi first
#define se second
using namespace std;

ll dp[1000005][3];


int main(){
    ll n,k;
    cin>>n;
    ll a[n][3];
    for(int i=0;i<=n;i++)dp[i][0]=dp[i][2]=dp[i][1]=0;
    for(int i=0;i<n;i++)for(int j=0;j<3;j++)cin>>a[i][j];
    //dp[0]=0;
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++)if(j!=k)dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
        }
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}

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

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> ans;
    for(int i = 1; i < 105; i++){
        if(a % i == 0 && b % i == 0) ans.push_back(i);
    }
    cout << ans[ans.size()-k] << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, s; cin >> n >> k >> s;
	int bad = 1;
	while(s % bad == 0) bad++;
	for(int i = 0; i < k; i++) cout << s << ' ';
	for(int i = k; i < n; i++) cout << bad << ' ';
	cout << endl;
	return 0;
}


Measured memory_bytes: 1280
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


immutable long MOD = 1000000007;


auto solve(long X, long Y) {
    if ((2 * X - Y) % 3 != 0 || (2 * Y - X) % 3 != 0)
        return 0;
    
    const a = (2 * Y - X) / 3;
    const b = (2 * X - Y) / 3;

    if (a < 0 || b < 0)
        return 0;

    return ModCalc(MOD).C(a + b, a);
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long X;
    X = input.front.to!long;
    input.popFront;

    long Y;
    Y = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(X, Y);
    else {
        auto ans = solve(X, Y);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}


struct ModCalc {
private:
    long mod;
    long[] fac;
    long[] inv;
    long[] finv;

public:
    this(long mod) {
        this.mod = mod;
        fac = [1, 1];
        inv = [0, 1];
        finv = [1, 1];
    }

    long factorial(long n) {
        assert(n >= 0);

        auto n_ = n.to!size_t;
        extendTable(n_ + 1);
        return fac[n_];
    }

    long P(long n, long k) {
        assert(0 <= k && k <= n);

        auto n_ = n.to!size_t;
        auto k_ = k.to!size_t;
        extendTable(n_ + 1);
        return fac[n_] * finv[n_ - k_] % mod;
    }

    long C(long n, long k) {
        assert(0 <= k && k <= n);

        auto n_ = n.to!size_t;
        auto k_ = k.to!size_t;
        extendTable(n_ + 1);
        return fac[n_] * finv[k_] % mod * finv[n_ - k_] % mod;
    }

    long H(long n, long k) {
        return C(n + k - 1, k);
    }

private:
    void extendTable(size_t size) {
        auto oldsize = fac.length;
        if (size <= oldsize)
            return;

        fac.length = size;
        inv.length = size;
        finv.length = size;

        foreach (i; oldsize .. size) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[(mod % i).to!size_t] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
}


Measured memory_bytes: 19708
def solve(s, k):
    can = set()

    for l in range(k):
        for i in range(len(s) - l):
            can.add(s[i:i + l + 1])
    can.discard('')
    can = sorted(can)
    return can[k-1]


s = input()
k = int(input())
print(solve(s, k))


Measured memory_bytes: 4464
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

int digits_sum(int d) 
{
    int sum = 0;
    while(d) {
        sum += d % 10;
        d /= 10; 
    }

    return sum;
}

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

    irep2(i, 1, n+1) {
        int c = digits_sum(i);
        if((c <= b) && (a <= c)) {
            ans += i;
        }
    }

    cout << ans << endl;

    return 0;
}
    



Measured memory_bytes: 256
n = int(input())
arr1 = str( input() )
arr1 = arr1.split()
arr = []

for i in arr1:
    arr.append(int(i))

leng = len(arr)
dp = [99999999999] * leng 
dp[0] = 0 

for i in range(leng):
    if (i + 1) >= leng:
        continue 
    dp[i + 1] = min ( dp[i] + abs(arr[i] - arr[i + 1]), dp[i + 1] )
    
    if (i + 2) >= leng:
        continue 
    dp[i + 2] = min(  ( dp[i] + abs( arr[i] - arr[i + 2] ) , dp[i + 2]) )

print(dp[-1])
    

Measured memory_bytes: 17900
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#include<algorithm>
using namespace std;
int n,a[220000],b;
long long ans;
int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	fo(i,1,n) a[i]-=i;
	sort(a+1,a+n+1);
	b=a[(n+1)>>1];
	fo(i,1,n) ans+=abs(b-a[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
typedef long long ll;
using namespace std;

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

int main(void)
{
  ll N, sum = 0;
  cin >> N;

  int i, j, k;
  for (i=1;i<=N;i++){
    for (j=1;j<=N;j++){
      for (k=1;k<=N;k++){
        sum += my_gcd(my_gcd(i, j), k);
      }
    }
  }

  cout << sum << endl;
  
  return 0;
}


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

int main()
{
    int a, b, c;
    int cnt = 0;
    cin >> a >> b >> c;
    for (int i = a; i <= b; ++i) {
        if (c % i == 0)
            ++cnt;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((int)(x).size())

using namespace std;
typedef long long ll;


void solve(std::string S){
  ll ans = 1;

//  ll size = S.size();
//  ll i;
//  char before = S[0];
//  for (i = 1; i < size - 2; i += 3) {
//    if (before == S[i]) {
//      ans += 2;
//    } else {
//      if (S[i] != S[i+1] && S[i+1] != S[i+2]) {
//        ans += 3;
//      } else {
//        ans += 2;
//      }
//    }
//
//    before = S[i + 2];
//  }
//
//  if (i == size - 1) {
//    if (before != S[size - 1]) {
//      ans += 1;
//    }
//  } else if (i == size - 2) {
//    if (before == S[size - 2]) {
//      ans += 1;
//    } else {
//      if (S[size - 2] == S[size - 1]) {
//        ans += 1;
//      } else {
//      }
//    }
//  }
//
//  printf("%lld\n", ans);

  char before1 = S[0];
  char before2 = -1;
  ll i = 1;
  ll size = S.size();
  while (i < size - 1) {
    char c1 = S[i];
    char c2 = S[i + 1];


    if (before2 == -1) {
      if (before1 == c1) {
        before1 = c1;
        before2 = c2;
        i += 2;
      } else {
        before1 = c1;
        before2 = -1;
        i += 1;
      }
    } else {
      before1 = c1;
      before2 = -1;
      i += 1;
    }
    ans++;
  }

  if (i == size - 1) {
    if (before2 == -1) {
      if (before1 != S[size - 1]) {
        ans += 1;
      }
    } else {
      ans += 1;
    }
  }

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

int main(){
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 772
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}
typedef  long double ld;
typedef pair<ld,ld> pdd;
long double dist(pair<long double,long double> x,pair<long double,long double> y){
  ld tmp1=abs(x.first-y.first);
  ld tmp2=abs(x.second-y.second);
  return sqrt((long double)(tmp1*tmp1+tmp2*tmp2));
}

void solve(long long N, std::vector<long long> x, std::vector<long long> y){
  if(N==2){
    cout<<dist(pdd(x[0],y[0]),pdd(x[1],y[1]))/2<<endl;
    return;
  }
  ld ans=0;
  For(i,N){
    FOR(j,i+1,N){
      FOR(k,j+1,N){
        {
          pdd xx=pdd(x[i],y[i]);
          pdd yy=pdd(x[j],y[j]);
          pdd zz=pdd(x[k],y[k]);
          pdd xy=pdd((long double)(x[i]+x[j])/2,(long double)(y[i]+y[j])/2);
          pdd yz=pdd((long double)(x[j]+x[k])/2,(long double)(y[j]+y[k])/2);
          pdd zx=pdd((long double)(x[k]+x[i])/2,(long double)(y[k]+y[i])/2);
          if(dist(xy,zz)-0.000000000000000001L<=dist(xy,xx)){
            ans=max(ans,dist(xy,xx));
          }
          else if(dist(yz,xx)-0.000000000000000001L<=dist(yz,yy)){
            ans=max(ans,dist(yz,yy));
          }
          else if(dist(zx,yy)-0.000000000000000001L<=dist(zx,zz)){
            ans=max(ans,dist(zx,zz));
          }else{
            pdd xxz=pdd(x[i]-x[k],y[i]-y[k]);
            pdd yyz=pdd(x[j]-x[k],y[j]-y[k]);
            ld m = abs(xxz.first*yyz.second-xxz.second*yyz.first)*2;
            ans=max(ans,dist(xx,yy)*dist(yy,zz)*dist(zz,xx)/m);
          }
        }
      }
    }
  }
  cout<<setprecision(1000)<< ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


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

using namespace std;

constexpr int64_t mod_base = 1'000'000'007LL;
constexpr int64_t M = 1'000'000'007LL;

typedef long long ll;

// const ll M = 998244353LL;

vector<ll> fac(300001);
vector<ll> ifac(300001);

ll mpow(ll x, ll n) {
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}

ll get_comb(ll a, ll b) {
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % M;
  return tmp * fac[a] % M;
}

// int64_t get_cmb(int64_t a, int64_t b) {
//   if (!b) return 1;
//   int64_t result = 1;
//   for (int64_t i = 0; i < b; ++i) {
//     result *= a;
//   }
//   for (int64_t i = 0; i < b; ++i) {
//     result /= i;
//   }
//   return result;
// }

void solve() {
  fac[0] = 1;
  ifac[0] = 1;
  for (ll i = 0; i < 300000; i++) {
    fac[i + 1] = fac[i] * (i + 1) % M;
    ifac[i + 1] =
        ifac[i] * mpow(i + 1, M - 2) % M;
  }

  int n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
    return;
  }
  vector<int64_t> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  vector<int64_t> pre(n + 1);
  for (int i = 0; i < n; ++i) {
    pre[i + 1] = (pre[i] + a[i]) % mod_base;
  }

  int64_t result = 0;
  for (int i = k - 1; i < n; ++i) {
    int64_t cmb = get_comb(i - 1, k - 2);
    int64_t left = pre[n - i];
    int64_t right = pre.back() - pre[i];
    auto diff = right - left;
    result += diff * cmb;
    result %= mod_base;
  }
  if (result < 0) result += mod_base;

  cout << (result % mod_base) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}


Measured memory_bytes: 6528
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <list>
using namespace std;

struct C
{
  int in;
  list<int> out;
  int mk;
};
static C d[ 'z' - 'a' + 1 ];

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

  for ( ; ; )
  {
    queue<int> lis;
    int n;

    scanf ( " %d", &n );
    if ( n == 0 ) break ;
    for ( i = 'a'; i <= 'z'; ++i )
    {
      d[ i - 'a' ].in = 0;
      d[ i - 'a' ].out.clear ( );
      d[ i - 'a' ].mk = 0;
    }
    for ( i = 0; i < n; ++i )
    {
      char t[ 48 ];
      char head, tail;

      scanf ( " %s", t );
      head = t[ 0 ] - 'a';
      tail = t[ strlen ( t ) - 1 ] - 'a';

      d[ head ].out.push_back ( tail );
      ++d[ tail ].in;
    }
    for ( i = 0; i <= 'z' - 'a'; ++i )
    {
      if ( d[ i ].in == 0
        && d[ i ].out.empty ( ) )
        d[ i ].mk = 1;
      else if ( lis.empty ( ) )
        lis.push ( i );
    }
    while ( !lis.empty ( ) )
    {
      list<int>::iterator it;
      const int t = lis.front ( );
      lis.pop ( );

      if ( d[ t ].mk ) continue ;
      d[ t ].mk = 1;

      for ( it = d[ t ].out.begin ( ); it != d[ t ].out.end ( ); ++it )
        lis.push ( *it );
    }
    for ( i = 0; i <= 'z' - 'a'; ++i )
      if ( !d[ i ].mk ) break ;
    if ( i <= 'z' - 'a' )
    {
      puts ( "NG" );
      continue ;
    }

    for ( i = 0; i <= 'z' - 'a'; ++i )
      if ( d[ i ].in != d[ i ].out.size ( ) ) break ;
    if ( i <= 'z' - 'a' )
    {
      puts ( "NG" );
    }
    else
    {
      puts ( "OK" );
    }
  }

  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 1404
n = int(input())
l = []
i = 1
while n > 0:
	n -= i
	t = i * (i - 1) // 2
	l += [list(range(t + 1, t + i + 1))]
	i += 1
if n < 0:
	print("No")
	exit()
print("Yes")
ans = []
i -= 1
for j in range(i):
	ans.append(list(map(str, [i] + l[j] + [l[k][j] for k in range(j + 1, i)])))
ans.append(list(map(str, [i] + [l[j][-1] for j in range(i)])))
print(i + 1)
print(*map(" ".join, ans))

Measured memory_bytes: 22260
def resolve():
    H, W = list(map(int, input().split()))
    Ch, Cw = list(map(lambda x: int(x)-1, input().split()))
    Dh, Dw = list(map(lambda x: int(x)-1, input().split()))
    S = [list(input()) for _ in range(H)]
    warps = [[-1 for _ in range(W)] for __ in range(H)]
    warpcnt = 0
    import collections
    warp_to = set()
    q = collections.deque([(Ch, Cw)])
    while q:
        while q:
            h, w = q.pop()
            if warps[h][w] != -1:
                continue
            warps[h][w] = warpcnt
            for dh, dw in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                nh = h+dh
                nw = w+dw
                if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and warps[nh][nw] == -1:
                    q.appendleft((nh, nw))
            for dh, dw in [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2)
                        ,(-1, -2), (-1, -1),          (-1, 1), (-1, 2)
                        ,(0, -2),                              (0, 2)
                        ,(1, -2),  (1, -1),           (1, 1),  (1, 2)
                        ,(2, -2),  (2, -1),  (2, 0),  (2, 1),  (2, 2)]:
                nh = h+dh
                nw = w+dw
                if 0 <= nh < H and 0 <= nw < W and S[nh][nw] == "." and warps[nh][nw] == -1:
                    warp_to.add((nh, nw))
        q = collections.deque(list(warp_to))
        warp_to = set()
        warpcnt += 1
    print(warps[Dh][Dw])

if '__main__' == __name__:
    resolve()


Measured memory_bytes: 138804
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    int a,b,sum=0;
    cin>>a>>b;
    int c[a];
    f(i,0,a){
        cin>>c[i];
        sum+=c[i];
    }
    double sum2=sum;
    double b2=b;
    sort(c,c+a);
    reverse(c,c+a);
    double ans=c[b-1];
    if(ans<sum2/(4*b2)){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, M = map(int, input().split())
    P = list(map(int, input().split()))
    uni = UnionFind(N)

    for i in range(N):
        P[i] -= 1

    for _ in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        uni.union(x,y)
    ans = 0
    for i in range(N):
        if P[i] == i:
            ans += 1
        else:
            if uni.same(i,P[i]):
                ans += 1

    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 85676
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
   int k,a,b;
   cin >> k >> a >> b;
   int j,i;
   j=a/k;
   i=b/k;
   bool c=0;
   for(int I=j; I<=i; I++){
       if(I*k>=a && I*k<=b) c=1;
   }
   if(c) cout << "OK" << endl;
   else cout << "NG" << endl;
}

Measured memory_bytes: 3588
import sys
sys.setrecursionlimit(1000000)

def solve():
    graph = [[] for _ in range(v)]
    for i in range(e):
        graph[s[i]].append(t[i])
        graph[t[i]].append(s[i])
    
    used = [False for _ in range(v)]
    ord = [0 for _ in range(v)]
    low = [10**6 for _ in range(v)]
    is_articulation = [False for _ in range(v)]
    
    def rec(v, prev, k):
        if used[v]:
            return
        used[v] = True
        k = k+1
        ord[v] = k
        low[v] = ord[v]
        cnt = 0
        for u in graph[v]:
            if not used[u]:
                cnt += 1
                rec(u, v, k)
                low[v] = min(low[v], low[u])
                if prev >= 0 and ord[v] <= low[u]:
                    is_articulation[v] = True
            elif u != prev:
                low[v] = min(low[v], ord[u])
        if prev == -1 and cnt >= 2:
            is_articulation[v] = True
        
        return k
    
    rec(0, -1, 0)
    
    for i in range(v):
        if is_articulation[i]:
            print(i)

def input(f):
    global v, e
    global s, t
    
    v, e = map(int, f.readline().split())
    s = [-1 for _ in range(e)]
    t = [-1 for _ in range(e)]
    for i in range(e):
        s[i], t[i] = map(int, f.readline().split())

with open('/dev/stdin') as f:
    input(f)
    solve()


Measured memory_bytes: 20540
#include <stdio.h>
#include <string.h>

int main(void){
    int n,i,len,hug=0;
    char str[101];
    
    scanf("%s",str);
    
    n = (int)strlen(str);
    len = n;
    
    if (len%2==0) {
        for (i=0;i<len/2;i++) {
            if (str[i] != str[n-1]) {
                hug++;
            }
            n--;
        }
    } else {
        for (i=0;i<(len-1)/2;i++) {
            if (str[i] != str[n-1]) {
                hug++;
            }
            n--;
        }
    }
    
    printf("%d\n",hug);
    
    return 0;
}


Measured memory_bytes: 128
while True:
    n = int(input())
    if n == 0:
        break
    s = list(map(int,input().split()))
    
    m = sum(s)/n

    total = 0
    for i in range(n):
        total += (s[i]-m)**2
    ans = (total/n)**0.5
    print(ans)
    




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

using namespace std;

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

	string s;
	cin >> s;
	int ans=0, cnt=0;
	for(int i=0; i<s.size(); i++){
        if(s[i]=='S'){
            ans=max(ans, cnt);
            cnt=0;
        }
        else
            cnt++;
	}
	ans=max(ans, cnt);
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3648
import sys
input = sys.stdin.readline
EPS = 10**(-8)
INF = 10**16

N, M = map(int, input().split())
graph = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    graph[a-1].add(b-1)

dp = [0]*N
dps = [0]*N
dpl = [0]*N
for n in reversed(range(N-1)):
    for p in graph[n]:
        if dp[p] != -1:
            dps[n] += dp[p]
            dpl[n] += 1
    if dpl[n] > 0:
        dp[n] = dps[n]/dpl[n] + 1
    else:
        dp[n] = -1

Weight = [0]*N
Weight[0] = 1
for n in range(N):
    for p in graph[n]:
        Weight[p] += Weight[n]/dpl[n]

def solve(n):
    dpt = dp[:]
    dpts = [0]*(n+1) + dps[n+1:]
    dptl = [0]*(n+1) + dpl[n+1:]
    dpt[n] = -1
    for p in reversed(range(n)):
        for q in graph[p]:
            if dpt[q] != -1:
                dpts[p] += dpt[q]
                dptl[p] += 1
        if dptl[p] > 0:
            dpt[p] = dpts[p]/dptl[p] + 1
        else:
            dpt[p] = -1
    if dpt[0] == -1: return INF
    return dpt[0]

ans = dp[0]
for n1 in range(N):
    if len(graph[n1]) == 1:
        continue
        #ans = min(ans, solve(n1))
    else:
        for n2 in graph[n1]:
            newE = (dps[n1]-dp[n2])/(dpl[n1]-1) + 1
            ans = min(ans, dp[0] - Weight[n1]*dp[n1] + Weight[n1]*newE)

print(ans)

Measured memory_bytes: 58460
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

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

    if (A > 8 || B > 8) cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}


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

int main() {
  string s, t; cin >> s >> t;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i)!=t.at(i)){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vector<P> p(n);
    ll x, y;
    REP(i, n) {
        cin >> x >> y;
        p[i] = {x, y};
    }
    VSORT(p);
    double res = 0, sum = 0;
    do{
        double cx = p[0].first, cy = p[0].second;
        for (auto t : p) {
            double d = sqrt((t.first - cx) * (t.first - cx) + (t.second - cy) * (t.second - cy));
            sum += d;
            cx = t.first, cy = t.second;
        }
  	}while(next_permutation(p.begin(), p.end()));
    double div = 1;
    REP(i, n) div *= (i + 1);
    res = sum / div;
    cout << fixed << setprecision(8) << res << endl;
    return 0;
}

Measured memory_bytes: 256
D, G = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(D)]
count_list = []

for i in range(2**D):
  point = 0
  count = 0
  bin_i = bin(i)[2:].zfill(D)
  for j in range(D):
    if bin_i[j] == '1':
      point += 100 * (j+1) * pc[j][0] + pc[j][1]
      count += pc[j][0]
  if point >= G:
    count_list.append(count)
  else:
    index = bin_i.rindex('0')
    for j in range(pc[index][0]-1):
        point += 100 * (index+1)
        count += 1
        if point >= G:
          count_list.append(count)
          break
          
print(min(count_list))

Measured memory_bytes: 3064
s = list(input())
k = int(input())
n = len(s)
map = {(chr(ord("a") + i)): (26-i)%26 for i in range(26)}
for i in range(n):
    if k >= map[s[i]]:
        k -= map[s[i]]
        s[i] = "a"
if k > 0:
    s[n-1] = chr((ord(s[n-1])+k%26)%123)
print("".join(s))


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

int main(){
  string s;
  cin >> s;
  
  if(s=="SUN") cout << 7;
  else if(s=="MON") cout << 6;
  else if(s=="TUE") cout << 5;
  else if(s=="WED") cout << 4;
  else if(s=="THU") cout << 3;
  else if(s=="FRI") cout << 2;
  else cout << 1;
  
  return 0;
}

Measured memory_bytes: 256
//#include<i_am_noob_orz>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define pii pair<int,int>
#define X first
#define Y second
#define mod ((ll)1e9+7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define endl '\n'
#define bit_count(x) __builtin_popcount((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define LOCAL
#ifdef LOCAL
#define debug(a) cerr<<#a<<" "<<a<<endl;
#else
#define debug(a)
#endif
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n;
	string s; 
	cin>>n;
	cin>>s;
	int ct=0,an=0;
	F(s.length())ct+=(s[i]=='R');
	F(ct)an+=(s[i]=='W');
	cout<<an<<endl;
return 0;
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (ll)1e9;
auto x = vector<double>();
auto y = vector<double>();
auto c = vector<int>({0,1,2,3,4,5,6,7});
int n;

int main(){
	cin >> n;
	x.resize(n,0);
	y.resize(n,0);
	
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i];
	}
  	double ave = 0;
	int count =0;
	do{
      	for(int i=0;i<n-1;i++){
          	int nc = c[i+1];
          	int pc = c[i];
        	double xx = (x[pc]-x[nc])*(x[pc]-x[nc]);
          	double yy = (y[pc]-y[nc])*(y[pc]-y[nc]);
            ave += sqrt(xx+yy);
          	//copy(c.begin(),c.begin()+n,ostream_iterator<int>(cout,""));
      		//cout <<" "<<pc << " " << nc << " "<<sum<<endl;
        }
      	count++;
	}while (next_permutation(c.begin(),c.begin()+n));
	ave/=count;
	cout << setprecision(10)<<fixed << ave << endl;

  	return 0;
}

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

int main(){
	int H, W, i;
	scanf("%d%d", &H, &W);
	for(i = 0; i <= W + 1; i++){
		printf("#");
	}
	printf("\n");
	for(i = 0; i < H; i++){
		printf("#");
		string sub;
		cin >> sub;
		cout << sub;
		printf("#");
		printf("\n");
	}
	for(i = 0; i <= W + 1; i++){
		printf("#");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin>>x;
  int ans = 1;
  FOR(i,2,1000){
	int y = i;
    while(y * i <= x){
		y *= i;
      	ans = max(ans, y);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #define cerr if(false)cerr
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
const ll MOD = 1e9 + 7;

inline void solve()
{
    int h, w, k;
    cin >> h >> w >> k;
    char c;
    vvll arr(h, vll(w, 0));
    for (auto &it : arr)
        for (auto &i : it)
            {
                cin >> c;
                if (c == '.')
                    i = 1;
                else
                    i = -1;
            }
    int ans = 0;
    for (int i = 0; i < (1 << h); i++)
    {
        for (int j = 0; j < (1 << w); j++)
        {
            int num = 0;
            for (int c1 = 0; c1 < h; c1++)
            {
                if (not (i & (1 << c1)))
                {
                    for (int c2 = 0; c2 < w; c2++)
                    {
                        if (not (j & (1 << c2)))
                            if (arr[c1][c2] == -1)
                                num++;
                    }
                }
            }
            if (num == k)
                ans++;
        }
    }
    cout << ans << endl;
}

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

    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int b_count = -1;
    for (int i = s.length() - 1; i >= 0; i--) {
        if (s[i] == 'W') {
            b_count = i;
            break;
        }
    }
    if (b_count == -1) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    for (int i = b_count - 1; i >= 0; i--) {
        if (s[i] == 'B') {
            ans += b_count - i;
            b_count--;
        }
    }
    cout << ans << endl;
    return 0;
}

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


#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, deque<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }



int main() {
    int N; 
    long long K;
    cin >> N >> K;
    vector<vector<int>> next(60, vector<int>(N));
    for (int v = 0; v < N; ++v) cin >> next[0][v], --next[0][v];
    for (int d = 0; d + 1 < 60; ++d) {
        for (int v = 0; v < N; ++v) {
            next[d+1][v] = next[d][next[d][v]];
        }
    }
    int v = 0;
    for (int d = 0; d < 60; ++d) {
        if (K & (1LL<<d)) v = next[d][v];
    }
    cout << v + 1 << endl;
}

Measured memory_bytes: 51016
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[n-1-i];
  }
  vector<int> dp(n,2e9);
  for(int i=0;i<n;i++){
    int t=distance(dp.begin(),upper_bound(dp.begin(),dp.end(),a[i]));
    dp[t]=a[i];
  }
  cout << distance(dp.begin(),lower_bound(dp.begin(),dp.end(),2e9)) << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){

    int S,h,m,s;
    scanf("%d", &S);

    h = S / 3600;
    m = (S - h*3600)/60;
    s = S - h*3600 - m*60;

    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

Measured memory_bytes: 592
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	s := make([]int, m)
	c := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&s[i], &c[i])
	}

	for i := 0; i < 1000; i++ {
		str := strconv.Itoa(i)
		rstr := []rune(str)
		if len(rstr) != n {
			continue
		}

		ans := true
		for j := 0; j < m; j++ {
			if string(rstr[s[j]-1]) != strconv.Itoa(c[j]) {
				ans = false
			}
		}
		if ans {
			fmt.Println(i)
			return
		}
	}

	fmt.Println(-1)
}

func reverse(str string) string {
	rs := []rune(str)
	for i, j := 0, len(str)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}


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

using namespace std;

int main() {
    pair <int, int> a[300000];
    long long int n, i, s=0, b[300000]={}, x, y;
    scanf("%lld", &n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld", &a[i].first);
        a[i].second=i;
    }
    sort(a+1, a+n+1);
    x=1;
    while(x<=n)
    {
        y=x;
        while(a[x].first==a[y].first)
            y++;
        for(i=x;i<y;i++)
            b[a[i].second]=y-x;
        s+=(y-x)*(y-x-1)/2;
        x=y;
    }
    for(i=1;i<=n;i++)
    {
        printf("%lld\n", s-b[i]+1);
    }
    
    
    
    
    return 0;
}

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

long long solve(long long n, vector<int> d, int first) {
  int sz = d.size();
  long long s = 0;
  long long mt = 1;
  for (int i = sz - 1; i >= 0; --i)
    s += d[i] * mt, mt *= 10;
  mt = 1;
  for (int i = 0; i < sz; ++i)
    mt *= 10;
  return (mt * first + s <= n ? first + accumulate(d.begin(), d.end(), 0) : -1);
}

int main() {
  long long n, x;
  scanf("%lld", &n), x = n;
  vector<int> d;
  while (n / 10 > 0) {
    d.push_back(9);
    n /= 10;
  }
  long long ans = -1;
  for (int i = 0; i < 10; ++i)
    ans = max(ans, solve(x, d, i));
  printf("%lld\n", ans);
  return 0;
}

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

int main(){
  ll i,N,a,ans=0;cin>>N;
  for(i=1;i*i<=N;i++){
    if(N%i==0)a=i;
  }
  a=N/a;
  while(a){
    a/=10;
    ans++;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {

	int room[4][3][10] = { 0 };

	int n;

	cin >> n;
	int b, f, r, v;
	for (int i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;

		room[b - 1][f - 1][r - 1] += v;

		
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j<3; j++) {
			for (int k = 0; k < 10; k++) {
				cout <<" "<< room[i][j][k];
				if (k == 9)cout << endl;

			}
			if (j == 2 &&i!=3)cout << "####################" << endl;
		}
	}


	return 0;
}



Measured memory_bytes: 3104