akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/code-festival-2017-quala/tasks/code_festival_2017_quala_c
//C - Palindromic Matrix
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
#if LOCAL&0
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll H,W; cin>>H>>W;
    vector<string> ahw(H);
    for(auto&& ah:ahw){
        cin>>ah;
    }
    unordered_map<char,ll> ch_cnt;
    REP(y,H){
        REP(x,W){
            auto c=ahw.at(y).at(x);
            ch_cnt[c]++;
        }
    }
    unordered_map<int,ll> needs;
    ll tw=W,th=H;
    if(tw%2==1 && th%2==1){
        needs[2]+=tw/2;
        needs[2]+=th/2;
        needs[1]+=1;
        --tw;
        --th;
    }else if(tw%2==1){
        needs[2]+=th/2;
        //needs[1]=1;
        --tw;
    }else if(th%2==1){
        needs[2]+=tw/2;
        dump(tw/2);
        //needs[1]=1;
        --th;
    }
    needs[4]+=(th/2)*(tw/2);

    bool ans=true;

    auto count_check = [&](ll type){
        FOR(i,0,needs[type]){
            bool found=false;
            for(auto& cnt:ch_cnt){
                if(type==1){
                    if(cnt.second!=0&&cnt.second%2==1){
                        cnt.second -= type;
                        found=true;
                        break;
                    }
                }else if(type==4){
                    if(cnt.second!=0&&cnt.second>=4){
                        cnt.second -= type;
                        found=true;
                        break;
                    }                    
                }else if(cnt.second!=0&&cnt.second%type==0){
                    cnt.second -= type;
                    found=true;
                    break;
                }
            }
            if(not found) ans=false;
        }
    };

    count_check(1);
    count_check(4);
    count_check(2);

    cout<<(ans?"Yes":"No")<<endl;

    return 0;
}

Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#include<algorithm>
int main()
{
    int n,a=0;
    cin>>n;
    vector<int>d(n);
    for(int i=0;i<n;i++)cin>>d.at(i);
    
    sort(d.begin(),d.end());
    
    for(int i=0;i<n;i++){
        if(d[i]==d[i+1]){
            a++;
        }
    }
    std::cout << n-a << std::endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int N=200050;
const int inf=1e9+7;
set<int> has[N];
int main()
{
	int n,m,k,i,j;
	scanf("%i %i %i",&n,&m,&k);
	while(k--) scanf("%i %i",&i,&j),has[j].insert(i);
	for(i=1;i<=m;i++) has[i].insert(n+1);
	int x=1,y=1,ans=inf,p=0;
	bool l=1;
	while(1)
	{
		int nxt=*has[y].lower_bound(x);
		if(nxt==x+1 && l) ans=min(ans,p+1);
		else ans=min(ans,p+nxt-x);
		if(nxt==x+1) break;
		p++;
		x++;
		l=0;
		if(y<m && !has[y+1].count(x)) y++,l=1;
	}
	printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 28416
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;
int main(){
	int n,ans=0;
	cin >> n;
	vector<int> b(n);
	for (int i = 0; i < n - 1; i++)cin >> b.at(i);
	ans = b.at(0);
	for (int i = 1; i < n; i++) {
		ans += min(b.at(i), b.at(i - 1));
	}
	cout << ans+b.at(n-2) << endl;
	return 0;
}

Measured memory_bytes: 3592
def main():
	n,x = map(int, input().split())
	a = list(map(int, input().split()))

	a.sort()
	for i in range(len(a)):
		x -= a[i]
		if x < 0:
			print(i)
			return
		elif x == 0:
			print(i+1)
			return
	print(len(a)-1)
	return

if __name__ == '__main__':
	main()

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    int field[1001][101];
    while (true) {
        int n, m, a;
        cin >> n >> m >> a;
        if (n==0 && m==0 && a==0) {
            break;
        }
        memset(field,0,sizeof(field));
        int st=0;
        for (int i=0; i<m; i++) {
            int h, p, q;
            cin >> h >> p >> q;
            field[h][p]=q;
            field[h][q]=p;
            st=max(st,h);
        }
        for (int i=st; i>0; i--) {
            if (field[i][a]!=0) {
                a=field[i][a];
            }
        }
        printf("%d\n",a);
    }
    return 0;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)
namespace{struct _{_(){
    cin.tie(0);
    ios::sync_with_stdio(false);
}}a;}

signed main() {
    int H, W;
    cin >> H >> W;
    vector<string> S;
    S.push_back(string(W+2, '.'));
    REP(i, H) {
        string s;
        cin >> s;
        S.push_back("." + s + ".");
    }
    S.push_back(string(W+2, '.'));

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

    FOR(i, 1, H) {
        FOR(j, 1, W) {
            if (S[i][j] == '#') {
                bool can = false;
                REP(k, 4) {
                    if (S[i+dy[k]][j+dx[k]] == '#') {
                        can = true;
                        break;
                    }
                }
                if (!can) {
                    cout << "No\n";
                    return 0;
                };
            }
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
if ARGV[0]=="LOCAL_DEV"
  define_method("debug") do |var|
    p var
  end
else
  define_method("debug") do |var|
  end
end

N, Z, W = STDIN.gets.strip.split.map(&:to_i)
a = STDIN.gets.strip.split.map(&:to_i)

debug a
puts [(W-a[N-1]).abs , (a[N-2]-a[N-1]).abs].max


Measured memory_bytes: 1916
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A+B>=24){
		System.out.println(A+B-24);
		}else{
			System.out.println(A+B);

		}
	}
}

Measured memory_bytes: 23124
dreamer = "dreamer"
eraser = "eraser"
dream = "dream"
erase = "erase"


def main():
    S = input()

    while len(S):
        lens = len(S)
        if S[lens - len(dreamer):] == dreamer:
            S = S[: lens - len(dreamer)]
        elif S[lens - len(eraser):] == eraser:
            S = S[:lens - len(eraser)]
        elif S[lens - len(dream):] == dream:
            S = S[:lens - len(dream)]
        elif S[lens - len(erase):] == erase:
            S = S[:lens - len(erase)]
        if lens == len(S):
            print("NO")
            return
    print("YES")
    return


main()


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A = N/4 +1, B = N / 7 +1;
  bool able = false;
  for(int a = 0; a < A; a++ ){
    for(int b = 0; b < B; b++){
      int sum = 4*a + 7 * b;
      if(sum == N) able = true;
    }
  }
  if(able) cout << "Yes" << endl;
  else cout << "No" << endl;
} 


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

