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

using namespace std;

struct node {
  node* children[26];
  int letters[26];

  node(){
    for(int i = 0; i < 26; i++){
      children[i] = NULL;
      letters[i] = 0;
    }
  }

  ~node(){
    for(int i = 0; i < 26; i++){
      delete children[i];
    }
  }

  void include_letters(int l){
    for(int i = 0; i < 26; i++){
      letters[i] += (l & (1 << i)) != 0;
    }
  }
};

char str[1000100];

int main(){
  int N;
  while(scanf("%d", &N) > 0){
    vector<string> S(N);
    
    node* root = new node();

    for(int i = 0; i < N; i++){
      scanf("%s", str);
      S[i] = str;
      reverse(S[i].begin(), S[i].end());
      int len = S[i].size();

      vector<int> letters(len);
      letters[len-1] = 1 << (S[i][len-1] - 'a');
      for(int j = len-2; j >= 0; j--){
	letters[j] |= letters[j+1] | (1 << (S[i][j] - 'a'));
      }

      node* u = root;
	
      for(int j = 0; j < S[i].size(); j++){
	u->include_letters(letters[j]);
	int ch = S[i][j] - 'a';

	if(!u->children[ch]){
	  u->children[ch] = new node();
	}

	u = u->children[ch];
      }
    }

    long long ans = 0;

    for(int i = 0; i < N; i++){
      node* u = root;

      int len = S[i].size();
      for(int j = 0; j < len-1; j++){
	int ch = S[i][j] - 'a';
	u = u->children[ch];
      }

      ans += u->letters[S[i][len-1] - 'a'] - 1;
    }

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

    delete root;
  }
}


Measured memory_bytes: 343852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define I(x) cin >> x;
#define D(x) cerr << (x) << " ";
#define BR cerr << "\n";
#define P(x) cout << (x) << endl;
#define FIX cout << fixed << setprecision(10);

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;
priority_queue<ll> A;
priority_queue<ll> space;


int main(void){
  
  I(N);
  REP(i, N) {
    ll tmp;
    I(tmp);
    A.push(tmp);
  }

  ll a = A.top();
  A.pop();
  space.push(a);
  while(!A.empty()) {
    a = A.top();
    A.pop();
    ll best = space.top();
    space.pop();
    ret += best;
    space.push(a);
    space.push(a);
  }

  P(ret);

}


Measured memory_bytes: 7916
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.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>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, D, X;
        cin >> N >> D >> X;
        vll A(N);
        rep(i, 0, N) cin >> A[i];

        ll sm = 0;
        rep(person, 0, N) {
                ll a = A[person];
                rep(i, 0, inf) {
                        ll d = i * a + 1;
                        if (d > D) break;
                        sm++;
                }
        }
        cout << sm + X << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>

typedef long long ll;

ll solve(int i, ll A, ll B)
{
	if(i == 0) return A == B ? 1 : 2; 
	if(((A >> i) & 1) != ((B >> i) & 1))
		return (1ll << i) - A + std::min((1ll << i) - A + solve(i - 1, 0, B - (1ll << i)), 1ll << i);
	else return solve(i - 1, A & ((1ll << i) - 1), B & ((1ll << i) - 1));
}

