akhauriyash/Code-Regression huggingface dataset:
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;



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

   int N;
   cin >> N;
   VI P(N+1);
   REP(i, N)
      cin >> P[i];

   llong bal = 1000;

   for (int i = 0; i < N; ) {
      for (; i < N && P[i] >= P[i+1]; ++i);
      if (i == N) break;
      // buy at price P[i]
      llong nstocks = bal / P[i];
      bal -= nstocks * P[i];
      for (; i < N && P[i] <= P[i+1]; ++i);
      assert(i < N);
      // sell at price P[i];
      bal += nstocks * P[i];
   }

   cout << bal << '\n';

   return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>
#define MAX 100
#define INFTY 2001
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,A[MAX][MAX];
int prim(void);

int main(){
  int i,j;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      scanf("%d",&A[i][j]);
      if(A[i][j] == -1)
	A[i][j] = INFTY;
    }
  }

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

  return 0;
}

int prim(){
  int i,u,v,mincost,sum = 0,d[MAX],pi[MAX],color[MAX];

  for(i=0; i<n; i++){
    d[i] = INFTY;
    pi[i] = NIL;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    mincost = INFTY;
    for(i=0; i<n; i++){
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if(mincost == INFTY)
      break;
    color[u] = BLACK;
    for(v=0; v<n; v++){
      if(color[v] != BLACK && A[u][v]  != INFTY){
	if(A[u][v] < d[v]){
	  pi[v] = u;
	  d[v] = A[u][v];
	}
      }
    }
  }

  for(i=0; i<n; i++){
    if(pi[i] != NIL)
      sum += A[i][pi[i]];
  }

  return sum;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main()
{
  finp;
  string s;
  cin>>s;
  int n = s.length();
  ll ans = 0;

  if(n==1)
  {
  	cout<<s;
  	return 0;
  }

  afor(i,0,(1 << (n-1))-1)
  {
  	ll curr = 0;
  	ll las = s[0]-'0';

  	afor(j,2,n)
  	{
  		
  		if( i & (1 << (j-2)))
  		{
  			ans+= las;
  			las=0;
  		}
  		las = las*10 + s[j-1]-'0';
  	}
  	curr+=las;
  	ans+=curr;
  }

  cout<<ans;
  
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
pair<int,int> pii;
vector<int> vec;
double dp[3000][3000];
int main()
{
  int n;
  double p[3005],ans=0;

  cin>>n;

  for(int i=0; i<n; i++){
    cin>>p[i];
  }
  dp[0][0]=1.0;
  for(int i=0; i<n; i++){
    dp[i+1][0]=dp[i][0]*(1.0-p[i]);
    for(int j=0; j<=i; j++){
      dp[i+1][j+1]=dp[i][j]*p[i]+dp[i][j+1]*(1.0-p[i]);
    }
  }

  for(int i=n/2+n%2; i<=n; i++){
    ans+=dp[n][i];
  }

  printf("%.15f\n",ans);
  return 0;
}


Measured memory_bytes: 68864
n = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
mx = A[0]; A = A[1:]
mn = A[0]
for a in A[1:]:
    if abs(mn-mx/2) > abs(a-mx/2):
        mn = a
    else:
        break
print(mx, mn)

Measured memory_bytes: 20056
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using ll = long long;
// const ll N = ;
using ii = pair <ll , ll>;
ll x,y,a,b,c;

int main() {
	scanf("%lld%lld%lld%lld%lld" , &x , &y , &a , &b , &c);
   vector <ll> p(a),q(b),r(c);
   for (ll i = 0 ; i < a ; i++) {
      scanf("%lld" , &p[i]);
   }
   for (ll i = 0 ; i < b ; i++) {
      scanf("%lld" , &q[i]);
   }
   for (ll i = 0 ; i < c ; i++) {
      scanf("%lld" , &r[i]);
   }
   sort(p.rbegin() , p.rend());
   sort(q.rbegin() , q.rend());
   sort(r.rbegin() , r.rend());
   vector <ll> v;
   for (ll i = 0 ; i < x ; i++) v.pb(p[i]);
   for (ll i = 0 ; i < y ; i++) v.pb(q[i]);
   sort(v.begin() , v.end());
   for (ll i = 0 ; i < c && i < x + y ; i++) {
      if (v[i] < r[i]) {
         v[i] = r[i];
      }
   }
   ll sol = 0;
   for (auto x : v) sol += x;
   printf("%lld\n" , sol);
	return 0;
}


Measured memory_bytes: 4724
package main

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

type pair struct {
	l, r int
}

func main() {
	q := getInt()
	ps := make([]pair, q)
	for i := range ps {
		ps[i].l = getInt() - 1
		ps[i].r = getInt()
	}

	ln := 100000
	primes := furui(ln)
	like2017s := make(map[int]bool)
	for i, p := range primes {
		f := (p + 1) / 2
		match := false
		for j := 0; j < i; j++ {
			if f == primes[j] {
				match = true
			}
		}

		if match {
			like2017s[p] = true
		}
	}

	s := make([]int, ln+1)
	for i := 1; i < len(s); i++ {
		s[i] = s[i-1]
		if _, ok := like2017s[i]; ok {
			s[i]++
		}
	}

	for _, p := range ps {
		res := s[p.r] - s[p.l]
		fmt.Println(res)
	}
}

func furui(n int) []int {
	ns := make([]int, n-1)
	for i := range ns {
		ns[i] = i + 2
	}

	for i := 0; ; i++ {
		p := ns[i]
		if p*p > n {
			break
		}
		for j := i + 1; j < len(ns); j++ {
			if ns[j]%p == 0 {
				ns = remove(ns, j)
				j--
			}
		}
	}

	return ns
}

func remove(s []int, i int) []int {
	return append(s[:i], s[i+1:]...)
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 7296
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	x := 0
	for i := 0; i < N; i++ {
		a[i] = getInt()
		x ^= a[i]
	}
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	for i := 0; i < N; i++ {
		fmt.Fprintln(w, a[i]^x)
	}
}


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

					#define pb push_back
					#define cend(s) return cout << s, 0;
					using namespace std;
					typedef long long ll;
					int main()
					{
						string s;
						int k;
						cin >> k >> s;
						if(s.size() > k)
						{
							for(int i = 0; i < k; i++)
								cout << s[i];
							cout << "...";
						}
						else cend(s);
					}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int A,B;

    cin >> A >> B;

    int b = B;
    int k = 0;

    while(b != 0){
        b /= 10;
        A *= 10;
    }

    int i = 1;

    while(i*i <= A+B){
        if(i*i == A+B){
            cout << "Yes" << endl;
            return 0;
        }
        i++;
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
n = gets.to_i

edges = []
g = Array.new(n){ [] }
(n-1).times do |i|
  e = gets.split.map(&:to_i).map{|k|k-=1}
  e[1], e[0] = e[0], e[1] if e[0] > e[1] # 辺は頂点 i < j の形で入れる。
  g[e[0]] << e[1] # 隣接リストに
  g[e[1]] << e[0] # 反対向きにも隣接リストに.無向グラフなので
  edges << e # 辺リストにいれる。辺が識別されてて、最後に辺リストから辺を回して色をとりだす。
end

colors = Hash.new() # Esge => color # 辺についてO(1)で使った色を見れる。O(1)はホントに?
colors_used = Array.new(n){Hash.new} # 頂点と色についてO(1)で使ったか確かめられる。
used = Array.new(n){false} # 頂点について探索済みかどうかO(1)でわかる。
que = [0] # 頂点0から見ていくので0が入っている # 探索待ちの未探索の頂点リスト

k = 0 # 答えとなる色の数
while !que.empty? do
  v = que.shift # queにある頂点を取り出す. 破壊的メソッドなので先頭は削除される。
  cur = 1 # 使ってない色がわからないので、とりあず色1から見ていく。
  g[v].each do |w| # vの隣接頂点wを見ていく。
    k = g[v].size if k < g[v].size  # 隣接する頂点数より色数が小さければ色数を更新
    v<w ? (i,j = v,w) : (i,j = w,v) # i < jの並びで頂点を捉える。
    next if used[w] == true
    # next if colors[[i,j]] != nil # nilでなければi-jの辺に色がついてて頂点jは探索済みで,次に。
    cur += 1 while colors_used[v][cur] == true # v周りの頂点で色をつかっていれば次の色に更新していく。塗る前に使ってない色にする。
    colors_used[v][cur] = true # vに色を使ったので記録する。
    colors_used[w][cur] = true # wに色を使ったので記録する。
    colors[[i,j]] = cur # 辺に使った色をいれる。
    que.push(w) #探索待ちの未探索頂点リストに頂点wを入れる。
  end
  used[v] = true # 頂点vを探索済みにする。
end

puts k
edges.each{ |e| puts colors[e] }

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long N, std::vector<std::string> s, std::vector<long long> t, std::string X){
    i64 ans = 0;
    bool flag = false;
    rep(i, N){
        if(X == s[i]) flag = true;
        else if(flag) ans += t[i];
    }
    cout << ans << endl;
}

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


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

const int mod=998244353;
int n, s, a[3004]; 
long long ans=0, dp[3004][3004][3];

int main(){
	cin >> n >> s;
	for (int i=0;i<n;i++) cin >> a[i];
	memset(dp,0,sizeof dp);
	dp[0][0][0]=1;
	for (int i=0;i<=n;i++){
		for (int j=0;j<=s;j++){
			// inserting left
			dp[i][j][1]+=dp[i][j][0];
			dp[i][j][1]%=mod;
			// inserting right
			dp[i][j][2]+=dp[i][j][1];
			dp[i][j][2]%=mod;
			// continuing 0
			dp[i+1][j][0]+=dp[i][j][0];
			dp[i+1][j][0]%=mod;
			// include a[i]
			if (a[i]+j<=s){
				dp[i+1][a[i]+j][1]+=dp[i][j][1];
				dp[i+1][a[i]+j][1]%=mod;
			}
			// exclude a[i]
			dp[i+1][j][1]+=dp[i][j][1];
			dp[i+1][j][1]%=mod;
			// continuing 2
			dp[i+1][j][2]+=dp[i][j][2];
			dp[i+1][j][2]%=mod;
		}
	}
	cout << dp[n][s][2] << "\n";	
}

Measured memory_bytes: 211840
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>

int main(void) {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> as;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    std::cin >> a;
    as.push_back(a);
    sum += a;
  }
  int cnt = 0;
  for (auto a : as) {
    if (4 * m * a >= sum) cnt++;
  }
  std::cout << (cnt >= m ? "Yes" : "No") << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <climits>
using namespace std;
typedef long long int int64;

vector<int64> P,Q;
int64 N,M,T;

int main(void)
{
	while(true)
	{
		N = 0;
		M = 0;
		P.clear();
		Q.clear();
		P.shrink_to_fit();
		Q.shrink_to_fit();
		cin >> N >> M;
		if(N == 0 && M == 0)
		{
			exit(0);
		}
		for(int i = 0;i < N;i++)
		{
			cin >> T;
			P.push_back(T);
		}
		P.push_back(0);
		for(auto itr = P.begin();itr < P.end();itr++)
		{
			for(auto itr2 = P.begin();itr2 < P.end();itr2++)
			{
				Q.push_back(*itr + *itr2);
			}
		}
		Q.push_back(LLONG_MAX / 2);
		Q.push_back(LLONG_MIN / 2);
		sort(Q.begin(),Q.end());
		int64 ms = 0;
		for(auto itr = Q.begin();itr < Q.end()+1;itr++)
		{
			ms = max(ms,*itr + *(lower_bound(Q.begin(),Q.end() - 1,M-*itr+1) - 1));
		}
		cout << ms << endl;
	}
}

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



int main() {
  int N;
  cin >> N;
  vector<string> All;
  vector<string> S(N);
  for (int i = 0; i < N; ++i){
    cin >> S.at(i);
    All.push_back(S.at(i));
  }
  
  int M;
  cin >> M;
  vector<string> T(M);
  for (int i = 0; i < M; ++i){
    cin >> T.at(i);
    All.push_back(T.at(i));
  }

  sort(All.begin(), All.end());
  All.erase(unique(All.begin(), All.end()), All.end());

  int coin_max = 0;
  for (int i = 0; i < All.size(); ++i){
    int plus = count(S.begin(), S.end(), All.at(i));
    int minus = count(T.begin(), T.end(), All.at(i));
    if (coin_max < plus - minus){
      coin_max = plus - minus;
    }
  }
  cout << coin_max << endl;

  return 0;
}

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

class node{
public:
  int p = -1, l, r;
};

void getd(vector<int>& d, vector<node>& t, int id, int num){
  if(id == -1) return;
  d[id] = num;
  getd(d, t, t[id].l, num + 1);
  getd(d, t, t[id].r, num + 1);
  return;
}

int geth(vector<int>& h, vector<node>& t, int id){
  if(id == -1) return -1;
  h[id] = max(geth(h, t, t[id].l), geth(h, t, t[id].r)) + 1;
  return h[id];
}

void solve(){
  int n; cin >> n;
  vector<node> t(n);
  for(int i = 0; i < n; i++){
    int id, l, r; cin >> id >> l >> r;
    t[id].l = l;
    t[id].r = r;
    if(l != -1) t[l].p = id;
    if(r != -1) t[r].p = id;
  }
  vector<int> d(n), h(n);
  for(int i = 0; i < n; i++){
    if(t[i].p == -1){
      getd(d, t, i, 0);
      geth(h, t, i);
      break;
    }
  }
  for(int i = 0; i < n; i++){
    cout << "node " << i << ": parent = " << t[i].p << ", sibling = ";
    if(t[i].p == -1) cout << -1;
    else{
      int pid = t[i].p;
      if(t[pid].l != -1 && t[pid].l != i) cout << t[pid].l;
      else if(t[pid].r != -1 && t[pid].r != i) cout << t[pid].r;
      else cout << -1;
    }
    cout << ", degree = ";
    if(t[i].l != -1 && t[i].r != -1) cout << 2;
    else if(t[i].l == -1 && t[i].r == -1) cout << 0;
    else cout << 1;
    cout << ", depth = " << d[i] << ", height = " << h[i];
    if(t[i].p == -1) cout << ", root\n";
    else if(t[i].l == -1 && t[i].r == -1) cout << ", leaf\n";
    else cout << ", internal node\n";
  }
  return;
}

int main(){
  solve();
  return 0;
}



Measured memory_bytes: 3108
n = int(input())
v = list(map(int, input().split()))

from collections import Counter

v1 = [v[i] for i in range(len(v)) if i%2 == 0]
v2 = [v[i] for i in range(len(v)) if i%2 != 0]

v1c = Counter(v1)
v1cs = v1c.most_common(1)[0][0]
v1c = sorted(v1c.values())

v2c = Counter(v2)
v2cs = v2c.most_common(1)[0][0]
v2c = sorted(v2c.values())

if v1cs != v2cs:
    ans = sum(v1c[:-1]) + sum(v2c[:-1])
else:
    if len(v1c) == 1 and len(v2c) == 1:
        ans = sum(v2c)
    elif len(v1c) == 1:
        ans = sum(v2c) - v2c[-2]
    elif len(v2c) == 1:
        ans = sum(v1c) - v1c[-2]
    else:
        ans = min(sum(v1c) - v1c[-2] + sum(v2c[:-1]), sum(v1c[:-1]) + sum(v2c) - v2c[-2])

print(ans)


Measured memory_bytes: 61804
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

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

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

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  string s;
  cin>>s;
  int n=s.size();
  n--;
  char a=s[n];
  if(a=='2'||a=='4'||a=='5'||a=='7'||a=='9') cout<<"hon";
  else if(a=='0'||a=='1'||a=='6'||a=='8') cout<<"pon";
  else cout<<"bon";
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

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

using namespace std;
typedef long long ll;



int main(void){
	ll a=1, b=0, c=-1;
	ll A, B, C,k;
	ll ans;
	cin >> A >> B >> C >> k;
	ll sa = k - A;


	if (k <= A) {
		cout <<k;
	}
	else{
		ans = a * A;
		rep(i, sa) {
			if (B>0) {
				ans += b;
				B--;
			}
			else if (C>0) {
				ans += c;
				C--;
			}
		}
		cout << ans;
	}
	cout << endl;
}


Measured memory_bytes: 3608
N = int(input())
S = [input() for _ in range(N)]
a, b, ab = 0, 0, 0
ans = 0
for s in S:
    ans += s.count('AB')
    if s[-1] == 'A' or s[0] == 'B':
        ab += 1
    if s[-1] == 'A':
        a += 1
    if s[0] == 'B':
        b += 1
print(ans + min(a, b, max(ab-1, 0)))


Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int x = scanner.nextInt();
		int idx = 0;
		for (int i=1;i<=m; i++) {
			int num = scanner.nextInt();
			if (num<x) {
				idx = i;
			}else {
				break;
			}
		}
		if (idx<=m-idx) {
			System.out.println(idx);
		}else {
			System.out.println(m-idx);
		}

	}

}

Measured memory_bytes: 21716
def myAnswer(N:int,K:int,R:int,S:int,P:int,T:str) -> int:
   dic = {"r":R,"s":S,"p":P}
   dic2 = {"r":["p","-"],"s":["r","-"],"p":["s","-"]}
   total = 0
   ans = []
   for n in range(N):
      target = T[n]
      if(n  < K):
         ans.append(dic2[target][0])
         total += dic[dic2[target][0]]
      else:
         if(ans[n - K] == dic2[target][0]):
            ans.append(dic2[target][1])
         else:
            ans.append(dic2[target][0])
            total += dic[dic2[target][0]]
   return total

def modelAnswer():
   return
def main():
   N,K = map(int,input().split())
   R,S,P = map(int,input().split())
   T = input()
   print(myAnswer(N,K,R,S,P,T))
if __name__ == '__main__':
   main()

Measured memory_bytes: 4212
#include<bits/stdc++.h>
#define mod 1e9+7;
using namespace std;
vector <int> v;
set <int> st;


int main()
{
  int a,b;
  cin  >> a >> b;
  int x = a+b;
  int y = a - b;
  int z = a*b;
  int mx =  max(x ,max(y,z));
  cout << mx << endl;
  //printf("%d+%d=%d, %d-%d=%d and %dx%d=%d. The largest among them is %d.",a,b,x,a,b,y,a,b,z,mx);
}


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

int main(){
  string s;

  while(cin >> s){
    for(int i = 0; i < s.length(); i += 2){
      if(s[i] == '2') cout << "k";
      if(s[i] == '3') cout << "s";
      if(s[i] == '4') cout << "t";
      if(s[i] == '5') cout << "n";
      if(s[i] == '6') cout << "h";
      if(s[i] == '7') cout << "m";
      if(s[i] == '8') cout << "y";
      if(s[i] == '9') cout << "r";

      if(s[i] == '0'){
	if(s[i + 1] == 'T') cout << "wa";
	if(s[i + 1] == 'U') cout << "nn";
	if(s[i + 1] == 'D') cout << "wo";
      }
      else{
	if(s[i + 1] == 'T') cout << "a";
	if(s[i + 1] == 'L') cout << "i";
	if(s[i + 1] == 'U') cout << "u";
	if(s[i + 1] == 'R') cout << "e";
	if(s[i + 1] == 'D') cout << "o";
      }
    }

    cout << endl;
  }
}

Measured memory_bytes: 1180
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "MyDisjointset.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <map>
#include <string.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const ll INF = 2000000000;
int main() {
	ll n, W; cin >> n >> W;
	ll *v = new ll[n], *w = new ll[n];
	for (int i = 0; i < n; i++)
		cin >> v[i] >> w[i];
	int h = n / 2;
	P *h1 = new P[1 << h];
	memset(h1, 0, sizeof(h1));
	for (int i = 0; i < (1 << h); i++)
		for (int j = 0; j < h; j++)
			if (i >> j & 1) { h1[i].second += v[j]; h1[i].first += w[j]; }
	sort(h1, h1 + (1 << h));
	int m = 0;
	for (int i = 1; i < (1 << h); i++) 
		if (h1[m].second < h1[i].second) 
			h1[++m] = h1[i];
	m++;
	int hr = n - n / 2;
	P *h2 = new P[1 << hr];
	memset(h2, 0, sizeof(h2));
	for (int i = 0; i < (1 << hr); i++)
		for (int j = 0; j < hr; j++)
			if (i >> j & 1) { h2[i].second += v[h + j]; h2[i].first += w[h + j]; }
	ll res = -1;
	for (int i = 0; i < (1 << hr); i++) {
		ll mw = W - h2[i].first;
		if (mw >= 0) {
			ll t = (lower_bound(h1, h1 + m, P(mw, INF)) - 1)->second;
			res = max(res, h2[i].second + t);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 35876
import numpy as np
from numba import njit
 
@njit(cache=True)
def main(N, s):
    dpt = np.zeros((N+1, N+1), dtype=np.int16)
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if s[j-1] == s[i-1]:
                if j - dpt[i-1][j-1] > i:
                    dpt[i][j] = dpt[i-1][j-1] + 1
 
    return np.amax(dpt)
 
if __name__ == '__main__':
    N = int(input())
    s = np.array([ord(c) for c in input()]) 
 
    print(main(N, s))

Measured memory_bytes: 166188
while True:
  a,op,b=map(str,input().split())
  a=int(a)
  b=int(b)
  if op == '?':
    break
  if op == '+':
    print(a+b)
  if op == '-':
    print(a-b)
  if op == '*':
    print(a*b)
  if op == '/':
    print(a//b)


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

typedef long long int ll;

int main(){
    ll n,r=0,b=0,g=0,tc=0,c=0;
    string s;
    cin >> n;
    cin >> s;

    for (int i = 0; i < n; ++i){
        if(s[i] == 'R') r++;
        if(s[i] == 'G') g++;
        if(s[i] == 'B') b++;
    }
    tc = r*b*g;
    for (int i = 0; i < n; ++i){
        for (int j = i+1; j < n; ++j){
            if(j+(j-i) < n && j > i ){
                if (s[i] != s[j] && s[i] != s[j+(j-i)] && s[j] != s[j+(j-i)])
                    c++;
            }
        }
    }
    cout << tc-c << endl;
    return 0;
}


Measured memory_bytes: 3632
import os
import sys
from functools import lru_cache

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N - 1)]
M = int(sys.stdin.buffer.readline())
VU = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

# N <= 50
# M <= 20


graph = [[] for _ in range(N)]
edges = {}
for i, (a, b) in enumerate(AB):
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)
    edges[a, b] = i
    edges[b, a] = i


@lru_cache(maxsize=None)
def path(v, u, p):
    if v == u:
        return [u]
    for nv in graph[u]:
        if nv == p:
            continue
        ret = path(v, nv, u)
        if ret is not None:
            return ret + [u]
    return None


# 辺ごとに、黒くしたときにどの制約を満たすことができるかを持つ
constraints = [0 for _ in range(N - 1)]
for i, (v, u) in enumerate(VU):
    v -= 1
    u -= 1
    pp = path(v, u, None)
    for pv, pu in zip(pp, pp[1:]):
        constraints[edges[pv, pu]] |= 1 << i

# for c in constraints:
#     import numpy as np
#
#     print(np.binary_repr(c, M))

# or したときに全部 True になる組み合わせの数
dp = [0 for _ in range(1 << M)]
dp[0] = 1
for c in constraints:
    for i in reversed(range(1 << M)):
        dp[i | c] += dp[i]
print(dp[-1])


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

#define ll long long

using namespace std;

int main(){

    int n, t, tempo, custo, resp = 1001;

    cin >> n >> t;

    for(int i = 0; i < n; i++){
        cin >> custo >> tempo;
        if(tempo <= t && custo < resp) resp = custo;
    }

    if(resp == 1001) cout << "TLE\n";
    else cout << resp << endl;

    return 0;
}

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

int main (){
    std::cin.tie(0); 
	std::ios::sync_with_stdio(false);
    
    int X,N; std::cin >> X >> N;
    std::vector<int> p(N);

    for (int i=0;i<N;++i){
        std::cin >> p[i];
    }
    
    for(int d=0;d<=100;++d){
        if (p.end()==std::find(p.begin(),p.end(),X-d)){
            std::cout<<(X-d);
            return 0;
        }
        if (p.end()==std::find(p.begin(),p.end(),X+d)){
            std::cout<<(X+d);
            return 0;
        }

    }

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main() {
  
  char c[3][3];
  
  for(int i=0; i<3; i++) {
    
    for(int j=0; j<3; j++) {
      
      cin>>c[i][j];
    
    }
  
  }
  
  cout << c[0][0] << c[1][1] << c[2][2] << endl;
  
  return 0;
  
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;




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

    int h,w,d;
    cin>>h>>w>>d;
    vvi a(h,vi(w,0));
    rep(i,h)rep(j,w)cin>>a[i][j];
    
    map<int,pair<int,int> > m;
    rep(i,h)rep(j,w){
        m[a[i][j]]=mp(i,j);
    }
    vvi dis(d),csum(d,vi(1,0));
    for(int i=1;i<=d;i++){
        int t=i;
        while(t+d<=h*w){
            dis[i-1].push_back(abs(m[t+d].first-m[t].first)+abs(m[t+d].second-m[t].second));
            t+=d;
        }
    }
    // cout<<"\n-----"<<endl;
    // for(int i=0;i<dis.size();i++){
    //     for(int j=0;j<dis[i].size();j++){
    //         cout<<dis[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<"-----"<<endl;
    for(int i=0;i<d;i++){
        for(int j=0;j<dis[i].size();j++){
            csum[i].push_back(csum[i][j]+dis[i][j]);
        }
    }
    // cout<<"\n-----"<<endl;
    // for(int i=0;i<csum.size();i++){
    //     for(int j=0;j<csum[i].size();j++){
    //         cout<<csum[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    // cout<<"-----"<<endl;

    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        int h=(l-1)%d;
        cout<<csum[h][(r-h-1)/d]-csum[h][(l-h-1)/d]<<endl;
    }
    //sum[1][3]-csum[1][1]
    //csum[2%3+1][2/3-1]-csum[2%3+1][2/3-1]
    

//////////////////////////////////////////////////////
return 0;}



Measured memory_bytes: 13440
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    long long a, bb, c;
    float b;
    cin >> a >> b;
    b *= 100;
    bb = b + 0.5;
    c = a * bb / 100;
    cout << c << endl;
}

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

int main() {
    int n,k;
    string s;
    //s = "ABCACCCA";
    //n = 8;
    //k = 5;
    cin >> n >> k;
    cin >> s;

    if(s[k-1] == 'A'){
        s[k-1] = 'a';
        std::cout << s << std::endl;
    }else if(s[k-1] == 'B'){
        s[k-1] = 'b';
        std::cout << s << std::endl;
    }else{
        s[k-1] = 'c';
        std::cout << s << std::endl;
    }
}

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

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = int.Parse(_[0]);
            var m = int.Parse(_[1]);
            var h = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();

            var r = new bool[n];
            for(var i = 0; i < n; i++){
                r[i] = true;
            }

            for(var i = 0; i < m; i++){
                var __ = Console.ReadLine().Split();
                var a = int.Parse(__[0]);
                var b = int.Parse(__[1]);

                if(h[a-1] <= h[b-1]){
                    r[a-1] = false;
                }

                if(h[b-1] <= h[a-1]){
                    r[b-1] = false;
                }
            }

            Console.WriteLine(r.Count(f => f));
        }
    }
}


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

