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

void solve(){
    ll n;
    cin >> n;
    matrix open(n,Vi(10));
    matrix p(n,Vi(11));
    rp(i,n){
        rp(j,10) cin >> open[i][j];
    }
    rp(i,n){
        rp(j,11) cin >> p[i][j];
    }
    ll ans=-INF;
    repi(mask,1,1024){
        Vi bits(10);
        rp(i,10){
            bits[i]=(mask>>i)%2;
        }
        ll profit=0;
        rp(i,n){
            ll ctr=0;
            rp(j,10){
                if(open[i][j]==1&&bits[j]==1) ctr++;
            }
            profit+=p[i][ctr];
        }
        chmax(ans,profit);
    }
    print(ans);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

#define _For(idx, from, to, inc, cmp) \
	for(auto idx=(from) ; idx cmp (to) ; inc idx)
#define ForLE(idx, from, to) \
	_For(idx, from, to, ++, <=)
#define ForGE(idx, from, to) \
	_For(idx, from, to, --, >=)
#define ForLT(idx, from, to) \
	_For(idx, from, to, ++, <)
#define ForGT(idx, from, to) \
	_For(idx, from, to, --, >)
#define For(idx, from, to) \
	_For(idx, from, to, ++, <)

void DisableIOSync() {
	std::cin.tie(0);
	std::cout.tie(0);
	std::ios::sync_with_stdio(false);
}

constexpr int NChar = 'z'-'a'+1;
struct Ent {
	int		jump[NChar];
};
constexpr int MaxLen = 200000 + 1;
Ent	Entry[MaxLen];
int Came[MaxLen];
int IdHist[MaxLen];

#include <cstring>
int main() {
	DisableIOSync();

	std::string str;
	std::getline(std::cin, str);
	std::memset(Came, 0xff, sizeof(Came));

	const int Len = str.length();
	int prev[NChar];
	for(auto& p : prev)
		p = Len;
	ForGE(i, Len-1, 0) {
		const auto c = str[i];
		const int id = c - 'a';

		auto& ent = Entry[i];
		For(j, 0, NChar) {
			ent.jump[j] = prev[j] - i;
		}
		prev[id] = i;
	}
	std::vector<int> cand[2];
	For(i, 0, NChar) {
		if(prev[i] == Len) {
			IdHist[Len] = i;
			Came[Len] = -100;
			goto END;
		}
		cand[0].push_back(prev[i]);
		Came[prev[i]] = -100;
		IdHist[prev[i]] = i;
	}
	for(;;) {
		cand[1].clear();
		for(auto& c : cand[0]) {
			auto& ent = Entry[c];
			For(i, 0, NChar) {
				const int next = c + ent.jump[i];
				if(next == Len) {
					Came[next] = c;
					IdHist[next] = i;
					goto END;
				} else {
					if(Came[next] == -1) {
						cand[1].push_back(next);
						Came[next] = c;
						IdHist[next] = i;
					}
				}
			}
		}
		std::swap(cand[0], cand[1]);
	}
	END:
	std::string hist;
	int cur = Len;
	for(;;) {
		hist.push_back(IdHist[cur] + 'a');
		cur = Came[cur];
		if(cur == -100)
			break;
	}
	std::reverse(hist.begin(), hist.end());
	std::cout << hist << std::endl;
	return 0;
}


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

int main(void){

    int n;
    string s;
    
    cin >> n >> s;
    
    int count = 1;
    char prev = s[0];
    for(int i=1; i<s.size(); i++) {
        if(prev != s[i]) {
            count++;
            prev = s[i];
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x,n;
	cin>>x>>n;
	std::vector<int> v;
    std::vector<int> v1;
	int ans=0;
	for(int i=0;i < n;i ++){
		int pi;
		cin>>pi;
		v.push_back(abs(pi-x));
        v1.push_back(pi);
    }
    //
	if(n == 0){
		ans = x;
	}
	else{
        sort(v.begin(),v.end());
        vector<int>::iterator it;
        if(v[0] > 0){
        	ans = x;
        }         
        else{
        	int i;
        	for(i=0;i < n;i ++){
                if(v[i] > (int)((i+1)/2)){
                	ans = x-(int)(i+1)/2;
                	it = find(v1.begin(),v1.end(),ans);
                	if(it != v1.end())
                		ans = x+ (int)(i+1)/2;
                	break;
                }
        	}
        	//
        	if(i == n){
        		ans = x - (int)(n+1)/2;
                it = find(v1.begin(),v1.end(),ans);
                if(it != v1.end())
                    ans = x+ (int)(i+1)/2;
        	}
        }
	}
    cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3628
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-25 18:25:04
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

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

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << '}';
}

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

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

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

  int n; cin >> n;
  vector<int> p(n); cin >> p;

  vector<int> bi(n);

  for (int i = 0; i < n; ++i) bi[p[i] - 1] = i;

  debug(bi);

  int beg = 0;
  int mx = 0;

  while (beg < n) {
    int end = beg;
    while (end + 1 < n && bi[end + 1] > bi[end]) {
      ++end;
    }
    int len = end - beg + 1;
    mx = max(mx, len);
    beg = end + 1;
  }

  cout << n - mx << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int n;
int p[20];
int main(void){
    cin >> n;
    REP(i,n) cin >> p[i];
    int count = 0;
    for(int i=1;i<n-1;i++){
        if ((p[i-1]<p[i] and p[i]<p[i+1]) or (p[i-1]>p[i] and p[i]>p[i+1]))
            count++;    
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	N, K := next(), nextInt()
	n := len(N)

	// dp[i][j][k]: 上からi桁目, nと同じ(1)/未満(0)の数字と確定, 0でない数字がちょうどk個であるものの個数
	dp := make([][2][4]int, n+2)
	// dp[1][0][1] = int(N[0]-'0') - 1
	// dp[1][0][0] = 1
	// dp[1][1][1] = 1
	dp[0][1][0] = 1
	for i := 0; i < n; i++ {
		ni := int(N[i] - '0')
		if ni == 0 {
			// 0を使う場合
			for k := 0; k <= 3; k++ {
				dp[i+1][0][k] = dp[i][0][k]
				dp[i+1][1][k] = dp[i][1][k]
			}
			// 0以外を使う場合
			for k := 0; k < 3; k++ {
				dp[i+1][0][k+1] += 9 * dp[i][0][k]
			}
		} else {
			// 0を使う場合
			for k := 0; k <= 3; k++ {
				dp[i+1][0][k] = dp[i][0][k] + dp[i][1][k]
			}
			// 0以外を使う場合
			for k := 0; k < 3; k++ {
				dp[i+1][0][k+1] += 9*dp[i][0][k] + (ni-1)*dp[i][1][k]
				dp[i+1][1][k+1] += dp[i][1][k]
			}
		}
	}

	ans := dp[n][0][K] + dp[n][1][K]
	puts(ans)
}


Measured memory_bytes: 1812
import java.util.*;

public class Main {
    static int[][] dp;
    static int[] values;
    static int[] weights;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();
        values = new int[n];
        weights = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
            weights[i] = sc.nextInt();
        }
        dp = new int[n][w + 1];
        System.out.println(dfw(n - 1, w));
    }
    
    static int dfw(int idx, int weight) {
        if (weight < 0) {
            return Integer.MIN_VALUE;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][weight] != 0) {
            return dp[idx][weight];
        }
        return dp[idx][weight] = Math.max(dfw(idx - 1, weight), dfw(idx - 1, weight - weights[idx]) + values[idx]);
    }
}


Measured memory_bytes: 31004
m = []
N = gets.to_i
N.times{|i|
  m[i] = gets.split.map &:to_i
}
cost = Array.new(N){Array.new(N, 0x7fffffff)}
N.times{|i| cost[i][i] = 0}
(1..N-1).each{|d|
  (0..N-d-1).each{|first|
    last = first + d
    (first..last-1).each{|s|
      mul = m[first][0] * m[s][1] * m[last][1]
      cost[first][last] = [cost[first][last], cost[first][s] + cost[s+1][last] + mul].min
    }
  }
}
puts cost[0][N-1]

Measured memory_bytes: 8916
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

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

	const int MAX_N = 200000;
	int R[MAX_N];

	rep(i, N){ cin >> R[i];}

	int minR = 2000000000;
	int ret = -minR;

	rep(i, N){
		ret = max(ret, R[i] - minR);
		minR = min(minR, R[i]);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3860
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN) = readLine.split(" ").map(_.toInt)
    val datA = for(i <- 1 to 2) yield (readLine.split(" ").map(_.toInt))

    val ans = (0 until datN).map(x => datA(0).take(x + 1).sum + datA(1).takeRight(datN - x).sum).max
    println(ans)
  }
}


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