int main()
{
	ll A, B; scanf("%lld%lld", &A, &B);
	if(A == B) return 0 * puts("1"); 
	printf("%lld\n", solve(60, A, B));
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
using namespace std;
int main()
{
    int x;
    cin >> x;
    if (x == 7 || x == 5 || x == 3)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> A >> B;
    cout << N / (A + B) * A + ((N % (A + B) > A) ? A : N % (A + B));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, a, b;		//N:都市数　M:道の数 a:都市１　b:都市２
  cin >> N >> M;	// NとMの入力
  vector<int> city(N);	//city():都市から出る道の数
  
  for(int i=0 ; i<M ; i++){	//道の数だけ繰り返す
    cin >> a >> b;	// aとbの入力
    city.at(a-1)++;
    city.at(b-1)++;
  }
  
  for(int i=0; i<N ; i++){	//出力
    cout << city.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
int main(){
	long long a,b,c;
	cin>>a>>b>>c;
	if(c-a-b>=0&&(c-a-b)*(c-a-b)>4*a*b)puts("Yes");
	else puts("No");
}


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

int main(){
  cin >> n;
  int def_half_n = n/2+2;
  int def_n = n;
  cout << n << ":";
  while(n%2==0){
    cout << " " << 2;
    n /= 2;
  }
  if(n==1){cout << endl; return 0;}
  for(int i = 3;i<def_half_n;i+=2){
    while(n%i==0){
      cout << " " << i;
      n /= i;
    }
    if(n==1)break;
  }
  if(n == def_n)cout << " " << n;
  cout << endl;
  return 0;
}

Measured memory_bytes: 3108
import itertools
import math
N = int(input())
xy = []
for count in range(N):
    xy.append(input().split())
    itertools.permutations(xy)
XY = []
sum = 0
ave = 0
count = 0
for XY in itertools.permutations(xy):
    for i in range(N-1):
        leng = math.sqrt(((int(XY[i+1][0]) - int(XY[i][0])) ** 2) +
                         ((int(XY[i + 1][1]) - int(XY[i][1])) ** 2))
        sum += leng

ave = sum / math.factorial(N)
print(ave)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a % 2 == 0 || b % 2 == 0){
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#ifndef DEBUG
#  define NDEBUG
#endif
#include <iostream>
#include <string>
#include <iterator>
#include <utility>
#include <type_traits>
#include <limits>
#include <cassert>
#include <set>

using namespace std;

// template {{{
// misc {{{
using Z = long long;
[[maybe_unused]]
constexpr Z INF = numeric_limits<Z>::max() / 3;
// }}}

// debug {{{
template <class T>
using enable_if_sequence_t = enable_if_t<
  is_same<
    typename iterator_traits<
      typename remove_cv_t<remove_reference_t<T>>::iterator
    >::iterator_category,
    random_access_iterator_tag>{}>;
#ifdef NDEBUG
# define dump(x)
# define debug if (0)
template <class T>
inline T&& ix(T&& value) { return value; }
template <class T, class Index, class... Indices, class = enable_if_sequence_t<T>>
inline auto&& ix(T&& container, Index index, Indices... indices) {
  return ix(container[index], indices...);
}
#else
# define dump(x) do { \
    cerr << "\e[33m[dump: " << __LINE__ << "] " << (#x) << " = " << x << "\e[0m" << endl; \
  } while (0);
# define debug
template <class T>
inline auto&& ix_impl([[maybe_unused]] int line, [[maybe_unused]] const char* code, T&& value) {
  return value;
}
template <class T, class Index, class... Indices, class = enable_if_sequence_t<T>>
inline auto&& ix_impl(int line, const char* code, T&& container, Index index, Indices... indices) {
  if (index < 0) {
    cerr << "\e[31mix: negative index at line " << line << ", ix(" << code << ")\e[0m" << endl;
    exit(1);
  }
  int size = container.size();
  if (index >= size) {
    cerr << "\e[31mix: index out of range at line " << line << ", ix(" << code << ")\n"
      << "index = " << index << " whereas size = " << size << "\e[0m" << endl;
    exit(1);
  }
  return ix_impl(line, code, container[index], indices...);
}
#define ix(...) ix_impl(__LINE__, #__VA_ARGS__, __VA_ARGS__)
#endif
// }}}

// IO {{{
template <class T, class U>
ostream& operator<< (ostream& os, pair<T, U> p) {
  os << '(' << p.first << ", " << p.second << ')';
  return os;
}
template <class T>
false_type is_container_impl(...);
template <class T, class = typename T::iterator>
true_type is_container_impl(T);
template <class T>
struct is_container : decltype(is_container_impl<T>(declval<T>())) {};
template <>
struct is_container <string> : std::false_type {};
template <class Container, class = enable_if_t<is_container<Container>{}>>
istream& operator>> (istream& is, Container& cont) {
  for (auto& v : cont) is >> v;
  return is;
}
template <class Container, class = enable_if_t<is_container<Container>{}>>
ostream& operator<< (ostream& os, Container const& cont) {
  bool first = true;
  constexpr char sep =
    is_container<typename Container::value_type>{} ? '\n' : ' ';
  for (auto const& v : cont) {
    if (!first) {
      os << sep;
    }
    first = false;
    os << v;
  }
  return os;
}
// }}}
// }}}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Z N;
  cin >> N;
  set<Z> As;
  for (auto i = 0; i < N; i++) {
    Z a;
    cin >> a;
    if (As.count(a)) {
      cout << "NO" << endl;
      return 0;
    }
    As.insert(a);
  }
  cout << "YES" << endl;
}



Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#define ll long long int
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    int a;
    string s;
    
    cin >> a >> s;

    if(a<3200) cout << "red" << endl;
    else cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int h[n];
	for (int i = 0;i < n;i++)cin >> h[i];
	sort(h, h + n);
	ll right = h[n - 1], left = 0;
	while (right - left > 1) {
		ll mid = (right + left) / 2;
		ll sum = 0;
		for (int i = 0;i < n;i++) {
			if (h[i] > b*mid) {
				if ((h[i] - b * mid) % (a - b) == 0)sum += (h[i] - b * mid) / (a - b);
				else sum += (h[i] - b * mid) / (a - b) + 1;
			}
		}
		if (sum > mid) {
			left = mid;
		}
		else {
			right = mid;
		}
	}
	cout << right << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h, n, a, b,i,j;
    scanf("%d %d",&h,&n);
    vector<long long> dp(h + 1,INT_MAX);
    dp[0]=0;
    for(i=0;i<n;i++) {
        scanf("%d %d",&a,&b);
        for (j=0;j<h;j++)
            dp[min(h,j+a)]=min(dp[min(h,j+a)],dp[j]+b);
    }
    printf("%d", dp[h]);
}

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

//Solve hard problem
int n;

vector<int>v1;
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    for (int i =  0; i<n; i+=1) {
        if(i==0)
        {
            int x;
            cin>>x;
            v1.push_back(x);
        }
        else{
            int prev = v1.back();
            int x;
            cin>>x;
            if(x==prev)
                continue;
            else{
                v1.push_back(x);
            }
        }
    }
    int ans = 1;
    bool flag = false;
    if(v1.size()==1)
    {
        cout<<ans<<endl;
        return 0;
    }
    if(v1[1]>v1[0])
    {
        flag = true;
    }
    else{
        flag = false;
    }
    for (int  i  = 2; i<v1.size(); i+=1) {
        if(v1[i]>v1[i-1]&&flag==true)
        {
            continue;
        }
        if(v1[i]<v1[i-1]&&flag==false)
            continue;
        if(v1[i]>v1[i-1])
        {
            flag = (v1[i]<v1[i+1]);
            ans+=1;
        }
        if(v1[i]<v1[i-1])
        {
            flag=(v1[i]<v1[i+1]);
            ans+=1;
        }
        
    }
    
    cout<<ans<<endl;
    
    
    return 0;
}