int main(){
	int n, m;
	int k[30], a[30][30];
	int answer[30] = {}, result = 0;
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		cin >> k[i];
		for(int j = 0; j < k[i]; j++){
			cin >> a[i][j];
			answer[a[i][j] - 1]++;
		}
	}

	for(int i = 0; i < m; i++){
		if(answer[i] == n) result++;
	}
	cout << result << endl;	
	return 0;
}


Measured memory_bytes: 256
//🅰🅸🅸🆂🅼🅴
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <numeric>
#include <stdlib.h>

using namespace std;

typedef long long ll;

const int AI1 = 10005;
const int AIMAX = 1e6 + 1;

int main()
{
    int n, m, k; cin >> n >> m >> k;
    if (k == 0)
    {
        cout << "Yes" << endl;
        return 0;
    }
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            if (i * (m - j) + j * (n - i) == k)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <math.h>
#include <stack>
#include <cctype>
using namespace std;
#define int long long
#define pi 2*acos(0.0)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)

signed main()
{
	char a;
	cin >> a;
	if (a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o') cout << "vowel" << endl;
	else cout << "consonant" << endl;
}


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


void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}




int main()
{
    init();

    int n,m ;cin>>n>>m; int a[m]; int sum=0;

    for (int i=0 ; i<m ;++i)

    {
        cin>>a[i]; sum+=a[i];
    }

    if (n-sum>=0) cout << n-sum;
    else cout << -1;

}




Measured memory_bytes: 3680
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

typedef long long LL;
LL a[100];
int main()
{
	int i, n;
	a[0] = 2LL, a[1] = 1LL;
	for(i = 2;i <= 86;i++)
		a[i] = a[i - 1] + a[i - 2];
		scanf("%d",&n);
		printf("%lld\n",a[n]);
	return 0;
}

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

const int MAXN = 1E5+3;

vector<pair<int,int> > a(MAXN);
vector<bool> appear(MAXN, 0);
vector<int> zero;

int sum = 0, cnt = 0;

int n, k;
int ans = 0;

signed main(){
  cin >> n >> k;
  for(int i=1; i<= n; ++i){
    cin >> a[i].second >> a[i].first;
  }
  sort(a.begin()+1, a.begin()+n+1, greater<pair<int,int> >());
  a[n+1] = {0, n+1};
  for(int i=1; i<= n+1; ++i){
    if(cnt > k) continue;
    if(!appear[a[i].second]){
      int cur = 0;
      if(zero.empty()) cur = 0;
      else if(k-cnt-1 >= (int)zero.size()) cur = zero.back();
      else if(k-cnt-1 >= 0) cur = zero[k-cnt-1]; 
      ans = max(ans, sum + cnt*cnt + cur);
      cerr << i << " " << sum << " " << cnt << " " << cur << "\n";
      appear[a[i].second] = 1;
      ++cnt;
      sum += a[i].first;
    }
    else{
      if(zero.empty()) zero.push_back(a[i].first);
      else zero.push_back(zero.back() + a[i].first);
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int K;
	cin >> K;
	vector<int> S{ 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cout << S[K - 1] << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

using namespace std;

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

    int n, p, aux;
    vector<int> h;
    vector<long long> min_cost;

    cin >> n;
    p = n;
    while(p--){
        cin >> aux;
        h.push_back(aux);
    }

    min_cost.assign(n, 0);
    min_cost[1] = abs(h[1]- h[0]);

    for(int i = 2; i < n; ++i){
        min_cost[i] = min(abs(h[i] - h[i-1]) + min_cost[i-1], abs(h[i] - h[i-2]) + min_cost[i - 2]);
    }

    cout << min_cost[n - 1] << '\n';

    return 0;
}

Measured memory_bytes: 1528
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val a = IntArray(N) { if (it == 0) 0 else readLine()!!.toInt() - 1 }
    val children = Array(N) { ArrayList<Int>() }

    for (i in 1 until N) {
        children[a[i]].add(i)
    }

    fun dfs(v: Int): Int {
        val u = ArrayList<Int>()

        for (c in children[v]) {
            u.add(dfs(c))
        }
        u.sortByDescending { it }

        if (u.size == 0) {
            return 0
        } else {
            return u.mapIndexed { index, value -> index + value + 1 }.max()!!
        }
    }

    println(dfs(0))
}


Measured memory_bytes: 85924
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j) for(int i;i<j;i++)
#define print(t) cout<<t<<endl
typedef long long ll;
typedef string str;

int main(){
	int x,a;
	cin >> x >> a;
	if(x<a){
		cout << 0 << endl;
	}else{
		cout << 10 << endl;
	}
	return 0;
}

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

using namespace std;

// arc98d
typedef long long ll;

ll n, A[200050];
int main(){
//	freopen("xorsum.in", "r", stdin);
	cin >> n;
	for(ll i = 0; i<n; i++){
		cin >> A[i];
	}
	ll s = 0, e = 0, cur = A[0], ans = 0;
	while(s < n){
		while(e+1 < n and (cur + A[e+1]) == (cur ^ A[e+1])) cur^=A[++e]; // while extendable
//		prllf("%d %d %d\n", s, e, cur);
		ans += e-s+1;
		assert(s <= e);
		cur^=A[s++];
	}
	cout << ans;
}


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

using namespace std;

using ll = long long;

struct _IN {
    _IN() {
        ios::sync_with_stdio(0);
        cin.tie(0);
    }
    template <typename T>
    operator T() const {
        T x;
        cin >> x;
        return x;
    }
    template <typename Container>
    void operator()(Container& c) {
        for (auto& x : c)
            cin >> x;
    }
} IN;

const ll MOD = 998244353;
const ll MODI = 499122177;

ll pow2(int e) {
    ll b = 2;
    ll res = 1;
    while (e) {
        if (e & 1)
            (res *= b) %= MOD;
        (b *= b) %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    ll N = IN, S = IN;
    vector<int> As(N);
    IN(As);
    vector<ll> dp(S + 1);
    dp[0] = pow2(N);
    for (auto a : As) {
        for (int i = S - a; i >= 0; i--) {
            (dp[i + a] += dp[i] * MODI) %= MOD;
        }
    }
    cout << dp[S] << endl;
}


Measured memory_bytes: 3652
#include <vector>
#include <stack>
#include <cstddef>
#include <algorithm>

struct strongly_connected_component {
	using size_type = std::size_t;
private :
	size_type _size;
	std::vector<std::vector<size_type>> g, scc;
	std::vector<size_type> low, order, index;
	std::vector<bool> instack;
	std::stack<size_type> stack;

	void chmin (size_type &a, const size_type &b) noexcept {
		if (a > b) a = b;
	}

	void dfs (size_type v) noexcept {
		low[v] = order[v] = ++_size;
		stack.push(v); instack[v] = true;
		for (const size_type &u : g[v]) {
			if (order[u] == 0) {
				dfs(u);
				chmin(low[v], low[u]);
			} else if (instack[u]) {
				chmin(low[v], order[u]);
			}
		}
		if (low[v] == order[v]) {
			scc.push_back(std::vector<size_type>());
			while (true) {
				const size_type u = stack.top();
				stack.pop(); instack[u] = false;
				scc.back().push_back(u);
				if (u == v) break;
			}
		}
	}

public :
	strongly_connected_component (size_type n)
	: g(n), scc(), low(n), order(n), index(n), instack(n, false), stack(), _size(0) { }

	void add_edge (size_type v, size_type u) noexcept {
		g[v].push_back(u);
	}

	size_type solve () noexcept {
		_size = 0;
		for (size_type i = 0; i < g.size(); i++) {
			low[i] = order[i] = index[i] = 0;
		}
		for (size_type v = 0; v < g.size(); v++) {
			if (order[v] == 0) dfs(v);
		}
		std::reverse(scc.begin(), scc.end());
		for (size_type i = 0; i < scc.size(); i++) {
			for (const size_type &v : scc[i]) index[v] = i;
		}
		return scc.size();
	}

	const std::vector<std::vector<size_type>> &get () const noexcept {
		return scc;
	}

	const size_type size () const noexcept {
		return scc.size();
	}

	const size_type &operator[] (size_type v) const noexcept {
		return index[v];
	}

};

#include <iostream>
#include <cstddef>

using usize = typename strongly_connected_component::size_type;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	usize n, m;
	std::cin >> n >> m;
	strongly_connected_component g(n);
	for (usize i = 0; i < m; i++) {
		usize a, b;
		std::cin >> a >> b;
		g.add_edge(a, b);
	}
	
	std::cout << g.solve() << '\n';
	for (const auto &vec : g.get()) {
		std::cout << vec.size();
		for (auto &v : vec) std::cout << ' ' << v;
		std::cout << '\n';
	}
	
	return 0;
}

Measured memory_bytes: 66432
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			XorData xorData = new XorData();
			int cnt = scn.nextInt();

			for(int i=0; i<cnt; i++) {
				xorData.add(scn.nextInt());
			}

			StringBuilder sb = new StringBuilder();
			IntStream.range(0, cnt).forEach(idx -> {
				if(0 < idx) {
					sb.append(' ');
				}
				sb.append(xorData.getOriginal(idx));
			});
			System.out.println(sb.toString());
		}
		/*
		XorData xorData = new XorData();
		IntStream.of(20, 11, 9, 24).forEach(xorData::add);
		IntStream.rangeClosed(0, 3).forEach(idx -> System.out.println(xorData.getOriginal(idx)));
		*/
	}

	public static class XorData {
		List<Integer> list = new ArrayList<>();

		int xorInt = 0;

		public int add(int xorNum) {
			list.add(xorNum);
			xorInt ^= xorNum;
			return xorInt;
		}

		public int getOriginal(int index) {
			return (xorInt ^ list.get(index));
		}
	}
}


