akhauriyash/Code-Regression huggingface dataset:
/* 
	Author: ankrypt
*/
#include <bits/stdc++.h>

using namespace std;

char x;
char y;
int num1;
int num2;

int main()
{
	cin >> x;
	cin >> y;
	if(x == 'A')
	{
		num1 = 10;
	}
	if(x == 'B')
	{
		num1 = 11;
	}
	if(x == 'C')
	{
		num1 = 12;
	}
	if(x == 'D')
	{
		num1 = 13;
	}
	if(x == 'E')
	{
		num1 = 14;
	}
	if(x == 'F')
	{
		num1 = 15;
	}
	if(y == 'A')
	{
		num2 = 10;
	}
	if(y == 'B')
	{
		num2 = 11;
	}
	if(y == 'C')
	{
		num2 = 12;
	}
	if(y == 'D')
	{
		num2 = 13;
	}
	if(y == 'E')
	{
		num2 = 14;
	}
	if(y == 'F')
	{
		num2 = 15;
	}
	if(num1 > num2)
	{
		 printf(">\n");
	}
	else if(num1 < num2)
	{
		printf("<\n");
	}
	else
	{
		printf("=");
	}


	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int init = 100000;
		for(int i = 0; i < n;i++){
			init = (int) ((int) init * 1.05);
			if(init%1000 != 0){
				init = ((init / 1000)+1) *1000;
			}
		}
		System.out.println(init);
		
	}

}

Measured memory_bytes: 23812
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
void YesNo(bool j){cout << (j ? "Yes" : "No") << endl; return;}
void yesno(bool j){cout << (j ? "yes" : "no") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}

vector<int> to[200005];

int main() {
    int n,m;
    cin >> n >> m;
    rep(i,m) {
        int u,v;
        cin >> u >> v;
       
        to[v].push_back(u);
        to[u].push_back(v);
    }
    vector<int> c(n+1,inf);
    queue<int> q;
    vector<int> ans(n+1,-1);

    c[1]=1;
    q.push(1);
    while(!q.empty()) {
        int a=q.front();q.pop();
        
        for(int i : to[a]) {
            if(c[i]!=inf) continue;
            c[i]=c[a]+1;
            ans[i]=a;
            q.push(i);
        }
    }
    /* bool ok=true;
    for(int i=1 ;i<n+1;i++) {
        if(c[i]==inf) ok=false;
    }
    if(!ok) {
        pt("No");
    }
    else {
        pt("Yes");
        for(int i=2; i<=n; i++) {
            pt(ans[i]);
        }
    }*/
    pt("Yes");
        for(int i=2; i<=n; i++) {
            pt(ans[i]);
        }
    return 0;
}


Measured memory_bytes: 12896
#include <iostream>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	int check = b * 10 + c;
	if (check % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}


	return 0;
}

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

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

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

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

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

    var(intmax_t, H, W);

    const auto updiv = [](intmax_t n, intmax_t d) { return (n + d - 1) / d; };
    output((H == 1 || W == 1) ? 1 : updiv(H * W, 2));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>

using namespace std;

typedef long long ll;