Measured memory_bytes: 892
#include <stdio.h>
long cache[87];
long lucas(int x) {
    if (cache[x]) {
        return cache[x];
    }
    if (x == 0) {
        cache[x] = 2;
        return lucas(x);
    }
    if (x == 1) {
        cache[x] = 1;
        return lucas(x);
    }
    cache[x] = lucas(x - 1) + lucas(x - 2);
    return lucas(x);
}
int n;
int main(void) {
    scanf("%d", &n);
    printf("%ld\n", lucas(n));
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repf(i, j, n) for (int i = (j); i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
using P = pair<int, int>;

struct Point {
  int x;
  int y;
  Point(){};
  Point(int x_, int y_) { x = x_, y = y_; };
  bool operator<(const Point& o) const { return tie(x, y) < tie(o.x, o.y); }
};

Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); }
Point operator+(Point a, Point b) { return Point(a.x + b.x, a.y + b.y); }

signed main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  vector<Point> c(n);
  rep(i, n) cin >> x[i] >> y[i];
  rep(i, n) c[i] = Point(x[i], y[i]);
  sort(begin(c), end(c));
  map<Point, int> cnt;
  rep(i, n) repf(j, i + 1, n) cnt[c[j] - c[i]]++;
  Point t;
  int mx = 0;
  for (auto&& u : cnt)
    if (u.second > mx) {
      mx = u.second;
      t = u.first;
    }
  set<Point> s;
  for (auto&& u : c) {
    s.insert(u);
    s.insert(u + t);
  }
  cout << s.size() - n << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 2e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

int solve() {
}

int n;
ll a[MAX_N];
ll cnt[MAX_N];
ll res[MAX_N][2];

ll get(ll x) {
    return ((x-1) * x) / 2;
}

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

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    ll ans = 0LL;
    for (int i = 1; i < MAX_N; i++) {
        res[i][0] = get(cnt[i]);
        ans += res[i][0];
        res[i][1] = get(max(0LL, cnt[i]-1));
    }

    for (int i = 1; i <= n; i++) {
        ll now = ans;
        now -= res[a[i]][0];
        now += res[a[i]][1];
        cout << now << "\n";
    }





    return 0;
}


Measured memory_bytes: 8832
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp11
{
    class Class78
    {
        static void Main()
        {
            string S = Console.ReadLine();
            char ans = 'A';
            for(int i = 97; i < 123; i++)
            {
                if (!S.Contains((char)i))
                {
                    ans = (char)i;break;
                }
            }
            Console.WriteLine(ans == 'A' ? "None" : ans.ToString());
        }
    }
}


Measured memory_bytes: 13536
#include<iostream>

using namespace std;
int main()
{
    long int num1;
    cin >> num1;
    long int X = 100;
    int i = 1;
    while(true)
    {
        X += (X/100);
        if( num1 <= X )
        {
            cout << i << endl;
            break;

        }
        i += 1;
    }
    
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void get() {}template<class H, class...T>void get(H&h, T&...t) { cin >> h; get(t...); }
template<class T>void geti(T&a) { for (auto&_ : a)cin >> _; }
template<class T>void getii(T&a) { for (auto&_ : a)geti(_); }
void put(string d) {}template<class H, class...T>void put(string d, H&h, T&...t) { cout << h; if (sizeof...(t))cout << d; put(d, t...); }
template<class T>void puti(T&a, string d = " ") { bool f = 1; for (auto&_ : a)cout << (exchange(f, 0) ? "" : d) << _; cout << endl; }
template<class T>void putii(T&a, string d = " ") { for (auto&_ : a)puti(_, d); }
#define dcl(...) ll __VA_ARGS__;get(__VA_ARGS__)
#define dclt(t,...) t __VA_ARGS__;get(__VA_ARGS__)

int main() {
    msi dic;
    int n, m;
    cin >> n;
    string s;
    rep(i, n) {
        cin >> s;
        if (dic.find(s) == dic.end()) {
            dic[s] = 1;
        }
        else {
            dic[s]++;
        }
    }
    cin >> m;
    rep(i, m) {
        cin >> s;
        if (dic.find(s) == dic.end()) {
            dic[s] = -1;
        }
        else {
            dic[s]--;
        }
    }
    int maxv = -INF;
    for (auto i : dic) {
        if (maxv < i.sc) {
            maxv = i.sc;
        }
    }
    cout << max(0, maxv);
    
}


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

const int N = 2e5 + 7;

LL dp[N][2];
LL A[N];

int main() {
  _upgrade;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }

  for (int i = 2; i <= n; i++) {
    if (i & 1) {
      dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
      dp[i][1] = max(dp[i - 2][0], dp[i - 2][1]) + A[i];
    } else {
      dp[i][0] = dp[i - 2][0] + A[i - 1];
      dp[i][1] = dp[i - 1][0] + A[i];
    }
  }

  cout << max(dp[n][0], dp[n][1]) << "\n";
  return 0;
}

