akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define all(v) (v).begin(), (v).end()

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

    string als,ls,rs,rls,rrs;
    als = s;
    reverse(all(als));
    if(s != als){
        cout << "No";
        return 0;
    }
    ls = s.substr(0, (s.length()-1)/2);
    rls = ls;
    reverse(all(rls));
    if(ls != rls){
        cout << "No";
        return 0;
    }
    rs = s.substr((s.length())/2+1, s.length());
    rrs = rs;
    reverse(all(rrs));
    if(rs != rrs){
        cout << "No";
        return 0;
    }
    cout << "Yes";
 

}

Measured memory_bytes: 256
N, K = map(int, input().split())
P = list(map(lambda x:int(x)-1, input().split()))
C = list(map(int, input().split()))

ans = -10**29
for start in range(N):
    now = start
    point = 0
    for j in range(K):
        now = P[now]
        point += C[now]
        ans = max(ans, point)
        if now == start:
            break
    loop_cnt = j+1
    left_k = K - loop_cnt
    if point < 0: continue
    tmp = point
    point *= left_k // loop_cnt + 1
    point -= tmp
    ans = max(ans, point)
    for j in range(left_k%loop_cnt+loop_cnt):
        now = P[now]
        point += C[now]
        ans = max(ans, point)

print(ans)


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