int main() {
    string s;   cin >> s;
    int n = s.length();

    for (int i = 0; i < n/2; i++) {
        if (s[i] != s[n-i-1]) {
            cout << "No" << endl;
            return 0;
        }
    }   

    for (int i = 0; i <= (n-1)/2-1; i++) {
        if (s[i] != s[(n-1)/2-1-i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    for (int i = 0; i < n/2; i++) {
        if (s[n/2 + i + 1] != s[n-1-i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define sz(x) ((int)x.size())
#define we first.first
#define du first.second
#define be second

bool compareInterval(pair< pair<int, int>, int > l, pair< pair<int, int>, int > r) 
{
    return l.we+l.du < r.we+r.du;
}

int mx[20005] = {0};
vector< pair< pair<int, int>, int > > v;

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        int w, s, b;
        cin >> w >> s >> b;
        v.pb({{w, s}, b});
    }
    sort(v.begin(), v.end(), compareInterval);
    for(auto &k: v)
    {
        // cout << k.we << " " << k.du << " " << k.be << endl;
        for(int i = k.du; i >= 0; i--)
            mx[i+k.we] = max(mx[i+k.we], mx[i]+k.be);
    }
    int ans = 0;
    for(int i = 0; i < 20005; i++)
        ans = max(ans, mx[i]);
    cout << ans << endl;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 1e18
#define five 100005;
#define six 1000005;
#define prllclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________

int main()
{
       speed;
       int n,m;
       cin>>n>>m;
       ld a[n];
       arrin(a,n);
       sort(a,a+n);
       reverse(a,a+n);
       ld sum = 0;
       fri(i,0,n){sum += a[i];}
       ld lim = sum/(4.00*m);
       //cout<<lim<<endl;
       bool ff = true;
       fri(i,0,m){
              if(a[i]<lim){
                     ff = false;
              }
       }
       if(ff){
              cout<<"Yes"<<endl;
       }
       else{
              cout<<"No"<<endl;
       }



}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

int main()
{
    int h, w, n;
    std::cin >> h >> w >> n;

    std::cout << ceil((double)n / std::max(h, w)) << std::endl;
}


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

using namespace std;

int main(){
  int k, s, count =0;
  cin >> k >> s;
  for(int i=0;i<=k;i++){
	for(int j=0;j<=k;j++){
      int z=s-i-j;
	  if((0<=z)&&(z<=k))count++;
	}
  }
  cout  << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	int n=read(),k=read(),s=read();
	int a=s,b=s+1;
	if (b>1e9) b=1;
	rep(i,1,k) printf("%d ",a);
	rep(i,k+1,n) printf("%d ",b);
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 200500000000000000
#define MOD 1000000007
#define N 100005
#define M 1000005
#define LOG 18
#define KOK 4000000
using namespace std;

int n,x,y,z;
int sub[N];
ll der[N];
ll ans;
vector<ii> v[N];

int fcnt(int node,int ata) {

	for(ii i:v[node]) {

		if(i.st==ata) continue ;

		if(sub[i.st]>n/2) return fcnt(i.st,node);

	}

	return node;

}

void dfs(int node,int ata) {

	ans+=2ll*der[node];

	sub[node]=1;

	for(ii i:v[node]) {

		if(i.st==ata) continue ;

		der[i.st]=der[node]+i.nd;

		dfs(i.st,node);

		sub[node]+=sub[i.st];

	}

}

int main() {

//	freopen("input.txt","r",stdin);	

	scanf("%d",&n);

	for(int i=1;i<n;i++) {

		scanf("%d %d %d",&x,&y,&z);

		v[x].pb({y,z});
		v[y].pb({x,z});

	}

	dfs(1,0);

	int root=fcnt(1,0);

	ans=0;

	der[root]=0;

	dfs(root,0);

	ll mn=inf;

	for(int i=1;i<=n;i++) {

		if(i==root) continue ;

		umin(mn,der[i]);

	}

	for(int i=1;i<=n;i++) {

		if(n-sub[i]-1<sub[i] && i!=root) {

			mn=der[i];

			break ;

		}

	}

	printf("%lld",ans-mn);

}



Measured memory_bytes: 12288
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
#include<math.h>
#include<sstream>
typedef long long ll;
#define N (1000000000+7)
#define INF (1e18)
using namespace std;
typedef pair<int, int> P;

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


int main(void) {
	ll n, ans = 0;
	cin >> n;
	vector<ll>a(n), b(n), c(n);
	for (ll i = 0;i < n;i++)cin >> a[i];
	sort(a.begin(), a.end());
	for (ll i = 0;i < n;i++)cin >> b[i];
	//sort(b.begin(), b.end());
	for (ll i = 0;i < n;i++)cin >> c[i];
	sort(c.begin(), c.end());
	for (ll i = 0;i < n;i++) {
		ll an = 0, cn = 0;
		if (binary_search(a.begin(), a.end(), b[i])) {
			an = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
			cn = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
			cn = n - cn;
		}
		else {
			an = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
			cn = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
			cn = n - cn;
		}
		//cout << an << " " << cn << endl;
		ans += an * cn;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
s = list(input())
t = list(input())

dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]#外側から内側のイメージ

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

ans = []
i = len(s)
j = len(t)
while True:
    if dp[i][j] == dp[i][j-1]:
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else:
        ans.append(s[i-1])
        i -= 1
        j -= 1

    if i == 0 or j == 0:
        break

ans.reverse()
print(''.join(ans))

Measured memory_bytes: 112604
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> bool chmax(Type_a &a,const Type_b &b){if(a<b){a=b;return true;}return false;}
template<class Type_a,class Type_b> bool chmin(Type_a &a,const Type_b &b){if(a>b){a=b;return true;}return false;}
template<class Type> Type igcd(Type x,Type y){if(y==0)return x;return igcd(y,x%y);}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	string t="CODEFESTIVAL2016";
	
	string s;
	cin>>s;
	
	int ans=0;
	REP(i,t.size()){
		if(t[i]==s[i]){}
		else ans++;
	}
	
	cout<<ans<<endl;
}

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

ops = []
for i in range(n):
  for j, b in enumerate(reversed(bs)):
    if n - i - j == b:
      bs.pop(n-i-j-1)
      ops.append(n-i-j)
      break
  if len(bs) == n-i:
    break
if len(ops) == n:
  print(*reversed(ops), sep="\n")
else:
  print(-1)

Measured memory_bytes: 39664
use std::cmp::max;
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//usage
//input! {
//  h: i32;
//  v: [i32; n]
//  x: [[i32; n]; m]
//  f: chars <- Vec<char>
//}

fn main() {
    input!{
        s: chars,
        t: chars
    }

    // dp[i][j] = sのi文字目までとtのj文字目までの中での部分列の最大
    // dp[i][j] = max(dp[i - 1][j - 1] + 1, dp[i - 1][j], dp[i][j - 1])
    let mut dp = vec![vec![0; s.len() + 1]; t.len() + 1];

    for i in 1..t.len() + 1 {
        for j in 1..s.len() + 1 {
            dp[i][j] = max(max(dp[i - 1][j - 1] + (t[i - 1] == s[j - 1]) as i64, dp[i - 1][j]), dp[i][j - 1]);
        }
    }

    let mut ans: Vec<char> = Vec::new();
    let (mut slen, mut tlen) = (s.len(), t.len());
    while slen > 0 && tlen > 0 {
        if dp[tlen][slen] == dp[tlen - 1][slen] {
            tlen -= 1;
        }
        else if dp[tlen][slen] == dp[tlen][slen - 1] {
            slen -= 1;
        }
        else {
            tlen -= 1;
            slen -= 1;
            ans.push(s[slen])
        }
    }
    println!("{}", ans.into_iter().rev().collect::<String>());

}

Measured memory_bytes: 90364
import std.stdio, std.string, std.array, std.conv, std.algorithm;

void main() {
    int n = readln.chomp.to!int;
    long[] a = readln.chomp.split.to!(long[]);
    a.sort;
    writeln(a[0], " ", a[n-1], " ", a.sum);
}


Measured memory_bytes: 2888
#include<iostream>
#include<string>
using namespace std;
long long x[100][100],y[100][100];
int main(){
	int h,w;
	while(true){
	cin>>w>>h;
	if(w==0&&h==0)
		break;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			x[i][j]=0;
			y[i][j]=0;
		}
	}
	for(int i=1;i<h;i++)
		x[i][0]=1;
	for(int i=1;i<w;i++)
		y[0][i]=1;
	for(int i=1;i<h;i++){
		for(int j=1;j<w;j++){
			for(int k=i-2;k>=0;k--)
				x[i][j]+=y[k][j];
			for(int k=j-2;k>=0;k--)
				y[i][j]+=x[i][k];
			if(x[i][j]>=100000)
				x[i][j]%=100000;
			if(y[i][j]>=100000)
				y[i][j]%=100000;
		}
	}
	cout<<(x[h-1][w-1]+y[h-1][w-1]+x[h-1][w-2]+y[h-2][w-1])%100000<<endl;
	}
	return 0;
}

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

const int DX[] = {-1, 0, 1, 0};
const int DY[] = {0, 1, 0, -1};
const int N = 2001;
char s[N][N];
bool visited[N][N];
int cnt[N][N][4], root[N][N];
int m, n;

void dfs(int x, int y) {
	visited[x][y] = true;
	for (int dir = 0; dir < 4; ++dir) {
		int nx = x + DX[dir], ny = y + DY[dir];
		if (nx >= 0 && nx < m && ny >= 0 && ny < n && !visited[nx][ny] && s[nx][ny] == '1') {
			dfs(nx, ny);
			cnt[nx + 1][ny + 1][dir] = 1;
		}
	}
}

int main() {
	ios::sync_with_stdio(false); cin.tie(NULL);
	cin >> m >> n;
	int nq; cin >> nq;
	for (int i = 0; i < m; ++i) cin >> s[i];
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < n; ++j) if (!visited[i][j] && s[i][j] == '1') {
			root[i + 1][j + 1] = 1;
			dfs(i, j);
		}
	}
	for (int i = 0; i <= m; ++i) {
		for (int j = 0; j <= n; ++j) {
			if (i > 0) {
				cnt[i][j][0] += cnt[i][j - 1][0];
				cnt[i][j][2] += cnt[i][j - 1][2];
			}
			if (j > 0) {
				cnt[i][j][1] += cnt[i - 1][j][1];
				cnt[i][j][3] += cnt[i - 1][j][3];
			}
			if (i > 0 && j > 0) {
				root[i][j] += -root[i - 1][j - 1] + root[i - 1][j] + root[i][j - 1];
			}
		}
	}
	for (int i = 0; i < nq; ++i) {
		int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		int res = root[x2][y2] + root[x1 - 1][y1 - 1] - root[x1 - 1][y2] - root[x2][y1 - 1];
// 		cout << "res" << res << endl;
		res += cnt[x2][y2][0] - cnt[x2][y1 - 1][0];
		res += cnt[x2][y1][1] - cnt[x1 - 1][y1][1];
		res += cnt[x1][y2][2] - cnt[x1][y1 - 1][2];
		res += cnt[x2][y2][3] - cnt[x1 - 1][y2][3];
		cout << res << '\n';
	}
}


Measured memory_bytes: 88704
#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 <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {

    int n,k;
    string s;
    string ans = "";
    cin>>n>>k;
    cin>>s;
    for (int i = 0; i < n; ++i) {
        if(i + 1 == k){
            if(s[i] == 'A'){
                ans+='a';
            }else if(s[i] == 'B'){
                ans +='b';
            }else{
                ans +='c';
            }
        }else{
            ans += s[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s;
    char x = ',';
    cin >> s;
    int sz = s.size();
    for (int i = 0; i <sz ; i++){
        if(s[i]== x){
            s[i] = ' ';
        }
    }
    cout << s << endl;
    return 0;
}


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

int main()
{
    long c = 0, a = 1;
    long h = 0;
    scanf("%ld", &h);
    while (h > 1)
    {
        c += a;
        h = h / 2;
        if (a == 1)
        {
            a++;
        }
        else
        {
            a *= 2;
        }
    }
    c += a;
    printf("%ld", c);
    return 0;
}

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

using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int N;
ll K;

struct matrix {
	int n;
	vector<vector<ll>> mat;

	matrix(int _n, int id = 0) {
		n = _n;
		mat.resize(n, vector<ll> (n, 0));
		if (id == 1) {
			for (int i = 0; i < n; i++)
				mat[i][i] = 1;
		}
	}

	matrix operator +(const matrix& b) {
		matrix sum(n);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				sum.mat[i][j] = mat[i][j] + b.mat[i][j];
		return sum;
	}

	matrix operator -(const matrix& b) {
		matrix dif(n);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				dif.mat[i][j] = mat[i][j] - b.mat[i][j];
		return dif;
	}

	matrix operator *(const matrix& b) {
		matrix prod(n);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++)
				for (int k = 0; k < n; k++)
					prod.mat[i][j] = prod.mat[i][j] + mat[i][k] * b.mat[k][j];
		}
		return prod;
	}

	matrix mul(const matrix& b) {
		matrix p(n);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				for (int k = 0; k < n; k++)
					p.mat[i][j] = (p.mat[i][j] + (mat[i][k] * b.mat[k][j]) % mod) % mod;
		return p;
	}

	matrix expo(ll pow) {
		matrix res(n, 1);
		while (pow) {
			if (pow & 1)
				res = res.mul(*this);
			*this = mul(*this);
			pow = pow >> 1;
		}
		return res;
	}
};

int main()
{
	ios_base::sync_with_stdio(0);

	cin >> N >> K;
	matrix graph(N);
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			cin >> graph.mat[i][j];
	matrix res = graph.expo(K);
	ll ans = 0;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			ans = (ans + res.mat[i][j]) % mod;
	cout << ans;

	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <array>
#include <math.h>
#include <algorithm>

using namespace std;
int main()
{
    //input data
    int N;
    cin >> N;
    int DP[100001];
    //dataset
    for (int i = 0; i < 100001; i++)
    {
        DP[100001] = 999;
    }
    DP[0] = 0;
    int min;

    for (int i = 1; i < 100001; i++)
    {
        min = DP[i - 1] + 1;

        for (int k = 1; k <= 6; k++)
        {
            if (i - (int)pow(6, k) + 1 > 0)
            {
                if (min > DP[i - (int)pow(6, k)] + 1)
                    min = DP[i - (int)pow(6, k)] + 1;
            }
        }

        for (int k = 1; k <= 5; k++)
        {
            if (i - (int)pow(9, k) + 1 > 0)
            {
                if (min > DP[i - (int)pow(9, k)] + 1)
                    min = DP[i - (int)(pow(9, k))] + 1;
            }
        }

        DP[i] = min;
    }

   
        cout << DP[N] << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll N, K;
    cin >> N >> K;
    vll H(N);
    rep(i, N) cin >> H[i];
    sort(H.begin(), H.end(), greater<ll>());
    ll ans = 0;
    for(ll i = K; i < N; i++) ans += H[i];
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;

struct lr{
  ll l,r,v;
  bool operator < (const lr &a) const {
    return r < a.r;
  }
} d[MAXn];
ll n,m;
ll seg[MAXn<<1],t[MAXn<<1];
void app(ll x,ll v){
  seg[x] += v;
  if (x < n) t[x] += v;
}
void push(ll x){
  for (ll h=__lg(n)+1;h>0;h--) {
    ll cur = x>>h;
    if (t[cur]) {
      app(cur<<1,t[cur]);
      app(cur<<1|1,t[cur]);
      t[cur] = 0;
    }
  }
}
void pull(ll x){
  while (x > 1) {
    x >>= 1;
    seg[x] = max(seg[x<<1],seg[x<<1|1]) + t[x];
  }
}
void ins(ll l,ll r,ll v){
  l += n, r += n;
  ll tl = l, tr = r;
  for (;l<r;l>>=1,r>>=1) {
    if (l&1) app(l++,v);
    if (r&1) app(--r,v);
  }
  pull(tl), pull(tr-1);
}
ll qr(ll l,ll r){
  ll ret = -INF;
  l += n, r += n;
  push(l), push(r-1);
  for (;l<r;l>>=1,r>>=1) {
    if (l&1) ret = max(ret,seg[l++]);
    if (r&1) ret = max(ret,seg[--r]);
  }
  return ret;
}
int main(){
  IOS();
  cin >> n >> m;
  REP (i,m) {
    cin >> d[i].l >> d[i].r >> d[i].v;
    d[i].l--, d[i].r--;
  }
  sort(d,d+m);

  ll idx = 0;
  REP (i,n) {
    ll tp = max(0LL,qr(0,i));
    ins(i,i+1,tp);
    while (idx < m && d[idx].r == i) ins(d[idx].l,d[idx].r+1,d[idx].v),idx++;
  }
  cout << max(0LL,qr(0,n)) << endl;
}


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

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

int main() {
    int n;
    int a[101000];
    int l[101000] = {0};
    int r[101000] = {0};
    ll ans = 0;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    for (int i = 1; i < n; i++) {
        l[i] = gcd(l[i - 1], a[i - 1]);
    }
    
    for (int i = (n - 2); i >= 0; i--) {
        r[i] = gcd(r[i + 1], a[i + 1]);
    }
    
    for (int i = 0; i < n; i++) {
        ans = max(ans, gcd(l[i], r[i]));
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int K;
string S;
// vector<int> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> K >> S;
  // A.resize(N);
  // for (int i = 0; i < N; i++) {
  //   int tmp;
  //   cin >> tmp;
  //   A[i] = tmp;
  // }

  for (int i = 0; i < S.size(); i++) {
    if (i < K) {
      cout << S[i];
    } else {
      cout << "...";
      break;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;

  ll t = 1;
  while(1){
    ll max = t * (t + 1) / 2;
    if(n <= max) break;
    t++;
  }
  cout << t << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int max = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int p = scan.nextInt();
            ans += p;
            max = Math.max(max, p);
        }
        System.out.println(ans - (max/2));
    }
}


Measured memory_bytes: 21716
#define rep(i,n) REP(i,0,n)
#define REP(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll MAXN = (ll)2e3+10;
const ll DIV = (ll)1e9+7;

int main(void) {
   ll N,K;
   cin>>N>>K;
   int A[200010] = {};
   rep (i,N) {
      ll a;
      cin>>a;
      A[a]++;
   }
   // N, i
   multimap<ll,ll,std::greater<ll>> B;
   for (int i = 0; i < 200010;i++) {
      if (A[i]>0) B.insert(make_pair(A[i],i));
      // if (A[i]>0)cout<<i<<" "<<A[i]<<endl;
   }
   ll ans = 0;
   if (B.size()<=K) ans = 0;
   else {
      auto itr2 = B.begin();
      rep(i,K) itr2 = B.erase(itr2);
      for (auto itr = B.begin();itr != B.end();itr++) {
         ans += itr->first;
      }
   }
   cout<<ans<<endl;
   return 0;
}

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

int main(){
  int N ; 
  cin >> N ; 
  vector<long long> A(N) ; 
  for(int i = 0 ; i < N ; i++) cin >> A.at(i) ; 
  
  long long  M = gcd(A.at(0) , A.at(1)) ; 
  for(int i = 2 ; i < N ; i ++){
    M = gcd(M,A.at(i)) ; 
  }
  
  cout << M << endl;
}

Measured memory_bytes: 3932
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		StringBuffer str = new StringBuffer(sc.nextLine());
		
		for (int i = 0; i < str.length(); i++)
		{
			char a = str.charAt(i);
			if (Character.isLowerCase(a))
				a -= 'a' - 'A';
			str.setCharAt(i, a);
		}
		System.out.println(str.toString());
	}
}

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

int main(){
    int n;
    int d[110];
    cin >> n;
    for(int i = 0; i< n; i++) cin >> d[i];

    set<int> values;
    for(int i=0; i<n; i++){
        values.insert(d[i]);
    }

    cout << values.size() << endl;
}

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

int main(){
	string a;
	string b;
	cin >> a;
	cin >> b;
	int ans=0;
	for(int i=0;i<(int)a.size();i++){
		if(a[i]!=b[i]) ans++;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3848
S=input()
s=len(S)
a=''
b=''
for i in range((s-1)//2):
    a+=S[i]
for n in range((s+3)//2-1,s):
    b+=S[n]
if a==b:
    A=a[::-1]
    B=b[::-1]
    if A==a and B==b:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 8840
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String N = sc.next();

        final int A = sc.nextInt();
        final int B = sc.nextInt();
        // final int N = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();
        System.out.println(A + B >= 10 ? "error" : A + B);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 22740
import sys

sys.setrecursionlimit(1000000)

n = int(input())
edge = [[] for i in range(n)]
a = [0] * n
b = [0] * n

color_dict = {}
k = 0

def dfs(x, last = -1, ban_color = -1):
    global k
    color = 1
    for to in edge[x]:
        if to == last:continue
        if color == ban_color:color += 1
        color_dict[(x, to)] = color
        dfs(to, x, color)
        color += 1
    k = max(k, color-1)

for i in range(n-1):
    a[i], b[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1
    edge[a[i]].append(b[i])
    edge[b[i]].append(a[i])


dfs(0)
print(k)

for i in range(n-1):
    if (a[i], b[i]) in color_dict:
        print(color_dict[(a[i], b[i])])
    else:
        print(color_dict[(b[i], a[i])])

Measured memory_bytes: 84520
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
	int n, i, j;
	int x[8], y[8];
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d%d", x+i, y+i);
	}
	double sum=0;
	for(i=0; i<n; i++){
		for(j=0; j<i; j++){
			double dx=x[i]-x[j];
			double dy=y[i]-y[j];
			sum += sqrt(dx*dx + dy*dy);
		}
	}
	printf("%.1000lf\n", sum*2/n);
}


Measured memory_bytes: 128
def problemB():
    """ B - 美しい文字列 """
    w = input()
    while True:
        if len(w) == 0:
            ans = 'Yes'
            break

        find = w[0]
        cnt = w.count(find)
        if cnt % 2 == 1:
            ans = 'No'
            break

        w = w.replace(find, '')

    print(ans)


if __name__ == '__main__':
    problemB()

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

int main() {
    int a, b;
    char op;
    while(true) {
        cin >>a >>op >>b;
        if ('?'==op)
            break;
        if ('+'==op)
            cout <<a+b <<endl;
        else if ('-'==op)
            cout <<a-b <<endl;
        else if ('*'==op)
            cout <<a*b <<endl;
        else
            cout <<a/b <<endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cstring>
using namespace std;
#define MAXN 100000
#define MOD 1000000007
char s[MAXN+5];
int len;
long long P3[MAXN+5];
long long QL[MAXN+5],QR[MAXN+5],KA[MAXN+5],KC[MAXN+5];
long long ans;
int main()
{
    scanf("%s",s+1);
    len=strlen(s+1);
    P3[0]=1;
    for(int i=1;i<=len;i++)P3[i]=(P3[i-1]*3)%MOD;
    for(int i=1;i<=len;i++)
    {
        if(s[i]=='A')KA[i]=KA[i-1]+1;
        else KA[i]=KA[i-1];
        if(s[i]=='?')QL[i]=QL[i-1]+1;
        else QL[i]=QL[i-1];
    }
    for(int i=len;i>=1;i--)
    {
        if(s[i]=='C')KC[i]=KC[i+1]+1;
        else KC[i]=KC[i+1];
        if(s[i]=='?')QR[i]=QR[i+1]+1;
        else QR[i]=QR[i+1];
    }
    for(int i=1;i<=len;i++)
    if(s[i]=='?'||s[i]=='B')
    {
        long long p1,p2,p3,p4;
        p1=(KA[i-1]*KC[i+1]*P3[QL[i-1]+QR[i+1]])%MOD;
        p2=(KA[i-1]*QR[i+1]*P3[QL[i-1]+QR[i+1]-1])%MOD;
        p3=(KC[i+1]*QL[i-1]*P3[QL[i-1]+QR[i+1]-1])%MOD;
        p4=(QL[i-1]*QR[i+1]*P3[QL[i-1]+QR[i+1]-2])%MOD;
        //printf("%lld %lld %lld\n",QL[i-1],QR[i+1],P3[QL[i-1]+QR[i+1]]);
        ans=((ans+p1)%MOD+(p2+p3)%MOD+p4)%MOD;
    }
    printf("%lld",ans);
}


Measured memory_bytes: 4224
import java.util.*;

public class Main {
	int INF = 1 << 24;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int [][] pass = new int[n][n];
			for(int i = 0 ; i < n; i++){
				Arrays.fill(pass[i], INF);
				pass[i][i] = 0;
			}
			for(int i = 0 ; i < m; i++){
				String [] input = sc.next().split(",");
				int a = Integer.parseInt(input[0]) - 1;
				int b = Integer.parseInt(input[1]) - 1;
				int cost1 = Integer.parseInt(input[2]);
				int cost2 = Integer.parseInt(input[3]);
				pass[a][b] = cost1;
				pass[b][a] = cost2;
			}
			String [] lastinput = sc.next().split(",");
			int from = Integer.parseInt(lastinput[0]) - 1;
			int to = Integer.parseInt(lastinput[1]) - 1;
			int money = Integer.parseInt(lastinput[2]);
			int h = Integer.parseInt(lastinput[3]);
			
			for(int j = 0; j < n; j++){
				for(int i = 0; i < n; i++){
					for(int k = 0; k < n; k++){
						pass[i][k] = Math.min(pass[i][k], pass[i][j] + pass[j][k]);
					}
				}
			}
			int ans = money - (pass[from][to] + pass[to][from] + h);
			System.out.println(ans);
		}
	}

	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 12000
def dfs(here, p, connect, depth, parent, d):
    parent[here] = p
    depth[here] = d
    for c in connect[here]:
        dfs(c, here, connect, depth, parent, d + 1)

from collections import defaultdict
v_num = int(input())
connect = defaultdict(list)
parent = [-1 for n in range(v_num)]
in_v = [0 for n in range(v_num)]
depth = [0 for n in range(v_num)]
for _ in range(v_num):
    inp = [int(n) for n in input().split(" ")]
    connect[inp[0]].extend(inp[2:])
    for c in inp[2:]:
        in_v[c] += 1
for i, n in enumerate(in_v):
    if not n:
        root = i
dfs(root, -1, connect, depth, parent, 0)
for v in range(v_num):
    if v == root:
        is_type = "root"
    elif len(connect[v]) == 0:
        is_type = "leaf"
    else:
        is_type = "internal node"
    print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format(v, parent[v], depth[v], is_type, connect[v]))

Measured memory_bytes: 33304
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int H,W;
  cin>>H>>W;
  vector<char> vec(H*W);//vecは各頂点の白か黒かを保持
  vector<int> answer(H*W+1,H+W);//各黒点からの距離のうち小さいものを保持(随時更新)
  for(ll i=0;i<H*W;i++){
    cin>>vec.at(i);
  }
  using Graph=vector<vector<int>>;
  Graph G(H*W+1);//グラフのサイズはマス目のサイズ+最初の仮想の点分の1
  for (ll i=0;i<H*W;++i){//グラフの作成
    if(vec.at(i)=='#'){//仮想の点からの辺を定義
      G[H*W].push_back(i);
    }
    if(i%W!=W-1){//左右方向の辺の定義
      G[i].push_back(i+1);
      G[i+1].push_back(i);
    }
    if(i<W*(H-1)){//上下方向の辺の定義
      G[i].push_back(i+W);
      G[i+W].push_back(i);
    }
  }
  vector<int> dist(H*W+1,-2);//全頂点を「未訪問」に初期化(-2だったら未訪問と判断)
  queue<int> que;
  dist[H*W]=-1;//仮想の点をスタートにする
  que.push(H*W);
  while(!que.empty()){
    int v=que.front();//キューから先頭頂点を取り出す
    que.pop();
    for(int nv:G[v]){//vから辿れる頂点をすべて調べる
      if(v==H*W || vec.at(nv)=='.'){ 
        if(dist[nv]!=-2){continue;}//すでに発見済みの頂点は探索しない
        dist[nv]=dist[v]+1;//新たな白色頂点nv について距離情報distを更新してキューに追加する
        answer.at(nv)=min(answer.at(nv),dist[nv]);//各黒点からの距離の最小値を必要に応じて更新
        que.push(nv);
      }
    }
  }
  int rock=0;//rockは各白点の(各黒点からの距離の最小値の)最大値を保持(随時更新)
  for(ll i=0;i<H*W;i++){
    if(vec.at(i)=='.'){rock=max(answer.at(i),rock);}
  }
  cout<<rock<<endl;
}

Measured memory_bytes: 71788
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n, X, M;
    while(cin>>n>>X>>M){
        --n;
        vl dp(M);
        dp[0] = X;
        fore(i,1,M){
            dp[i] = (dp[i-1]*dp[i-1])%M;
        }
        // print(dp);
        if(n<M){
            ll sum = 0;
            forn(i,n+1) sum+=dp[i];
            cout<<sum<<"\n"; continue;
        }

        set<ll> seen;
        int stval = -1;
        for(auto x: dp){
            if(!seen.count(x)){
                seen.insert(x);
            }else{
                stval = x; break;
            }
        }
        
        int st = 0, ed = 0;
        if(stval!=-1){
            while(dp[st]!=stval) ++st;
            ed = st;
            while(dp[ed+1]!=dp[st]) ++ed;
        }else st = M, ed = M;

        ll sum = 0;
        forn(i,st) sum+=dp[i];
        n-=(st-1);
        int clen = (ed-st+1);
        ll cycsum = 0;
        for(int i=st; i<=ed; ++i) cycsum+=dp[i];
        
        sum+=(cycsum)*(n/clen);
        int rem = n%clen;
        forn(i,rem) sum+=dp[st+i];
        cout<<sum<<"\n";


    }
    return 0;
}

Measured memory_bytes: 6268
#include <bits/stdc++.h>
using namespace std;
int main(){
        int q, n; cin >> q >> n;
        set<int> s;
        for (int x = 1; x <= n; ++x){
            int v; cin >> v;
            s.insert(v);
        }
        for (int y = 0; ; ++y){
            if (s.find(q-y) == s.end()){
                cout << q-y << endl;
                break;
            }
            if (s.find(q+y) == s.end()){
                cout << q+y << endl;
                break;
            }
        }
    return 0;
}


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

cost = abs(a[0])
for i in range(1,n):
    cost += abs(a[i]-a[i-1])
#print(cost)
cost+=abs(a[-1])
ans = [0]*n
#print(cost)
#ans[0] = cost - abs(a[1]-a[0])-abs(a[0])+abs(a[1])
an =  cost - abs(a[1]-a[0])-abs(a[0])+abs(a[1])
#ans[n] = cost - abs(a[n])
print(an)
for i in range(1,n-1):
    key = cost-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])
    #ans[i] = key
    print(key)
print(cost-abs(a[-1])+abs(a[-2])-abs(a[-1]-a[-2]))

Measured memory_bytes: 20420