Measured memory_bytes: 65568
N = int(input())
A = input()
B = input()
C = input()
ans = 0
for i in range(N):
  if A[i] == B[i] == C[i]:
    continue
  elif A[i] == B[i] and B[i] != C[i]:
    ans += 1
  elif A[i] == C[i] and C[i] != B[i]:
    ans += 1
  elif B[i] == C[i] and C[i] != A[i]:
    ans += 1
  else:
    ans += 2
print(ans)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, X: int, Y: int):
    ans = 10**9
    if A + B < 2 * C:#C=0
        ans = A*X + B*Y
    else:#C>1
        #Aを2*Cで補うときの利益 > Bを2*Cで補うときの利益
        if (A-2*C)*X + B*max(Y-X, 0) > (B-2*C)*Y + A*max(X-Y, 0):
            #A=0
            ans = 2*C*X + max(Y-X, 0)*B
        else:#B=0
            ans = 2*C*Y + max(X-Y, 0)*A
        if 2*C < A and 2*C < B:
            ans = min(ans, 2*C*max(X,Y))
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(A, B, C, X, Y)

if __name__ == '__main__':
    main()


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

int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    vector<ll> b(n, 0);
    rep(i, n) {
        cin >> a.at(i);
        b.at(i) = a.at(i) - (i+1);
    }
    sort(b.begin(),b.end());
    ll res = 0;
    if(n==1){
        res = b.at(0);
    }
    else {
        res = b.at(n/2LL);
    }

    ll ans = 0;
    for(ll i=0; i<n; i++){
        ans += (ll)abs(b.at(i)-res);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3328
implicit none
integer :: a,b
character(11) :: s
integer :: i
read *,a,b
read *,s

do i = 1, a
   if (s(i:i) == '-') then
      write(*,'(a)') 'No'
      stop
   endif
enddo

if (s(a+1:a+1) /= '-') then
   write(*,'(a)') 'No'
   stop
endif

do i = a+2,a+1+b
   if (s(i:i) == '-') then
      write(*,'(a)') 'No'
      stop
   endif
enddo

write(*,'(a)') 'Yes'
stop
end

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int n1,n2,n3;
	
	scanf("%d %d %d",&n1,&n2,&n3);
	
	if(n1<=n2&&n2<=n3) printf("%d %d %d\n",n1,n2,n3);
	else if(n1<=n3&&n3<=n2) printf("%d %d %d\n",n1,n3,n2);
	else if(n2<=n1&&n1<=n3) printf("%d %d %d\n",n2,n1,n3);
	else if(n2<=n3&&n3<=n1) printf("%d %d %d\n",n2,n3,n1);
	else if(n3<=n1&&n1<=n2) printf("%d %d %d\n",n3,n1,n2);
	else if(n3<=n2&&n2<=n1) printf("%d %d %d\n",n3,n2,n1);
	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[100010],b[100010];

int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	ll nowa=a[0],nowb=b[0];
	for(int i=0;i<n;i++){
		ll so=(a[i]+nowa-1)/a[i];
		so=max(so,(b[i]+nowb-1)/b[i]);
		nowa=a[i]*so;nowb=b[i]*so;
	}
	cout << nowa+nowb;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication32
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[2];
            a=Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] b = new int[a[0]];
            b=Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(b);
            Array.Reverse(b);
            int ans =0;
            for(int c =0;c<a[1];c++)
            ans+=b[c];
            Console.WriteLine(ans);
            }
      }
}