int main () {
  int n;
  cin>>n;
  int a[n];
  for (int i=0;i<n;i++) {
    cin>>a[i];
  }
  int dp[n]={0,abs(a[1]-a[0])};
  if (n==2) {
    cout<<abs(a[1]-a[0])<<endl;
  }
  else {
    for (int i=2;i<n;i++) {
      if (dp[i-2]+abs(a[i]-a[i-2])<=dp[i-1]+abs(a[i]-a[i-1])) {
        dp[i]=dp[i-2]+abs(a[i]-a[i-2]);
      }
      else {
        dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
      }
    }
    cout<<dp[n-1]<<endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
	int u,s;
	string t;
	cin>>t;
	u=(t[0]-'0')*10+t[1]-'0';
	s=(t[2]-'0')*10+t[3]-'0';
	if((u>12&&s>12)||(u==0&&s==0)||(u>12&&s==0)||(u==0&&s>12))cout<<"NA";
	else if(u<=12&&(s>12||s==0))cout<<"MMYY";
	else if((u>12||u==0)&&s<=12)cout<<"YYMM";
	else cout<<"AMBIGUOUS";
	cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 200005;
const ll MOD = 1000000007;

int n, a[MAXN];
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n;
    ll suf = 0;
    REP (i, n) {
        cin >> a[i];
        suf += a[i];
    }

    ll pre = 0, ans = 0x3f3f3f3f3f3f3f3f;
    REP (i, n-1) {
        pre += a[i];
        suf -= a[i];
        ans = min(ans, abs(pre - suf));
    }

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  }
  else if ((A + B) == (C + D)) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
import sys
import math
from io import StringIO
import unittest

lines = [[0,1,2], [3,4,5], [6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]

def resolve():
    table = [int(s) for s in input().split()]
    table += [int(s) for s in input().split()]
    table += [int(s) for s in input().split()]

    lis = [int(input()) for _ in range(int(input()))]

    ans = [ n in lis for n in table ]

    for line in lines:
        valid = True
        for num in line:
            if not ans[num] :
                valid = False
                break

        if valid:
            print('Yes')
            return

    print('No')
resolve()

Measured memory_bytes: 50928
#include <iostream>
#include <bitset>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX_N = 10;

int main(int argc, char const *argv[])
{
    int n, m, k[MAX_N], p[MAX_N];

    cin >> n >> m;
    vector<vector<int> > s(m);
    for (int i = 0; i < m; ++i) {
        cin >> k[i];
        for (int j = 0; j < k[i]; ++j) {
            int si;
            cin >> si;
            si--;
            s[i].emplace_back(si);
        }
        sort(s[i].begin(), s[i].end());
    }
    for (int i = 0; i < m; ++i) {
        cin >> p[i];
    }

    int ans = 0;

    for (int i = 0; i < (1<<n); ++i) {
        bitset<10> bs(i);
        vector<int> switchs;
        for (int j = 0; j < n; ++j) {
            if (bs[j]==1) {
                switchs.emplace_back(j);
            }
        }
        int cnt = 0;
        for (int j = 0; j < m; ++j) {
            vector<int> vec_inter;
            set_intersection(switchs.begin(), switchs.end(), s[j].begin(), s[j].end(), std::back_inserter(vec_inter));
            if (vec_inter.size()%2==p[j]) cnt++;
        }
        if (cnt==m) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

def main():
    N,K,S = map(int,input().split())
    if S == 10**9:
        l = [S]*K+[S-1]*(N-K)
    else:
        l = [S]*K+[S+1]*(N-K)
    
    print(*l)
    
if __name__ == "__main__":
    main()


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int h,w; cin >> h >> w;
  for(int i = 0; i < h; ++i){
    string s; cin >> s;
    cout << s << endl << s << endl;
  }
}



Measured memory_bytes: 3632
/*
██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗
██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗
█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║
██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║
██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝
╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝
Believe in yourself ,( try and try and then try ), You can do it
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define clr(arr, x) memset(arr, x, sizeof arr)
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define OO 0x3f3f3f3f3f3f3f3fLL
const int oo = 0x3f3f3f3f, Mod = 1e9 + 7;
using namespace std;
typedef long long ll;
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K(){
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int n;
vector<int>arr;
ll dp[3005][3005][2];
ll sol(int i, int j, int turn){
	if (i > j)
		return 0;
	ll &ret = dp[i][j][turn];
	if (~ret)
		return ret;
	if (!turn){
		ll ch1 = sol(i + 1, j, !turn) + arr[i];
		ll ch2 = sol(i, j - 1, !turn) + arr[j];
		return ret = max(ch1, ch2);
	}
	else{
		ll ch1 = sol(i + 1, j, !turn) - arr[i];
		ll ch2 = sol(i, j - 1, !turn) - arr[j];
		return ret = min(ch1, ch2);
	}
}
int main(){
	K_K();
	cin >> n;
	arr.resize(n);
	clr(dp, -1);
	for (auto &it : arr)
		cin >> it;
	cout << sol(0, n - 1, 0);
}

Measured memory_bytes: 144924
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int n,a[maxn],m;
ll s[maxn],L[maxn],R[maxn];

int main() {
   // freopen("in.cpp","r",stdin);
    cin>>n>>m;
    for(int i=1; i<=n; i++) {
        cin>>a[i];
        s[i] = s[i-1] + a[i];
    }
    for(int i=1; i<=n; i++) {
        L[i] = L[i-1];
        if(a[i]>0)L[i] += a[i];
    }
    for(int i=n; i>=1; i--) {
        R[i] = R[i+1];
        if(a[i]>0)R[i] += a[i];
    }
    ll ret=0;
    for(int i=1;i<=n;i++){
        if(i+m-1>n)break;
        ll tmp = max(0LL, s[i+m-1]-s[i-1]);
        //cout<<"dfs"<<tmp<<endl;
        if(i>1)tmp+=L[i-1];
        if(i+m-1<n)tmp+=R[i+m];
        ret=max(ret,tmp);
    }
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

const int MAX = 100005;
vector<P> g[MAX];
int x[MAX];
bool used[MAX];
vector<int> ans;
int dfs(int v) {
   used[v] = true;
   int res = x[v];
   for (P e : g[v]) {
      if (used[e.first]) continue;
      int r = dfs(e.first);
      if (r) ans.push_back(e.second);
      res ^= r;
   }
   return res;
}

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

   int n, m;
   cin >> n >> m;
   vector<P> a(n);
   rep(i, 0, n) cin >> a[i].first >> a[i].second;
   sort(a.begin(), a.end());
   x[0] = a[0].second;
   rep(i, 0, n - 1) x[i + 1] = a[i].second ^ a[i + 1].second;
   x[n] = a[n - 1].second;

   rep(i, 0, m) {
      int l, r;
      cin >> l >> r;
      l = lower_bound(a.begin(), a.end(), P(l, 0)) - a.begin();
      r = upper_bound(a.begin(), a.end(), P(r, 1)) - a.begin();
      g[l].emplace_back(r, i + 1);
      g[r].emplace_back(l, i + 1);
   }
   rep(i, 0, n + 1) {
      if (used[i]) continue;
      if (dfs(i)) {
         cout << -1 << endl;
         return 0;
      }
   }
   cout << ans.size() << endl;
   sort(ans.begin(), ans.end());
   rep(i, 0, ans.size())
       printf("%d%c", ans[i], i == ans.size() - 1 ? '\n' : ' ');
   return 0;
}

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

int sums[100005];

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int n,q;cin>>n>>q;
  string s;cin>>s;
  for(int i=1;i<s.size();i++){
    if(s[i]=='C'&&s[i-1]=='A')sums[i]++;
    sums[i]+=sums[i-1];
  }
  while(q--){
    int l,r;cin>>l>>r;l--,r--;
    cout<<sums[r]-sums[l]<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 4164
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  // freopen("input.txt", "r", stdin);

  int n, l; cin >> n >> l;
  vector<int> t(n); REP(i, n) cin >> t[i];
  double x = 0, y = 0;
  long long nC3 = (long long)n * (n - 1) * (n - 2) / 6;
  REP(i, n) FOR(j, i + 1, n) {
    int small = i + (n - j - 1), big = j - i - 1;
    x += cos(M_PI * (t[i] + t[j]) / l) * small / nC3;
    y += sin(M_PI * (t[i] + t[j]) / l) * small / nC3;
    x -= cos(M_PI * (t[i] + t[j]) / l) * big / nC3;
    y -= sin(M_PI * (t[i] + t[j]) / l) * big / nC3;
  }
  printf("%.10f %.10f\n", x, y);
  return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    rep(i, s.size() - 2)
    {
        if (s.substr(i, 3) == "ABC")
            cnt++;
    }

    OP(cnt);
    return 0;
}

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


typedef struct {
  int men[6];
}dice;



int dice_change(dice *d,int x,int y,int k)
{
  if((x == d->men[1] && y == d->men[2]) ||(x == d->men[2] && y == d->men[4]) ||(x == d->men[4] && y == d->men[3]) ||(x == d->men[3] && y == d->men[1])){
  k = d->men[0];
  return k;
  }
  else if((x == d->men[0] && y == d->men[3]) ||(x == d->men[3] && y == d->men[5]) ||(x == d->men[5] && y == d->men[2]) ||(x == d->men[2] && y == d->men[0])){
  k = d->men[1];
  return k;
  }
  else if((x == d->men[0] && y == d->men[1]) ||(x == d->men[1] && y == d->men[5]) ||(x == d->men[5] && y == d->men[4]) ||(x == d->men[4] && y == d->men[0])){
    k = d->men[2];
  return k;
  }
  else if((x == d->men[0] && y == d->men[4]) ||(x == d->men[4] && y == d->men[5]) ||(x == d->men[5] && y == d->men[1]) ||(x == d->men[1] && y == d->men[0])){
    k = d->men[3];
  return k;
  }
  else if((x == d->men[0] && y == d->men[2]) ||(x == d->men[2] && y == d->men[5]) ||(x == d->men[5] && y == d->men[3]) ||(x == d->men[3] && y == d->men[0])){
    k = d->men[4];
  return k;
  }
  else if((x == d->men[1] && y == d->men[3]) ||(x == d->men[3] && y == d->men[4]) ||(x == d->men[4] && y == d->men[2]) ||(x == d->men[2] && y == d->men[1])){
    k = d->men[5];
  return k;
  }
}

int main()
{

  int i,n = 0;
  int k = 9;
  int x,y;
  int dice_right = 0;
  dice s;


  for (i = 0; i < 6; i++)
    scanf("%d", &s.men[i]);

  scanf("%d",&n);

  int dice_kekka[n];

  for(i = 0;i < n;i++)
    {
    scanf("%d",&x);
    scanf("%d",&y);
                                                                                                                                                                                                                                                 dice_kekka[i] = dice_change(&s,x,y,k);
    }
  for(i = 0;i < n;i++)                                                                                                                                                                                                                         printf("%d\n",dice_kekka[i]);
  return 0;

}


Measured memory_bytes: 2012
#include <bits/stdc++.h>
#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void)
{
    string n;
    cin >> n;
    ((n[0] == n[2]) ? (puts("Yes")) : (puts("No")));
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))

tmp_num=1
tmp_cnt=0
cnt=0
for i in range(n):
    if a[i]==tmp_num:
        tmp_num+=1
        cnt+=tmp_cnt
        tmp_cnt=0
    else:
        tmp_cnt+=1
cnt+=tmp_cnt
print(-1 if tmp_cnt==len(a) else cnt)


Measured memory_bytes: 24744
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

template <size_t T>
bool prevSubset(bitset<T>& bs, const bitset<T>& mask)
{
    bs = bs.to_ulong() - 1ull;
    bs &= mask;
    if(bs.none())
        return false;
    return true;
}

const int INF = INT_MAX / 2;

int main()
{
    int n;
    cin >> n;
    vector<int> v(3);
    for(int i=0; i<3; ++i)
        cin >> v[i];
    vector<int> l(n);
    for(int i=0; i<n; ++i)
        cin >> l[i];

    vector<int> dp(1<<n, INF);
    dp.back() = 0;
    for(int i=0; i<3; ++i){
        vector<int> nextDp(1<<n, INF);
        for(int a=1; a<(1<<n); ++a){
            bitset<32> mask(a);
            bitset<32> bs = mask;
            do{
                int sum = 0;
                for(int j=0; j<n; ++j){
                    if(bs[j])
                        sum += l[j];
                }
                int b = (mask ^ bs).to_ulong();
                nextDp[b] = min(nextDp[b], dp[a] + abs(sum - v[i]) + ((int)bs.count() - 1) * 10);
            }while(prevSubset(bs, mask));
        }
        dp = move(nextDp);
    }
    int ans = *min_element(dp.begin(), dp.end());
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#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() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n;
  cin >> n;

  string ans = "";
  while(n != 0) {
    int v = n % 26 - 1;
    if(v < 0) v += 26;
    char c = v + 'a';
    ans.push_back(c);
    if(n % 26 == 0) {
      n /= 26;
      n--;
    }
    else n /= 26;
  }
  reverse(ans.begin(),ans.end());
  cout << ans << '\n';
}


Measured memory_bytes: 3652
fun main(args: Array<String>) {

    val n = readLine()!!.toInt()
    val s = readLine()!!

    var sum = 0
    for (i in 0..999) {
        var chars = "%03d".format(i).toCharArray()
        var si = 2
        for (j in 0 until n) {

            if (s[j] == chars[si]) {
                si -= 1
            }

            if (si == -1) {
                sum++
                break;
            }
        }
    }
    println(sum)
}

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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

char s[maxn];
int a,b,n;

int main() {
    scanf("%s",s+1);n=strlen(s+1);
    ll ans=0;
    for(int i=1;i<=n;i++)
        if(s[i]=='B') b++;
        else ans+=b;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let s: Vec<char> = iter.next().unwrap().chars().collect();
    let n = s.len();
    let k: usize = iter.next().unwrap().parse().unwrap();
    
    let mut heap = std::collections::BinaryHeap::<Rev<(Vec<char>, usize)>>::new();
    for i in 0..n {
        heap.push(Rev((vec![s[i]], i)));
    }
    let mut memo = std::collections::HashSet::new();
    let mut cnt = k;
    while let Some(Rev(mut h)) = heap.pop() {
        if !memo.contains(&h.0) {
            cnt -= 1;
            memo.insert(h.0.clone());
            if cnt == 0 {
                println!("{}", h.0.into_iter().collect::<String>());
                break;
            }
        }
        if h.1 + h.0.len() < n {
            let x = {h.0.len()};
            h.0.push(s[h.1 + x]);
            heap.push(Rev((h.0, h.1)));
        }
    }
}

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);
impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<std::cmp::Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> std::cmp::Ordering {
        other.0.cmp(&self.0)
    }
}

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

l = input()
S1, S2 = [], []

sum = 0
n = len(l)
for i in range(n):
	if l[i] == "\\":
		S1.append(i)
	elif l[i] == "/" and S1:
		j = S1.pop()
		a = i - j
		sum += a

		while S2 and S2[-1][0] > j:
			a += S2.pop()[1]
		S2.append([j, a])

print(sum)
print(len(S2), *(a for j, a in S2))

Measured memory_bytes: 8236
h, n = map(int, input().split())
a, b = [0], [0]
for _ in range(n):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)
dp = [[0 for _ in range(h + max(a))] for _ in range(n + 1)]
for i in range(n + 1):
    for j in range(1, h + max(a)):
        if i == 0:
            dp[i][j] = 10 ** 9
        elif a[i] > j:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i]] + b[i])
ans = 10 ** 9
for i in range(h, h + max(a)):
    if ans > dp[n][i]:
        ans = dp[n][i]
print(ans)

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

#define MOD 1000000007

int h, w, k;
int dp[110][10];

bool isOK(int i){
  int no = 0;
  for(int j = 0;j < 10;j++){
    if(i & (1 << j)){
      if(no == 1){
        return false;
      }else{
        no = 1;
      }
    }else{
      no = 0;
    }
  }

  return true;
}

long long dfs(int i, int n){
  if(i == h){
    if(n == k){
      return 1;
    }else{
      return 0;
    }
  }

  if(dp[i][n] != -1){
    return dp[i][n];
  }


  long long ans = 0;
  for(int j = 0;j < (1 << (w-1));j++){
    if(isOK(j)){
      if((j & (1 << n))){
        ans = (ans + dfs(i+1, n+1)) % MOD;
      }else if(0 < n && (j & (1 << (n-1)))){
        ans = (ans + dfs(i+1, n-1)) % MOD;
      }else{
        ans = (ans + dfs(i+1, n)) % MOD;
      }
    }
  }

  return dp[i][n] = ans;
}

int main(){
  cin >> h >> w >> k;
  k--;

  memset(dp,-1,sizeof(dp));


  cout << dfs(0, 0) << endl;

  return 0;
}

Measured memory_bytes: 256
// 解き直し.
// https://img.atcoder.jp/m-solutions2019/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repx(i, a, b) for(LL i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
const LL MOD = 1e9 + 7;
const LL LIMIT = 202020;
LL FAC[LIMIT + 1];
LL INV[LIMIT + 1];

// Fermat's little theorem から, 大きな冪乗の計算を行う.
// @param a: べき乗したい正整数.
// @param b: 指数.
// @return:  べき乗した計算結果(mod版).
LL mPow(LL a, LL b){
    LL t = 1;
    while(b){
        if(b & 1) t = (t * a) % MOD;
        a *= a;
        a %= MOD;
        b >>= 1;
    }
    return t % MOD;
}

// 組み合わせ(nCk)計算用(mod版).
// ※配列FAC, INV は, 事前に計算済のものを使う.
// @param n: 対象となる要素の個数.
// @param k: 選択する要素の個数.
// @return: 組み合わせ(nCk)の計算結果.
LL combination(LL n, LL k){
    if(n < 0 || k < 0 || k > n) return 0;
    LL ret = FAC[n] * INV[k] % MOD * INV[n - k] % MOD;
    return ret;
}

int main(){

    // 1. 入力情報.
    LL N, A, B, C;
    scanf("%lld %lld %lld %lld", &N, &A, &B, &C);
    FAC[0] = 1;
    repx(i, 1, LIMIT) FAC[i] = i * FAC[i - 1] % MOD;
    rep(i, LIMIT)     INV[i] = mPow(FAC[i], MOD - 2) % MOD;
    // printf("%lld\n", combination(30, 5)); // 142506 で OK.
    
    // 2. 解説参照(※一部修正).
    // 2-1. 分母.
    // ※ 解説上, mPow(100, N - 1) * (100 - C) の 形で記載されていたが, 
    // mPow(100, M) * (100 - C) が 正しいと推測されるので, 方針を変更.
    // -> 但し, 100 の M乗 の場合, M は 動的に変わるので, 
    // 計算しやすくするため, mPow(100, 2 * N - 2) * (100 - C) の 形に統一.
    // -> そもそも, 解説上, A, B は, 引き分けが無い場合で取り扱っているので, 
    // ここでは, A = 100 * A / (A + B), B = 100 * B / (A + B) に 変換して考える必要がある.
    // -> 以上を考慮すると, 分母は, mPow(A + B, M) * (100 - C) となる.
    // -> 但し, M は 動的に変わるので, 計算しやすくするため, mPow(A + B, 2 * N - 1) * (100 - C) を 採用.
    // -> A + B = 100 - C なので, mPow(A + B, 2 * N) と 式変形.
    LL Q = mPow(A + B, 2 * N) % MOD;
    
    // 2-2. 分子.
    LL P = 0, subP;
    repx(i, N, 2 * N){
        subP = mPow(A, N) * mPow(B, i - N) % MOD;
        subP += mPow(A, i - N) * mPow(B, N) % MOD;
        subP %= MOD;
        subP *= i;
        subP %= MOD;
        subP *= 100;
        subP %= MOD;
        subP *= combination(i - 1, N - 1);
        subP %= MOD;
        subP *= mPow(A + B, 2 * N - 1 - i);
        subP %= MOD;
        P += subP;
        P %= MOD;
    }
    // printf("P=%lld Q=%lld\n", P, Q);
    
    // 3. R の 計算.
    // 3-1. P, Q を 最大公約数 で 割り戻す.
    LL gcdPQ = __gcd(P, Q);
    P /= gcdPQ;
    Q /= gcdPQ;
    
    // 3-2. Q の 逆元 から, R を 計算.
    LL R = P * mPow(Q, MOD - 2) % MOD;
    // printf("P=%lld Q=%lld R=%lld\n", P, Q, R);
    
    // 4. 出力.
    printf("%lld\n", R);
    return 0;
    
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, M;

int main()
{
    while (cin >> N >> M)
    {
        if (N == 0 && M == 0)
            return 0;
        map<int, int> mp;
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            int d, v;
            cin >> d >> v;
            mp[d] = max(mp[d], v);
        }
        for (auto &p : mp)
        {
            ans += p.second;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3088
def main():
    n = int(input())
    s = input()
    w_ruisekiwa = [0] * (n+1)
    e_ruisekiwa = [0] * (n+1)

    for i in range(n):
        w_ruisekiwa[i+1] = w_ruisekiwa[i] + (1 if s[i] == "W" else 0)
        e_ruisekiwa[i+1] = e_ruisekiwa[i] + (1 if s[i] == "E" else 0)

    mn = 10 ** 10

    for i in range(n):
        l_total = w_ruisekiwa[i] - w_ruisekiwa[0]
        r_total = e_ruisekiwa[n] - e_ruisekiwa[i+1]
        mn = min(l_total + r_total,mn)

    print(mn)






if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;


int main(){
	//ios_base::sync_with_stdio(0);
	int N, ans=0;
	int s[105];

	cin >> N;
	rep(i,N) cin >> s[i];

	bool dp[100005]={};
	dp[0] = true;
	rep(i,N) rrep(j,10005){
		if( dp[j] ){
			dp[ j + s[i] ] = true;
		}
	}

	rrep(j,10005){
		if( dp[j] && j % 10 ){
			ans = j;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
    int K,S;
    cin >> K >> S;
    int buf = 0;
    int count = 0;
    for(int i=0;i<K+1;i++) {
        for(int j=0;j<K+1;j++) {
            buf = S - i - j;
            if (0 <= buf and buf <= K) {
                count++;
            }
        }
    }
    cout << count << endl;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

int main()
{
    int n ;
    cin >> n ;
    int x = n * 800 - (n/15) * 200 ;
    cout << x ;

    return 0 ;
}


Measured memory_bytes: 256
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return(false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return(true);
  }

  int find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = find(data[k]));
  }

  int size(int k)
  {
    return(-data[find(k)]);
  }

  bool same(int x, int y)
  {
      return find(x) == find(y);
  }
};

string op(int sign)
{
    return sign == 0 ? "+" : "-";
}

int main()
{
    string s;
    cin >> s;
    int A = s[0] - '0';
    int B = s[1] - '0';
    int C = s[2] - '0';
    int D = s[3] - '0';
    REP(i, 2) REP(j, 2) REP(k, 2)
    {
        int sum = A;
        sum += (i == 0) ? B : -B;
        sum += (j == 0) ? C : -C;
        sum += (k == 0) ? D : -D;
        if (sum == 7)
        {
            cout << A << op(i) << B << op(j) << C << op(k) << D << "=7" << endl;
            return 0;
        }
    }
    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
//template end



int main(){
    ll n; scanf("%lld",&n);
    bool f=0;
    rep(i,1,10)rep(j,1,10)if(i*j==n)f=1;
    printf(f?"Yes\n":"No\n");
    return 0;
}

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

int v,e;
char a[100100];
vector<int> g[100100];

int main(){
  cin >> v >> e;
  for(int i=0;i<v;i++)cin >> a[i];
  for(int i=0;i<e;i++){
    int s,t;
    cin >> s >> t;
    g[s].push_back(t); g[t].push_back(s);
  }

  for(int i=0;i<v;i++){
    if(a[i] == '?'){
      bool use[30] = {};
      for(int j=0;j<(int)g[i].size();j++){
	int u = g[i][j];
	if(a[u] != '?')use[a[u]-'a'] = true;
      }
      
      for(int j=0;j<26;j++){
	if(!use[j]){
	  cout << (a[i] = (char)('a' + j));
	  break;
	}
      }
    }else cout << a[i];
  }
  cout << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 998244353;
const int N = (int)2e5 + 10;
int pw[N];

int dd[N][5];
int tree[N * 2 + 512];

int lim;
void upd(int idx, int v){
  idx += lim;
  tree[idx] += v;
  idx /= 2;
  while(idx > 0){
    tree[idx]=tree[idx*2]+tree[idx*2+1];
    idx /= 2;
  }
}

int ask(int l, int r){
  l += lim;
  r += lim;
  int cc = 0;
  while(l <= r){
    if(l % 2 == 1) cc += tree[l ++ ];
    if(r % 2 == 0) cc += tree[r -- ];
    l /= 2;
    r /= 2;
  }
  return cc;
}

int main(){
  fastIO;
  pw[0]=1;
  for(int i = 1; i < N ; i ++ )
    pw[i]=(pw[i-1]*2ll)%MOD;
  int n;
  cin >> n;
  lim = n;
  vector<int> xc, yc;
  vector<pii> cc(n);
  for(int i = 0 ; i < n; i ++ ){
    cin >> cc[i].fi >> cc[i].se;
    xc.push_back(cc[i].fi);
    yc.push_back(cc[i].se);
    dd[i][4]=1;
  }
  sort(xc.begin(),xc.end());
  sort(yc.begin(),yc.end());
  for(auto &p : cc){
    p.fi = lower_bound(xc.begin(), xc.end(), p.fi) - xc.begin();
    p.se = lower_bound(yc.begin(), yc.end(), p.se) - yc.begin();
  }
  sort(cc.begin(), cc.end());
  for(int i = 0 ; i < n; i ++ ){
    dd[i][3]=ask(0,cc[i].se);
    dd[i][0]=ask(cc[i].se,n-1);
    upd(cc[i].se, +1);
  }
  for(int i = 0 ; i <= n * 2 + 10; i ++ ){
    tree[i]=0;
  }
  for(int i = n - 1; i >= 0 ; i -- ){
    dd[i][2]=ask(0,cc[i].se);
    dd[i][1]=ask(cc[i].se,n-1);
    upd(cc[i].se, +1);
  }
  int cur;
  int answ = 0;
  for(int i = 0 ; i < n ; i ++ ){
    for(int q = 0 ;q < 32; q ++ ){
      vector<bool> hh;
      for(int k = 0 ; k < 5; k ++ ){
        if((q&(1<<k)))hh.push_back(true);
        else hh.push_back(false);
      }
      if(hh[4] || (hh[0] && hh[2]) || (hh[1] && hh[3])) cur = 1;
      else cur = 0;
      for(int q = 0; q < 5; q ++ ){
        if(hh[q]){
          cur = (cur * 1ll * (pw[dd[i][q]] - 1)) % MOD;
        }
      }
      answ = (answ + cur) % MOD;
    }
  }
  cout << answ << "\n";
  return 0; 
}


Measured memory_bytes: 9836
n = int(input())
string_a = input()
string_b = input()
string_c = input()

ans = 0
for a, b, c in zip(string_a, string_b, string_c):
    if a == b:
        if a != c:
            ans += 1
    else:
        if a != c and b != c:
            ans += 2
        else:
            ans += 1
print(ans)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(200002, 0);
  string out = "IMPOSSIBLE";
  for(int i = 0; i < m; i++){
    int c, d;
    cin >> c >> d;
    if(c == 1) a.at(d)++;
    if(d == n) a.at(c)++;
    if(a.at(d) == 2){
      out = "POSSIBLE";
    }
    if(a.at(c) == 2){
      out = "POSSIBLE";
    }
  }
  cout << out;
}

Measured memory_bytes: 1024
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
#include<numeric>
#include<chrono>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
#define mkp(a,b) make_pair(a,b)
using namespace std;
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	// This is code taken from geeksforgeek
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
/*ll power(ll x, ll y)
{
	// This is code taken from geeksforgeek
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}*/
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x);

		y = y >> 1;
		x = (x * x);
	}
	return res;
}


