akhauriyash/Code-Regression huggingface dataset:
def dfs(graph, sx, sy):
    stack = [[sx, sy]]
    visited = []
    cnt = 0
    while stack:
        label = stack.pop(0)
        try:
            g = graph[label[1]][label[0]]
            if (label[0] < 0) or (label[0] > graph[0].__len__() - 1):
                continue
            if (label[1] < 0) or (label[1] >graph.__len__() - 1):
                continue
            if g == '#':
                continue
            if [label[0], label[1]] not in visited:
                # graph[label[1], label[0]] = '#'
                cnt += 1
                visited = [[label[0], label[1]]] + visited
                stack = [[label[0]+1, label[1]], [label[0]-1, label[1]], [label[0], label[1]+1], [label[0], label[1]-1]] + stack
        except IndexError:
            pass
    return cnt


if __name__ == '__main__':
    STR = []
    W, H = [int(i) for i in input().split()]
    while W != 0:
        for j in range(H):
            STR.append(list(input()))
            if '@' in STR[j]:
                sx, sy = STR[j].index('@'), j
        print(dfs(STR, sx, sy))
        STR = []
        W, H = [int(i) for i in input().split()]

Measured memory_bytes: 7684
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
int l[maxn] , h[maxn];
int main()
{
    ios::sync_with_stdio(false);
    ll n , q; cin >> n >> q;
    ll ans = (n - 2) * (n - 2) , maxl = n , maxh = n;
    for (int i = 2 ; i <= n ; i++){
        l[i] = n;
        h[i] = n;
    }
    while (q--){
        int op , x; cin >> op >> x;
        if (op == 1){
            if (x < maxl){
                for (int i = x ; i <= maxl - 1 ; i++) l[i] = maxh;
                maxl = x;
            }
            ans -= l[x] - 2;
        }else {
            if (x < maxh){
                for (int i = x ; i <= maxh - 1 ; i++) h[i] = maxl;
                maxh = x;
            }
            ans -= h[x] - 2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5212
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
X = A + B + C
N = int(input())
L = []
for i in range (N):
  K = int(input())
  L.append(K)
ck = 'No'
if A[0] in L and A[1]in L and A[2] in L:
  ck = 'Yes'
elif B[0] in L and B[1]in L and B[2] in L:
  ck = 'Yes'
elif C[0] in L and C[1]in L and C[2] in L:
  ck = 'Yes'
elif A[0] in L and B[0]in L and C[0] in L:
  ck = 'Yes'
elif A[1] in L and B[1]in L and C[1] in L:
  ck = 'Yes'
elif A[2] in L and B[2]in L and C[2] in L:
  ck = 'Yes'
elif A[0] in L and B[1] in L and C[2] in L:
  ck = 'Yes'
elif A[2] in L and B[1] in L and C[0] in L:
  ck = 'Yes'
print(ck)

Measured memory_bytes: 9228
#include<bits/stdc++.h>
//#define local
#define forn(a,n) for(int i = a; i < n; i++)


using namespace std;

typedef long long int ll;
typedef vector<int> vec;
typedef vector<ll> vecl;
typedef unsigned long long int ull;
typedef vector<ull> vecu;


void print(const vec &a)
{
    forn(0,a.size())
        cout << a[i] << " ";
    cout << "\n";
}


void solve()
{
    int n, x ,t;
    cin >> n >> x >> t;
    ll ans;
    if(n % x)
        ans = t *((n/x) + 1);
    else
        ans = t * (n/x);
    cout << ans;
    
}

int main()
{
    #ifdef local
        freopen("input.txt", "r", stdin);
    #endif

        solve();
}

Measured memory_bytes: 3592
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

int32_t main(){_
    //freopen("input","r",stdin);
	string s;
	cin >> s;
	string st = "festival";
	rc(s.substr(0,sz(s) - sz(st)));
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
 
//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if(a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

struct RUP{
  int n; vector<ll> dat,laz;
  RUP(){}
  RUP(int n_){init(n_);}
  void init(int n_){
    n=1; while(n<n_) n*=2;
    dat.clear(); dat.resize(2*n-1,INF);
    laz.clear(); laz.resize(2*n-1,-INF);
  }
  inline void eval(int len,int k){
    if(laz[k]==-INF) return;
    if(k*2+1<n*2-1)laz[k*2+1]=laz[k],laz[k*2+2]=laz[k];
    dat[k]=laz[k];laz[k]=-INF;
  }
  ll update(int a,int b,ll x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b) return laz[k]=x;
    eval(r-l,k);
    dat[k]=min(update(a,b,x,k*2+1,l,(l+r)/2),
    update(a,b,x,k*2+2,(l+r)/2,r));
    return dat[k];
  }
  void update(int a,int b,ll x){update(a,b,x,0,0,n);}
  ll query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return INF;
    if(a<=l&&r<=b) return dat[k];
    return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
  }
  ll query(int a,int b){return query(a,b,0,0,n);}
};

int main(){
  int n; scanf("%d",&n);
  vector<int> h(n),a(n);
  rep(i,0,n)scanf("%d",&h[i]);
  rep(i,0,n)scanf("%d",&a[i]);
  RUP rup(200010); rup.update(0,1,0);
  rep(i,0,n){
    ll val=rup.query(0,h[i]); val-=a[i];
    rup.update(h[i],h[i]+1,val);
    cerr<<rup.query(h[i],h[i]+1)<<endl;
  }
  printf("%lld\n",-rup.query(0,n+1));
  return 0;
}


Measured memory_bytes: 9984
N, W = map(int, input().split())
A = list()
for n in range(N):
	A.append(list(map(int, input().split())))
dp = [[0 for w in range(W+1)] for n in range(N+1)]
for i in range(W+1):
	dp[0][i] = 0
for p in range(1, N+1):
	for q in range(W+1):
		dp[p][q] = dp[p-1][q]
		if (A[p-1][0] <= q):
			dp[p][q] = max(dp[p][q], dp[p-1][q - A[p-1][0]] + A[p-1][1])
# print(dp)
print(dp[N][W])

Measured memory_bytes: 173576
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    if(a <= 9 && b <= 9){
        cout << a*b;
    }else{
        cout << -1;
    }
}

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

bool lunlun(i64 n){
  i64 d = n % 10;
  n = n/10;
  while(n!= 0){
    i64 d2 = n % 10;
    i64 delta = d2 - d;
    if(delta < 0) delta = -1 * delta;
    
    if(delta > 1){
      return false;
    }

    n = n/10;
    d = d2;
  }
  return true;
}


int main() {
  int K;
  cin >> K;
  queue<i64> q;
  for(int i=1;i<10;i++) q.push(i64(i));
  
  int lCount = 0;
  i64 kLun = 0;
  while(true){
   	
    i64 l = q.front();
    q.pop();
    i64 lastD = l % 10;
    i64 nextL = l * 10;
    if (lastD != 0){
      q.push(nextL + lastD - 1);
    }
    q.push(nextL +lastD);
    if (lastD != 9){
      q.push(nextL + lastD + 1);
    }
    
    lCount++;
    if(lCount >= K){
       kLun = l;
       break;
    }
  }
  cout << kLun << endl;
}


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

#define ll long long
#define mod 1000000007
#define f(i, a, b) for (long long i = a; i < b; i++)
#define rep(i, a, b) for (long long i = a; i <= b; i++)
#define fm(i, a, b) for (long long i = a; i > b; i--)
#define repm(i, a, b) for (long long i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define pqmaxi priority_queue<int>
#define pqmaxl priority_queue<ll>
#define pqmini priority_queue<int, vi, greater<int>>
#define pqminl priority_queue<ll, vl, greater<ll>>
#define all(x) x.begin(), x.end()
#define test     \
    ll test;     \
    cin >> test; \
    while (test--)
#define pb(i) push_back(i)
#define mp(i, j) make_pair(i, j)
#define fast                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL)
ll expMod(ll A, ll B, ll C)
{
    // Base cases
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    // If B is even
    ll y;
    if (B % 2 == 0) {
        y = expMod(A, B / 2, C);
        y = (y * y) ;//% C;
        if(y>=C)
        {
            y = y % C;
        }

    }

    // If B is odd
    else {
        y = A % C;
        y = (y * expMod(A, B - 1, C) % C) % C;
    }

    return (ll)((y + C) % C);
}
int main(){
    //fast;
    ll n;
    scanf("%lld\n",&n);
    string s;
    map <string,int> freq;
    freq.insert({"AC",0});
    freq.insert({"WA",0});
    freq.insert({"TLE",0});
    freq.insert({"RE",0});
    //for(auto i:freq)
    //i=0;
    //cout << i.first << " " <<i.second;
    f(i,0,n)
    {
        getline(cin,s);
        //cout << endl;
        freq[s]++;
    }
    cout << "AC" <<  " x "<< freq["AC"]<<endl;
    cout << "WA" <<  " x "<< freq["WA"]<<endl;
    cout << "TLE" <<  " x "<< freq["TLE"]<<endl;
    cout << "RE" <<  " x "<< freq["RE"]<<endl;
    return 0;
}


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

int main() {
    int n,l;
    cin >> n >> l;

    vector<string> s;
    rep(i, n){
        string str;
        cin >> str;
        s.push_back(str);
    }

    sort(all(s));

    for(string str : s){
        cout << str;
    }
}

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

int main()
{
int N;scanf("%d\n",&N);
int A[N],maxA=0,secondmaxA=0,count=0;
for(int i=0;i<N;i++){scanf("%d\n",&A[i]);maxA=max(A[i],maxA);}
for(int i=0;i<N;i++){if(A[i]!=maxA)secondmaxA=max(A[i],secondmaxA);else count++;}
for(int i=0;i<N;i++)
{
  if(A[i]==maxA)
  {
    if(secondmaxA==0||count>1)printf("%d\n",maxA);
    else printf("%d\n",secondmaxA);
  }
  else printf("%d\n",maxA);
}  
}

Measured memory_bytes: 4604
def popcount(x):
  x = x - ((x >> 1) & 0x5555555555555555)
  x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
  x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
  x = x + (x >> 8) # 16bitごと
  x = x + (x >> 16) # 32bitごと
  x = x + (x >> 32) # 64bitごと = 全部の合計
  return x & 0x0000007f
n = int(input())
x = str(input())
ans = [1 for _ in range(n)]
c = 0
for i in range(n):
  if x[i] == "1":
    c += 1
m1 = c-1
m2 = c+1
a1 = 0
a2 = 0
rl1 = [0 for _ in range(n)]
rl2 = [0 for _ in range(n)]
r1 = 1
r2 = 1
if m1 == 0:
  rl2 = [0 for _ in range(n)]
  ans = [1 for _ in range(n)]
  for i in range(n):
    if x[n-i-1] == "1":
      a2 = (a2+r2)%m2
    rl2[i] = r2
    r2 = (r2*2)%m2
  b = [0 for _ in range(n)]
  for i in range(n):
    if x[i] == "1":
      ans[i] = 0
      b[i] = 0
    else:
      bi = (a2 + (rl2[n-i-1]))%m2
      b[i] = bi
  while sum(b) != 0:
    for i in range(n):
      if b[i] !=0:
        b[i] = b[i]%(popcount(b[i]))
        ans[i] += 1
  for ai in ans:
    print(ai)
  exit()
for i in range(n):
  if x[n-i-1] == "1":
    a1 = (a1+r1)%m1
    a2 = (a2+r2)%m2
  rl1[i] = r1
  rl2[i] = r2
  r1 = (r1*2)%m1
  r2 = (r2*2)%m2
b = [0 for _ in range(n)]
for i in range(n):
  if x[i] == "1":
    bi = (a1 - (rl1[n-i-1]))%m1
    b[i] = bi
  else:
    bi = (a2 + (rl2[n-i-1]))%m2
    b[i] = bi
ans = [1 for _ in range(n)]
while sum(b) != 0:
  for i in range(n):
    if b[i] !=0:
      b[i] = b[i]%(popcount(b[i]))
      ans[i] += 1
for ai in ans:
  print(ai)
  
      
      
    
    
  
  
    
    
    
  
  
    
    
  

Measured memory_bytes: 137408
def main():
    N, M = map(int, input().split())
    ret = N * (N - 1) + M * (M - 1)
    print(ret // 2)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


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

int main()
{
    int n;
    cin>>n;
    double a[n+1];
    for(int i=0; i<n; i++)cin>>a[i];
    sort(a,a+n);
    double res=a[0];
    for(int i=1; i<n; i++)
    {
        res = (res+a[i])/2;
        //cout<<res<<endl;
    }
    cout<<res<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REPR(i,n) for(int i=n-1; i>=(int)(0); i--)
#define FOR(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define FORR(i,a,b) for(int i=(int)(b)-1; i>=(int)(a); i--)
#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()
//**関数リスト**//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) {
	ll keta = 1;
	while (F / 10 > 0) {
		keta++;
		F /= 10;
	}
	return keta;
}
ll gcd(ll x, ll y) {
	ll r;
	if (x < y) {
		swap(x, y);
	}
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll isPrime(ll x) {
	ll i;
	if (x < 2) {
		return 0;
	}
	else if (x == 2) {
		return 1;
	}
	else if (x % 2 == 0) {
		return 0;
	}
	else {
		for (i = 3; i * i <= x; i += 2) {
			if (x % 1 == 0) {
				return 0;
			}
		}
		return 1;
	}
}
void eratos(vl isPrime) {
	//(注)isPrimeのサイズはN+1にする！実際にはmain内に配置して使用
	ll i, j;
	REP(i, isPrime.size()) {
		isPrime[i] = 1;
	}
	isPrime[0] = 0; isPrime[1] = 0;
	for (i = 2; i * i <= isPrime.size() - 1; i++) {
		if (isPrime[i] == 1) {
			j = i * 2;
			while (j <= isPrime.size() - 1) {
				isPrime[j] = 0;
				j = j + i;
			}
		}
	}
}
ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
void bitSearch(ll n) {
	//実際にはコピーして中身を改変して使う
	ll i;
	REP(i, pow(2, n)) {
		ll p = i;
		REP(i, n) {
			cout << p % 2;
			p /= 2;
		}
		cout << endl;
	}
}

void bfs(ll now) {
	//中身は毎回書き換えて使用
	queue<ll> Q;
	Q.push(now);
	ll u;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		//ll v=;
		//Q.push(v);
	}
}
//**定義場所**//
ll i, j, k, l, m, n;
ll N, M, K, H, W;
ll MOD = 1000000007;
ll ans = 0;
//***********//

int main() {
	ll ans = 0;
	cin >> N;
	vector<string> S(N);
	vector<string> T(N);
	for (i = 0; i < N; i++) {
		cin >> S[i];
		sort(S[i].begin(), S[i].end());
	}
	sort(S.begin(), S.end());
	ll equal = 1;
	for (i = 0; i < N-1; i++) {
		if (S[i] == S[i + 1]) {
			equal++;
		}
		else {
			ans += (equal * (equal - 1)) / 2;
			equal = 1;
		}
	}
	ans += (equal * (equal - 1)) / 2;
	cout << ans;
}

Measured memory_bytes: 8064
#include <iostream>

using namespace std;

int n = 1;

void print( int a ){
  cout << n << ":";
    for( int i = 0 ; i < a ; i++ ) cout << "*";
    cout << endl;
    n++;
}

int main(void){

  int n;
  double s[40];
  int a[6] = {0};

  cin >> n;
    for( int i = 0 ; i < n ; i++ ){
      cin >> s[i];
      if( s[i] < 165 ) a[0]++;
      else if( 165 <=s[i] && s[i] < 170 ) a[1]++;
      else if( 170 <= s[i] && s[i] < 175 )a[2]++;
      else if( 175 <= s[i] && s[i] < 180 ) a[3]++;
      else if( 180 <= s[i] && s[i] < 185 ) a[4]++;
      else a[5]++;
    } 
    for( int i = 0 ; i < 6 ; i++ ){
      print(a[i]);
    }
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    string S, T; cin >> S >> T;
    int ans = 0;
    REP(i, 3) if(S[i] == T[i]) ans++;
    Out(ans);

    return 0;
}


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

const int MAXN = 100005;
long long vet[MAXN], ans[MAXN];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i=0; i<n; i++){
		scanf("%lld", &vet[i]);
		if(i%2 == 0) ans[0] += vet[i];
		else ans[0] -= vet[i];
	}
	printf("%lld", ans[0]);
	for (int i=1; i<n; i++){
		ans[i] = 2*(vet[i-1] - (ans[i-1]/2));
		printf(" %lld", ans[i]);
	}
	printf("\n");
}

