akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long int ll;

int main(){
  while(1){
    int n,m; cin >> n >> m;
    if(n==0&&m==0)break;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    a.push_back(0);
    vector<ll> v;
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
        v.push_back(a[i]+a[j]);
      }
    }
    sort(v.begin(),v.end());
    ll ans=0;
    for(int i=0;i<v.size();i++){
        if(m-v[i]>=0){
            int left=-1,right=v.size();
            while(right-left>1){
                int mid=(right+left)/2;
                if(v[mid]<=m-v[i]){
                    left=mid;
                }
                else{
                    right=mid;
                }
            }
            ans=max(ans,v[i]+v[left]);
        }
    }
    cout << ans << endl;
  }
  return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;

    int ans;
    for (int i = 1; i <= (int)sqrt(n); i++) {
        if (i*i <= n) {
            ans = i*i;
        }
        if (i*i > n) {
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
#define N 200100
#define LL long long

LL s[N],n,m,d[N],sum[N*4];
map<LL,int>mp;
int tmp;

void add(int x)
{
    while(x < N)
    {
        sum[x]++;
        x += (x & -x);
    }
}

LL get(int x)
{
    LL su = 0;
    while(x > 0)
    {
        su += sum[x];
        x -= (x & -x);
    }
    return su;
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;
    LL x;
    for(int i=1;i<=n;i++)
    {
        cin >> x;
        x -= m;
        s[i] = s[i-1] + x;
        d[i] = s[i];
    }
    sort(d,d+1+n);
    mp.clear();
    tmp = 0;
    for(int i=0;i<=n;i++)
     if(!mp[d[i]])
         mp[d[i]] = ++tmp;
    LL ans = 0;
    for(int i=0;i<=n;i++)
    {
        ans += get(mp[s[i]]);
        add(mp[s[i]]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 19584
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <queue>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}

int main(){
    int n ;
    string s ;
    cin >> n >> s ;
    int ans = 0 ;
    int now = 0 ;
    for (int i = 0; i < s.size(); i++)
    {
        if (s.at(i) == 'I')
        {
            now ++ ;
        }else
        {
            now -- ;
        }
        ans = max(now,ans) ;
        
    }
    cout << ans << endl ;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int g[101][101];

vector<int> G[(1 << 16)];
int dist[(1 << 16)];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,K;
    cin >> n >> m >> K;
    vi d(m),unzip(n,-1);
    rep(i,m){
        cin >> d[i];
        --d[i];
        unzip[d[i]] = i;
    }
    rep(i,n){
        rep(j,K){
            cin >> g[i][j];
            --g[i][j];
        }
    }
    rep(i,(1 << m)){
        vi pos;
        rep(j,m){
            if((i >> j) & 1){
                pos.pb(d[j]);
            }
        }
        rep(k,K){
            int to = 0;
            rep(j,len(pos)){
                int nx = unzip[g[pos[j]][k]];
                if(nx >= 0){
                    to |= (1 << nx);
                }
            }
            G[i].pb(to);
        }
    }
    rep(i,(1 << m)){
        dist[i] = INF;
    }
    queue<int> que;
    que.push((1 << m)-1);
    dist[(1 << m)-1] = 0;
    while(!que.empty()){
        int p = que.front();
        que.pop();
        rep(i,len(G[p])){
            if(dist[G[p][i]] > dist[p]+1){
                dist[G[p][i]] = dist[p]+1;
                que.push(G[p][i]);
            }
        }
    }
    cout << dist[0] << "\n";
    return 0;
}

Measured memory_bytes: 38852
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)

signed main() {
  int q; cin >> q;
  int n = 100000; 
  vector<bool> is_prime(n+1, true);
  is_prime[0] = false;
  is_prime[1] = false;
  for(int i=2; i<=n; i++) 
    if(is_prime[i]) 
      for(int j = 2; i * j <= n; j++) 
        is_prime[i*j] = false;

  vector<int> c(n+1);
  rep(i,n) {
    c[i] += is_prime[i] && is_prime[(i+1)/2];
    c[i+1] += c[i];
  }

  rep(i,q) {
    int l,r; cin >> l >> r;
    cout << c[r] - c[l-1] << endl;
  }
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

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

int main(int argc, char **argv)
{
	ll K, T; cin >> K >> T;
	vector<ll> A(T);
	REP(i, T) cin >> A[i];

	sort(ALL(A), greater<ll>());
	ll m = A.front();
	ll sum = accumulate(next(A.begin()), A.end(), 0ll);
	std::cout << max(m - sum - 1, 0ll) << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    Hello
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b + c >= 22)
        cout << "bust";
    else
        cout << "win";
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb(x)           push_back(x)
#define mkp(x,y)        make_pair(x,y)
#define L               length()
#define int             long long
#define bs              binary_search
#define mod             1e9+7
#define IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(v)          v.begin(),v.end()
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define F               first
#define S               second
#define pii             pair<int,int>
#define vi              vector<int>
#define vs              size()
#define gcd(a,b)        __ gcd(a,b)
#define endl            '\n'
#define atoi            stoi
#define elasped_time    1.0 * clock() / CLOCKS_PER_SEC
#define si              set <int>
#define vpii            vector < pair <int,int> >
#define memf(a)         memset(a,false,sizeof(a))
#define memt(a)         memset(a,true,sizeof(a))
#define xxx             998244353
#define pi              3.141592653589
#define ninf            INT_MIN
#define inf             INT_MAX
#define sz(v)           ((int)(v).size())
int max(int a,int b){if(a>b){return a;}else{return b;}}
int min(int a,int b){if(a<b){return a;}else{return b;}}
void dpv(vi v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void dpv(vpii v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i].F<<" "<<v[i].S<<endl;
    }
}
void dpv(set <int> v)
{
    for(auto i:v)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}
//////////////////////**TREE MOVES STARTS**//////////////////////////////
///// **TREE MOVES ENDS**////////////////////////////

////*SOLUTION TO THE QUESTION STARTS HERE*///////
int dp[100005];
vector <vi> v(100005);
bool vis[100005];//vis1[100005];
void dfs(int x)
{
    vis[x]=true;
    for(auto i:v[x])
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
    if(sz(v[x]))
    {
        int ma=-inf;
        for(auto i:v[x])
        {
            //cout<<dp[i]<<" ";
            ma=max(ma,dp[i]);
        }
        //cout<<ma<<endl;
        dp[x]=1+ma;
    }
    else
    {
        dp[x]=0;
    }
}
void oblivious()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
    }
    for(int i=1;i<=n;i++)
    {
        if(!sz(v[i]))
        {
            dp[i]=0;
        }
    }
    memf(vis);
    //memf(vis1);
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
    int ma=-inf;
    for(int i=1;i<=n;i++)
    {
        //cout<<dp[i]<<" ";
        ma=max(dp[i],ma);
    }
    cout<<ma<<endl;
}
signed main()
{
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    int t=1;
    //cin>>t;
    while(t--)
    {
        oblivious();
    }
    return 0;
}
//Md Zuhair

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main()
{
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> k;
    for (int i=1; i<=min(A, B); ++i) {
        if (A%i == 0 and B%i == 0) k.push_back(i);
    }
    sort(k.rbegin(), k.rend());
    cout << k[K-1] << endl;
}


Measured memory_bytes: 256
def main():
    s = input()
    t = s.replace("x", "")
    M = len(t)
    for i in range(M//2):
        if t[i] != t[M-i-1]:
            print(-1)
            return
    xcnt = [0] * (M+1)
    i = 0
    for c in s:
        if c == "x":
            xcnt[i] += 1
        else:
            i += 1
    ans = 0
    for i in range((M+1)//2):
        ans += abs(xcnt[i] - xcnt[M-i])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41328
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

int main() {
	string s; cin >> s;
	bool x, y;
	if ((s[0] == '1'&&((s[1]=='0')|| (s[1] == '1') || (s[1] == '2')) ) || s[0] == '0'&&s[1]!='0')x = 1;
	else x = 0;
	if ((s[2] == '1' && ((s[3] == '0') || (s[3] == '1') || (s[3] == '2'))) || s[2] == '0'&&s[3] != '0')y = 1;
	else y = 0;
	
	if (x == 1 && y == 1)cout << "AMBIGUOUS" << endl;
	else if (x == 1 && y == 0)cout << "MMYY" << endl;
	else if (x == 0 && y == 1)cout << "YYMM" << endl;
	else cout << "NA" << endl;
}



Measured memory_bytes: 256
x,n = map(int, input().split())
if n==0:
  print(x)
else:
  p = list(map(int,input().split()))
  for i in range(100):
    if x-i not in p:
      print(x-i)
      break
    elif x+i not in p:
      print(x+i)
      break 


Measured memory_bytes: 9172
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 998244353
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<ll> v(n);
    map<ll,ll> m;
    for(auto &x:v)
    {
        cin>>x;
        m[x]++;
    }
    if(m[0]>1)
    {
        cout<<0<<endl;
        return 0;
    }
    if(v[0]>0)
    {
        cout<<0;
        return 0;
    }
    vector<ll> v2;
    vector<ll> v1;
    for(auto x:m)
    {
        v1.pb(x.fi);
        v2.pb(x.se);
    }
    ll sz = v1.size();
    if(v1[sz-1]!=sz-1)
    {
        cout<<0;
        return 0;
    }
//    return 0;
    ll ans = 1ll;
    for(ll i=0;i<(v2.size()-1);i++)
    {
        ll temp = powmod(v2[i],v2[i+1],M);
        temp = temp%M;
        ans = (ans*temp)%M;
    }
    ans = ans%M;
    cout<<ans;
    return 0;
}































Measured memory_bytes: 9076
var
	l, k, n, i, q : integer;
begin
	readln(n,k);
	l := 1;
	for i := 1 to n do
	begin
		if (l*2) > (l+k) then
		begin
			l := l+k;
		end
		else begin
			l := l*2;
		end;
	end;
	writeln(l);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while (b <= a) {
        b *= 2;
        k--;
    }
    while (c <= b) {
        c *= 2;
        k--;
    }
    if (k >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(int argc, char const *argv[]) {
  long long a, b, i, max;
  int flag=0;

  cin >> a>> b;
  if (a>b) {
    max=a;
  } else {
    max=b;
  }
  for (i=0; i < max; i++) {
    if (abs(a-i)==abs(b-i)) {
      cout << i << endl;
      flag=1;
      break;
    }
  }
  if (flag==0) {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#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[i];
    if(a[0] != 0){
        cout << -1 << endl;
        return 0;
    }

    bool flag = true;
    for(int i = 0; i < n - 1; i++){
        if(a[i] < a[i + 1] && a[i] + 1 != a[i + 1]){
            flag = false;
            break;
        }
    }

    if(!flag){
        cout << -1 << endl;
        return 0;
    }

    a.push_back(10000000000000);
    long long ans = 0;
    for(int i = n - 1; i >= 0; i--){
        if(a[i + 1] - 1 == a[i]) continue;
        else{
            //cout << i << endl;
            ans += a[i];
        }
    }

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

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll H, n;
    cin >> H >> n;
    
    vl a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }

    vvl dp(n+1, vl(H+1, INF));  // dp[i+1][j] : i番目までの魔法でモンスターの体力がj以下のとき倒すまでに消耗する魔力の合計の最小値
    rep(i, n+1) {
        dp[i][0] = 0;
    }
    rep(i, n) {
        exrep(j, 1, H) {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][j], dp[i+1][max(0LL, j - a[i])] + b[i]);
        }
    }
    
    out(dp[n][H]);
    re0;
}

Measured memory_bytes: 78592
#include <bits/stdc++.h>
using namespace std;
long long n;
long long dp[3001][3001];

long long func(long long i,long long j,long long *a,long long total){
    if(i==j){
        return a[i];
    }
    if(dp[i][j]!=-1)
        return dp[i][j];
    dp[i][j]= max(total-func(i+1,j,a,total-a[i]),total-func(i,j-1,a,total-a[j]));
    return dp[i][j];
}

int main() {
	long long n;
	
	cin>>n;
	memset(dp,-1,sizeof(dp));
	long long a[n+1];
	long long total=0;
	for(long long i=1;i<=n;i++){
	    cin>>a[i];
	    total+=a[i];
	}
	cout<<2*func(1,n,a,total)-total;
    
}


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

int main() {
  int n, m;
  cin >> n >> m;
  if (n == m) {
 	cout << "Yes" << endl;
  } else {
 	cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  if(N<K+1){
    cout << N*X << endl;
  } else{
	cout << K*X + (N-K)*Y << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <set>
std::multiset<int> tail;
int A, N;

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A);
    auto ptr = tail.lower_bound(A);
    if (ptr != tail.begin()) {
      tail.erase(--ptr);
    }
    tail.insert(A);
  }
  printf("%u\n", tail.size());
  return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll a,b,m; cin>>a>>b>>m;
    ll res=1001001001;
    vector<ll> rei(a,0), den(b,0);
    ll reimin=1001001001, denmin=1001001001;
    rep(i,a){
        cin>>rei[i];
        chmin(reimin,rei[i]);
    }
    rep(i,b){
        cin>>den[i];
        chmin(denmin,den[i]);
    }
    res=reimin+denmin;
    rep(i,m){
        ll x,y,c; cin>>x>>y>>c;
        chmin(res,rei[x-1]+den[y-1]-c);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1792
f = 0
while 1:
  a, b = map(int, raw_input().split())
  if a == b == 0: break
  x = [i for i in range(a, b + 1) if (i % 4 == 0 and (i % 100 != 0 or i % 400 == 0))]
  if x == []: x = ["NA"]

  if f: print
  for e in x: print e
  f = 1

Measured memory_bytes: 4304
use std::io::{BufRead, Write};
use std::io;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut buf = String::new();
    input.read_line(&mut buf).unwrap();
    let m: u8 = buf.trim_right().parse().unwrap();
    writeln!(output, "{}", 48 - m).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }

    #[test]
    fn case1() {
        test(
            "21
",
            "27\n",
        );
    }

    #[test]
    fn case2() {
        test(
            "12
",
            "36\n",
        );
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define AC ios::sync_with_stdio(0),cin.tie(0);
#define ll long long int

ll dp[3015][3015];
ll a[3015];

int main(){
	AC
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		dp[i][i]=0;
	}
	for(int k=1;k<=n;k++){
		for(int j=0;j+k<=n;j++){
			int r=j+k;
			if(k%2==n%2)dp[j][r]=max(dp[j+1][r]+a[j],dp[j][r-1]+a[r-1]);
			else dp[j][r]=min(dp[j+1][r]-a[j],dp[j][r-1]-a[r-1]);
		}
	}
	cout<<dp[0][n]<<endl;
}


Measured memory_bytes: 49768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll a, b; cin >> a >> b;
	print(a*b)
	
	
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000000
#define loop(i,a,b) for(int i=a;i<b;i++)
int main()
{
    //freopen("contest.txt","r",stdin);
    //freopen("contest.txt","w",stdout);
    IOS
    int w,s;
    cin>>s>>w;
    if(w>=s)
        cout<<"unsafe"<<endl;
    else
        cout<<"safe"<<endl;
    return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define int             long long
#define no_of_test(x)   int x; cin>>x; while(x--)
const int mod = 1e9 + 7;
void very_fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}
int binary_exponentation(int a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b & 1) ret = (ret * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ret;
}

int32_t main()
{
	very_fast();
//	no_of_test(x)
	{
		int n, m;
		cin >> n >> m;
		int w = min(n, m);
		int r = max(n, m);
		for (int i = 0; i < r; i++)
		{
			cout << w;
		}
		cout << "\n";

	}
	return 0;

}


Measured memory_bytes: 3604
#include <cstdio>
#include <set>
#include <utility>

int main() {
    std::multiset<int> s;
    
    int a;
    while (~scanf("%d", &a)) {
       s.insert(a);
    }
    for (auto i = s.rbegin(); i != s.rend(); ++i) {
        printf("%d%c", *i, std::next(i) != s.rend() ? ' ' : '\n');
    }
}

Measured memory_bytes: 1016
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var t = new Test();
            var n = t.ParseIntList(t.ReadInput());
            var h = t.ParseLongList(t.ReadInput());
            var ansDic = new Dictionary<long, bool>();
            var towerDic = new Dictionary<int, long>();
            var count = 0;
            for(var i = 1; i<=h.Count; i++)
            {
                ansDic.Add(i, true);
                towerDic.Add(i, h[i - 1]);
            }
            
            for(var i = 0; i< n[1]; i++)
            {
                var temp = t.ParseIntList(t.ReadInput());
                if(towerDic[temp[0]] < towerDic[temp[1]])
                {
                    ansDic[temp[0]] = false;
                }
                else if (towerDic[temp[0]] > towerDic[temp[1]])
                {
                    ansDic[temp[1]] = false;
                }
                else
                {
                    ansDic[temp[0]] = false;
                    ansDic[temp[1]] = false;
                }
            }            

            foreach(var v in ansDic)
            {
                if (v.Value)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }


        public int ReadInputOneLine()
        {
            return int.Parse(Console.ReadLine());
        }

        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public List<int> ParseIntList(string[] x)
        {
            var convertedList = new List<int>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(int.Parse(x[i]));
            }

            return convertedList;
        }


        public List<double> ParseDoubleList(string[] x)
        {
            var convertedList = new List<double>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(double.Parse(x[i]));
            }

            return convertedList;
        }

        public List<long> ParseLongList(string[] x)
        {
            var convertedList = new List<long>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(long.Parse(x[i]));
            }

            return convertedList;
        }

        public int CountContainWords(string source, string word)
        {
            var count = 0;
            var loopCount = source.Length - (word.Length - 1);
            for (var i = 0; i < loopCount; i++)
            {
                if (source.Substring(i, word.Length) == word)
                {
                    count++;
                }
            }
            return count;
        }
    }
}