/*ll modInverse(ll n, ll p)
{
	return power(n, p - 2, p);
}*/

ll sum(ll n)
{
	return (n * (n + 1)) / 2;
}
ll sum_digit(ll n)
{
	ll ans = 0;
	while (n)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	s[k-1]=tolower(s[k-1]);
	cout<<s;
	return 0;
}


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

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

using namespace std;

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  rep(i, n) std::cin >> a[i];

  std::set<int> se;

  int wild = 0;
  rep(i, n) {
    if (a[i] >= 3200) {
      wild++;
    } else {
      se.insert(a[i] / 400);
    }
  }

  int maxv = se.size() + wild;
  int minv = 0;
  if (se.size() == 0) {
    minv = 1;
  } else {
    minv = se.size();
  }

  std::cout << minv << " " << maxv << std::endl;

  return 0;
}


Measured memory_bytes: 3604
import scala.io.StdIn.readLine

object Main extends App {
  val Array(r, c) = readLine.split(" ").map(_.toInt)

  val records = for (e <- 1 to r) yield {
    val record = readLine().split(" ").map(_.toInt).toBuffer
    record :+ record.sum
  }

  val lastRecord = scala.collection.mutable.ArrayBuffer[Int]()

  for (i <- 0 to c) {
    var sum = 0
    for (j <- 0 until r) {
      sum += records(j)(i)
    }
    lastRecord += sum
  }