Measured memory_bytes: 2816
S=str(input())
AA=int(S[0:2])
BB=int(S[2:])
if 1<=AA and AA<=12 and 1<=BB and BB<=12:
	print('AMBIGUOUS')
elif 1<=AA and AA<=12 and (BB==0 or 13<=BB and BB<=99):
	print('MMYY')
elif (AA==0 or 13<=AA and AA<=99) and 1<=BB and BB<=12:
	print('YYMM')
else:
	print('NA')

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

char S[101010];

int main() {
    scanf("%s", S);

    bool app[26];
    for (int i = 0; i < 26; ++i) {
        app[i] = false;
    }
    for (int i = 0; S[i] != '\0'; ++i) {
        app[S[i] - 'a'] = true;
    }
    for (int i = 0; i < 26; ++i) {
        if (!app[i]) {
            printf("%c\n", (char)(i + 'a'));
            return 0;
        }
    }
    puts("None");
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
#include <queue>
#include <sstream>
#include <map>
#include <unordered_map>
#include <cmath>
using namespace std;
using LLI = long long int;

#define Rep(i, N) for (int i = 0; i < N; i++)


int main(int argc, char *argv[])
{
    int N, K, Q;
    cin >> N >> K >> Q;
    
    vector<int> A;
    Rep(i, Q) {
        int a;
        cin >> a;
        A.push_back(a);
    }

    vector<int> P(N);
    Rep(i, Q) {
        P[A[i]-1]++;
    }

    Rep(i, N) {
        if (P[i] > Q - K) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1528
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

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-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
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; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;
int dx[8] = { -1,-1,-1,0,0,1,1,1, };
int dy[8] = { 1,0,-1,1,-1,1,0,-1 };

int F[101][11];
int p[101][11];
void solve() {
	int N; cin >> N;
	REP(i, N) {
		REP(j, 10)cin >> F[i][j];
	}
	REP(i, N) {
		REP(j, 11)cin >> p[i][j];
	}
	int ans = -1e9;
	
	REP(bit, 1 << 10) {
		//print(bit);
		vector<int>v(10);
		if (bit == 0)continue;
		bool ok = false;
		REP(j, 10) {
			if (bit&(1 << j)) {
				v[j] = 1;
				ok = true;
			}
			else v[j] = 0;
		}
		//print(bit);
		//print_space(v);
		
		//REP(i, 5) {
		//	if ((!v[i]) && (!v[i + 1]))ok = false;
		//}
		int res = 0;
		if (!ok)continue;
		REP(i, N) {
			int cnt = 0;
			REP(j, 10) {
				if ((v[j]) && (F[i][j]))cnt++;
			}
			//pe(i); print(cnt);
			res += p[i][cnt];
		}
		//print(res);
		ans = max(res, ans);
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) begin(x)+(a), begin(x)+(n)
#define ADD(a, b) ((((a)%MOD+MOD)%MOD+((b)%MOD+MOD)%MOD)%MOD)
#define SUB(a, b) ((((a)%MOD+MOD)%MOD-((b)%MOD+MOD)%MOD+MOD)%MOD)
#define MUL(a, b) (((((a)%MOD+MOD)%MOD)*(((b)%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int K, N;
int A[200010];


signed main(){
    cin >> K >> N;
    rep(i, 0, N) cin >> A[i];

    int ans = min(A[N-1]-A[0], K-(A[1]-A[0]));
    rep(i, 1, N-1) chmin(ans, min(K-(A[i]-A[i-1]), K-(A[i+1]-A[i])));
    chmin(ans, K-(A[N-1]-A[N-2]));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
class FUnionFind
  attr_reader :nodes, :parents, :ranks

  def initialize(n)
    @parents = (0...n).to_a
    @nodes = @parents.map{ |x| [x] }
  end

  def find(i)
    @parents[i]
  end

  def union(i,j)
    i = @parents[i]; j = @parents[j]
    return if i == j
    j,i = i,j if @nodes[i].size < @nodes[j].size
    #p [i,j,@nodes[i],@nodes[j]]
    #p [i,j,@nodes[i].size,@nodes[j].size]
    @nodes[j].each{ |k| @parents[k] = i }
    @nodes[i].concat(@nodes[j])
    @nodes[j].clear
  end

  def setsize(i)
    @nodes[find(i)].size
  end
end

N,M = gets.split.map &:to_i
UF = FUnionFind.new(N)
M.times {
  x,y,z = gets.split.map &:to_i
  UF.union(x-1, y-1)
}
p Hash[UF.parents.map{ |x| [x,1] }].size


Measured memory_bytes: 19196
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<string>
typedef long long ll;
using namespace std;
#define maxn 1005
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;

ll read() {
	ll 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;
}

ll quickpow(ll a, ll b) {
	ll ans = 0;
	while (b > 0) {
		if (b % 2)ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a%b);
}

int a[103];

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int i, j;
	for (i = 1; i <= n; i++)cin >> a[i];
	int cnt = 0;
	for (i = 2; i <= n; i++) {
		if (a[i] == a[i - 1]) {
			cnt++;
			a[i] = 1000;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
n=int(input())
long=0
middle=0
short=0
count=0
pre=0
a=0
b=0
c=0
list=[]
list=input().split()
for i in range(len(list)):
  list[i]=int(list[i])

for i in range(n-2):
 for s in range(i+1,n-1):
  for t in range(s+1,n):
   if list[i]!=list[s] and list[s]!=list[t] and list[i]!=list[t]:
    if list[i]>list[s] and list[i]>list[t]:
     long=i
     if list[s]>list[t]:
      middle=s
      short=t
     else:
      middle=t
      short=s
#
    if list[s]>list[i] and list[s]>list[t]:
     long=s
     if list[i]>list[t]:
      middle=i
      short=t
     else:
      middle=t
      short=i
#
    if list[t]>list[s] and list[t]>list[i]:
     long=t
     if list[s]>list[i]:
      middle=s
      short=i
     else:
      middle=i
      short=s
    if int(list[long])<int(list[middle])+int(list[short]):
     count+=1
print(count)

Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, M, Q;
	cin >> N >> M >> Q;
	string S[2000];
	rep(i, N) cin >> S[i];
	int B[2001][2001] = {};
	rep(i, N) {
		rep(j, M) {
			B[i + 1][j + 1] = B[i + 1][j] + S[i][j] - '0';
		}
	}
	rep(j, M) rep(i, N) {
		B[i + 1][j + 1] += B[i][j + 1];
	}
	int C[2001][2001] = {};
	int D[2001][2001] = {};
	rep(i, N) {
		rep(j, M) {
			if (i != 0) C[i + 1][j + 1] += (S[i - 1][j] - '0') & (S[i][j] - '0');
			if (j != 0) D[i + 1][j + 1] += (S[i][j - 1] - '0') & (S[i][j] - '0');
		}
	}
	rep(i, N) rep(j, M) {
		C[i + 1][j + 1] += C[i + 1][j];
		D[i + 1][j + 1] += D[i + 1][j];
	}
	rep(j, M) rep(i, N) {
		C[i + 1][j + 1] += C[i][j + 1];
		D[i + 1][j + 1] += D[i][j + 1];
	}
	
	rep(q, Q) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;

		int kotae;
		kotae = B[c][d] - B[c][b - 1] - B[a - 1][d] + B[a - 1][b - 1];
		kotae -= C[c][d] - C[c][b - 1] - C[a][d] + C[a][b - 1];
		kotae -= D[c][d] - D[c][b] - D[a - 1][d] + D[a - 1][b];
		co(kotae);

	}

	Would you please return 0;
}

Measured memory_bytes: 52992
console.log((args=>{
  const [HW,...S] = args.trim().split('\n');
  const [H,W] = HW.split(' ').map(v=>parseInt(v));
  const trail = Array.from({length:H},_=>Array(W).fill(false));
  const dir = [[-1,0],[0,-1],[1,0],[0,1]];
  let p = 0;
  for ( let i = 0; i < H; i++ ) {
    for ( let j = 0; j < W; j++ ) {
      if ( trail[i][j] ) continue;
      const stack = [[i,j]];
      trail[i][j] = true;
      let w = S[i][j]==='.'|0, b = w^1;
      while ( stack.length ) {
        const [x,y] = stack.pop();
        for ( const [dx,dy] of dir ) {
          const nx = x+dx, ny = y+dy;
          if ( nx < 0 || H <= nx || ny < 0 || W <= ny
            || trail[nx][ny] || S[x][y] === S[nx][ny] ) continue;
          trail[nx][ny] = true;
          if ( S[nx][ny] === '#' ) b++; else w++;
          stack.push([nx,ny]);
        }
      }
      p += w * b;
    }
  }
  return `${p}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 48572
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <time.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000001
#define mod 1000000009
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)

int main()
{
    string sample = "CODEFESTIVAL2016";
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0;i < 16; i++){
        if(s[i] != sample[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

void Main()
{
    long x;
    long a = 100;
    cin >> x;
    for (int i = 0; i < 10000000; i++)
    {
        a = a + a / 100;
        if(x <= a){
            cout << i+1 << endl;
            return;
        }
    }
    
    cout << a << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3612
#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, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  vector<vector<int>> A(N, vector<int>(M));
  rep(i, M)
  {
    cin >> B[i];
  }
  rep(i, N)
  {
    rep(j, M)
    {
      cin >> A[i][j];
      //printf("%d:%d = %d\n", i, j, A[i][j]);
    }
  }
  int ans = 0;
  rep(i, N)
  {
    int tmp = 0;
    rep(j, M)
    {
      tmp += B[j] * A[i][j];
    }
    if (tmp + C > 0)
    {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

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

        while(sc.hasNextInt()){
        	int haba = sc.nextInt();
            int menseki = 0;

            for(int i = 0; i * haba < 600; i++){
                menseki += (i * haba) * (i * haba) * haba;
            }

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

Measured memory_bytes: 17184
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	int  num = Integer.parseInt(br.readLine());
	String s = br.readLine();
	int left = 0;
	for (int i = 0; i < num; i++) {
	    if(s.charAt(i) == '(') left++;
	    else left--;
	    if (left < 0) {
		s = "(" + s;
		num++;
		i++;
		left++;
	    }
	}
	for (int i = left ; i > 0; i--) {
	    s = s + ")";
	}
	System.out.println(s);
    }
}

Measured memory_bytes: 21204
N = int(input())
A = list(map(int, input()))

num = 0
for i in range(N):
    num += (N - 1 == (i | N - 1 - i)) * ((-1)**i) * A[i]
if num % 2 == 1:
    print(1)
else:
    for i in range(N - 1):
        if abs(A[i]-A[i+1]) == 1:
            print(0)
            break
    else:
        B = []
        for i in range(N-1):
            if A[i] == A[i+1]:
                B.append(0)
            else:
                B.append(1)
        for i in range(N-1):
            num += (N - 2 == (i | N - 2 - i)) * ((-1)**i) * B[i]
        if num % 2 == 1:
            print(2)
        else:
            print(0)

Measured memory_bytes: 119204
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

typedef vector<int> vertex;
typedef vector<vertex> graph;
typedef long long i64;
const int inf = (int)1.05e9;

pair<int, int> compute_distant_vertex(graph& g, int from)
{
	vector<int> dist(g.size(), inf);
	queue<pair<int,int>> q;
	int ans_v = from;

	q.push({from, 0});

	while(!q.empty()) {

		int v = q.front().first;
		int d = q.front().second;
		q.pop();

		if(dist[v] <= d) {
			continue;
		}
		dist[v] = d;
		if(dist[v] > dist[ans_v]) {
			ans_v = v;
		}

		for(auto& w : g[v]) {
			q.push({w, d + 1});
		}
	}

	return {ans_v, dist[ans_v]};
}

int compute_diameter(graph& g)
{
	auto d1 = compute_distant_vertex(g, 0);
	auto d2 = compute_distant_vertex(g, d1.first);
	return d2.second;
}

int main()
{
	int n;
	graph g;

	scanf("%d", &n);
	g.resize(n);
	for(int i = 0; i < n - 1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a -= 1;
		b -= 1;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	int d = compute_diameter(g) + 1;

	vector<bool> win(d + 1, false);

	win[0] = false;
	win[1] = true;
	win[2] = false;

	for(int i = 3; i <= d; i++) {
		win[i] = (!win[i - 1]) || (!win[i - 2]);
	}

	printf("%s\n", win[d] ? "First" : "Second");

	return 0;
}

/* waffle */


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

int main() {
  string s; cin >> s;
  
  int a = (s[0] - '0');
  int b = (s[1] - '0');
  int c = (s[2] - '0');
  int d = (s[3] - '0');
  
  int e = (s[5] - '0');
  int f = (s[6] - '0');
  int g = (s[8] - '0');
  int h = (s[9] - '0');
  
  if (a * 1000 + b * 100 + c * 10 + d < 2019) {
    cout << "Heisei" << endl;
    return 0;
  } else if (a * 1000 + b * 100 + c * 10 + d == 2019) {
    if (e * 10 + f < 4 || (e * 10 + f == 4 && g * 10 + h <= 30)) {
      cout << "Heisei" << endl;
      return 0;
    }
  }
      
  cout << "TBD" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
using namespace std;
 
main() {
  int N;
  cin >> N;
  vector<string> blue(N);
  for(int i=0; i<N; i++)
    cin >> blue[i];
  
  int M;
  cin >> M;
  vector<string> red(M);
  for(int i=0; i<M; i++)
    cin >> red[i];
  
  vector<int> point(N);
  for(int i=0; i<N; i++){
    int cnt=0;
    
    for(int j=0; j<N; j++){
      if(blue[i] == blue[j])
        cnt++;
    }  
  
    for(int k=0; k<M; k++){
      if(blue[i] == red[k])
        cnt--;
    }
    
    point[i] =cnt;
  }
  
  sort(point.begin(),point.end());
  int Ans;
  if( point.back() >=0 )
    Ans = point.back();
  if( point.back() < 0 )
    Ans = 0;
  cout << Ans << endl;
  return 0;
}  
  
  

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    int D;
    GI(D);
    if(D==25)
        cout<<"Christmas"<<endl;
    else if(D==24)
        cout<<"Christmas Eve"<<endl;
    else if(D==23)
        cout<<"Christmas Eve Eve"<<endl;
    else
        cout<<"Christmas Eve Eve Eve"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5+5;

struct Bit {
	int bit[maxn] = {};
	int lowbit(int x) {
		return ((x)&(-x));
	}
	void upd(int x,int val) {
		for (int i = x; i < maxn; i += lowbit(i)) 
			bit[i] = max(bit[i], val);
	}
	int qry(int x) {
		int ret = 0;
		for (int i = x; i > 0; i -= lowbit(i))
			ret = max(ret, bit[i]);
		return ret;
	}
} bit;

int h[maxn], a[maxn];
int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> h[i];
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		int mx = bit.qry(h[i]-1) + a[i];
//		cout << mx << "\n";
		bit.upd(h[i], mx);
		
	}
	cout << bit.qry(n) << "\n";
}

Measured memory_bytes: 8296
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n;
int a[2000];
int d[2000];
int x;
int main() {
    scanf("%d%d", &n, &x);
    llong ans = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
        d[i] = a[i];
        ans += d[i];
    }
    for (int i = 1; i < n; ++i) {
        llong sum = 0;
        for (int j = 0; j < n; ++j) {
            d[j] = min(d[j], a[(j + n - i) % n]);
            sum += d[j];
        }
        ans = min(ans, sum + (llong)x * i);
    }
    printf("%lld\n", ans);
	return 0;
}


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

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static bool Calc(int[] xs) {
        int n2 = 0;
        int n4 = 0;
        int m = 0;
        foreach (var x in xs) {
            if (x % 4 == 0) n4++;
            else if (x % 2 == 0) n2++;
            else m++;
        }

        if (n2 > 0) {
            return n4 >= m;
        }
        else {
            return n4 + 1 >= m;
        }
    }

    static void Main() {
        ReadInt();
        var xs = ReadInts();
        var ok = Calc(xs);
        Console.WriteLine(ok ? "Yes" : "No");
    }
}

Measured memory_bytes: 21728
n = int(input())
v = list(map(int,input().split()))
 
ans = 0
v.sort()
 
 
 
for i in range(n-1):
    if i == 0:
        ans = (v[i] + v[i+1]) / 2
    else:
        ans = (v[i+1] + ans)/2
 
        
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int one_s_pos[100000];
int one_e_pos[100000];

int main()
{
	int N, K, sum, ans = 0;
	string S;
	int index = 0;
	char pre = '0';

	cin >> N >> K >> S;

	S = '1' + S + '1';
	N += 2;

	rep(i, N) {
		if (pre == '0' && S[i] == '1') {
			one_s_pos[index] = i;
			if (i == N - 1) {
				one_e_pos[index] = i;
				index++;
			}
		}
		else if (pre == '1' && S[i] == '0') {
			one_e_pos[index] = i - 1;
			index++;
		}
		else if (i == N - 1 && S[i] == '1') {
			one_e_pos[index] = i;
			index++;
		}
		pre = S[i];
	}

	if (index == 1 || index - 1 < K) ans = N - 2;
	else {
		rep(i, index - K) {
			sum = one_e_pos[i + K] - one_s_pos[i] + 1;
			if (one_e_pos[i + K] == N - 1) sum--;
			if (one_s_pos[i] == 0) sum--;
			ans = max(ans, sum);
		}
	}

	cout << ans << endl;

	return 0;
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n, p;
	string s;
	cin >> n >> p >> s;

	ll ans = 0;
	if (p == 2 || p == 5) {
		for (int i = 0; i < n; i++) {
			int d = s[i] - '0';
			if (d % p == 0) ans += i + 1;
		}
	}
	else {
		vi ps(n+1);
		map<int,int> cnt {{0, 1}};
		int base = 1;
		for (int i = n-1; i >= 0; i--) {
			int d = s[i] - '0';
			ps[i] = (((d * base) % p) + ps[i+1]) % p;
			cnt[ps[i]]++;
			base = (base * 10) % p;
		}
		//debug(ps);
		for (auto x : cnt) ans += (ll)x.second * (x.second - 1) / 2;
	}

	cout << ans << endl;
}


Measured memory_bytes: 1668
#include <stdio.h>
int main ()
{
    int a,b,c,i,t;
      scanf("%d", &t);
    for(i=1;i<=t;i++){
    scanf("%d %d %d", &a,&b,&c);
    if (a*a+b*b==c*c || b*b+c*c==a*a || a*a+c*c==b*b){
     printf("YES\n");
}
else {
printf("NO\n");
}
}
return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep (i, n) cin >> p[i];
    rep (i, n) p[i] += 1;
    int ans_sum = 0, sum = 0;
    rep (i, k) sum += p[i];
    ans_sum = sum;
    repp (i, k, n) {
        sum += p[i] - p[i - k];
        chmax(ans_sum, sum);
    }
    printf("%.16lf\n", (double)ans_sum / 2);
    return 0;
}

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

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

    long double r = R ;

    long double pie = 3.141592653589 ;

    long double ans = pie * 2.0 * r ;
    cout << fixed << setprecision ( 10 ) << ans ;

    return 0 ;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
vector<pair<ll,ll>> a , b;
priority_queue<ll , vector<ll> , greater<ll>>Q;
int main()
{
    ios::sync_with_stdio(false);
    int t; cin >> t;
    while (t--){
        a.clear();
        b.clear();
        int n ; cin >> n;
        ll ans = 0;
        for (int i = 1 ; i <= n ; i++){
            ll k , l , r; cin >> k >> l >> r;
            if (k == n) ans += l;
            else if (l > r) ans += r , a.push_back(make_pair(k , l - r));
            else ans += l , b.push_back(make_pair(n - k , r - l));
        }
        sort(a.begin() , a.end());
        sort(b.begin() , b.end());
        for (auto & g : a){
            // 排序之后不可能出现 Q.size() > g.k的情况吧
            if (Q.size() < g.first) Q.push(g.second);
            else if (Q.top() < g.second) Q.pop() , Q.push(g.second);
        }
        while (Q.size()) ans += Q.top() , Q.pop();
        for (auto & g : b){
            if (Q.size() < g.first) Q.push(g.second);
            else if (Q.top() < g.second) Q.pop() , Q.push(g.second);
        }
        while (Q.size()) ans += Q.top() , Q.pop();
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 8376
#include "bits/stdc++.h"
using namespace std;

long long int mod=1e9+7;

int main(){
  int n;
  cin>>n;
  if(n<=104){
    cout<<0<<endl;
    return 0;
  }
  if(n<=134){
    cout<<1<<endl;
    return 0;
  }
  if(n<=164){
    cout<<2<<endl;
    return 0;
  }
  if(n<=188){
    cout<<3<<endl;
    return 0;
  }
  if(n<=194){
    cout<<4<<endl;
    return 0;
  }
  cout<<5<<endl;
  return 0;
}


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

std::vector<unsigned> gaps;

unsigned insertion_sort(unsigned a[], unsigned n, unsigned gap = 1){
  unsigned count = 0;
  for(unsigned i = gap; i < n; i++){
    unsigned v = a[i];
    int j = i - gap;
    while(j >= 0 && a[j] > v){
      a[j+gap] = a[j];
      j -= gap;
      count++;
    }
    a[j+gap] = v;
  }
  return count;
}

void make_gap_table(unsigned n){
  unsigned h = 1;
  while(h <= n){
    gaps.push_back(h);
    h = 3*h + 1;
  }
  std::reverse(gaps.begin(),gaps.end());
}

void shell_sort(unsigned a[], unsigned n){
  make_gap_table(n);
  unsigned count = 0;
  for(auto const &v : gaps){
    count += insertion_sort(a,n,v);
  }

  std::cout << gaps.size() << '\n';

  for(int i=0;i<gaps.size()-1;i++){
    std::cout << gaps[i] << ' ';
  }
  std::cout << gaps[gaps.size()-1] << '\n';

  std::cout << count << '\n';
}

int main(){
  unsigned n;
  unsigned buf;
  std::vector<unsigned> a;
  std::cin >> n;
  for(unsigned i = 0; i < n; i++){
    std::cin >> buf;
    a.push_back(buf);
  }

  shell_sort(a.data(),a.size());
  for(auto &v : a){
    std::cout << v << '\n';
  }
}

Measured memory_bytes: 6720
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

int a[200123], x[200123], cnt;

int main()
{
	int n;
	LL k;
	cin >> n >> k;
	Rep(i, n) scanf("%d", a+i);
	set<int> s;
	int f = 0;
	for(int i = 1;;) {
		if(s.count(i)) {
			while(x[f] != i) ++f;
			break;
		}
		else s.insert(i);
		x[cnt++] = i;
		i = a[i];
	}
	cout << (k < cnt ? x[k]: x[(k-cnt)%(f-cnt)+f]) << endl;
	return 0;
}


Measured memory_bytes: 14368