Measured memory_bytes: 8344
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
#define  MAX 100
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};
int field[MAX][MAX]; 
int w,h;
int xs,ys,xg,yg;
int n;
int color;
bool flag = false;

void blockset(int a,int b,int xx,int yy){
	if(b == 0){
		field[yy][xx] = a;	
		field[yy][xx+1] = a;	
		field[yy][xx+2] = a;	
		field[yy][xx+3] = a;	
		field[yy+1][xx] = a;	
		field[yy+1][xx+1] = a;	
		field[yy+1][xx+2] = a;	
		field[yy+1][xx+3] = a;	
	}else if(b == 1){
		field[yy][xx] = a;	
		field[yy+1][xx] = a;	
		field[yy+2][xx] = a;	
		field[yy+3][xx] = a;	
		field[yy][xx+1] = a;	
		field[yy+1][xx+1] = a;	
		field[yy+2][xx+1] = a;	
		field[yy+3][xx+1] = a;
	}
}

void dfs(int x,int y){
	field[y][x] = 0;
	
	if(x == xg && y == yg){
		flag = true;
		return;
	}
	for(int i = 0;i < 4;i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(nx < 0 || ny < 0 || nx >= w || ny >= h){
			continue;
		}else if(field[ny][nx] == color){
			dfs(nx,ny);
		} 
	}
	
	
}