Measured memory_bytes: 43700
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A[]= new long[N];
		for (int i=0;i<N;i++) {
			A[i] = sc.nextLong();
		}
		Map<Long,Integer> map = new HashMap<Long,Integer>();
		for (int i=0;i<N;i++) {
			long temp = (i+1+A[i])*-1;
			if (map.containsKey(temp)) {
				Integer in = map.get(temp);
				in++;
				map.put(temp, in);
			} else {
				map.put(temp, 1);
			}
		}
		long result=0;
		for (int i=0;i<N;i++) {
			long temp = A[i]-i-1;
			if (map.containsKey(temp)) {
				int count = map.get(temp);
				if (A[i]==0) {
					count--;
				}
				result +=count;
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 68876
#include<stdio.h>
int main()
{
    int n,q;
    scanf("%d",&n);
    if(n<10)
    {
        if(n==2 || n==4 || n==5 || n==7 || n==9)
        {
            printf("hon\n");
        }
        else if(n==0 || n==1 || n==6 || n==8)
        {
            printf("pon\n");
        }
        else if(n==3)
        {
            printf("bon\n");
        }
    }
    else if(n>=10 && n<100)
    {
        q=n%10;
        if(q==2 || q==4 || q==5 || q==7 || q==9)
        {
            printf("hon\n");
        }
        else if(q==0 || q==1 || q==6 || q==8)
        {
            printf("pon\n");
        }
        else if(q==3)
        {
            printf("bon\n");
        }
    }
    else if(n>=100 && n<1000)
    {
        q=n%100;
       if(q>=10 && q<100)
        {
            q=q%10;
            if(q==2 || q==4 || q==5 || q==7 || q==9)
            {
                printf("hon\n");
            }
            else if(q==0 || q==1 || q==6 || q==8)
            {
                printf("pon\n");
            }
            else if(q==3)
            {
                printf("bon\n");
            }
        }
    }
}


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

using lint=long long;



void solve(){
    int a,b,c;cin>>a>>b>>c;
    if(a+b+c>=22)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
}

signed main(){
    //while(1)
    solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
int main() {
  long n,m;
  cin>>n>>m;
  vector<int>h(n);
  rep(i,n){
    cin>>h.at(i);
  }
  vector<int>d[n];
  vector<int>a(m),b(m);
  rep(i,m){
    cin>>a.at(i)>>b.at(i);
    a.at(i)--;
    b.at(i)--;
    d[a.at(i)].push_back(b.at(i));
    d[b.at(i)].push_back(a.at(i));
  }
  int ans=0;
  rep(i,n){
    bool ch=true;
    int p=d[i].size();
    rep(j,p){
      if(h.at(i)<=h.at(d[i].at(j))){
        ch=false;
      }
    }
    if(ch){
      ans++;
    }
  }
  
  cout<<ans<<endl;
}




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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)
  ll X;
  IN(X);

  ll Y = 100;
  double Y_d;
  ll count = 0;
  while(X>Y){
    Y_d = (double)Y*1.01;
    Y = (ll)Y_d;
    count++;
  }
  OUT(count);

  return 0;
}


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

int main(){
    int m1=0, m2=0;
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        if(a[i] > m1){
            m1 = a[i];
        }else if(a[i] >= m2){
            m2 = a[i];
        }
    }

    for(int i : a){
        if(i == m1){
            cout << m2 << endl;
        }else{
            cout << m1 << endl;
        }
    }
}