Measured memory_bytes: 13396
#include<iostream>
#include<vector>
using namespace std;
int main(void){
    int N;
    cin>>N;
    vector<int>price(N,0);
    vector<int>cost(N,0);

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

    vector<int>sa(N,0);
    int total=0;
    for(int k=0;k<N;k++){
        sa[k]=price[k]-cost[k];
        if(sa[k]>0){
            total=total+sa[k];
        }
    }
    
    cout<<total<<endl;


    return 0;
}

Measured memory_bytes: 256
N = int(input())
li = [ int(it) for it in input().split() ] 

keta = 0
p = max(li)
for i in range(100000):
  if (p>0):
    keta+=1
    p//=2
  else:
    break

bli = [ [0]*keta for i in range(N) ]

for i in range(len(li)):
  p = li[i]
  for j in range(100000):
    if (p>0):
      bli[i][j]=p%2
      p//=2
    else:
      break
      
sli = [ [0]*(N+1) for i in range(keta) ]
for k in range(keta):
  for i in range(N):
    sli[k][i+1] = sli[k][i] + bli[i][k] 


s = 0
x = 0
y = 1
gli=[]
for i in range(N*N):
    
    flag = True
    for k in range(keta):
      if (sli[k][y] - sli[k][x] < 2):
        pass
      else:
        flag=False


    if flag:
      if ( len(gli) > 0 ):
        if (gli[-1][0]==x):
          gli.pop()
      gli.append([x,y])    

    if (x==N-1 and y==N):
      break
     
    
    if (flag):
      y+=1
      if(y>N):
        x+=1
      y=min(y,N)
    else:
      x+=1
      y-=1
      x = min(N,x)