int main(){
	while(true){
		cin >> w >> h;
		if(w == 0 && h == 0) break;
		cin >> xs >> ys >> xg >> yg;
		xs--;
		ys--;
		xg--;
		yg--;
		cin >> n;
		for(int i = 0;i < n;i++){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			x--;
			y--;
			blockset(c,d,x,y);
		}
		color = field[ys][xs];
		flag = false;
		if(color)dfs(xs,ys);

		if(flag){
			cout << "OK" << endl;
		}else{
			cout << "NG" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1168
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    S = readline().strip().decode()
    K = int(readline())
    if S[0] != '1':
        print(S[0])
        return 

    cnt = 0
    for i in S:
        if i == '1':
            cnt += 1
        else:
            break
    if K <= cnt:
        print('1')
    else:
        print(S[cnt])
if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <iostream>
using namespace std;
int main(){
	int n,a[5001],s,m;
	while(1){
		cin>>n;
		if(!n)break;
		for(int i=0;i<n;i++)cin>>a[i];
		m=-10000000;
		for(int i=0;i<n;i++){
			s=0;
			for(int j=i;j>=0;j--){
				s+=a[j];
				if(s>m)m=s;
			}
		}
		cout<<m<<endl;
	}
	return 0;
}

Measured memory_bytes: 3020
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#define rep(i, n) for(ll i = 0; i < (n); i++)
#define forn(i, n, m) for (ll i = (n); i<=(m); i++)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

ll mul(ll a, ll b) {
	ll val = a * b - (ll)((ld)a * b / mod) * mod;
	if (val < 0) val += mod;
	if (val >= mod) val -= mod;
	return val;
}
ll poww(ll a, ll b) {
	ll val = 1;
	a %= mod;
	while (b > 0) {
		if (b % 2) val = mul(a, val);
		a = mul(a, a);
		b >>= 1;
	}
	return val % mod;
}
ll inv(ll a) {
		return poww(a, mod - 2);
}


ll const maxn = 2e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll l, r; cin >> l >> r; ll cnt = 0;
	//for (ll x = l; x <= r; x++) {
	//	for (ll y = x; y <= r; y++) {
	//		if ((x ^ y) == (y % x)) (cnt += 1) %= mod, cout << x << " " << y << endl;
	//	}
	//}
	// 0: y < r && x > l
	// 1: y = r && x > l
	// 2: y < r && x = l
	// 3: y = r && x = l
	ll bitr = 0;
	ll bitl = 0;
	for (ll bit = 63; bit >= 0; bit--) {
		ll kek = 1LL << bit;
		if (kek & r) {
			bitr = bit;
			break;
		}
	}
	for (ll bit = 63; bit >= 0; bit--) {
		ll kek = 1LL << bit;
		if (kek & l) {
			bitl = bit;
			break;
		}
	}
	ll ans = 0;
	for (ll fst = bitr; fst >= bitl; fst--) {
		ll dp[70][4];
		for (ll i = 0; i < 70; i++)
			for (ll j = 0; j < 4; j++)
				dp[i][j] = 0;
		
		if(fst == bitr && fst == bitl)
			dp[fst][3] = 1;
		else if (fst == bitr) {
			dp[fst][1] = 1;
		}
		else if (fst == bitl) {
			dp[fst][2] = 1;
		}
		else {
			dp[fst][0] = 1;
		}
		
		for (ll bit = fst - 1; bit >= 0; bit--) {
			ll kek = 1LL << bit;
			dp[bit][0] += dp[bit + 1][0] * 3;
			bool f = false;
			if ((kek & l) && (kek & r)) {
				dp[bit][1] += dp[bit + 1][1] * 2; dp[bit][0] += dp[bit + 1][1];
				dp[bit][2] += dp[bit + 1][2];
			}
			else if (kek & r) {
				dp[bit][1] += dp[bit + 1][1] * 2; dp[bit][0] += dp[bit + 1][1];
				dp[bit][2] += dp[bit + 1][2] * 2; dp[bit][0] += dp[bit + 1][2];
				dp[bit][2] += dp[bit + 1][3]; dp[bit][1] += dp[bit + 1][3];
			}
			else if (kek & l) {
				f = true;
				dp[bit][1] += dp[bit + 1][1];
				dp[bit][2] += dp[bit + 1][2];
			}
			else {
				dp[bit][1] += dp[bit + 1][1];
				dp[bit][2] += dp[bit + 1][2] * 2; dp[bit][0] += dp[bit + 1][2];
			}
			if (f) dp[bit][3] = 0;
			else {
				dp[bit][3] = dp[bit + 1][3];
			}
			for (ll i = 0; i < 4; i++) dp[bit][i] %= mod;
		}
		ans += (dp[0][0] + dp[0][1] + dp[0][2] + dp[0][3]) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}
/*

*/

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

struct Conv {
    char s;
    char d;
    
    Conv(char as, char ad) {
        s = as;
        d = ad;
    }
};

int main() {
    string s, t;
    cin >> s >> t;
    int l = s.length();
    vector<Conv> v;
    bool is_exists;
    
    for (int i = 0; i < l; i++) {
        is_exists = false;
        
        for (int ii = 0; ii < v.size(); ii++) {
            if (v[ii].s == s[i]) {
                if (v[ii].d != t[i]) {
                    cout << "No" << endl;
                    return 0;
                }
                
                is_exists = true;
                break;
            }
        }
        
        if (!is_exists) {
            v.push_back(Conv(s[i], t[i]));
        }
    }
    
    for (int i = 0; i < v.size(); i++) {
        for (int ii = 0; ii < v.size(); ii++) {
            if ((v[i].d == v[ii].d) && (v[i].s != v[ii].s)) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 検索用タグ、lambdaの練習。sort()

# 実装を行う関数
def resolve(test_def_name=""):
    # 数値取得サンプル
    #   1行N項目 x, y = map(int, input().split())
    #   N行N項目 x = [list(map(int, input().split())) for i in range(n)]

    # 文字取得サンプル
    aa = input()
    x = list(map(lambda xx: int(xx), input().split()))

    new_x = list(enumerate(x, 1))

    new_x = sorted(new_x, key=lambda xx: xx[1])

    ans = []
    for i in new_x:
        ans.append(i[0])

    print(*ans)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
2 3 1"""
        output = """3 1 2"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """5
1 2 3 4 5"""
        output = """1 2 3 4 5"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """8
8 2 7 3 4 5 6 1"""
        output = """8 2 4 5 6 7 3 1"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()


Measured memory_bytes: 80744
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
const int maxn = 2e5+2;

int a[maxn], n;
map<int,int> g;

inline uint32_t bsr_highest_bit(uint32_t x) {
  if (!x) return 0;
  uint32_t bit;
  asm(
    "bsr %1, %0"
    : "=r" (bit)
    : "r" (x)
  );
  return (1 << bit);
}

int main() {
    cin>>n;
    for(int i=0;i<n;++i) {
        cin >> a[i];
        g[a[i]]++;
    }
    int ans = 0;
    sort(a,a+n);
    for(int i=n-1;i>=0;--i){
        if(g[a[i]]) {
            g[a[i]]--;
            int x = a[i];
            int y = bsr_highest_bit(x);
            y <<= 1;
            if(g[y-x]) {
                g[y-x]--;
                ans++;
            }
            
        }
    }
    cout << ans << endl;
}

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

int main()
{
	int a, b, c, d;
	string S;
	while (cin >> S, S != "#") {
		int W = 0, H = 1;
		bool once = true;
		for (auto c : S) {
			if (c == '/') {
				once = false;
				H++;
			}
			else if (c == 'b') {
				if (once) W++;
			}
			else if (isdigit(c)) {
				if (once) W += c - '0';
			}
		}
		vector<vector<int>> state(H, vector<int>(W));
		int y = 0, x = 0;
		for (auto c : S) {
			if (c == '/') {
				y++;
				x = 0;
			}
			else if (c == 'b') {
				state[y][x++] = 1;
			}
			else if (isdigit(c)) {
				x += c - '0';
			}
		}
		cin >> a >> b >> c >> d;
		state[a - 1][b - 1] = 0;
		state[c - 1][d - 1] = 1;
		for (int i = 0; i < H; i++) {
			int sp = 0;
			for (int j = 0; j < W; j++) {
				if (state[i][j]) {
					if (sp) cout << sp;
					cout << 'b';
					sp = 0;
				}
				else {
					sp++;
				}
			}
			if (sp) cout << sp;
			if (i != H - 1) cout << '/';
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3188
n = int(input())
res = 0
ans = 0
maxNum = -1
for i in range(1,n+1):
    cnt = i
    res = 0
    while True:
        if i % 2 != 0:
            break
        else:
            i //= 2
            res += 1
    if maxNum < res:
        maxNum = res
        ans = cnt
print(ans)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-


def warshall_floyd(dist):
    v_count = len(dist[0])

    for k in range(v_count):
        for i in range(v_count):
            for j in range(v_count):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    return dist


def main():
    h, w = map(int, input().split())
    c = [list(map(int, input().split())) for _ in range(10)]
    a = [list(map(int, input().split())) for _ in range(h)]
    ans = 0

    results = warshall_floyd(c)

    for i in range(h):
        for j in range(w):
            if a[i][j] != -1:
                ai = a[i][j]
                ans += results[ai][1]

    print(ans)


if __name__ == '__main__':
    main()


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 N, K;
  cin >> N >> K;
  vector<int64> P(N), C(N);
  REP(i, N) {
    cin >> P[i];
    P[i]--;
  }
  REP(i, N) cin >> C[i];
  int64 res = -INF_LL;
//  REP(i, N) {
//    if (P[i] == i) {
//      chmax(res, C[i]);
//      chmax(res, C[i] * K);
//      continue;
//    }
//    vector<int64> cnt(N, -1);
//    vector<int64> score(N, -1);
//    int64 prev = -1, now = i;
//    cnt[now] = 0; score[now] = 0;
//    while (1) {
//      prev = now;
//      now = P[now];
//      if (cnt[now] != -1) break;
//      cnt[now] = cnt[prev]+1;
//      score[now] = score[prev] + C[now];
//    }
//    int64 len = cnt[prev] - cnt[now] + 1, loop = score[prev] - score[now] + C[now];
////    cout << prev << " " << now << " " << score[prev] << " " << score[now] << " " << C[now] << endl;
//    int64 v = i, turn = 0;
//    int64 ret = 0;
//    REP(j, K) {
//      if (v == now) break;
//      turn++;
//      v = P[v];
//      ret += C[v];
//      chmax(res, ret);
//    }
//    turn = K - turn;
////    cout << len << " " << loop << " " << ret << " " << turn << endl;
//    if (loop >= 0) {
//      ret += loop * (turn / len);
//      turn %= len;
//    } else {
//      turn = len;
//    }
//    REP(j, turn) {
//      v = P[v];
//      ret += C[v];
//      chmax(res, ret);
//    }
//  }
  REP(i, N) {
    int64 ret = 0, turn = 0, v = i;
    REP(j, K) {
      if (turn != 0 && v == i) break;
      v = P[v];
      turn++;
      ret += C[v];
      chmax(res, ret);
    }
    if (ret >= 0) {
      ret = ret * ((K / turn) - 1);
      turn = K - turn * ((K / turn) - 1);
    } else {
      ret = 0;
    }
    v = i;
    REP(j, turn) {
      v = P[v];
      ret += C[v];
      chmax(res, ret);
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 3660
S = input()
f = 0
x = 0
y = 0
Y = []
for i in range(len(S)):
  if S[i] == ">":
    if f == 1:
      y += 1
    elif f == 0:
      x = y
      y = 1
      f = 1
  else:
    if f == 0:
      y += 1
    else:
      Y.append([x, y])
      x = 0
      y = 1
      f = 0
if f == 0:
  Y.append([y, 0])
else:
  Y.append([x, y])
      
ans = 0
for y in Y:
  M = max(y)
  m = min(y)
  ans += (M * (M+1) // 2 + m * (m-1) // 2)
print(ans)

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

int main(){
    string s;
    cin>>s;
    if(s == "RRR") cout<<3<<endl;
    else if(s == "RRS" || s == "SRR") cout<<2<<endl;
    else if(s == "SSS") cout<<0<<endl;
    else cout<<1<<endl;
    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

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

    ll N,A,B;
    string S;
    cin >> N>>A>>B;
    if(N==1){
        if(A==B){
            cout << 1 << endl;
        }
        else{
            cout << 0 << endl;
        }
    }

    else if(A>B){
        cout << 0 << endl;
    }
    else if(A==B){
        cout << 1 << endl;
    }
    else{
        ll max = (N - 1) * B + A;
        ll min = (N - 1) * A + B;

        cout << max - min + 1 << endl;
    }



}


Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <map>
#include <set>
#include <vector>

int main() {
    int n;
    while (~scanf("%d", &n)) {
        if (n == 0) break;
        
        std::vector<unsigned int> v;
        std::map<unsigned int, unsigned long long int> m;
        
        unsigned int a;
        unsigned long long int b, c;
        for (int i = 0; i < n; ++i) {
            scanf("%u %llu %llu", &a, &b, &c);
            v.push_back(a);
            m[a] += b * c;
        }
        
        std::set<unsigned int> dup;
        bool found = false;
        for (auto i : v) {
            if (m[i] >= 1000000 && dup.count(i) == 0) {
                printf("%u\n", i);
                dup.insert(i);
                found = true;
            }
        }
        if (!found) {
            printf("NA\n");
        }
    }
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> p;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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;
}

string s, t;
int dp[3100][3100];
pair<int, int> prevIndex[3100][3100];

int main() {
  rep(i, 3100) rep(j, 3100) prevIndex[i][j] = pair<int, int>(-1, -1);
  cin >> s >> t;
  rep(i, s.size()) {
    rep(j, t.size()) {
      if(s[i] == t[j]) {
        if(chmax(dp[i + 1][j + 1], dp[i][j] + 1)) {
          prevIndex[i + 1][j + 1] = pair<int, int>(i, j);
        }
      } else {
        if(chmax(dp[i][j + 1], dp[i][j])) {
          prevIndex[i][j + 1] = prevIndex[i][j];
        }
        if(chmax(dp[i + 1][j], dp[i][j])) {
          prevIndex[i + 1][j] = prevIndex[i][j];
        }
      }
    }
  }
  int maxlen = 0;
  int si = -1, ti = -1;
  rep(i, s.size() + 1) {
    rep(j, t.size() + 1) {
      if(chmax(maxlen, dp[i][j])) {
        si = i;
        ti = j;
      }
    }
  }

  string ans = "";
  while(ans.size() < maxlen) {
    pair<int, int> siti = prevIndex[si][ti];
    si = siti.first;
    ti = siti.second;
    ans = s[si] + ans;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 111744
import sys

h,w=map(int,input().split())

s=[["" for i in range(w)] for j in range(h)]

for i in range(h):
    a=input()
    for j in range(w):
        s[i][j]=a[j]
        
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            if i != 0:
                if s[i-1][j] == "#":
                    continue
            if i != h-1:
                if s[i+1][j] == "#":
                    continue
            if j != 0:
                if s[i][j-1] == "#":
                    continue
            if j != w-1:
                if s[i][j+1] == "#":
                    continue
            print("No")
            sys.exit()
print("Yes")

Measured memory_bytes: 3064
"use strict";
const Main = input => {
    const value = input[0].split(' ');
    const n = Number(value[0]), 
    A = Number(value[1]), 
    B = Number(value[2]), 
    C = Number(value[3]);
    let l = new Array(n);
    for(let i=0;i<n; i++) {
        l[i] = Number(input[i+1]);
    }    
    const INF = 1000000000;
    const dfs = (cur, a, b, c) => {
        if (cur == n) {
            if (Math.min(a,b,c) > 0) {
                return Math.abs(a-A) + Math.abs(b-B) + Math.abs(c-C)- 30;
            } else {
                return INF;
            }
        }
        return Math.min(dfs(cur+1,a,b,c), 
        dfs(cur+1,a+l[cur],b,c)+10, 
        dfs(cur+1,a,b+l[cur],c)+10, 
        dfs(cur+1,a,b,c+l[cur])+10);
    };
    console.log(dfs(0,0,0,0));
    
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 9636
<?php
  fscanf(STDIN, "%d", $a);
  fscanf(STDIN, "%s", $b);

if($a == 0||$a % 2 != 0) {
  echo "No";
  exit();
}

$word = str_split($b);
$l = 0;
while($l < count($word)/2) {
  if($word[$l] !== $word[count($word)/2+$l]) {
    echo 'No';
    exit();
  }
  $l++;
  if($l === count($word)/2){
    echo 'Yes';
  }
}

Measured memory_bytes: 5112
#include<bits/stdc++.h>
using namespace std;
const int maxn=2*1e3;
int main(){
   int cnt[maxn];
   memset(cnt,0,sizeof(cnt));
   int n,x,y;
   cin>>n>>x>>y;
   for(int i=1;i<n;i++)
   for(int j=i+1;j<=n;j++){
   	   int k,ans=0;
   if(i<=x)
   {  
   if(j<=x)   ans=j-i;
   	else {
   		
		 if(j>x&&j<=y){
		 	if(j-x<y-j+1)  k=j-x;
        else k=y-j+1;
		 ans=x-i+k;
		 } 
   	     else if(j>y) 
			{
					if(j-x<j-y+1)  k=j-x;
                    else k=j-y+1; 
			 ans=x-i+1+j-y;
         }
         } 
    }
   else {
   	if(j<=y)    {
   		if(j-i<y-j+i-x+1) k=j-i;
   	    else k=y-j+i-x+1;
	   ans=k;
	   }
   	else if(j>y){
   		if(j-i<j-y+i-x+1) k=j-i;
   	    else k=j-y+i-x+1;
   		ans=k;
	   }  
     }
     cnt[ans]++;
   }
   for(int i=1;i<=n-1;i++){
   	cout<<cnt[i]<<endl;
   }
   return 0;
}

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

int main(){
	int n, p[20], i, ans = 0;
	cin >> n;
	for (i = 0; i < n; i++){
		cin >> p[i];
	}
	for (i = 1; i < n - 1; i++){
		if (p[i - 1] < p[i]){
			if (p[i] < p[i + 1]){
				ans++;
			}
		}
		else if (p[i - 1] > p[i]){
			if (p[i] > p[i + 1]){
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	long long int ans = 0;
	long long int A[10] = { 1,1,2,4,8,16,32,64,128,256}, c = 1;
	string S;
	cin >> S;
	for (long long int i = 0; i < S.size(); i++)
	{
		long long int a = c, b = 1, x = S[i] - '0';
		for (long long int j = i+1; j < S.size(); j++)b *= 10;
		for (long long int j = 0; j < S.size()-i; j++)
		{
			//for (int k = i - 1; k < S.size(); k++)
			//for (int k = 0; k < S.size(); k++)
			//{
			//}
			ans = ans + a*b*A[j]*x;
			b /= 10;
		}
		c *= 2;
	}
	cout << ans;
}


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

#define MAX_N 100000

int N;
long long A[MAX_N];

int main()
{
	cin >> N;
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}

	sort( A, A + N );

	long long ans1 = 0;
	int i = 0;
	int j = N - 1;
	int flag = 0;
	while( i < j ) {
		ans1 += abs(A[i] - A[j]);
		if( flag ) {
			j -= 2;
			flag = 0;
		}
		else {
			i += 2;
			flag = 1;
		}
	}
	i = 0;
	j = N - 2;
	flag = 0;
	while( i < j ) {
		ans1 += abs(A[i] - A[j]);
		if( flag ) {
			j -= 2;
			flag = 0;
		}
		else {
			if( i == 0 ) {
				i++;
			}
			else {
				i += 2;
			}
			flag = 1;
		}
	}

	long long ans2 = 0;
	i = N - 1;
	j = 0;
	flag = 0;
	int cnt = 0;
	while( i > j && ++cnt <= N / 2 ) {
		ans2 += abs(A[i] - A[j]);
		if( flag ) {
			j += 2;
			flag = 0;
		}
		else {
			if( i == N - 1 ) {
				i--;
			}
			else {
				i -= 2;
			}
			flag = 1;
		}
	}
	i = N - 1;
	j = 1;
	flag = 0;
	while( i > j ) {
		ans2 += abs(A[i] - A[j]);
		if( flag ) {
			j += 2;
			flag = 0;
		}
		else {
			i -= 2;
			flag = 1;
		}
	}

	cout << max( ans1, ans2 ) << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  char x='C'+(n-1)/999;
  cout<<"AB"<<x<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3660
import heapq
def dijkstra_heap(s):
    d = [float("inf")] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d
import sys
input = sys.stdin.readline
n =int(input())
 
edge = [[] for i in range(n)]
#edge[i] : [weght,to]
for i in range(n-1):
    a, b, c = map(int,input().split())
    a, b = a-1, b-1
    edge[a].append([c,b])
    edge[b].append([c,a]) 
q, k = map(int, input().split())
k = k-1
d = dijkstra_heap(k)
for i in range(q):
  x, y = map(int, input().split())
  x, y = x-1, y-1
  print(d[x]+d[y])

Measured memory_bytes: 100272
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    string A, B; cin >> A >> B;
    if (A == B) {
        printf("%s\n", "EQUAL");
        return 0;
    }
    else {
        if (A.length() > B.length()) {
            printf("%s\n", "GREATER");
            return 0;
        }
        else if (A.length() < B.length()) {
            printf("%s\n", "LESS");
            return 0;
        }
        else {
            if (A > B) {
                printf("%s\n", "GREATER");
                return 0;
            }
            else if (A < B) {
                printf("%s\n", "LESS");
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3604
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P;
map<int, int> dp;
#define REP(i, n) for (int i = 0; i < n; i++)

bool in(int target, int max) { return 0 <= target && target < max - 1; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  vector<int> nums(4);

  REP(i, 4) nums[i] = (int)(S[i] - '0');
  auto left = nums[0] * 10 + nums[1];
  auto right = nums[2] * 10 + nums[3];
  // cout << left << " " << right << endl;
  if ((left > 12 || left == 0) && (right > 12 || right == 0)) {
    cout << "NA" << endl;
    return 0;
  }
  if (left <= 12 && (right > 12 || right == 0)) {
    cout << "MMYY" << endl;
    return 0;
  }
  if ((left > 12 || left == 0) && right <= 12) {
    cout << "YYMM" << endl;
    return 0;
  }
  if (left <= 12 && right <= 12) {
    cout << "AMBIGUOUS" << endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 256