#define TRUE 1
#define FALSE 0

int bubble_sort(int *A, int N) {
	int itmp, change_number = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - i - 1; j++) {
			if (A[j] > A[j + 1]) {
				itmp = A[j];
				A[j] = A[j + 1];
				A[j + 1] = itmp;
				change_number++;
			}
		}
	}
	return change_number;
}

int main(void) {
	int N, answer;
	int *Array;
	scanf("%d", &N);
	Array = (int *)malloc(sizeof(int) * N);
	for (int i = 0; i < N; i++) {
		scanf("%d", Array + i);
	}
	answer = bubble_sort(Array, N);
	for (int i = 0; i < N-1; i++) {
		printf("%d ", Array[i]);
	}
	printf("%d\n%d\n", Array[N - 1], answer);
	return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = 0;
  if (k % 2 == 0) ans = a - b;
  else ans = b - a;
  if (abs(ans) > 1000000000000000000) {
    cout << "Unfair" << endl;
  } else {
    cout << ans << endl;
  }
}

int main() {
  solve();
  return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;

signed main() {
	int z;
	while (cin >> z, z) {
		int z3 = z*z*z;
		int x(1), y(1);
		int ans(INF);
		for (x = 1; z3 - x*x*x >= 0; x++) {
			int x3 = x*x*x;
			for (y = 1; z3 - x3 - y*y*y >= 0; y++) {
				int y3 = y*y*y;
				ans = min(ans, z3 - x3 - y3);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#include<iostream>
    using namespace std;
     
    int main()
    {
      long N;
      cin >> N;
      int count0=0,count1=0,count2=0;
      for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(a%4==0) count2++;
        else if(a%2==0) count1++;
        else count0++;
      }
      
      if(count0 <= count2) cout << "Yes" << endl ;
      else if((count0 == 1+count2) && count1 == 0) cout << "Yes" << endl ;
      else cout << "No" << endl ;
      
      return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include <iomanip>
//https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
 
using namespace std;
typedef long long ll;

bool cmp(pair<ll, ll> &a, pair<ll, ll> &b)
{
    return a.second < b.second;
}

int main()
{
    ll N, M;
    cin >> N >> M;
    // ll* P = new ll[M];
    // ll* Y = new ll[M];
    std::unordered_map<ll, std::vector<pair<ll, ll> > > resultMap;
    for(ll i = 0; i < M; i ++){
        ll P, Y;
        cin >> P >> Y;
        pair<ll,ll> newPair = make_pair(i, Y);
        resultMap[P].push_back(newPair);
    }
    pair<ll, ll>* resultString = new pair<ll, ll>[M];
    for(auto itr = resultMap.begin(); itr != resultMap.end(); ++itr) {
        sort(itr->second.begin(), itr->second.end(), cmp);
        for(ll i = 0; i < itr->second.size(); i ++){
            resultString[itr->second[i].first] = make_pair(itr->first, i + 1);
        }
    }

    for(ll i = 0; i < M; i ++){
        cout << setfill('0') << setw(6) << resultString[i].first;
        cout << setfill('0') << setw(6) << resultString[i].second << endl;
    }
    
    return 0;
}

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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;

ll gcd(ll a, ll b) {
    if (a < b) {
        swap(a, b);
    }

    /* ユークリッドの互除法 */
    ll r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

constexpr int64_t __pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int64_t t = __pow_mod(n, p / 2, mod);
        return (t * t) % mod;
    }
    return (n * (__pow_mod(n, p - 1, mod) % mod)) % mod;
}

constexpr int64_t pow_mod(int64_t n, int64_t p, int64_t mod) noexcept {
    int64_t res = __pow_mod(n, p, mod);
    if (res == 0) {
        res = mod;
    }
    return res;
}

constexpr int64_t nCr_mod(int64_t n, int64_t r, int64_t mod) noexcept {
    int64_t count = 1;
    auto a = r;
    for (auto i = n; i > n - r; i--) {
        count *= i;
        if (count % mod != 0) {
            count %= mod;
        }
        int64_t inv = pow_mod(a, mod - 2, mod);
        count *= inv;
        if (count % mod != 0) {
            count %= mod;
        }
        a--;
    }
    return count;
}

string bfs(ll n) {
    queue<string> q;
    for (int i = 1; i <= 9; i++) {
        q.push(to_string(i));
    }

    for (int i = 1; i <= n; i++) {
        string top = q.front();
        q.pop();
        // cout << top << ' ';
        if (i == n) {
            return top;
        }

        ll prev = top[top.length() - 1] - '0';
        for (int j = -1; j <= 1; j++) {
            if (prev + j >= 0 && prev + j <= 9) {
                string ns = top + to_string(prev + j);
                q.push(ns);
            }
        }
    }
    return "error";
}

void solve(long long K) {
    if (K < 10) {
        cout << K << endl;
    } else {
        cout << bfs(K) << endl;
    }
}

int main() {
    long long K;
    std::cin >> K;
    solve(K);
    return 0;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long int 
#define pb  push_back
#define mp  make_pair
#define pii pair<int, int>
using namespace std;

const ll mod = 1e9+7;
const ll infi = 2e18;
const int N = 4e2;

ll arr[N+1] = {0};
ll dp[N+1][N+1] = {0};
ll pre_sum[N+1] = {0};

void initialise(){
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			dp[i][j] = infi;
		}
	}
}

ll dp_recurse(ll l, ll r){
	if(l==r){
		return 0;
	}

	if(dp[l][r] != infi){
		return dp[l][r];
	}

	for(ll i=0;i<(r-l);i++){
		dp[l][r] = min(dp[l][r], dp_recurse(l, l+i) + dp_recurse(l+i+1, r) + pre_sum[r] - pre_sum[l-1]);
	}

	return dp[l][r];
}


void solve(){
    //solve here//
	ll n;
	cin >> n;

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

	pre_sum[0] = 0;
	for(int i=1;i<=n;i++){
		pre_sum[i] = pre_sum[i-1] + arr[i];
	}

	initialise();
	cout << dp_recurse(1, n) << endl;
}


int main(){
    ll t=1;
    //cin >> t;
    while(t--){
        solve();
    }
}



Measured memory_bytes: 1536
MOD = 10**9 + 7


def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from itertools import accumulate
    S = list(accumulate([0] + A))
    ans = 0
    for i in range(N-1):
        ans += A[i] * (S[N] - S[i+1])
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 103700
fun main() {
    val (n, m) = next2Int()
    val michi = Array(n + 1) { arrayListOf<Int>() }
    repeat(m) {
        val (a, b) = next2Int()
        michi[a].add(b)
        michi[b].add(a)
    }
    val signs = IntArray(n + 1)
    signs[0] = 1
    signs[1] = 1
    var nextList = arrayListOf<Pair<Int, Int>>()
    for (next in michi[1]) {
        nextList.add(1 to next)
    }
    while (nextList.isNotEmpty()) {
        val tmpList = arrayListOf<Pair<Int, Int>>()
        for ((current, next) in nextList) {
            if (signs[next] == 0) {
                signs[next] = current
                for (tmp in michi[next]) {
                    tmpList.add(next to tmp)
                }
            }
        }
        nextList = tmpList
    }
    if (signs.all { it > 0 }) {
        printString {
            appendln("Yes")
            for (i in 2..n) {
                appendln(signs[i])
            }

        }
    } else {
        println("No")
    }
}

val sc = java.util.Scanner(System.`in`)
fun next(): String = sc.next()
fun nextInt() = sc.nextInt()
fun next2Int() = Pair(nextInt(), nextInt())
fun next3Int() = Triple(nextInt(), nextInt(), nextInt())
fun nextIntArray(size: Int) = IntArray(size) { nextInt() }
fun nextLong() = sc.nextLong()
fun nextLine(): String = sc.nextLine()
fun nextList() = nextLine().split(" ")
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")
fun printString(action: StringBuilder.() -> Unit) = println(buildString(action))

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

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()
{
    int N;
    cin >> N;

    long long a[N];
    long long ans = 0LL;
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
        map<long long, int> m;
        m = prime_factor(a[i]);
        ans += m[2];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include<algorithm>//sort(all(変数),greater<型名>())で降順に、*max_element(all(変数))で最大値を獲得
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric>
// xとyのgcdは__gcd(x,y),xとyのlcmは(x*y)/__gcd、accumulate(all(変数),0)で要素の全加算
#include<queue>//priority_queue<型名> 変数
#include<set>
#include<stack>
#include<string>//変数.substr(どこから,いくつ)
#include<vector>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
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; }

int main(){
  int a,b; cin >> a >> b;
  cout << a*b;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};

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

	for(;;)
	{
		int k;
		cin >> k;
		if(cin.fail()) break;

		int ans=-1;
		int x=0, u=7;
		for(int i=1;i<=k;i++)
		{
			x=(x+u)%k;
			if(x==0)
			{
				ans=i;
				break;
			}
			u=(u*10)%k;
		}
		cout << ans << "\n";
	}
	return 0;
}


Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
	//file();
	fast();
	int x, y; cin >> x >> y;
	for (int i = 0; i <= x; i++) {
		if (i * 2 + (x - i) * 4 == y)
			RT("Yes\n");
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
vector <int> edges[100000];
long long H[100000];
int main(){
  int N;
  int M;
  cin >> N >> M;

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

  for(int i = 0; i < M; i++){
    int a;
    int b;
    cin >> a >> b;
    edges[a - 1].push_back(b - 1);
    edges[b - 1].push_back(a - 1);
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    bool valid = true;
    for(int j = 0; j < edges[i].size(); j++){
      if(H[edges[i][j]] >= H[i]){
        valid = false;
        break;
      }
    }
    if(valid){
      ans ++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9468
// RAM RAM
    #include <bits/stdc++.h>
    #define int long long
    #define pb push_back
    #define ppb pop_back
    #define vi vector<int>
    #define mp make_pair
    #define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
    #define N 55
    const int MOD=1000000007;
    using namespace std;
     
    int32_t main()
    {
    	ios_base::sync_with_stdio(false);cin.tie(0);
    	
     

     
        int n,m;cin>>n>>m;

        char grid1[n][n],grid2[m][m];

        for(int i=0;i<n;i++){
        	for(int j=0;j<n;j++){
        		cin>>grid1[i][j];
        	}
        }
     
     	for(int i=0;i<m;i++){
        	for(int j=0;j<m;j++){
        		cin>>grid2[i][j];
        	}
        }

       
        bool  mila=false;
        for(int i=0;i<n-m+1;i++){
        	for(int j=0;j<n-m+1;j++){
        		bool hoga=true;
        		//cout<<i<<" "<<j<<endl;

        		for(int k=i;k<m+i && hoga;k++){
        			for(int l=j;l<m+j && hoga;l++){
        				if(grid1[k][l]!=grid2[k-i][l-j]){
        					hoga=false;
        				}
        			}
        		}


        		if(hoga)
        			mila=true;
        	}
        }

        if(mila)
        	cout<<"Yes"<<endl;
        else
        	cout<<"No"<<endl;
    	return 0;
    }

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	int n,row_min;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		int table[n][n],min_of_row[n],max_of_col[n];

		for(int i = 0; i < n; i++){
			max_of_col[i] = -1;
		}

		for(int i = 0; i < n; i++){
			row_min = 2147483647;
			for(int k=0; k < n; k++){
				scanf("%d",&table[i][k]);
				if(row_min > table[i][k]){
					row_min = table[i][k];
					min_of_row[i] = row_min;
				}
				max_of_col[k] = (max_of_col[k] >= table[i][k])?max_of_col[k]:table[i][k];
			}
		}

		int ans = 0;
		for(int i=0; i < n; i++){
			for(int k=0; k < n; k++){
				if(table[i][k] == min_of_row[i] && table[i][k] == max_of_col[k]){
					ans = table[i][k];
				}
			}
		}
		printf("%d\n",ans);

	}
    return 0;
}

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

using namespace std;
using ll = long long;

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

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

    string s; cin >> s;
    int length = s.size() - 1;

    ll total = 0;

    for (int i = 0; i < 1 << length; i++) {
        bitset<10> b(i);

        ll ans = 0;
        string term = s.substr(0, 1);

        for (int i = 0; i < length; i++) {
            if (b.test(i)) {
                ll iterm = stoll(term);
                ans += iterm;
                term = "";
            } 
            term += s.substr(i + 1, 1);
        }
        ll iterm = stoll(term);
        ans += iterm;

        total += ans;

    }

    cout << total << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

char abc[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

int main() {
    char a;
    cin >> a;
    rep(i, 26){
        if(a == abc[i]){
            cout << "a" << endl;
            return 0;
        }
    }
    cout << "A" << endl;
}

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

int main()
{
	int n,t,count=0;
	vector<int> x;
	cin >> n >> t;
	int ct[n][2];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			cin >> ct[i][j];
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (ct[i][1] <= t)
		{
			x.push_back(ct[i][0]);
			count++;
		}
	}
	sort(x.begin(), x.end());
	if (count == 0)
	{
		cout << "TLE";
	}
	else
	{
		cout << x[0];
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>

using namespace std;

class ele
{
public:
	ele();
	int key;
	ele *prev, *next;
};

ele::ele(){}

ele *null = new ele();

void insert(int n)
{
	ele *node = new ele();
	node->key = n;
	node->prev = null;
	node->next = null->next;
	null->next->prev = node;
	null->next = node;
}

ele* search(int n)
{
	ele *ser = new ele();
	ser = null->next;
	while (ser != null&&ser->key != n)
	{
		ser = ser->next;
	}
	return ser;
}

void adelete(ele* a)
{
	if (a == null)return;
	a->prev->next = a->next;
	a->next->prev = a->prev;
	delete a;
}

void searchdelete(int n)
{
	adelete(search(n));
}

void deletefirst()
{
	adelete(null->next);
}

void deletelast()
{
	adelete(null->prev);
}
	
int main()
{
	null->prev = null->next = null;
	int n, i, a;
	char c[11];
	string str;
	ele *e = new ele();
	e = null;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%s",c);
		str=c;
		if (str == "deleteLast")deletelast();
		else if (str == "deleteFirst")deletefirst();
		else if (str == "insert") { scanf("%d", &a); insert(a); }
		else { scanf("%d", &a); searchdelete(a); }
	}
	e = e->next;
	while (e != null->prev)
	{
		printf("%d ", e->key);
		e = e->next;
	}
	printf("%d\n", e->key);
    return 0;
}

Measured memory_bytes: 32480
#include <bits/stdc++.h>
using namespace std;
int main() {
    int K; cin>>K;
    if(K%2!=0){
        int tmp=K/2;
        int ans=tmp*(tmp+1);
        cout<<ans;
    }
    else{
        int tmp=K/2;
        int ans=tmp*tmp;
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 256
(defun on-p (switches status p)
  (let ((switch-count
          (count-if-not #'zerop
                        (mapcar (lambda (switch)
                                  (digit-char-p
                                   (aref status (1- switch))))
                              switches))))
    (if (zerop p) (evenp switch-count) (oddp switch-count))))

(defun all-on-p (switches ps status)
  (zerop
   (loop :for i :from 0 :to (1- (length switches))
         :count (not (on-p (elt switches i) status (elt ps i))))))

(defun main ()
  (let* ((n (read))
        (m (read))
        (switches (loop :repeat m
                        :collect (loop :repeat (read)
                                       :collect (read))))
        (p (loop :repeat m
                 :collect (read))))
    (format t "~A~%"
            (loop :for i :from 0 :to (1- (expt 2 n))
                  :count
                  (let ((status (format nil (concatenate 'string "~" (write-to-string n) ",'0b") i)))
                    (all-on-p switches p status))))))

(main)


Measured memory_bytes: 20712
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const ll inf = 99900100100;
const int MOD = 998244353;
const double EPS = 1e-9;

vector<vector<pair<int,int> > > G(1100);

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n){
      int u,k;
      cin >> u >> k;
      rep(j,k){
        int v,c;
        cin >> v >> c;
        G[u].push_back(mp(v,c));
      }
    }
    ll d[1100] = {};
    rep(i,1100) d[i] = inf;
    d[0] = 0LL;
    while(true){
        bool update = false;
        rep(i,n){
          for(auto o : G[i]){
            if(d[o.fi] > d[i]+o.se){
                d[o.fi] = d[i]+o.se;
                update = true;
            }
          }
        }
        if(!update) break;
    }
    rep(i,n) cout << i << " " << d[i] << endl;
    return 0;
}



Measured memory_bytes: 3196
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	int N;
	cin >> N;
	vvi v{
		{2, 4, 5, 7, 9},
		{0, 1, 6, 8},
		{3}
	};
	vector<string> a{"hon", "pon", "bon"};
	rep(i,0,3)
	if(count(all(v[i]), N%10))
		cout << a[i];
}


Measured memory_bytes: 3660
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> f(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());
    ll l = -1, r = 1e18;
    while(r-l>1) {
        ll m = (r+l)/2LL;
        ll cnt = 0;
        rep(i, n) {
            if (a[i] * f[i] > m) {
                cnt += (a[i] * f[i] - m) / f[i];
                if ((a[i] * f[i] - m) % f[i]) ++cnt;
            }
        }
        if (cnt > k) l = m;
        else r = m;
    }
    cout << r << endl;
    return 0;
}


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

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

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

	int m = 0;
	for(int i=0;i<n;i++){
		if(a[i]==m+1){
			m++;
		}
	}
	if(m==0){
		cout << "-1" << endl;
	}else{
		cout << n-m << endl;
	}

	

	return 0;
}


Measured memory_bytes: 4424
from collections import defaultdict
from bisect import bisect_right

def main():
    S = input()
    T = input()
    Ls = len(S)
    Lt = len(T)
    d = defaultdict(list)
    for i in range(Ls):
        d[S[i]].append(i+1)

    now = 0
    ans = 0
    for i in range(Lt):
        if not d[T[i]]:
            print(-1)
            exit()
        ni = bisect_right(d[T[i]], now)
        if ni >= len(d[T[i]]):
            now = 0
            ans += Ls
            ni = bisect_right(d[T[i]], now)
            now = d[T[i]][ni]
        else:
            now = d[T[i]][ni]

    ans += now
    print(ans)


if __name__ == "__main__":
    main()

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

N = N % 10

if N == 2 or N == 4 or N == 5 or N == 7 or N == 9:
    print('hon')
elif N == 0 or N == 1 or N == 6 or N == 8:
    print('pon')
else:
    print('bon')

Measured memory_bytes: 9120
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
using namespace std;

int gcd(int x, int y)
{
	return y == 0 ? x : gcd(y, x % y);
}

int main() {
	int n, x;
	int temp;
	int gcm = 0;

	cin >> n;
	cin >> x;
	cin >> temp;

	gcm = abs(temp - x);
	
	for (int i = 0; i < n - 1; i++) {
		cin >> temp;
		gcm = gcd(gcm, abs(temp - x));
	}

	cout << gcm << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
main()
{
    int a[3];
    int i,j,k,max;
    for(i=0;i<3;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0; i<3; i++)
    {
        for(j=i+1; j<3; j++)
        {
            if(a[i]<a[j])
            {
                k=a[i];
                a[i]=a[j];
                a[j]=k;
            }
        }
    }
    max=(a[0]*10)+a[1]+a[2];
    printf("%d",max);
    return 0;
}


Measured memory_bytes: 128
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

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

   if(N==1||N==2||N==3||N==5||N==6||N==9||N==10||N==13||N==17){
       cout<<"No"<<endl;
   }
   else{
       cout<<"Yes"<<endl;
   }
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    ll H, W, d;
    cin >> H >> W >> d;
    string color[] = {"R", "Y", "G", "B"};
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ll x = i + j;
            ll y = i - j;
            ll cl = (((x + 10000000000LL * d) / d % 2) << 1) | ((y + 10000000000LL * d) / d % 2);
            cout << color[cl];
        }
        cout << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
typedef long long i64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5;
int n, a[N]; i64 ans;
int main()
{
    n = read(); for(int i = 1; i <= n; ++i) a[i] = read();
    for(int i = 1; i <= n; ++i)
    {
        if(a[i] >= i||a[i+1]-a[i]>1) return puts("-1"), 0;
        if(i < n&&a[i]+1 == a[i+1]) continue; ans += a[i];
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<string>
#include<utility>
#include<algorithm>
using namespace std;

int main()
{
		double a;
		int n;
		double sum = 0;
		double result = 0;

		cin >> n;
		for (int i = 0; i < n; i++)
		{
			cin >> a;
			
			sum = 1 / a + sum;
		}

		result = 1 / sum;

		cout << result << endl;

	return 0;
}

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

int main()
{
    string s;
    cin >> s;

    string ans;
    if (s == "Sunny")
        ans = "Cloudy";
    else if (s == "Cloudy")
        ans = "Rainy";
    else
        ans = "Sunny";
    cout << ans << endl;

    return 0;
}

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

bool pairCompare(const pair<string, int> &firstPair, const pair<string, int> &secondPair)
{
  if (firstPair.first == secondPair.first)
  {
    return firstPair.second > secondPair.second;
  }
  return firstPair.first < secondPair.first;
}

int main()
{
  vector<pair<string, int>> scores;
  int N;
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    string country;
    int score;
    cin >> country >> score;
    scores.push_back(make_pair(country, score));
  }

  vector<int> indices(scores.size());
  iota(indices.begin(), indices.end(), 1);

  sort(indices.begin(), indices.end(), [&scores](int i1, int i2) {
    if (scores[i1-1].first == scores[i2-1].first)
    {
      return scores[i1-1].second > scores[i2-1].second;
    }
    return scores[i1-1].first < scores[i2-1].first;
  });

  for (auto v : indices)
  {
    cout << v << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
 
using namespace std;
const int maxn=300010;
int ans=0,tot=0,sum[maxn],a[maxn],f[maxn],g[1<<26],n,l,r;
char s[maxn];
void read(int &k){
    k=0; int f=1; char c=getchar();
    while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    while ('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
    k*=f;
}
int main(){
    scanf("%s",s+1);
    int n=strlen(s+1);
    for (int i=1;i<=n;i++) sum[i]=sum[i-1]^(1<<(s[i]-'a'));
    memset(f,32,sizeof(f)); memset(g,32,sizeof(g));
    g[0]=0;
    for (int i=1;i<=n;i++){
        f[i]=min(f[i],g[sum[i]]+1);
        for (int j=0;j<26;j++) f[i]=min(f[i],g[sum[i]^(1<<j)]+1);
        g[sum[i]]=min(g[sum[i]],f[i]);
    }
    printf("%d\n",f[n]);
    return 0;
}

Measured memory_bytes: 265216
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1<<29)
#define LINF (1LL<<60)
using namespace std;
using INT = long long;
using P = pair<int,int> ;

int main(){
    INT x,a=100;
    INT i=0;
    cin >> x;
    while(x>a){
        a *= 1.01;
        i++;
    }
    cout << i << endl;
	return 0;
}



Measured memory_bytes: 3636
from heapq import heappush,heappop,heapify

def f(p):
  res = 0
  s = len(p)
  for i in range(s):
    if p[i][0] > s:
      p[i][0] = s
  p.sort(reverse = True)
  hq = []
  idx = 0
  for i in range(s,0,-1):
    #print('p:',p,'i:',i)
    while(idx < s and p[idx][0] == i):
      heappush(hq,-p[idx][1])
      idx += 1
    #print('hq:',hq)
    if len(hq) > 0:
      res -= heappop(hq)
      #print('res:',res)
  return res

def solve():
  n = int(input())
  pl = []
  pr = []
  ans = 0
  for i in range(n):
    k,l,r = map(int,input().split())
    m = min(l,r)
    l -= m
    r -= m
    ans += m
    if l > 0:
      pl.append([k,l])
    else:
      pr.append([n-k,r])
  #print('pl:',pl,'pr:',pr,'ans:',ans)
  ans += f(pl)
  ans += f(pr)
  print(ans)

t = int(input())
for i in range(t):
  solve()

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

int main(){
  string str;
  int cnt = 0;
  cin >> str;
  if(str[str.size()-1] == 'A') {++cnt;}
  for(int i=0; i<str.size()-1; ++i){
    if(str[i] == 'A'){
      ++cnt;
    }else if(str[i] >= str[i+1] && str[i+1] != 'A'){
      ++cnt;
    }
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3224
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <complex>
#include <bitset>
 
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef double ld;

int main() {
    //ifstream cin("input.txt");
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;
    vector<int> cnt(26);
    vector<int> r(4);

    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < m; ++j)
            ++cnt[s[j] - 'a'];
    }

    for (int i = 0; i < 26; ++i) {
        ++r[cnt[i] % 4];
    }

    if (((n * m) & 1) < r[1] + r[3]) {
        cout << "No\n";
        return 0;
    }

    if (r[1] == 1) {
        r[1] = 0;
        ++r[0];
    }

    if (r[3] == 1) {
        r[3] = 0;
        ++r[2];
    }

    int x = 0;
    if (n & 1)
        x += m / 2;
    if (m & 1)
        x += n / 2;
    if (r[2] > x) {
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>

using namespace std;

#define ALL(a) (a).begin(),(a).end()
#define REP(index, begin, end) for (int (index) = (begin); (index) < (end); (index)++)
#define RE(index, end) REP(index, 0, end)
#define INF INT_MAX / 3
#define LLINF LLONG_MAX / 3
#define DINT(x) printf(#x " = %d\n", x);
#define GETINT(x) scanf("%d", &x)
#define GETLL(x) scanf("%lld", &x)
#define GETSTR(x) scanf("%s", x)

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int main()
{
	int x_litter, y_kihon, y_lit_max, y_litter, usage;
	GETINT(x_litter);
	GETINT(y_kihon);
	GETINT(y_lit_max);
	GETINT(y_litter);
	GETINT(usage);
	int x_cost = x_litter * usage,
		lit = usage - y_lit_max,
		y_cost = y_kihon;
	if (lit > 0)
	{
		y_cost += lit * y_litter;
	}

	if (x_cost < y_cost)
	{
		printf("%d\n", x_cost);
	}
	else
	{
		printf("%d\n", y_cost);
	}
	return 0;
}

Measured memory_bytes: 3212
n = int(input())
S = map(int,input().split())
Number = list(S)
count_number = 0

for i in range(n-2):
    if Number[0] > Number[1] > Number[2] or Number[2] > Number[1] > Number[0]:
        count_number += 1
    del Number[0]

print(count_number)

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

#define ran 22

const int go[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};

int n, m;
char s[ran][ran];
int q[ran*ran*2], l, r;
bool visd[ran][ran];
int dist[ran][ran];

void pb(int x, int y, int d) {
	q[r++] = x; q[r++] = y;
	visd[x][y] = true;
	dist[x][y] = d;
}

int bfs(int st_x, int st_y) {
	l = r = 0;
	memset(dist, -1, sizeof dist);
	memset(visd, false, sizeof visd);
	pb(st_x, st_y, 0);
	
	int res = 0;
	while(l<r) {
		int x = q[l++], y = q[l++];
		int d = dist[x][y];
		for(int i=0;i<4;i++) {
			int _x = x+go[i][0], _y = y+go[i][1];
			if(_x<0 || _x>=n || _y<0 || _y>=m || s[_x][_y]!='.' || visd[_x][_y])
				continue;
			pb(_x, _y, d+1);
			res = max(res, d+1);
		}
	}
	return res;
}

int main() {
	scanf("%d%d", &n, &m);
	for(int i=0;i<n;i++) scanf("%s", s[i]);
	
	int ans = 0;
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
		if(s[i][j]=='.') ans = max(ans, bfs(i, j));
	printf("%d\n", ans);
	
	return 0;
}

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

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

    int N;
    cin >> N;
    map<ll, int> mp;
    while (N--) {
        ll A;
        cin >> A;
        mp[A] ^= 1;
    }

    int ans = 0;
    for (auto &p : mp) {
        ans += p.second;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528