akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

int main()
{
  int n,m;
  cin >> n >> m;
  //  vector<int> a(n),b(m);
  map<int,int> raw,col;
  rep(i,n){
    int a;
    cin >> a;
    raw[a]++;
    //    cin >> a[i];
  }
  rep(i,m){
    int b;
    cin >> b;
    col[b]++;
    //    cin >> b[i];
  }

  // rep1(i,n*m){
  //   cout << raw[i] << "\n";
  //   raw[i] = 0;
  //   col[i] = 0;
  // }

  // rep(i,n){
  //   raw[a[i]]++;
  // }
  // rep(i,m){
  //   col[b[i]]++;
  // }

  int cntr=0,cntl=0,cnt=0;
  mint res(1);
  for(int i=n*m;i>0;--i){
    int x = raw[i];
    int y = col[i];
    //    cout << i << ":" << x << ":" << y << "\n";
    if(x>=2||y>=2){
      cout << 0 << "\n";
      return 0;
    }
    if(x==1&&y==1){
      cntr++;
      cntl++;
    }
    else if(x==1&&y==0){
      res *= (mint)cntl;
      cntr++;
    }
    else if(x==0&&y==1){
      res *= (mint)cntr;
      cntl++;
    }
    else if(x==0&&y==0){
      res *= (mint)(cntr*cntl-cnt);
    }
    cnt++;
  }

  cout << res.x << "\n";
  
  return 0;
}


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

using namespace std;

void test()
{
    int n;
    cin>>n;

    if(n%1000==0)
    {
        cout<<0;
        return;
    }

    cout<<1000-n%1000;

}

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

    test();

    return 0;
}