  for (e <- records) println(e.mkString(" "))
  println(lastRecord.mkString(" "))
}


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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long)(1e15)
//#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');
    cerr.write(names, name-names) << " = " << arg1 << endl;
    _F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){
    in >> q.F >> q.S; return in;
}template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}

void solve(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(i%3 == 0 && i%5 == 0)ans += 0;
        else if(i%3 && i%5)ans += i;
        else ans += 0;
    }
    cout << ans << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(12);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif

    //cin >> t;

    for(int i = 1; i <= t; ++i){
        //cout << "Case #" << i << ": ";
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}

Measured memory_bytes: 3660
n=input()
n_list=[]
for letter in n:
    n_list.append(int(letter))
last_integer=0
count=0
max_count=0
for n in n_list:
    if n!=last_integer:
        last_integer=n
        count=1
    else:
        count+=1
    if count>max_count:
        max_count=count
if max_count>=3:
    print("Yes")
else:
    print("No")

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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

void solve()
{
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();
  if(n <= k)
  {
    cout << s;
  }
  else
  {
    cout << s.substr(0,k);
    cout << "...";
  }
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 3684
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

const int SIZE = 510;

double dp[SIZE][SIZE];

int main(){
  int n,m;
  int a[SIZE];
  long long sum[SIZE];
  
  scanf("%d%d",&n,&m);

  sum[0] = 0;

  for(int i=0;i<n;i++){
    scanf("%d",a+i);
    sum[i+1] = a[i] + sum[i];  
  }

  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      dp[i][j] = -1e18;
    }
  }

  dp[0][0] = 0;

  double ans = 0;
  
  for(int i=0;i<m;i++){
    for(int j=0;j<=n;j++){
      for(int k=j+1;k<=n;k++){
        dp[i+1][k] = max(dp[i+1][k], dp[i][j] + (double)(sum[k] - sum[j]) / (k-j));
      }
    }
  }

  for(int i=0;i<m;i++){
    ans = max(dp[i+1][n], ans);
  }
  
  printf("%.10lf\n",ans);
  
  return 0;
}
  