using namespace std;

#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 sq(x) ((x) * (x))
#define bit(x) bitset<32>(x)
#define vsort(v)  sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<llint>())
#define debug(x) cout << #x << " " << (x) << endl
#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


template<typename Tn> Tn __lcm(Tn a, Tn b)
{
    return a / __gcd(a, b) * b;
}

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

int main()
{
    int a, p;
    ci >> a >> p;

    co << (a * 3 + p) / 2 << en;
  
    return 0;
}


Measured memory_bytes: 256
"use strict";

const gcdArray = array => {
  let len, a, b;
	
  len = array.length;
	a   = array[0];
	
  for (let i=1; i<len; i++) {
		b = array[i];
		a = getGcd(a, b);
	}

	return a;
}

const getGcd = (a, b) => {
    return a ? getGcd(b % a, a) : b;
}

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    let A = arg[1].split(" ").map(n=>parseInt(n)).sort((a,b)=>b-a);
    
    const max = A[0];
    let   gcd = gcdArray(A);
    
    if(max < K) {
        console.log("IMPOSSIBLE");
        return;
    }
    
    console.log(K % gcd === 0 ? "POSSIBLE" : "IMPOSSIBLE");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N, M;
bool f[100010];

int main() {
	cin >> N >> M;
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		f[a] ^= 1;
		f[b] ^= 1;
	}

	bool ok = 1;
	rep(i, N) {
		if (f[i]) {
			ok = 0;
		}
	}
	puts(ok ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
int a[101];

int main()
{
	int n,x;
	cin>>n;
	
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=1;	
	}	
	
	int s=0;
	for(int i=1;i<=101;i++)
	{
		if(a[i]==1)  s++;
	}
	
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = [int(x) - 1 for x in input().split()]
    answer = {i: 0 for i in range(n)}
    for aa in a:
        answer[aa] += 1
    for i in range(n):
        print(answer[i])


if __name__ == '__main__':
    main()



Measured memory_bytes: 38924
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
        cout << 0 << endl;
    else
        cout << min(min(a * b, a * c), b * c) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
int main(){
    int n,m;
    cin>>n>>m;
    vin a(m);
    rep(i,m)cin>>a[i];
    int sum=0;
    rep(i,m)sum+=a[i];
    int ans=-1;
    if(sum<=n)ans=n-sum;
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>

#define maxn 1000 + 8

using namespace std;

typedef unsigned long long ll;

int n;
char s[maxn];
ll f[maxn][maxn],res;

void figure(int pos,ll num) {
	if (pos>=n) res+=num;
	for (int i=pos;i<n;++i) figure(i+1,num+f[pos][i]);
}

int main() {
	while (scanf("%s",s)==1) {
		n=strlen(s);
		res=0llu;
		for (int i=0;i<n;++i) {
			f[i][i]=ll(s[i]-'0');
			for (int j=i+1;j<n;++j)
				f[i][j]=f[i][j-1]*10llu+ll(s[j]-'0');
		}
		figure(0,0llu);
		printf("%llu\n",res);
	}
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
q = int(input())
d = defaultdict(lambda: 0)
Sum = 0
for nums in a:
    d[nums] += 1
for keys in d:
        cnt = d[keys]
        keys = int(keys)
        Sum += keys*cnt
for i in range (q):
    b,c = map(int,input().split())
    d[c] += d[b]
    Sum += (c-b)*d[b]
    del d[b]
    print(Sum)

Measured memory_bytes: 24204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                ll now = 0;
                for (int m = 0; m < n; m++) {
                    now = m+1;
                    if (s[m] - '0' == i)break;
                }
                for (int m = now; m < n; m++) {
                    now = m + 1;
                    if (s[m] - '0' == j)break;
                }
                for (int m = now; m < n; m++) {
                    now = m + 1;
                    if (s[m] - '0' == k) {
                        ans++;
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3664
def main(n,k,a):

    mod = 10**9 + 7
    t1, t2 = 0, 0
    for i in range(n):
        for j in range(n):
            if a[i] > a[j]:
                t1 += 1
        for j in range(n - i - 1):
            if a[i] > a[j + i + 1]:
                t2 += 1

    count = (t1 * ((k * (k - 1)) // 2)) % mod
    count += (t2 * k) % mod
    print(int(count % mod))


if __name__ == '__main__':
    n, k = map(int, input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int n,k,cnt=0,z=0,ans=1000000000;
	cin>>n>>k;
	vector<int>vec;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(a<0){
			cnt++;
		}
		else if(a==0){
			k--;
			break;
		}
		vec.push_back(a);
	}
	if(k==0){
		cout<<0<<endl;
		return 0;
	}
	for(int i=max(z,cnt-k);i<min(cnt+1,n-k+1);i++){
		int st=vec[i],en=vec[i+k-1];
		//cout<<st<<" "<<en<<endl;
		if(st<0&&en<0){
			ans=min(ans,st*-1);
		}
		else if(st>0&&en>0){
			ans=min(ans,en);
		}
		else{
			ans=min(ans,min(st*-1,en)*2+max(st*-1,en));
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1400
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#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 <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
#define vecout(v,n) for(int i=0; i<n; i++)cout<<v[i]<<" "; cout<<endl;

const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}




signed main() {
	int n,k,a=0;
	string s;
	cin >> n >> k >> s;
	char c = s[0];
	rep(i, n-1) {
		if (s[i] != s[i + 1]) {
			a++;
		}
		
	}
	cout << n - max(a - k * 2, 0ll)-1 << endl; 
}



Measured memory_bytes: 512
#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 fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



string S[2];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S[0] >> S[1];

    if (S[0][0] == S[1][2] and S[0][1] == S[1][1] and S[0][2] == S[1][0]) printf("YES\n");
    else printf("NO\n");
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            int h = in.nextInt();
            int w = in.nextInt();
            if (H % h == 0 && W % w == 0) {
                out.println("No");
            } else {
                out.println("Yes");
                for (int r = 0; r < H; ++r) {
                    for (int c = 0; c < W; ++c) {
                        if (r % h == 0 && c % w == 0) {
                            out.print((int) 1e9 - 1);
                        } else if (r % h == h - 1 && c % w == w - 1) {
                            out.print((int) -1e9);
                        } else {
                            out.print(0);
                        }
                        out.print(" ");
                    }
                    out.println();
                }
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}



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

int main() {
    int N;
  	cin >> N;
    map<int, int> m;
    for (int i = 1; i <= N; i++) {
        m[i] = 0;
    }
    for (int i = 0; i < N - 1; i++) {
        int num;
        cin >> num;
        m[num] += 1;
    }
    for (int i = 1; i <= N; i++) {
        cout << m[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 13008
/*************************************\
*           بِسْمِ اللهِ الرَّحْمٰنِ الرَّحِيْمِ             *
*             رَّبِّ زِدْنِى عِلْمًا                *
*   Mir Abdullah yousuf, KUET_EEE14   *
\*************************************/
#include <bits/stdc++.h>
#define LL              long long
#define PI              acos(-1.0)
#define PII             pair<int,int>
#define xx              first
#define yy              second
#define MS(a,b)         memset(a, b, sizeof (a))
#define MP(a,b)         make_pair(a, b)
#define pb              push_back
#define sf(a)           scanf("%d", &a)
#define READ()          freopen("input.txt", "r", stdin)
#define WRITE()         freopen("output.txt", "w", stdout)
#define GCD(a, b)       __gcd(a, b)
#define LCM(a, b)       (a * b) / GCD(a, b)
#define sqr(a)          (a) * (a)
#define MOD             100000007
#define MAX             1000005
#define inf             2147483647
using namespace std;

///***********-8-direction*************/
//int fx[] = {1, -1, 0, 0, 1, -1, -1, 1};
//int fy[] = {0, 0, 1, -1, 1, 1, -1, -1};

///***********-4-direction*************/
//int fx[] = {1, -1, 0, 0};
//int fy[] = {0, 0, 1, -1};


int main()
{
    int n; sf(n);

    cout << "ABC" << n << endl;
    return 0;
}


Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        x: i64,
        y: i64,
    }

    if x == 0 {
        if y > 0 {
            println!("{}", y);
            return;
        } else {
            println!("{}", y.abs() + 1);
            return;
        }
    } else if y == 0 {
        if x > 0 {
            println!("{}", x + 1);
            return;
        } else {
            println!("{}", x.abs());
            return;
        }
    }

    if x > 0 && y > 0 {
        if x < y {
            println!("{}", y - x);
        } else {
            println!("{}", x - y + 2);
        }
    } else if x > 0 && y < 0 {
        println!("{}", (x.abs() - y.abs()).abs() + 1);
    } else if x < 0 && y > 0 {
        println!("{}", (x.abs() - y.abs()).abs() + 1);
    } else if x < 0 && y < 0 {
        if x > y {
            println!("{}", (y - x).abs() + 2);
        } else {
            println!("{}", (x.abs() - y.abs()).abs());
        }
    } else {
        unreachable!();
    }
}


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

char incrementChar(char x){
    return static_cast<char>(x + 1);
}

int weekToInt(string x){
    int num;
    if(x == "SUN"){
        num = 1;
    }else if(x == "MON"){
        num = 2;
    }else if(x == "TUE"){
        num = 3;
    }else if(x == "WED"){
        num = 4;
    }else if(x == "THU"){
        num = 5;
    }else if(x == "FRI"){
        num = 6;
    }else if(x == "SAT"){
        num = 7;
    }else{
        num = 0;
    }

    return num;
}

int main(){
    int A, B;
    cin >> A >> B;
    if(A > 9 || B > 9){
        cout << -1 << endl;
    }else{
        cout << A * B << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll s[100001];
	ll ans=0;
	scan(N);
	rep(i,N){
		scan(s[i]);
	}
	rep1(C,(N-1)/2-1){
		ll sum=0;
		map<int,bool> alre;
		for(int k=1;C*k<N-1&&N-1-C*k-C>0&&alre[C*k]==0&&alre[N-1-C*k]==0&&C*k!=N-1-C*k;k++){
			sum+=s[C*k]+s[N-1-C*k];
			ans=max(sum,ans);
			alre[C*k]=1;
			alre[N-1-C*k]=1;
			//printf("C:%d k:%d A:%d B:%d plus:%lld,%lld  ans:%lld\n",C,k,N-1-C*k,N-1-C*k-C,C*k,N-1-C*k,sum);
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 7680
#include <cstdio>

int main(){

    long long x, k, d;
    scanf("%lld%lld%lld", &x, &k, &d);
    if(x < 0)
        x = -x;
    long long t = x / d;
    if(t >= k){
        printf("%lld\n", x - k * d);
        return 0;
    }
    x -= t * d;
    if(x == 0){
        if((k - t) % 2 == 0)
            printf("0\n");
        else
            printf("%lld\n", d);
        return 0;
    }
    if((k - t) % 2 == 0)
        printf("%lld\n", x);
    else
        printf("%lld\n", d - x);
    return 0;
}


Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt(); 
        int b = scanner.nextInt();
        System.out.println(multiply(a, b));
    }

    private static String multiply(int a, int b) {
        return (a * b) % 2 == 0 ? "Even" : "Odd";
    }
}

Measured memory_bytes: 35572
function Main(input) {
	input = input.trim();
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  	var a = input[0];
  	var b = input[1];
  if(a+b >= 24){
     console.log(a + b - 24);
     }else{
       console.log(a + b);
     }
}

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


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

int main(){
  int64_t mod,ans;
  mod=1000000000+7;
  int N;
  cin >>N;
  int64_t tmp=1;
  
  for(int i=1;i<=N;i++){
    tmp*=i;
    tmp%=mod;
  }
  cout <<tmp<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

ll mpow(ll a, ll b){
	if(b==0){
		return 1;
	}else if(b%2==0){
		ll memo = mpow(a,b/2);
		return memo*memo%MOD;
	}else{
		return mpow(a,b-1) * a % MOD;
	}
}

ll gcd(ll a, ll b){
	if(b==0){
		return a;
	}else{
		return gcd(b, a%b);
	}
}

int main(void){
	int n;
	int p;
	cin>>n;
	vector<int> P;
	rep(i,n){
		cin>>p;
		P.push_back(p);
	}

	int count = 0;
	reps(i,n){
		if(P[i-1] != i){
			count++;
		}
	}
	if(count <= 2){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        vector<int> z(2*n), m(n), a(n), b(n);
        for (int i = 0; i < n; ++i) {
            cin >> m[i] >> a[i] >> b[i];
            z[i] = a[i], z[i+n] = b[i];
        }
        sort(z.begin(), z.end());
        z.erase(unique(z.begin(), z.end()), z.end());
        vector<int> S(z.size());
        for (int i = 0; i < n; ++i) {
            int l = lower_bound(z.begin(),z.end(), a[i]) - z.begin();
            int r = lower_bound(z.begin(),z.end(), b[i]) - z.begin();
            S[l] += m[i]; S[r] -= m[i];
        }
        for (int i = 0; i+1 < z.size(); ++i) {
            S[i+1] += S[i];
        }
        if(*max_element(S.begin(),S.end()) > 150) puts("NG");
        else puts("OK");
    }
    return 0;
}


Measured memory_bytes: 3140
N = int(input())

h_list = list(int(i) for i in input().split())

ans = 1

for i in range(1, N):
    can_view = True
    for j in range(i):
        if h_list[j]>h_list[i]:
            can_view = False
    if can_view:
        ans+=1

print(ans)


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

using namespace std;

class DisjointSet{
public:
    vector<int> rank, p;
    
    DisjointSet() {}
    DisjointSet(int size){
        rank.resize(size, 0);
        p.resize(size, 0);
        for(int i=0; i<size; i++) makeSet(i);
    }
    
    void makeSet(int x){
        p[x] = x;
        rank[x] = 0;
    }
    
    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    
    void unite(int x, int y){
        link(findSet(x), findSet(y));
    }
    
    void link(int x, int y){
        if(rank[x] > rank[y]){
            p[y] = x;
        } else {
            p[x] = y;
            if(rank[x] == rank[y]){
                rank[y]++;
            }
        }
    }
    
    int findSet(int x){
        if(x != p[x]){
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main() {
    int n, a, b, q;
    int t;
    
    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);
    
    for(int i=0; i<q; i++){
        cin >> t >> a >> b;
        if(t==0) ds.unite(a, b);
        else if(t==1) {
            if(ds.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 3208
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	double r,sx,sy,tx,ty;
};

struct Point{
	void set(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}
	double x,y;
};

typedef Point Vector;

struct Segment{
	void set(double x1,double y1,double x2,double y2){
		p1.x = x1;
		p1.y = y1;
		p2.x = x2;
		p2.y = y2;
	}
	Point p1,p2;
};

typedef Segment Line;

double cross(Vector a,Vector b){
	return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
	return a.x*b.x + a.y*b.y;
}

Point calc_minus(Point a,Point b){
	Point ret;

	ret.x = a.x-b.x;
	ret.y = a.y-b.y;

	return ret;
}

double calc_len(Vector a){
	return sqrt(a.x*a.x+a.y*a.y);
}

double getDistanceLP(Line l,Point p){
	return fabs(cross(calc_minus(l.p2,l.p1),calc_minus(p,l.p1))/calc_len(calc_minus(l.p2,l.p1)));
}

double getDistanceSP(Segment s,Point p){
	if(dot(calc_minus(s.p2,s.p1),calc_minus(p,s.p1)) < 0.0)return calc_len(calc_minus(p,s.p1));
	if(dot(calc_minus(s.p1,s.p2),calc_minus(p,s.p2)) < 0.0)return calc_len(calc_minus(p,s.p2));
	return getDistanceLP(s,p);
}

bool dp[65536];

int main(){

	int POW[17];
	for(int i = 0; i < 17; i++)POW[i] = pow(2,i);

	int N;
	scanf("%d",&N);
	Info info[N];

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf %lf %lf",&info[i].r,&info[i].sx,&info[i].sy,&info[i].tx,&info[i].ty);
	}

	for(int state = 0; state < POW[N]; state++)dp[state] = false;
	dp[0] = true;

	int ans = 0,tmp_num;
	bool is_init_pos[N];
	Segment move_line;
	Point point;

	bool FLG;

	for(int state = 0; state < POW[N]; state++){
		if(!dp[state])continue;
		tmp_num = 0;

		for(int loop = 0; loop < N; loop++){
			if(state & (1 << loop)){
				is_init_pos[loop] = false;
				tmp_num++;
			}else{
				is_init_pos[loop] = true;
			}
		}
		ans = max(ans,tmp_num);

		for(int i = 0; i < N; i++){
			if(!is_init_pos[i])continue;

			move_line.set(info[i].sx,info[i].sy,info[i].tx,info[i].ty);
			FLG = true;

			for(int k = 0; k < N; k++){
				if(i == k)continue;

				if(is_init_pos[k]){
					point.set(info[k].sx,info[k].sy);
				}else{
					point.set(info[k].tx,info[k].ty);
				}

				if(getDistanceSP(move_line,point) < info[i].r+info[k].r){
					FLG = false;
					break;
				}
			}

			if(FLG){
				dp[state+POW[i]] = true;
			}
		}
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 3432
#include<iostream>
#include<string>
int main(void){
  int N;
  std::string S;
  std::cin >> N >> S;
  int count = 0;
  for (int i=0;i<N-2;i++){
    int b = 0;
    for (int j=0;j<3;j++){
      if (S.at(i+j) == 65+j) b++;
    }
    if (b==3) count++;
  }
  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

void solve(){
	long long N;
	cin >> N;
	cout << int(sqrt(N))*int(sqrt(N)) << endl;
}

int main(){
	// while(1){
		solve();
	// }
	return 0;
}

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

using ll = long long;

const int MAXN = 200010;
int ma[MAXN];
int pref[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string S; cin >> S;
	int N = int(S.size());
	for (int i = 0; i < N; i++) {
		pref[i+1] = pref[i] + (S[i] == 'A');
	}

	int nxt = N;
	for (int i = N-2; i >= 0; i--) {
		if (S[i] == 'B' && S[i+1] == 'C') {
			ma[i] = 1;
			if (nxt != N && pref[nxt] - pref[i+2] == (nxt - (i+2))) {
				ma[i] += ma[nxt];
			}
			nxt = i;
		}
	}

	ll ans = 0;
	ll cur = 0;
	for (int i = N-2; i >= 0; i--) {
		if (S[i] != 'A') continue;
		if (S[i+1] != 'A') {
			cur = ma[i+1];
		}
		ans += cur;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2196
/*
    Code by CNH_Tourist
*/
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unrolled-loops")

using namespace std;

/*----------------Define----------------*/
#define inp "TestCode.inp"
#define out "TestCode.out"
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FileInOut freopen(inp,"r",stdin);freopen(out,"w",stdout);
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define pi acos(-1)
#define pii pair<int,int>
#define ppiii pair< pair <int,int> ,int>
#define INF 1000000
#define endl '\n'
#define ll long long
#define pq priority_queue
const int mod=1e9+7;
int test=1;
/*--------------------------------------*/

int n;
int a[100100][4];

int main()
{
    FAST
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i][1]>>a[i][2]>>a[i][3];
    for(int i=2;i<=n;i++)
    {
        a[i][1]+=max(a[i-1][2],a[i-1][3]);
        a[i][2]+=max(a[i-1][1],a[i-1][3]);
        a[i][3]+=max(a[i-1][1],a[i-1][2]);
    }
    cout<<max(max(a[n][1],a[n][2]),a[n][3]);
}



Measured memory_bytes: 1792
#include <stdio.h>
 
int main(void) {
 
  int A, P;
 
  do {
    scanf("%d %d", &A, &P);
  } while (A < 0 || P > 100);
 
  printf("%d\n", ((A * 3) + P) / 2);
 
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
main(){int n;while(scanf("%d",&n), n){int p[10]={0},t;for(;n;n--)scanf("%d",&t),p[t]++;for(t=0;t<10;t++){if(p[t])for(n=p[t];n;n--)printf("*");else printf("-");puts("");}}}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int N;
vector<complex<double>>vec;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0) {}
		else {
			vec.push_back(complex<double>(x, y));
		}
	}
	N = vec.size();
	double ans = 0;
	sort(vec.begin(), vec.end(), [](const complex<double>& c1, const complex<double>& c2) {
		return arg(c1) < arg(c2);
		});
	for (int i = 0; i < N; ++i) {
		vec.push_back(vec[i]);
	}
	for (int i = 0; i < N; ++i) {
		for (int j = i; j <= i + N; ++j) {
			complex<double>sum(0, 0);
			for (int k = i; k < j; ++k) {
				sum += vec[k];
			}
			ans = max(ans, abs(sum));
		}
	}
	cout.precision(20);
	cout << fixed;
	cout << ans << endl;
	return 0;
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, m, p;
	while(1) {
		cin >> n >> m >> p;
		if (n == 0 && m == 0 && p == 0) break;
		int x;
		int cnt = 0;
		rep (i, n) {
			int temp;
			cin >> temp;
			if (m == i + 1) x = temp;
			cnt += temp;
		}
		int sum = 100 * cnt;
		int ans = x == 0? 0 : (sum - (sum * (p / 100.0))) / x;
		cout << ans << endl;
	}
	return 0;
}

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

int main(void){
    char data[3][101] = {};
    // memset(a,'\0',sizeof(int) * 101);
    // memset(b,'\0',sizeof(int) * 101);
    // memset(c,'\0',sizeof(int) * 101);
    int datan[3] = {};
    scanf("%s",data[0]);
    // printf("%s",a);
    scanf("%s",data[1]);
    scanf("%s",data[2]);
    char tmp = 'a';
    char ans = '0';
    while(tmp != '\0'){
        if(tmp == 'a'){
            tmp = data[0][datan[0]];
            datan[0]++;
            ans = 'A';
        }else if(tmp == 'b'){
            tmp = data[1][datan[1]];
            datan[1]++;
            ans = 'B';
        }else{
            tmp = data[2][datan[2]];
            datan[2]++;
            ans = 'C';
        }
    }
    printf("%c",ans);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    boolean[][] symmetryFlg = new boolean[128][128];

    symmetryFlg['i']['i'] = true;
    symmetryFlg['w']['w'] = true;
    symmetryFlg[')']['('] = true;
    symmetryFlg['('][')'] = true;

    while(sc.hasNext()){
      char[] s = sc.next().toCharArray();
      int n = s.length;
      int modifyCount = 0;

      for(int i = 0; i < (n + 1) / 2; i++){
        if(!symmetryFlg[s[i]][s[n - i - 1]]){
          modifyCount++;
        }
      }

      System.out.println(modifyCount);
    }
  }
}

Measured memory_bytes: 11000
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[100050];
int main()
{
    int n,k=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    for(int i=0;i<n; )
    {
        if(a[i]==a[i+1])
            i=i+2;
        else
        {
            k++;
            i++;
        }
    }
    printf("%d\n",k);
    return 0;

}


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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])
typedef long long ll;

ll intwo(ll num){
    ll ans = 0;
    while(num > 0){
        num = num / 2;
        ans++;
    }
    return ans;
}

int main() {
    ll H;
    cin >> H;
    ll T = pow(2,intwo(H)) -1;
    cout << T << endl;
}

Measured memory_bytes: 256