Measured memory_bytes: 2432
#include <stdio.h>
#include <string.h>
int main(void)
{
    char sa[105],sb[105],sc[105];
    char aa[1]={'a'};
    char bb[1]={'b'};
    char cc[1]={'c'};
    char null[1]={'\0'};
    int a=0, b=0, c=0, turn=0; 
    scanf("%s%s%s", sa, sb, sc);

    while(1)
    {
        if(turn==0)
        {
            if(strncmp(sa+a, null, 1)==0)
            {
                printf("A");
                break;
            }

            if(strncmp(sa+a, aa, 1)==0)
            {
                turn=0;
                a++;
            }
            else if(strncmp(sa+a, bb, 1)==0)
            {
                turn=1;
                a++;
            }
            else if(strncmp(sa+a, cc, 1)==0)
            {
                turn=2;
                a++;
            }
        }
        else if(turn==1)
        {
            if(strncmp(sb+b, null, 1)==0)
            {
                printf("B");
                break;
            }

            if(strncmp(sb+b, aa, 1)==0)
            {
                turn=0;
                b++;
            }
            else if(strncmp(sb+b, bb, 1)==0)
            {
                turn=1;
                b++;
            }
            else if(strncmp(sb+b, cc, 1)==0)
            {
                turn=2;
                b++;
            }

        }
        else if(turn==2)
        {
            if(strncmp(sc+c, null, 1)==0)
            {
                printf("C");
                break;
            }

            if(strncmp(sc+c, aa, 1)==0)
            {
                turn=0;
                c++;
            }
            else if(strncmp(sc+c, bb, 1)==0)
            {
                turn=1;
                c++;
            }
            else if(strncmp(sc+c, cc, 1)==0)
            {
                turn=2;
                c++;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

	int AnsCount = 0;
	for (int i = 0; i <= a; ++i)
	{
		for (int j = 0; j <= b; ++j)
		{
			for (int k = 0; k <= c; ++k)
			{
				if(500*i + 100*j + 50*k == x) AnsCount++;
			}
		}
	}

	cout << AnsCount << endl;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    stack<char> q;
    for (char c : s) {
        if (!q.empty() && q.top() == 'S' && c == 'T') q.pop();
        else q.push(c);
    }
    cout << q.size() << '\n';
}


Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
 
int main(void) {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int N;
	cin >> N;
	
	int L[2 * N];
	for(int i = 0; i < 2 * N;i++)
	{
		cin >> L[i];
	}

	sort(L, L + 2 * N);

	int ret = 0;
	for(int i = 0; i < 2 * N;i += 2)
	{
		ret += L[i];
	}

	cout << ret;
}

Measured memory_bytes: 384
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	
	dishes := make([]int, n)
	points := make([]int, n)
	bonuses := make([]int, n-1)
	
	for i := 0; i < n; i++ {
		scanner.Scan()
		j, _ := strconv.Atoi(scanner.Text())
		dishes[i] = j - 1
	}
	
	for i := 0; i < n; i++ {
		scanner.Scan()
		j, _ := strconv.Atoi(scanner.Text())
		points[i] = j
	}
	
	for i := 0; i < n-1; i++ {
		scanner.Scan()
		j, _ := strconv.Atoi(scanner.Text())
		bonuses[i] = j
	}
	
	answer := 0
	
	for i, s := range dishes {
		if i != 0 {
			if s == dishes[i-1]+1 {
				answer += bonuses[s-1]
			}
		}
		answer += points[s]
	}
	
	fmt.Println(answer)
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int use[34][100004];
int sum[34][100004];

int main(){
  int N, C;
  scanf("%d", &N);
  scanf("%d", &C);
  std::vector<int > s(N), t(N), c(N);
  for (int i=0; i<N; i++){
    scanf("%d", &s[i]);
    scanf("%d", &t[i]);
    scanf("%d", &c[i]);
    c[i]--;
    use[c[i]][s[i]]++;
    use[c[i]][t[i]+1]--;
  }
  for (int c=0; c<C; c++){
    for (int i=1; i<100003; i++){
      sum[c][i] = sum[c][i-1] + use[c][i];
      //printf("sum[%d][%d]=%d\n", c, i, sum[c][i]);
    }
  }
  int max=0;
  for (int i=0; i<100003; i++){
    int cnt=0;
    for (int c=0; c<C; c++){
      //printf("sum[%d][%d]=%d\n", c, i, sum[c][i]);
      if (sum[c][i]>0) cnt++;
    }
    //printf("i=%d, cnt=%d\n", i, cnt);
    max = std::max(max, cnt);
  }
  std::cout << max << std::endl;
  return 0;
}


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

int n,i,j,k,first,last;
long long res;
int a[200100],t[200100];
priority_queue <int,vector<int>,greater<int> > q[200100];


void mix(int x,int y) {
    while (q[x].size()) {
        q[y].push(q[x].top());
        q[x].pop();
    }
}

int main() {
    /*freopen("sort.inp","r",stdin);
    freopen("sort.out","w",stdout);//*/

    scanf("%d",&n);
    for (i=1;i<=n;i++) {
        scanf("%d",&a[i]);
        q[i].push(a[i]);
        t[i]=i;
    }
    sort(a+1,a+1+n);
    first=1; last=n;
    for (i=1;i<=n;++i) {
        k=first;
        if (q[t[first]].top()!=a[i]) {
            for (j=first+1;j<=last;++j) {
                mix(t[j],t[first]);
                k=j;
                if (q[t[first]].top()==a[i]) break;
            }
        }

        q[t[first]].pop();
        if (q[t[first]].size()>0) {
            t[++last]=t[first];
            res+=q[t[first]].size();
        }
        first=k+1;
    }
    cout << res << endl;
}



Measured memory_bytes: 19216
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    int i,j,k,m,n;
    cin>>m>>n;
    for(i=1;i<=m;i++)
    {
        cin>>a;
        cout<<a<<endl<<a<<endl;
    }
    return 0;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;

struct Tree {
  ll node_num;
  ll edge_num;
  ll diameter = -1;
  ll far_index = -1;
  vector<vector<ll>> to;
  vector<bool> visited;
  vector<int> depth;

  Tree(ll nn) : node_num(nn){
    edge_num = node_num - 1;
    to = vector<vector<ll>> (node_num);
    visited = vector<bool> (node_num, false);
    depth = vector<int> (node_num);
  }


  pair<ll, ll> get_far(ll from, ll d){
    visited[from] = true;
    for(auto a : to[from]){
      if(!visited[a]){
        get_far(a, d+1);
      }
    }
    if(diameter < d){
      diameter = d;
      far_index = from;
    }
    return {far_index, diameter};
  }

  ll get_diameter(ll from){
    pair<ll, ll> i_and_d = get_far(0, 0);
    init();
    diameter = get_far(i_and_d.first, 0).second;
    init();
    return diameter;
  }

  void init(){
    visited = vector<bool> (node_num, false);
  }

  int set_depth(int from, int d){
    visited[from] = true;
    depth[from] += d;
    // if(from != 0 && to[from].size() == 1) return depth[from];
    for(auto a : to[from]){
      if(!visited[a]) set_depth(a, depth[from]);
    }
    return depth[from];
    // return depth[from] = d;
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  Tree t(n);
  rep(i, n-1){
    int from, to;
    cin >> from >> to;
    from--; to--;
    t.to[from].push_back(to);
    t.to[to].push_back(from);
  }
  vector<p> query(q);

  for (int i = 0; i < q; i++) {
    cin >> query[i].first >> query[i].second;
    query[i].first--;
    t.depth[query[i].first] += query[i].second;
  }
  t.set_depth(0, 0);

  rep(i, n) cout << t.depth[i] << ' ';
  cout << endl;

}


Measured memory_bytes: 22784
import numpy as np

K, X = [int(i) for i in input().split(" ")]

l = X - K + 1
r = X + K - 1

if l < -1000000:
    l = -1000000
if r > 1000000:
    r = 1000000

x = np.arange(l,r+1)
for i in x:
    print(i, end=" ")

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

int N, A[100009], cnt, maxn = 0;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		if (A[i] == 1) { cnt++; }
		else { cnt = 0; }
		maxn = max(maxn, cnt);
	}
	cout << maxn + 1 << endl;
	return 0;
}


Measured memory_bytes: 3096
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
import re
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    s = SR(n)
    a = 0
    b = 0
    ab = 0
    ans = 0
    for si in s:
        if si[0] == "B" and si[-1] == "A":
            ab += 1
        elif si[0] == "B":
            b += 1
        elif si[-1] == "A":
            a += 1
        ans += si.count("AB")
    if ab:
        ans += ab - 1
        ans += (a > 0) + (b > 0)
        a -= a > 0
        b -= b > 0
    ans += min(a, b)
    print(ans)

    return


#main
if __name__ == '__main__':
    solve()


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

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

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      // #はそのまま出力
      if (s[i][j] == '#') {
        cout << '#';
        continue;
      }

      int count = 0;
      for (int k = -1; k <= 1; k++) {
        for (int l = -1; l <= 1; l++) {
          // 地雷があるかチェックしたい座標を変数に格納する
          int x = i + k;
          int y = j + l;

          if (x < 0 || x >= h || y < 0 || y >= w) {
            continue;
          }

          if (s[x][y] == '#') {
            count++;
          }
        }
      }
      cout << count;
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b;
	int add;
	int count;

	while (scanf("%d %d", &a, &b) != EOF){

		add = a + b;
	
		count = 0;
	
		while (add){
			add /= 10;

			count++;
		}

	printf("%d\n", count);
	}

	return (0);
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<ll,ll> pint;

vector<pint> vp[100001];
ll d[100001];
ll INF=1000100010001000100;
int n;
int dijkstra(int st){
    priority_queue<pint,vector<pint>,greater<pint> > pq;
    rep(i,n) d[i]=INF;
    d[st]=0;
    pq.push(make_pair(0,st));
    while(!pq.empty()){
        pint pi=pq.top();pq.pop();
        int t=pi.second;
        if(d[t]<pi.first) continue;
        for(auto it:vp[t]){
            if(d[it.second]>d[t]+it.first){
                d[it.second]=d[t]+it.first;
                //pe[it.second]=t;
                pq.push(make_pair(d[it.second],it.second));
            }
        }
    }
}
int a[3];
int main(){
    int m,s,t;
    cin>>n>>m>>s>>t;
    --s,--t;
    int co;
    rep(i,m){
        rep(j,3) cin>>a[j],--a[j];
        cin>>co;
        rep(j,3)rep(k,3)if(k!=j)vp[a[j]].pb(co,a[k]);
    }
    dijkstra(s);
    cout<<d[t]<<endl;
    return 0;
}


Measured memory_bytes: 23800
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
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; }
using ll=long long;
using namespace std;
int main(){
int x;
cin>>x;
if(x==0) cout<<1;
else cout<<0;
}


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

typedef long long ll;
const int N = 100005;
const int M = 1000000007;

int n, m, tot;
map<pair<int, int>, int> id;

typedef int wtype;
struct Node {
  int v; wtype w;
  bool operator<(const Node &r)const { return w > r.w; }
};
vector<Node> e[N * 22]; wtype dist[N * 22];
void Dijkstra(int src) {
  memset(dist, 0x3f, sizeof(dist));
  priority_queue<Node> que; que.push((Node) {src, dist[src] = 0});
  while (!que.empty()) {
    int u = que.top().v; wtype w = que.top().w; que.pop();
    if (w > dist[u]) { continue; }
    for (int i = 0; i < (int)e[u].size(); i++) {
      int v = e[u][i].v; wtype w = e[u][i].w;
      if (dist[v] > dist[u] + w) {
        dist[v] = dist[u] + w; que.push((Node) {v, dist[v]});
      }
    }
  }
}

inline int get(int x, int y) {
  if (id.find({x, y}) != id.end()) { return id[ {x, y}]; }
  e[x].push_back({tot, 1}); e[tot].push_back({x, 0});
  return id[ {x, y}] = tot++;
}

int main() {
  scanf("%d%d", &n, &m);
  tot = n + 1;
  for (int i = 0, u, v, c; i < m; i++) {
    scanf("%d%d%d", &u, &v, &c);
    int uid = get(u, c), vid = get(v, c);
    e[uid].push_back({vid, 0}); e[vid].push_back({uid, 0});
  }
  Dijkstra(1);
  printf("%d\n", dist[n] == 0x3f3f3f3f ? -1 : dist[n]);
}


Measured memory_bytes: 105720
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

char S[1000];
int DP[400][400][400];

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

  int K;
  scanf("%s%d", S, &K);
  int N = strlen(S);
  FORD(i,N,0)FOR(j,i+1,N+1)REP(k,K+1) {
    if (j == i+1) {
      DP[i][j][k] = 1;
      continue;
    }
    DP[i][j][k] = max(DP[i][j-1][k], DP[i+1][j][k]);
    if (S[i] == S[j-1]) DP[i][j][k] = max(DP[i][j][k], DP[i+1][j-1][k] + 2);
    if (k > 0) DP[i][j][k] = max(DP[i][j][k], DP[i+1][j-1][k-1] + 2);
  }

  printf("%d\n", DP[0][N][K]);
}


Measured memory_bytes: 188160