Measured memory_bytes: 4752
let () =
  let counter = ref 0 in
  let rec msort (array : int array) left right =
    let merge (array : int array) left mid right =
      let init n p = Array.init (n+1) (fun i -> if i=n then max_int else array.(p+i)) in
      let xs = init (mid-left) left in
      let ys = init (right-mid) mid in
      let rec loop i j k =
        if k < right then
          (incr counter;
           if xs.(i) <= ys.(j) then (array.(k) <- xs.(i); loop (i+1) j (k+1))
           else (array.(k) <- ys.(j); loop i (j+1) (k+1)) )
      in loop 0 0 left in
    if left+1 < right then
      let mid = (left+right)/2 in
      msort array left mid;
      msort array mid right;
      merge array left mid right in
  let n = read_int () in
  let (l : int array) = Array.init n (fun _ -> Scanf.scanf "%d " (fun x -> x)) in
  msort l 0 n;
  Array.iteri (fun i v -> Printf.printf (if i = n-1 then "%d\n" else "%d ") v) l;
  Printf.printf "%d\n" !counter

Measured memory_bytes: 19384
import java.io.*;
import java.text.*;
import java.util.*;

public class Main{

    static InputReader sc = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        solver s = new solver();
        int t = 1;
        while (t > 0) {
            s.solve();
            t--;
        }
        out.close();
    }

    static class InputReader {

        public BufferedReader br;
        public StringTokenizer token;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream), 32768);
            token = null;
        }

        public String sn() {
            while (token == null || !token.hasMoreTokens()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return token.nextToken();
        }

        public int ni() {
            return Integer.parseInt(sn());
        }

        public String snl() throws IOException {
            return br.readLine();
        }

        public long nlo() {
            return Long.parseLong(sn());
        }

        public double nd() {
            return Double.parseDouble(sn());
        }

        public int[] na(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.ni();
            return a;
        }

        public long[] nal(int n) {
            long a[] = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.nlo();
            return a;
        }
    }

    static int inf = 5000013;

    static class solver {
        DecimalFormat df = new DecimalFormat("0.00000000");
        long maxi = Integer.MAX_VALUE;
        long mod = (long) (1e9 + 7);

        void solve() {
            int n = sc.ni();
            double h[] = new double[n];
            double t[] = new double[n];
            for (int i = 0; i < n; i++) {
                h[i] = sc.nd();
                t[i] = 1 - h[i];
            }
            double dp[][] = new double[n + 1][n + 1];
            dp[0][0] = 1.0;
            for (int i = 1; i <= n; i++) {
                for (int j = 0; j <= i; j++) {
                    if (j == 0)
                        dp[i][j] = dp[i - 1][j] * (t[i - 1]);
                    else
                        dp[i][j] = dp[i - 1][j] * t[i - 1] + dp[i - 1][j - 1] * h[i - 1];
                }
            }
            double ans = 0.0;
            for (int i = 1; i <= n; i++) {
                int d = n - i;
                if (i > d)
                    ans += dp[n][i];
            }
            out.println(ans);
        }
    }
}


Measured memory_bytes: 131404
N = int(input())
A = list(map(int, input().split()))
NN = ((N + 1) * N // 2 + 1) // 2

def ok(x):
    B = [0] * (2 * N + 1)
    res, cum, cur = 0, 0, 0
    B[0] += 1
    for a in A:
        if a >= x:
            cum += 1
            cur += B[cum]+1
        else:
            cur -= B[cum]-1
            cum -= 1
        B[cum] += 1
        res += cur
    return res >= NN

B = sorted(set(A))
l = 0
r = len(B)
while r - l > 1:
    m = (l + r) // 2
    if ok(B[m]):
        l = m
    else:
        r = m
print(B[l])

Measured memory_bytes: 15100