Measured memory_bytes: 3668
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#pragma region DEBUG
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
lli arr[MAX];
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int DFS(int s, vector <bool> &visited, vector <vector<lli> > &adj){
    int ctr = 1;
    visited[s] = true;
   // cout<<s<<endl;
    for(auto i : adj[s]){
        if(!visited[i])
            ctr += DFS(i,visited,adj);
    }
    return ctr;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli t;
    t =1 ;
    while(t--){
        lli n,m;
        cin>>n>>m;
        vector <vector <lli> > adj(n+1);
        for(int i = 0; i<m; i++){
            lli a,b;
            cin>>a>>b;
            a--;
            b--;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        int maxm = -1;
        vector <bool> visited(n+1,0);
        for(int i = 0; i<n; i++){
            if(!visited[i])
                maxm = max(maxm,DFS(i,visited,adj));
        }
        cout<<maxm<<endl;
    
    }
}

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

int main()
{
    int result[4] = {0, 0, 0, 0};
    
    int N = 0;
    
    cin >> N;
    
    for (int i = 0; i < N; ++i) {
        string line;
        cin >> line;
        
        if (line == "AC"){
            result[0] += 1;
        }
        else if (line == "WA"){
            result[1] += 1;
        }
        else if (line == "TLE"){
            result[2] += 1;
        }
        else if (line == "RE"){
            result[3] += 1;
        }
    }
    
    cout << "AC x " <<  result[0] << endl;
    cout << "WA x " <<  result[1] << endl;
    cout << "TLE x " <<  result[2] << endl;
    cout << "RE x " <<  result[3] << endl;
}


Measured memory_bytes: 3624
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc163_e
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000

int n;
vector<pair<ll, int>> a;
map<ll, ll> dp;

ll go(int i, int l, int r) {
    if(i>=n) {
        return 0ll;
    }
    ll k = i*100000000ll + l*10000ll + r;
    if(dp.find(k) != dp.end()) {
        return dp[k];
    }
    ll x = go(i+1, l+1, r) + a[i].first * abs(a[i].second-l);
    ll y = go(i+1, l, r-1) + a[i].first * abs(a[i].second-r);
    dp[k] = max(x, y);
    return max(x, y);
}


int main() {
    scanf("%d", &n);
    a.assign(n, {0ll, 0});
    for(int i=0; i<n; i++) {
        scanf("%lld", &a[i].first);
        a[i].second = i;
    }
    sort(a.begin(), a.end(), greater<pair<ll, int>>());
    ll rs = go(0, 0, n-1);
    printf("%lld\n", rs);
}


Measured memory_bytes: 129112
#include <bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define int long long int
using namespace std;

const int N = 1e6+5;
const int mod = 1e9+7;

void solve() {
	string s;
	cin >> s;
	if(s[1] == 'B')
		cout << "ARC";
	else 
		cout << "ABC";
	return;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int testcases = 1,i = 1;
	//cin >> testcases;
    while(testcases--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int A,B,C; cin >> A >> B >> C;
    cout << (A+B < C ? "No" : "Yes") << endl;
    return 0;
}

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

namespace debug
{
    public static partial class Program
    {
        public static void Main()
        {
            var nd = Console.ReadLine().ToLongArray();
            var n = nd[0];
            var d = nd[1];

            Console.WriteLine(Math.Ceiling(n / (d * 2.0 + 1)));
        }
    }

    public static partial class Program
    {
        //テンプレここから
        private static long GCD(long aaa, long bbb) => bbb == 0 ? aaa : GCD(bbb, aaa % bbb);
        public static long LCM(long aaa, long bbb) => aaa * bbb / GCD(aaa, bbb);
        public static long ToLong(this double ddd) => (long) ddd;
        public static long ToLong(this string str) => long.Parse(str);
        public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
        public static long[] ToLongArray(this string str, char opr = ' ') => str.Split(opr).ToLong();
        public static long Diff(long aaa, long bbb) => Math.Abs(Math.Max(aaa, bbb) - Math.Min(aaa, bbb));
        public static long Sign(this long iii) => Math.Sign(iii);
        public static bool IsEven(this long iii) => iii % 2 == 0;
        public static readonly int[] Dx = {0, -1, 0, 1};
        public static readonly int[] Dy = {-1, 0, 1, 0};
        public const int MOD = 1000000007;
        public const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        public const string alphabet = "abcdefghijklmnopqrstuvwxyz";
        public static long ToLong(this char ccc) => ccc.ToString().ToLong();
        public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
        public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);

        public static string JoinToStr(this IEnumerable<long> array, string sep = "")
            => array.Select(xxx => xxx.ToString()).Join(sep);

        //テンプレここまで
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main() {
	string A;
	cin >> A;
	int N = A.length();
	vector<vector<int>> a(N+1);
	a[0] = vector<int>(26);
	for (int i = 0; i < N; ++ i) {
		a[i+1] = a[i];
		++ a[i+1][A[i]-'a'];
	}
	long long r = 1;
	for (int i = 0; i < N; ++ i) {
		for (int j = 0; j < 26; ++ j) if (j != A[i]-'a') r += a[i][j];
	}
	cout << r << endl;
}


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

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

  int prev = 0;
  int ans = 0;
  int tmp_cnt = 0;
  for(int i = 0; i < N; i++){
    int h;
    cin >> h;

    if(prev >= h){
      tmp_cnt++;
      prev = h;
      ans = max(ans, tmp_cnt);
    }else{
      tmp_cnt = 0;
      prev = h;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000
using namespace std;
int main()
{
    int q;
    cin >> q;
    long long cnt1 = 0, cnt2 = 0;
    rep(i, q)
    {
        long long p, n;
        char c;
        scanf("%d %c %d", &p, &c, &n);
        //cin >> p >> c >> num;
        if (c == '(')
            cnt1 += n;
        if (c == ')')
            cnt2 += n;
        if (cnt1 == cnt2)
            printf("Yes\n");
        //cout << "Yes" << endl;
        else
            printf("No\n");
        //cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef int64_t ll;
typedef long double ld;
using namespace std;
const ll mod=1000000007;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main(){
    init();
    ll H;cin>>H;
    map<ll,ll>mp;
    mp[H]=1;
    while(H>1){
      mp[H/2]=mp[H]*2;
      H/=2;
    }
    ll ans=0;
    for(auto&&i:mp)ans+=i.second;
    cout<<ans<<endl;
}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int main() {
  int N,W,V;
  cin >> N >> W;
  VI w(N),v(N);
  REP(i,N){
    cin >> w.at(i) >> v.at(i);
    V += v.at(i);
  }
  
  VVLL DP(N+1,VLL(V+1,W+1));
  
  DP.at(0).at(0) = 0;
  
  REP(i,N){
    REP(j,V+1){
      if(j < v.at(i)){ 
        DP.at(i+1).at(j) = DP.at(i).at(j);
      }else{
        DP.at(i+1).at(j) = min(DP.at(i).at(j),DP.at(i).at(j-v.at(i))+w.at(i));
      }
    }
  }
  REP(i,V+1){
    if(W>=DP.at(N).at(V-i)){
      cout << V-i << endl;
      break;
    }
  }
  
  return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

const ll div2 = 500000004;

ll f[200005], fi[200005];

ll comb(int r, int c) {
    if (r < c) return 0;
    return f[r] * fi[c] % MOD * fi[r - c] % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int B, W;
    cin >> B >> W;

    f[0] = 1;
    for (int i = 1; i <= 200000; i++) {
        f[i] = f[i - 1] * i % MOD;
    }

    fi[200000] = modpow(f[200000], MOD - 2);
    for (int i = 200000; i > 0; i--) {
        fi[i-1] = fi[i] * i % MOD;
    }

    ll sumb = 0, sumw = 0;
    for (int i = 0; i < B + W; i++) {
        ll vb = 0;
        if (i >= B) {
            vb = comb(i - 1, B - 1) * modpow(div2, i) % MOD;
        }
        sumb = (sumb + vb) % MOD;

        ll vw = 0;
        if (i >= W) {
            vw = comb(i - 1, W - 1) * modpow(div2, i) % MOD;
        }
        sumw = (sumw + vw) % MOD;

        ll rest = (MOD * 2 + 1 - sumb - sumw) % MOD;

        //cerr << sumb << " " << sumw << " " << rest << endl;
        cout << (sumw + rest * div2 % MOD) % MOD << endl;
    }

    return 0;
}

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

namespace ABC145C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var pointList = new List<Point>();

            for (var i = 0; i < N; i++)
            {
                var p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
                pointList.Add(new Point(p[0], p[1]));
            }

            var length = 0.0;
            var allRoute = Permutation(pointList, N).ToArray();

            foreach (var points in allRoute)
            {
                for (var i = 0; i < N - 1; i++)
                {
                    var p1 = points.ToArray()[i];
                    var p2 = points.ToArray()[i + 1];

                    length += Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2));
                }
            }

            Console.WriteLine(length / allRoute.Length);
        }

        static IEnumerable<IEnumerable<T>> Permutation<T>(IEnumerable<T> items, int k)
        {
            if (k == 1)
            {
                yield return new T[] { items.First() };
                yield break;
            }
            foreach (var item in items)
            {
                var leftside = new T[] { item };
                var unused = items.Except(leftside);
                foreach (var rightside in Permutation(unused, k - 1))
                    yield return leftside.Concat(rightside).ToArray();
            }
        }

        struct Point
        {
            public int X { get; set; }
            public int Y { get; set; }

            public Point(int x, int y)
            {
                this.X = x;
                this.Y = y;
            }
        }
    }
}

Measured memory_bytes: 24172
#include <iostream>
#include <string>


using namespace std;


int main(void)
{
    string S;
    cin >> S;
    int ans = 0;
    char bef = 'I';
    for (auto ch = S.begin(); ch != S.end(); ++ch) {
        if (*ch != bef)
            ans++;
        bef = *ch;
    }
    cout << (ans - 1) << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>

int main()
{
    int n, debt = 100000;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        debt *= 1.05;
        int r = debt % 1000;
        if (r) debt += 1000 - r;
    }
    std::cout << debt << std::endl;
}

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

using namespace std;

bool nop[100010];
int ans[100010];

int main() {
    memset(nop, false, sizeof(nop));
    nop[0] = nop[1] = true;
    for (int i = 2; i < 100001; i++)
        for (int j = 2; i * j < 100001; j++)
            nop[i * j] = true;
    ans[0] = 0;
    for (int i = 1; i <= 100000; i++) {
        if (i % 2 == 1 && nop[i] == false && nop[(i + 1) / 2] == false)
            ans[i] = ans[i - 1] + 1;
        else
            ans[i] = ans[i - 1];
    }

    int q, l, r;
    while(scanf("%d", &q) != EOF) {
        while(q--) {
            scanf("%d %d", &l, &r);
            printf("%d\n", ans[r] - ans[l - 1]);
        }
    }
    return 0;
}

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

int main() {
  ll N, ans = 0, MOD = 1e9+7, i;
  cin>>N;
  ll tmp = 1;
  for (i=0;i<N;i++) {
    tmp *= 10;
    tmp %= MOD;
  }
  ans += tmp % MOD;

  tmp = 1;
  for (i=0;i<N;i++) {
    tmp *= 9;
    tmp %= MOD;
  }
  ans -= tmp * 2 % MOD;
  if (ans < 0) ans += MOD;

  tmp = 1;
  for (i=0;i<N;i++) {
    tmp *= 8;
    tmp %= MOD;
  }
  ans += tmp % MOD;

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


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
char a[5]={'a','e','i','o','u'};
int main(){char c;c=getchar();for(int i=0;i<5;i++)if(c==a[i]){cout<<"vowel"<<endl;return 0;}cout<<"consonant"<<endl;return 0;}

Measured memory_bytes: 256
#include <stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)

int main(void)
{
	long long n,a[6],b=0,c=10000000000000000,f[7],g,i;
	scanf("%lld",&n);
	for(i=0;i<5;i++){
		scanf("%lld",&a[i]);
		b=max(b,a[i]);
		c=min(c,a[i]);
	}
	if(n%c==0){
		c=n/c;
	}else{
		c=n/c+1;
	}
	if(c==0) c++;
	printf("%lld",c+4);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
string s;
int c;
main()
{
	int n;cin>>n;
    cin>>s;
    bool f=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='o')
        {
            f=0;
        }
        else
        {
            if(f==0)
            {
                f=1;
            }
            else
            {
                cout<<c<<endl;
                return 0;
            }
        }
        c++;
    }
    cout<<c<<endl;
}



Measured memory_bytes: 3336
from collections import deque
N=int(input())
tree=[[] for _ in range(N)]
tree2=[]
for i in range(N-1):
    a,b=map(int,input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    tree2.append([a-1,b-1])
score=list(map(int,input().split()))
score.sort(reverse=True)
#print(tree,tree2,score)
v=0
d=deque()
seen=[0]*N
d.append(v)
ans=[]
l=[0]*N
s=0
while len(ans)!=N:
    v=d.popleft()
    seen[v]=1
    ans.append(v)
    for j in tree[v]:
        if seen[j]!=1:
            d.append(j)
    #print(ans,seen)
    #input()
for i in range(N):
    l[ans[i]]=score[i]
#print(l)
for i in range(N-1):
    s=s+min(l[tree2[i][0]],l[tree2[i][1]])
print(s)
print(*l,sep=" ")




Measured memory_bytes: 52440
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
	"math"
	"sort"
)

func main() {
	sc := NewScanner()

	n := sc.NextInt()

	// make([]int, length, capacity)
	s := make([]int, n, n)

	for i := 0; i < n; i++ {
		s[i] = sc.NextInt()
	}

	sort.Ints(s)
	a := s[n-1]
	h := float64(a) / 2
	min := a
	b := 0
	for i := 0; i < n-1; i++ {
		tmp := int(math.Abs(float64(s[i]) - float64(h)))
		if tmp < min {
			min = tmp
			b = s[i]
		}
	}
	fmt.Printf("%v %v\n", a, b)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 5504
N = int(input())
A = [[x-1 for x in list(map(int, input().split()))[::-1]] for _ in range(N)]


def can_match(i, A, next_set):
  if not A[i]:
    return
  j = A[i][-1]
  if A[j][-1] == i:
    if i < j:
      next_set.add((i,j))
    else:
      next_set.add((j,i))

      
next_set = set()
for i in range(N):
  can_match(i, A, next_set)
  
day = 0
battle = 0
while next_set:
  day += 1
  current_set = next_set.copy()
  next_set = set()
  for match in current_set:
    battle += 1
    del A[match[0]][-1]
    can_match(match[0], A, next_set)
    del A[match[1]][-1]
    can_match(match[1], A, next_set)
if battle == N*(N-1)//2:
  print(day)
else:
  print(-1)

Measured memory_bytes: 35612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
typedef pair<int,int> pii;

ll C2(ll k){
    ll cnt = 0;
    while(k % 2 == 0){
        cnt++;
        k /= 2;
    }
    return cnt;
}

map<long long, int> prime_factor(long long n){
    map< long long, int> ret;

    for(long long i = 2; i * i <= n; i++){
        while(n % i == 0){
            ret[i]++;
            n /= i;
        }
    }

    if( n != 1) ret[n] = 1;
    return ret;
}

int main(){
    ll N, M; cin >> N >> M;
    vector<ll > A(N);
    rep(i, 0, N) cin >> A[i];
    int x = 0;
    
    rep(i, 0, N){
        if(i == 0) x = C2(A[i]);
        else{
            if(x != C2(A[i])){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    
    map<ll, int> mp;
    ll lcm = 1;
    lcm = A[0];
    rep(i, 1, N){
        lcm = lcm * A[i] / __gcd(lcm, A[i]);
    }
    lcm /= 2;
    //cout << lcm << endl;
    cout << M  / lcm  - M / (lcm * 2) << endl;

    


}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <string>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#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 REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)


ll modpow(ll x, ll n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        ll h = modpow(x, n / 2);
        return h * h % MOD;
    } else {
        return x * modpow(x, n - 1) % MOD;
    }
}

int gcd(int a,int b)  {
	if (a%b==0)  return(b);
	else return(gcd(b,a%b));
}

int main() {
    string S; cin >> S;
    int ans = 0;
    rep(i,S.size()){
      if(S[i]=='+') ans++;
      else  ans--;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using int64 = long long;

int main()
{
  int N, A[100000];
  char op[100000];

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

  int64 all = A[0];
  for(int i = 1; i < N; i++) {
    if(op[i] == '+') all += A[i];
    else all -= A[i];
  }

  int64 cost = 0, ans = all, add = 0;
  for(int i = N - 1; i > 0; i--) {
    if(op[i] == '+') {
      cost += 2 * A[i];
    } else {
      ans = max(ans, all + add - cost);
      add += 2 * A[i];
      cost = 0;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include<set>
#include<string>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
long double pi = 3.14159265358979323846;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);


int main()
{
	fast
		ll sum = 0;
	ll mx = 0;
		ll k, n;  cin >> k >> n;
	ll z, z1;
	cin >> z1;
	int m= z1;
	mx = 0;
	
	for (int i = 1; i < n; i ++ ) {
		cin >> z;
	   
		mx = max(mx, z - z1);
		z1 = z;
		
	}


	mx = max(mx, (k- z)+m);
	
	cout << k - mx;
	
	return 0;

}

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

#define rep(i, s, n) for (int i = s; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s, t;
    cin >> s >> t;
    rep(i, 0, s.size()) {
        s = s[s.size() - 1] + s.substr(0, s.size() - 1);
        if (s == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
struct node{
  int key;
  struct node *left;
  struct node *right;
  struct node *parent;
};
typedef struct node* Node;
Node rootnode,NIL;


Node getMinimum(Node node){
  while(node->left!=NIL)
    node=node->left;
  return node;
}

Node getSuccessor(Node node){
  Node delete=node->parent;
  if(node->right!=NIL)
    return getMinimum(node->right);

  while(delete!=NIL && node==delete->right){
    node=delete;
    delete=delete->parent;
  }
  return delete;
}

Node Find(Node node,int key){
  while(node!=NIL && node->key!=key){
    if(node->key<key)
      node=node->right;
    else
      node=node->left;
  }
  return node;
}

void Insert(int key){
  Node node=rootnode,z,y=NIL;
  z=(Node)malloc(sizeof(struct node));
  z->key=key;
  z->left=NIL;
  z->right=NIL;

  while(node!=NIL){
    y=node;
    if(key>node->key)
      node=node->right;
    else
      node=node->left;
  }
  z->parent=y;
  if(y==NIL)rootnode=z;
  else{
    if(key>y->key)
      y->right=z;
    else
      y->left=z;
  }
}

void Preorder(Node node){
  if(node!=NIL){
    printf(" %d",node->key);
    Preorder(node->left);
    Preorder(node->right);
  }
}
void Inorder(Node node){
  if(node->left!=NIL)
    Inorder(node->left);
  printf(" %d",node->key);
  if(node->right!=NIL)
    Inorder(node->right);
}

void Delete(Node node){
  Node delete;
  Node child;

  if(node->left==NIL || node->right==NIL)
    delete=node;
  else
    delete=getSuccessor(node);
   
  
  //setting child
  if(delete->left!=NIL)
    child=delete->left;
  else
    child=delete->right;
  
  if(child!=NIL)
    child->parent=delete->parent;
  
  
  //if deletenode is rootnode
  if(delete->parent==NIL)
    rootnode=child;
  //deletenode is not rootnode
  else{
    if(delete->parent->left==delete)
      delete->parent->left=child;
    else
      delete->parent->right=child;
  }

  if(delete!=node)
    node->key=delete->key;
  free(delete);
}

int main(void){
  int n,i,key;
  char command[7];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",command);
    if(command[0]=='i'){
      scanf("%d",&key);
      Insert(key);
    }
    else if(command[0]=='p'){
      Inorder(rootnode);
      printf("\n");
      Preorder(rootnode);
      printf("\n");
    }
    else if(command[0]=='f'){
      scanf("%d",&key);
      if(Find(rootnode,key)!=NIL)
	printf("yes\n");
      else printf("no\n");
    }
    else if(command[0]=='d'){
      scanf("%d",&key);
      Delete(Find(rootnode,key));
    }
  }

  return 0;
}



Measured memory_bytes: 20440
# D - Even Relation

from collections import deque

n = int(input())

# adjacency list
alist = [[] for _ in range(n)]

for _ in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    alist[u].append((v, w%2))
    alist[v].append((u, w%2))

#print(alist)

dlist = [-1] * n
dlist[0] = 0

q = deque()
q.append(0)

while len(q)>0:
    node = q.popleft()
    for i, j in alist[node]:
        if dlist[i]<0:
            q.append(i)
            dlist[i] = (dlist[node] + j)%2
        else:
            continue

'''
def dfs(node, par, dist):
    dlist[node] = dist%2
    for i, j in alist[node]:
        if i==par:
            continue
        else:
            dfs(i, node, dist+j)
dfs(0,0,0)
'''

for i in range(n):
    print(dlist[i])    


Measured memory_bytes: 35988
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  vector<ll> v(3); rep(i, 3) cin >> v[i];
  sort(v);
  if (v[0] % 2 == 0 || v[1] % 2 == 0 || v[2] % 2 == 0) outl(0);
  else outl(v[0] * v[1]);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)



//// D
int main(){
    int n, m; cin >> n >> m;
    priority_queue<int> q;
    rep(i,n){
        int a;
        cin >> a;
        q.push(a);
    }
    rep(i, m){
        int a = q.top(); q.pop();
        q.push(a/2);
    }
    long long ans = 0;
    rep(i, n){
        ans += q.top(); q.pop();
    }
    cout << ans << endl;

}

Measured memory_bytes: 892
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	m := map[string]int{}
	for i := 0; i < n; i++ {
		s := stringLineScan()
		m[s] += 1
	}
	x := 0
	for _, v := range m {
		if v > x {
			x = v
		}
	}
	ans := make([]string, 0)
	for k, v := range m {
		if v == x {
			ans = append(ans, k)
		}
	}
	sort.Strings(ans)
	for _, k := range ans {
		fmt.Println(k)
	}
}


Measured memory_bytes: 30720
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))
import copy
N, M = mi()
D = dp2(float('inf'), N, N)
memo = []
cnt = 0

for i in range(M):
    s, t = mi()
    s, t = s-1, t-1
    memo.append((s, t))
    D[s][t] = D[t][s] = 1

for x in range(M):
    d = copy.deepcopy(D)
    s, t = memo[x][0], memo[x][1]
    d[s][t] = d[t][s] = float('inf')
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

    for i in range(N):
        for j in range(i+1, N):
            if d[i][j] == float('inf'):
                cnt += 1
                break
        else:
            continue
        break

print(cnt)

Measured memory_bytes: 58332
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
    int A,B,sum=0;
    cin >> A >> B;
    for(int i=A;i<=B;i++){
        if(i%10==i/10000 && (i/10)%10==(i/1000)%10)sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
from collections import Counter, defaultdict
import sys

sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque



def main():
    list_num, max_num, num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]

    kari_list = [i + 1 for i in range(max_num)]

    ans = 0
    for key_list in itertools.combinations_with_replacement(kari_list, list_num):
        now_list = sorted(key_list)
        now_cost = 0
        for i in range(num):
            if now_list[data[i][1] - 1] - now_list[data[i][0] - 1] == data[i][2]:
                now_cost += data[i][3]

        ans = max(ans, now_cost)

    print(ans)






if __name__ == '__main__':
    main()


Measured memory_bytes: 76012
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[200001];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        a[i] -= i;
    }
    sort(a + 1, a + n + 1);
    int b = a[1 + n / 2];
    ll sol = 0;
    for (int i = 1; i <= n; ++i)
        sol += abs(a[i] - b);
    cout << sol;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
c = [0] * (n + 1)
for i in a:
  if i <= n:
    c[i] += 1
s = 0
for i in range(1, n + 1):
  if c[i] >= i:
    s += i
print(n - s)


Measured memory_bytes: 14244
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N + 1), y(M + 1);
    for (int i = 0; i < N; i++) cin >> x[i];
    x[N] = X;
    for (int i = 0; i < M; i++) cin >> y[i];
    y[M] = Y;

    sort(x.begin(), x.end(), greater<int>());
    sort(y.begin(), y.end());

    if (x[0] < y[0])
        cout << "No War" << endl;
    else
        cout << "War" << endl;

    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LS(): return input().split()
def I(): return int(input())
def F(): return float(input())
def S(): return input()


def main():
    a = I()
    b = I()
    if a > b:
        a,b = b,a
    if b-a > a+360-b:
        a += 360
    return (a+b) / 2.0 % 360


print(main())

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int main(){
   int r; cin>>r;
   cout<<(double)2*r*M_PI<<endl;
}

Measured memory_bytes: 3756
N = int(input())

st = set()
for d in range(1, int(pow(N, 0.5)) + 1):
    if N % d == 0:
        st.add(d)
        st.add(N // d)

# 約数集合
# k(m+1)を満たすmなので、
# Nの約数から1引いた数のうち、
# 実際にNを割って余りがkになるもの
# m正よりm>0
# Nを割り切るmや
# m<=kとなるmは不適

ans = 0
for dd in st:
    dd -= 1
    if dd == 0: continue
    q, r = divmod(N, dd)
    if q == r:
        ans += dd
print(ans)


Measured memory_bytes: 3828
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    p = list(map(int, input().split()))

    c = 0
    for i in range(n):
        if (i + 1) != p[i]:
            c += 1
    if c <= 2:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        long long int n,w;cin>>n>>w;
        long long int wt[n],vl[n];
        for(int i=0;i<n;i++){
            cin>>wt[i]>>vl[i];
        }
        long long ans[w+1]={0};
        for(long long int i=0;i<n;i++){
            for(long long int j=w;j>=wt[i];j--){
                ans[j]=max(ans[j],vl[i]+ans[j-wt[i]]);
            }
        }
        cout<<ans[w];
        return 0;
    }

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);


int main()
{
	int n,i;
	sc(n);
	int t,x,y;
	int px=0,py=0,pt=0;
	bool check=true;
	rep(i,n)
	{
		sc(t);sc(x);sc(y);
		int d=abs(px-x)+abs(py-y);
		int dt=t-pt;
		px=x;py=y;pt=t;
		//cout << d  << " " << dt << endl;
		if(d<=dt && d%2==dt%2)
		{
			continue;
		}
		else
		{
			//cout << "s " << endl;
			check=false;
		}
	}
	if(check)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    string s;
    cin>>s;
    if(s=="AKIHABARA" || s=="AKIHBARA" || s=="AKIHABRA" || s== "AKIHABAR" || s== "KIHABARA" 
    || s=="KIHBARA" || s=="AKIHBRA" || s=="AKIHABR" || s== "KIHABAR" || s== "KIHABRA" || s=="AKIHBAR" 
    || s=="KIHABR" || s=="AKIHBR" || s=="KIHBRA" || s== "KIHBAR" || s=="KIHBR") cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


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

import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		System.out.println(Math.min(a, b) + Math.min(c, d));
		
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 23252
using System;
using System.Linq;

namespace ABC124B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var line = Console.ReadLine().Split(' ').ToArray();

            int[] H = new int[N];

            for(var i = 0; i < N; i++)
            {
                H[i] = int.Parse(line[i]);
            }

            int max = 0;
            int count = 0;

            for(var i = 0; i < N; i++)
            {
                if(max <= H[i])
                {
                    max = H[i];
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>

#define lli long long int

int main(void)
{
	int n;
	scanf("%d",&n);
	char *s;
	s = (char *)calloc(n+5,sizeof(char));
	int i = 0;
	int j = 0;

	scanf("%s",s);
	s[n] = '\0';
	i = 1;
	j = 1;
	while (i < n)
	{
		if(s[i-1] != s[i])
			j++;
		i++;
	}
	printf("%d\n",j);
	return (0);
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] p = new int[n];
            for (int i = 0; i < n; i++) {
                p[i] = in.nextInt();
            }

            int count = 0;
            for (int i = 1; i < n - 1; i++) {
                int[] ps = new int[]{p[i - 1], p[i], p[i + 1]};
                Arrays.sort(ps);
                if (ps[1] == p[i]) {
                    count++;
                }
            }
            out.println(count);
        }

    }
}



Measured memory_bytes: 21844