s=0
for a,b in gli:
  s+=b-a
print(s)


Measured memory_bytes: 133408
N,M = [int(i) for i in input().split()]
student = [[int(i) for i in input().split()] for j in range(N)]
check = [[int(i) for i in input().split()] + [j+1] for j in range(M)]
print("\n".join(map(str, [min(check, key=lambda x: abs(i[0] - x[0]) + abs(i[1] - x[1]))[-1] for i in student])))

Measured memory_bytes: 9148
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

ll a[1010],a1[1010];

int main()
{
	int e, y;
	cin >> e >> y;

	if (e == 0) {
		if (y >= 1989 && y <= 2016)cout << "H" << y - 1989 + 1 << endl;
		if (y >= 1926 && y <= 1988)cout << "S" << y - 1926 + 1 << endl;
		if (y >= 1912 && y <= 1925)cout << "T" << y - 1912 + 1 << endl;
		if (y >= 1868 && y <= 1911)cout << "M" << y - 1868 + 1 << endl;
	}
	else if (e == 1)cout << 1868 + y - 1 << endl;
	else if (e == 2)cout << 1912 + y - 1 << endl; 
	else if (e == 3)cout << 1926 + y - 1 << endl;
	else if (e == 4)cout << 1989 + y - 1 << endl;

	return	0;
}

Measured memory_bytes: 3096