akhauriyash/Code-Regression huggingface dataset:
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll N, K;
    cin >> N >> K;
    V a(N + 1, 0);
    priority_queue<P>Q;
    rep1(i, N){
        cin >> a[i];
        Q.push(P(a[i], i));
    }
    queue<ll>ans;
    for(;;){
        ll idx;
        while(!Q.empty()){
            idx = Q.top().second;
            Q.pop();
            if(a[idx] == 0){
                cout << -1 << endl;
                return 0;
            }
            ans.push(idx);
            a[idx]--;
        }
        if(K == 0)break;
        K--;
        rep1(i, N)if(i != idx)Q.push(P(a[i], i));
    }
    
    cout << ans.size() << endl;
    while(!ans.empty()){
        cout << ans.front();
        ans.pop();
        if(ans.empty())cout << endl;
        else cout << " ";
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = myRead.readInt();
            var a = myRead.readLongArray();
            long ans = 0;
            long h = 0;
            for (int i = 1; i < n; i++)
            {
                if (a[i - 1] > a[i])
                {
                    ans += a[i - 1] - a[i];
                    a[i] = a[i - 1];
                }
            }
            WriteLine(ans);
        }
    }
    public static class myRead
    {
        public static int readInt() { return int.Parse(ReadLine()); }
        public static long readLong() { return long.Parse(ReadLine()); }
        public static string readStr() { return ReadLine(); }
        public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        public static string[] readStrArray() { return ReadLine().Split(' '); }
    }


    public static class MyMath
    {
        public static long Factorical(long n)
        { return n <= 1 ? 1L : n * Factorical(n - 1); }
        public static long Permutation(long n, long m)
        { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); }
        public static long Combination(long n, long m)
        { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); }
        public static long Gcd(long n, long m)
        { return n % m == 0 ? m : Gcd(m, n % m); }
        public static long Lcm(long n, long m)
        { return n * m / Gcd(n, m); }
        public static long Pow(long n, long m)
        { return m == 0 ? 1L : m == 1 ? n : n * Pow(n, m - 1); }
    }


}

Measured memory_bytes: 47504
<?php
fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%s', $s);
fscanf(STDIN, '%d', $k);

$result = '';
$target = substr($s, $k-1, 1);
for ($i  = 0; $i < $n; $i++) {
    $currentWord = substr($s, $i, 1);
    if ($currentWord === $target) {
        $result .= substr($s, $i, 1);
    } else {
        $result .= '*';
    }
}

echo $result;


Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

ll n,q;
ll x[2000005],cnt[2000005];
vl g[2000005];
void dfs(ll cur,ll par=-1,ll sum=0){
    sum+=x[cur];
    cnt[cur]=sum;
    for(ll to:g[cur]){
        if(to==par)continue;
        dfs(to,cur,sum);
    }
}
void solve(){
    cin>>n>>q;
    rep(i,n-1){
        ll a,b;cin>>a>>b;
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
    }
    rep(i,q){
        ll p,xx;cin>>p>>xx;
        x[p-1]+=xx;
    }
    dfs(0);
    rep(i,n){
        if(i>0)cout<<" ";
        cout<<cnt[i];
    }
    cout<<endl;
}

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


Measured memory_bytes: 71040
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int n;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	vector<pair<string, int> > d(n);
	vector<int> idx(n);

	for (int i = 0; i < n; ++i) {
		idx[i] = i;
		cin >> d[i].first >> d[i].second;
	}
	
	for (int i = 1; i < n; ++i) {
		int j = i-1, u = idx[i];
		for ( ; j >= 0; --j) {
			int v = idx[j];
			if (d[u].first < d[v].first || (d[u].first == d[v].first && d[u].second > d[v].second)) {
				idx[j+1] = v;
			} else {
				idx[j+1] = u;
				break;
			}
		}

		if (j < 0)
			idx[0] = u;
	}

	for (int i = 0; i < n; ++i) {
		cout << idx[i] + 1 << endl;
	}

	return 0;
}

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

int main(){
	string a,b;
	int i,c;
	while (1) {
		cin >> a;
		if (a == "0") {
			break;
		}
		c = 0;
		for (i = 0; i < a.size(); i++) {
			b = a.substr(i, 1);
			if (b == "1") {
				c += 1;
			}
			if (b == "2") {
				c += 2;
			}
			if (b == "3") {
				c += 3;
			}
			if (b == "4") {
				c += 4;
			}
			if (b == "5") {
				c += 5;
			}
			if (b == "6") {
				c += 6;
			}
			if (b == "7") {
				c += 7;
			}
			if (b == "8") {
				c += 8;
			}
			if (b == "9") {
				c += 9;
			}
		}
		cout << c << endl;
	}
	return 0;
}

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

void fnInput(int& rnMember, int& rnScore, vector<int>& rvnAnsMem)
{
  int nMemSiz, nAnsSiz;
  cin >> rnMember >> rnScore >> nAnsSiz;

  rvnAnsMem.resize(nAnsSiz);
  for (int& rnAnsMem : rvnAnsMem)
    cin >> rnAnsMem;
}

void fnScoreCheck(int nMember, int nScore, const vector<int>& cnrvnAnsMem)
{
  vector<int> vnMemScore(nMember + 1, nScore);

  for (int nAnsMem : cnrvnAnsMem)
    vnMemScore[ nAnsMem ]++;

  for (int i = 1; i < vnMemScore.size(); i++)
    if (vnMemScore[i] > cnrvnAnsMem.size())
      cout << "Yes" << endl;
    else
      cout << "No"  << endl;
}

int main()
{
  int nMember, nScore;
  vector<int> vnAnsMem;

  fnInput(nMember, nScore, vnAnsMem);
  fnScoreCheck(nMember, nScore, vnAnsMem);

  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>

namespace keng
{
	inline void inc(int a,int &b){b+=a;}
	const int N=6,M=52;

	int L[N+1];
	int n,m,S;

	void initialize()
	{
		scanf("%d%d",&n,&m);S=1<<(n-1);
		for(int i=1;i<=n;i++)
			scanf("%d",L+i);
		for(int i=1;i<n;i++)
			if(L[i]>L[n])std::swap(L[i],L[n]);
	}

	int F[N],ind[N];

	double ans,tmp;

	int f[N*M][N*M][1<<N];
	double dp()
	{
		int O_O=1;for(int i=1;i<n;i++)O_O*=m;

		for(int i=1;i<n;i++)ind[F[i]]=i;
		memset(f,0,sizeof(f));

		f[1][L[n]*n][0]=1;
		int lim=n*m;
//		printf("lim = %d , S = %d\n",lim,S);
		for(int i=0;i<lim;i++)
			for(int j=0;j<=lim+1;j++)
				for(int k=0;k<S;k++)
				{
					int v=f[i][j][k],id;
					if(!v)continue;

//					printf("f[%d][%d][%d] = %d\n",i,j,k,v);

					if(i+1<=j)inc(v,f[i+1][j][k]);

					id=ind[i%n];
					if(!id || (k&(1<<(id-1))))continue;

//					printf("id = %d\n",id);
					inc(v,f[i+1][std::max(std::min(i+L[id]*n,lim+1),j)][k|1<<(id-1)]);
				}
		
		return (double)f[lim][lim+1][S-1]/O_O;
	}

	bool vis[N];
	void dfs(int p)
	{
		if(p==n)
		{
			ans+=dp();
			tmp+=1;
			return;
		}
		for(int i=1;i<n;i++)
			if(!vis[i])vis[F[p]=i]=1,dfs(p+1),vis[i]=0;
	}

	void solve()
	{
		initialize();
		ans=tmp=0,dfs(1);
		ans/=tmp;
		printf("%.20lf\n",ans);
	}
}

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


Measured memory_bytes: 24576
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a;
    cin>>a;
    if(a>='a' && a<='z')
        cout<<"a"<<endl;
    else if(a>='A' && a<='Z')
        cout<<"A"<<endl;
    
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int n , m , p , q ;
    long long sum = 0;
    cin >> n;
    int arr[n];
    for (int i = 0 ; i < n ; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    cin >> m;
    while(m--){
        cin >> p >> q;
        cout << sum - arr[p-1] + q << endl;
    }
    return 0;
}

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

int N;
double dp[302][302][302];
double rec(int i, int j, int k){
    if(dp[i][j][k] >= 0) return dp[i][j][k];
    if(i == 0 && j == 0 && k == 0) return 0;
    double ret = 0.0;
    if(i > 0) ret += rec(i-1, j, k) * i;
    if(j > 0) ret += rec(i+1, j-1, k) * j;
    if(k > 0) ret += rec(i, j+1, k-1) * k;
    ret += N;
    ret *= 1.0 / (i + j + k);
    return dp[i][j][k] = ret;
}

int main(){
    cin >> N;
    int a;
    int I = 0, J = 0, K = 0;
    for(int i=0;i<N;i++){
        cin >> a;
        if(a == 1) I++;
        if(a == 2) J++;
        if(a == 3) K++;
    }

    memset(dp, -1, sizeof(dp));

    cout << fixed << setprecision(10) << rec(I, J, K) << endl;
    return 0;
}

Measured memory_bytes: 215424
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline


def main():
    n = get_int()
    A = get_li()
    m1 = 0
    sign = 1
    for i in range(n):
        m1 += sign * A[i]
        sign *= -1
    m = [m1] * n
    for i in range(1, n):
        m[i] = -1 * m[i-1] + 2 * A[i-1]
    print(' '.join(map(str,m)))
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()


Measured memory_bytes: 104800
#include <iostream>
#include <set>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <map>
#include <cstdio>
using namespace std;
#define rep(i,n) for(i = 0; i < n; i++)
#define repe(i,n) for(i = 0; i <= n; i++)
#define FOR(i,m,n) for(i = m, i < n; i++)
#define repr(i,n) for(i = n; i >= 0; i--)
#define INF = 999999999
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD = 1000000007;

  
int main(){
  int i,x;
  set<int> n;
  int d;
  cin >> x;
  rep(i,x){
    cin >> d;
    n.insert(d);
  }
  cout << n.size() << endl;
  return 0;  
}

       


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

int main()
{
    string s,t;
    cin>>s>>t;
    int ans = 0;
    REPALL(i,s)
        ans += (s[i] != t[i]);
    cout<<ans<<endl;

    return 0;
}


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

int main(){

	int r, c;
	cin >> r >> c;

	// should we once store all inputs in a multi-dim array
	// , compute the sums, and then outputs?
	// Or, should we just use cin and cout in alternation?
	
	int sum_hor, tot = 0;
	int input;
	int sum_ver[c] = {0};

        for(int i=0; i<r; ++i){
		sum_hor = 0;
		for(int j=0; j<c; ++j){
			cin >> input;
			sum_hor    += input;
			sum_ver[j] += input;
			cout << input << " ";
		}
		cout << sum_hor << endl;
		tot += sum_hor;
	}

	for(int j=0; j<c; ++j){
		cout << sum_ver[j] << " ";	
	}

	cout << tot << endl;

	return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
const int maxN = 110;
const int maxC = 1e6 + 10;
const int INF = 1e9;


int a[maxN];
int n;
int p;
int main()
{
	scanf("%d%d",&n,&p);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		if(i == n && p!=a[i])
		{
			break;
		}
		if(a[i] <= p)
		{
			p-= a[i];
			ans++;
		}
		else
			break;
		
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int X, A;
    cin >> X >> A;
    int ans = 0;

    if(X < A) {
        cout << ans << endl;
        return 0;
    } else {
        ans = 10;
    }
    cout << ans << endl;
}


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

using namespace std;

const int N = 55;
const int Z = 26;

int n;
char s[N];
int have[N][Z];
int min_have[Z];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    for (int j = 0; s[j]; j++) have[i][s[j] - 'a']++;
  }
  for (int i = 0; i < 26; i++) min_have[i] = 1 << 30;
  for (int i = 0; i < n; i++) for (int j = 0; j < 26; j++) min_have[j] = min(min_have[j], have[i][j]);
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < min_have[i]; j++) putchar('a' + i);
  }
  puts("");
  return 0;
}            

Measured memory_bytes: 256
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , W , w[maxN] , v[maxN];
ll dp[101][maxN];
void solve(){
	cin>> n >> W ;
	for(ll i=0;i<n ;i++){
		cin>>w[i]>>v[i];
	}
	for(ll i=0;i<=n ;i++){
		for(ll j=0;j<=W ; j++){
			if(i==0 || j==0){
				dp[i][j]=0;
				continue;
			}
			dp[i][j]=dp[i-1][j];
			if(j-w[i-1]>=0)dp[i][j]=max(dp[i][j] , v[i-1]+dp[i-1][j-w[i-1]]);
		}
	}
	cout<<dp[n][W]<<endl;

}
int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

Measured memory_bytes: 82868
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
	int n;
	cin >> n;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j==n){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
# ABC 151C
n, m = map(int, input().split())
ac = 0
wa = 0
cnt = [0]*n
for i in range(m):
    p, s = input().split()
    p = int(p)
    p -= 1
    if cnt[p] == -1:
        continue
    if s == 'AC':
        ac += 1
        wa += cnt[p]
        cnt[p] = -1
    else:
        cnt[p] += 1
print(ac, wa)


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  vector<char> front = {};
  vector<char> back(S.begin(),S.end());
  int Q;
  cin >> Q;
  bool rev = false;
  for(int i = 0; i < Q; i++){
    int T;
    cin >> T;
    if(T == 1){
      rev = !rev;
    }else{
      int F;
      char C;
      cin >> F;
      cin >> C;
      if(F == 1){
        if(rev){
          back.push_back(C);
        }else{
          front.push_back(C);
        }
      }else{
        if(rev){
          front.push_back(C);
        }else{
          back.push_back(C);
        }
      }
    }
  }
  if(rev){
    for(int i = 0; i < back.size(); i++){
      cout << back[back.size()-1-i];
    }
    for(int i = 0; i < front.size(); i++){
      cout << front[i];
    }
    cout << "" << endl;
  }else{
    for(int i = 0; i < front.size(); i++){
      cout << front[front.size()-1-i];
    }
    for(int i = 0; i < back.size(); i++){
      cout << back[i];
    }
    cout << "" << endl;
  }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
long long int flagE,flagW,n,ans=10000000;
char prevchar='W',s[300001];
int main()
{
	long long int i,j;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>s[i];
		if((prevchar=='E')&&(s[i]=='E')&&  ((flagW-flagE-1)<ans))
		ans=(flagW-flagE-1);
		if(s[i]=='W')
		flagW++;
		else
		flagE++;
		prevchar=s[i];
	}
	if(0<ans)
	cout<<flagE;
	else
	cout<<(ans+flagE)<<'\n';
	return 0;
}




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

#define int long long
#define form2(i, a, b) for (int i = (a); i < (b); ++i)
#define ford2(i, a, b) for (int i = (a-1); i >= (b); --i)
#define form(i, n) form2(i, 0, n)
#define ford(i, n) ford2(i, n, 0)

#define chmax(x, v) x = max(x, (v))
#define chmin(x, v) x = min(x, (v))
#define fi first
#define se second

const long long BIG = 1000000000000000000LL;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

void solve();
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}

const int UNDEF = -BIG-100;
const int borne = (int)(1e5) + 5;
int val[borne];
vector<int> adj[borne];
pair<int, int> ivOk[borne];
int nbNod;

void dfs1(int nod, int par, bool imp)
{
	if (val[nod] != UNDEF && (val[nod] % 2 == 1) != imp) {
		cout << "No\n";
		exit(0);
	}

	ivOk[nod] = {-BIG, BIG};
	if (imp) ivOk[nod] = {-BIG+1, BIG+1};
	if (val[nod] != UNDEF) ivOk[nod] = {val[nod], val[nod]};

	for (int vo : adj[nod]) if (vo != par) {
		dfs1(vo, nod, imp^true);
		chmax(ivOk[nod].fi, ivOk[vo].fi - 1);
		chmin(ivOk[nod].se, ivOk[vo].se + 1);
	}

	if (ivOk[nod].fi > ivOk[nod].se) {
		cout << "No\n";
		exit(0);
	}
}

void dfs2(int nod, int par, int cv)
{
	if (cv-1 < ivOk[nod].fi) ++cv;
	else --cv;
	assert(cv <= ivOk[nod].se);
	val[nod] = cv;

	for (int vo : adj[nod]) if (vo != par) {
		dfs2(vo, nod, cv);
	}
}

void solve()
{
	cin >> nbNod;
	form(iEdge, nbNod-1) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	form(i, nbNod) val[i] = UNDEF;
	int nbPut; cin >> nbPut;
	int root = -5;
	form(i, nbPut) {
		int nod, putval;
		cin >> nod >> putval;
		--nod;
		val[nod] = putval;
		root = nod;
	}

	dfs1(root, -1, val[root]%2);
	dfs2(root, -1, ivOk[root].fi+1);
	cout << "Yes\n";
	form(nod, nbNod) {
		cout << val[nod] << '\n';
	}
}


Measured memory_bytes: 16512
/*
   ~~~~~~~~~~~~~~~~~~~
   \  |\/| | |\ | |  /
   /  |  | | |/ |_|  \
   ~~~~~~~~~~~~~~~~~~~
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> lve;
typedef vector<char> cve;
typedef vector<pair<ll,ll> > lvp;
typedef vector<pair<string,int> > svp;

#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back
#define PI         2*acos(0)
#define pb         push_back
#define mp         make_pair
#define GCD(x,y)   __gcd(x,y)
#define lb         lower_bound
#define up         upper_bound
#define bs         binary_search
#define LCM(x,y)   ((x*y)/GCD(x,y))
#define For(i,j,k) for(i=j;i<k;i++)
#define FOR(i,j,k) for(i=j;i>=k;i--)
#define sp(x)      cout<<fixed<<setprecision(x)

const   long long  inf=1e18;
const   long long  mod=1e9+7;
const   long long  cs=200005;
int main()
{	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);
    
 	ll t,n,m,a,b,c,d,e,k,x,y,z,i;
 	cin>>n;
 	x=n%1000;
 	if(x!=0) cout<<1000-x<<endl;
 	else cout<<x<<endl;

 	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e19;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
string dir[8] = { "R","L","D","U","RD","RU","LD","LU" };
bool flag[201010];
ll ans[201010];

vector<vector<ll>>to;

void dfs(ll v) {
	flag[v] = true;
	for (auto nv : to[v]) {
		if (flag[nv] == false) {
			ans[nv] += ans[v];
			dfs(nv);
		}
	}
}

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>x(n), y(n);
	vector<ll>z(n), w(n);
	rep(i, n) {
		cin >> x[i] >> y[i];
		z[i] = x[i] + y[i];
		w[i] = x[i] - y[i];
	}
	sort(z.begin(), z.end());
	sort(w.begin(), w.end());
	ll ans = max(z[n - 1] - z[0], w[n - 1] - w[0]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9524
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
typedef pair<int, int> P;

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


Measured memory_bytes: 256
/*----------------by syr----------------*/
/*
  -----  -----  -----
  |   |  |---|    _/
  |   |  | \_    /
  -----  |   \  -----

  |---\  \   /  |\  /|
  |   |   \_/   | \/ |
  |   |   / \   |    |
  |---/  /   \  |    |
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i,x,y) for(int i=(x);i<(y);++i)
#define REP(i,x,y) for(int i=(x);i<=(y);++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;

const int INF=1e9+7;
const int maxn=1e5+5;

int n;
int h[maxn],dp[maxn];

int main(){
	scanf("%d",&n);
	REP(i,1,n) scanf("%d",h+i);
	dp[1]=0;
	REP(i,2,n){
		dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
		if(i>2) dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
	}
	printf("%d\n",dp[n]);
	return 0;
}


Measured memory_bytes: 1024
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main() {
    let (h, a): (usize, usize);
    input!(h, a);
    if h % a == 0 {
        println!("{}", h / a);
    } else {
        println!("{}", (h / a) + 1);
    }
}


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

// Common file
#include <ext/pb_ds/assoc_container.hpp>
// Including tree_order_statistics_node_update
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>



#define pb push_back
#define F first
#define S second
#define rep(i,n) for(int i = 0; i < (n); i++)

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ReadFile            freopen("input.in","r",stdin)
#define WriteFile           freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = (1LL<<62);
const ld EPS = 1e-7;
double Pi=acos(-1);
const ld rad=Pi/180.0;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll nCr (ll n,ll m)
{
        return(m == 0)?1:n*nCr(n-1,m-1)/m;
}
/*****************************************************/


const int N = (int)1e5 + 5;
int a[N] , n , numNeg = 0 , mn = INT_MAX;
ll sum = 0;

int main()
{
    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> a[i];
        if(a[i] < 0)
            numNeg++;
        sum += abs(a[i]);
        mn = min(mn , abs(a[i]));
    }

    if(numNeg&1)
        cout << sum - (2 * mn) << "\n";
    else
        cout << sum << "\n";

    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  int a = m - n;
  if(a<=0) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> x(m);
  rep(i,m) cin >> x.at(i);
  sort(x.begin(), x.end());
  int ans = x.at(m-1) - x.at(0);
  vector<int> y(m-1);
  rep(i,m-1) y.at(i) = x.at(i+1) - x.at(i);
  sort(y.begin(), y.end());
  reverse(y.begin(), y.end());
  rep(i,n-1) ans -= y.at(i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll X,A,B;
  cin>>X>>A>>B;
  if(X+A<B) {
cout<<"dangerous"<<endl;
  }
  else if(B<=A) {
cout<<"delicious"<<endl;
  }
  else {
cout<<"safe"<<endl;
  }
}

Measured memory_bytes: 3588
a = {}
b = {}
i = 0
for c, d in zip(input(), input()):
    if c not in a and d not in b:
        a[c] = b[d] = i
        i += 1
    elif c in a and d in b:
        if a[c] != b[d]:
            print('No')
            break
    else:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
using namespace std;
int pow(int x,int y){
  int z = 1;
  while(y){
    z *= x;y--;
  }
  return z;
}
int mathceil(int x,int y){
  if(x%y) return x/y+1;
  else return x/y;
}
int main(){
  int d,g,ans = 100000,i,j,sum,mid,need,h;cin >> d >> g;g /= 100;
  int a[d][2],b[d] = {};b[0] = -1;
  for(i=0;i<d;i++){
    cin >> a[i][0] >> a[i][1];a[i][1] /= 100;
  }
  for(i=0;i<pow(2,d);i++){
    b[0]++;mid = -1;sum = 0;need = 0;
    for(j=0;j<d;j++){
      if(b[j]==2){
        b[j] = 0;b[j+1]++;
      }
      if(b[j]==1){
        sum += (j+1)*a[j][0]+a[j][1];need += a[j][0];
      } else mid = max(mid,j);
    }
    if(sum >= g) ans = min(ans,need);
    else{
      h = mathceil(g-sum,mid+1);
      if(h < a[mid][0]) ans = min(ans,need+h);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np

MOD = 10**9+7

n,m = map(int,input().split())
X = np.array([int(x) for x in input().split()], dtype = np.int64)
Y = np.array([int(x) for x in input().split()], dtype = np.int64)

coef_X = np.arange(n)*2-(n-1)
X_sum = np.sum(np.mod(X * coef_X,MOD))%MOD

coef_Y = np.arange(m)*2-(m-1)
Y_sum = np.sum(np.mod(Y * coef_Y,MOD))%MOD

answer = (X_sum*Y_sum)%MOD
print(answer)

Measured memory_bytes: 26112
#include<iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int h[100] = {0};
    int Sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        if (i == 0) {
            Sum += h[0];
        } else if (h[i - 1] < h[i] ) {
            Sum += h[i] - h[i - 1];
        }
    }
    cout << Sum << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >>s;
  int ans=0;
  for(int i=0; i<s.size()-1; i++){
    if((s[i]=='B' && s[i+1]=='W')
       ||s[i]=='W' && s[i+1]=='B') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int inf = 1e9;

int main() {
	string w;
	cin>>w;
	sort(all(w));
	int N=w.size();
	string ans="No";
	int cnt=0;
	if(N%2==0){
		for (int i = 0; 2*i+1 < N; ++i){
		if(w[2*i]==w[2*i+1])cnt+=2;
		}
		if(cnt==N)ans="Yes";
	}
	cout<<ans<<endl;
}

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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    string s;
    cin >>s;

    for (int i = 0; i < s.length(); i++){
        if(i%2==0)cout << s[i];
    }
    

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << endl;

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


Measured memory_bytes: 512
#include<iostream>
#define ll long long
using namespace std;

int main(){

	ll L,R;
	cin >> L >> R;

	ll ans = 2018;

	for(ll i=L ; i<=R ; i++){
		for(ll k = i+1 ; k<=R ; k++){
			if(i>=k) continue;
			if(ans ==0 )
				break;
			ans = min(ans , (i*k)%2019);
		}
		if(ans == 0 ) break;
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int min = -1;
		int max = Integer.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			min = Math.max(min, in.nextInt());
			max = Math.min(max, in.nextInt());
		}
		System.out.println(max - min + 1 > 0 ? max - min + 1 : 0);
		in.close();
	}
}

Measured memory_bytes: 62024
import math


def f(x, y):
    return max(int(math.log10(x) + 1), int(math.log10(y) + 1))


count = 10 ** 10
N = int(input())

for i in range(1, int(math.sqrt(N)) + 1):
    if N % i == 0:
        tmp = f(i, N // i)
        if tmp <= count:
            count = tmp
print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int main() {
  int N,Z,W; cin >>N >>Z >>W;
  vector<int> A(N); rep(i, N) cin >>A[i];
  vector<int> X(N+1), Y(N+1);
  rep(i, N){
    X[i+1] = A[i]; Y[i+1] = A[i];
  }
  X[0] = Z; Y[0] = W;
  vector<vector<int>> dp(N+1, vector<int>(2, 0));
  // dp[i][j] := 手番はj ? Y : X で相手はXorY[i]を持っている。最適に行動した時のスコア
  // 相手がN-1を持っている場合こちらはNを取るしかない
  for (int enm=N-1; enm>=0; enm--){
    // 相手がenmを持っていて自分の番が来た
    // こちらが山札を全て取りNを取った場合
    dp[enm][0] = abs(X[N] - Y[enm]);
    dp[enm][1] = abs(X[enm] - Y[N]);
    for (int i=N-1; i>enm; i--){
      // こちらが山札を全ては取らない(enm < i < N) 場合
      chmax(dp[enm][0], dp[i][1]);
      chmin(dp[enm][1], dp[i][0]);
    }
  }
  cout <<dp[0][0] <<endl;
}


Measured memory_bytes: 384
// https://atcoder.jp/contests/abc135/tasks/abc135_b

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v(n), t;
    REP(i, n) cin >> v[i];
    t = v;
    sort(ALL(v));
    int cnt = 0;
    REP(i, n) {
        if (v[i] != t[i]) {
            cnt++;
        }
    }
    if (cnt <= 2) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}


Measured memory_bytes: 256
def main(str)
  xyabc, ps, qs, rs = str.split("\n").map { |x| x.split(" ").map(&:to_i) }
  x, y, _a, _b, _c = *xyabc
  ps = ps.sort.reverse[0...x]
  qs = qs.sort.reverse[0...y]
  rs.sort!
  replaces = []
  loop do
    break unless rs.any?
    g = rs.pop
    if ps.any? && qs.any?
      pdiff = g - ps.last
      qdiff = g - qs.last
      break if pdiff <= 0 && qdiff <= 0
      if pdiff > qdiff
        ps.pop
      else
        qs.pop
      end
    elsif ps.any?
      pdiff = g - ps.last
      break if pdiff <= 0
      ps.pop
    elsif qs.any?
      qdiff = g - qs.last
      break if qdiff <= 0
      qs.pop
    else
      raise
    end
    replaces << g
  end
  (ps + qs + replaces).inject(&:+)
end

puts main($stdin.read.chomp)


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

int n;

int pr[200005];

int findfa(int x)
{
    if(pr[x]==x)
        return x;
    return pr[x]=findfa(pr[x]);
}

struct ha
{
    long long x,y;
    int id;
}q[200005];

int p;

struct gg
{
    int l,r;
    long long v;
}a[200005];

bool cmpx(const ha &aa,const ha &bb)
{
    return aa.x<bb.x;
}
bool cmpy(const ha &aa,const ha &bb)
{
    return aa.y<bb.y;
}
bool cmp(const gg &aa,const gg &bb)
{
    return aa.v<bb.v;
}


int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&q[i].x,&q[i].y);
        q[i].id=i;
    }
    sort(q+1,q+1+n,cmpx);
    for(int i=1;i<n;i++)
    {
        p++;
        a[p].l=q[i].id;
        a[p].r=q[i+1].id;
        a[p].v=abs(q[i+1].x-q[i].x);
    }
    sort(q+1,q+1+n,cmpy);
    for(int i=1;i<n;i++)
    {
        p++;
        a[p].l=q[i].id;
        a[p].r=q[i+1].id;
        a[p].v=abs(q[i+1].y-q[i].y);
    }

    sort(a+1,a+1+p,cmp);

    for(int i=1;i<=n;i++)
    {
        pr[i]=i;
    }

    long long ans=0;

    for(int i=1;i<=p;i++)
    {
        if(findfa(a[i].l)!=findfa(a[i].r))
        {
            //cout<<a[i].l<<" "<<a[i].r<<" "<<a[i].v<<endl;
            pr[findfa(a[i].l)]=findfa(a[i].r);
            ans+=a[i].v;
        }
    }

    printf("%lld",ans);

    return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, a, b; cin >> n >> a >> b;
  auto calc = [&](int x){
    int res = 0;
    while(x){
      res += x % 10;
      x /= 10;
    }
    return res;
  };
  int ans = 0;
  for(int i = 1; i <= n; i++){
    int t = calc(i);
    if(t >= a && t <= b)ans += i;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int n;
    cin>>n;
    int max_height=0;
    for (size_t i = 0; i < n; i++)
    {
        int h;
        cin>>h;
        if(i==0){
            max_height = h - 1;
        }
        else{
            if(h<max_height){
                cout<<"No"<<endl;
                return 0;
            }
            else if(h>max_height){
                max_height = h - 1;
            }
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <limits.h>
using namespace std;
typedef long long LL;
typedef bitset<305> BS;
const int B=305;
const int N=400;
const BS one=BS().set(0);
const BS zero=BS();
const LL M=998244353;

struct LB {
	int sz;
	BS b[B];

	void build(BS *a,int n) {
		sz=0;
		for(int i=0;i<B;i++) {
			b[i].reset();
		}
		for(int i=0;i<n;i++) {
			BS x=a[i];
			for(int j=B-1;j>=0;j--) {
				if(((x>>j)&one)==one) {
					if(b[j]!=zero) x^=b[j];
					else {
						b[j]=x;
						sz++;
						for(int k=j-1;k>=0;k--) {
							if(b[k]!=zero && ((b[j]>>k)&one)==one) b[j]^=b[k];
						}
						for(int k=j+1;k<B;k++) {
							if(((b[k]>>j)&one)==one) b[k]^=b[j];
						}
						break;
					}
				}
			}
		}
	}
}lb;

int n,m,b;
BS a[N];
LL dp[N],pw[N];

int main() {
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++) {
		a[i].reset();
		for(int j=0;j<m;j++) {
			scanf("%d",&b);
			if(b) a[i].set(j);
		}
	}
	lb.build(a,n);

	pw[0]=1;
	for(int i=1;i<N;i++) {
		pw[i]=pw[i-1]*2%M;
	}
	LL ans=(pw[lb.sz]-1+M)%M*pw[n-lb.sz]%M*pw[m-1]%M;
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
n= int(input())
a= list(map(int,input().split()))
b= sum(list(map(int,input().split())))
c= list(map(int,input().split()))

for i in range(n-1):
    if a[i+1]-a[i]==1:
        b+= c[a[i]-1]
print(b)


Measured memory_bytes: 2940
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30) 

int H, A[MAX + 1];

void maxHeapify(int i)
{
	int l, r, largest;
	l = 2 * i;
	r = 2 * i + 1;
	
	if(l <= H && A[l] > A[i])
		largest = l;
	else
		largest = i;
	if(r <= H && A[r] > A[largest])
		largest = r;
		
	if(largest != i)
	{
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}
}

int extract()
{
	int maxv;
	if(H < 1)
		return -INFTY;
	maxv = A[1];
	A[1] = A[H--];
	maxHeapify(1);
	return maxv;
}

void increaseKey(int i, int key)
{
	if(key < A[i])
		return;
	A[i] = key;
	while(i > 1 && A[i/2] < A[i])
	{
		swap(A[i], A[i/2]);
		i = i / 2;
	}
}

void insert(int key)
{
	H++;
	A[H] = -INFTY;
	increaseKey(H, key);
}

int main()
{
	int key;
	char s[10];
	while(1)
	{
		scanf("%s", s);
		if(s[0] == 'e' && s[1] == 'n')
			break;
		if(s[0] == 'i')
		{
			scanf("%d", &key);
			insert(key);
		}
		else
			printf("%d\n", extract());
	}
	
	return 0;
}



Measured memory_bytes: 6468
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define SIZE(x) ((int)(x).size())
#define UQ(v) v.erase(unique(v,begin(),v,end()),v.end());
ll INF = 1LL <<30;
#define pb push_back 
int dxy4[5] = { 0,1,0,-1,0 };
int dxy8[9] = { 0,1,1,0,-1,1,-1,-1,0 };
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
ll mod7 = 1000000007;
ll mod9 = 1000000009;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define FOR(i,x,n) for(int i=x;i<n;++i)
//vector< vector<int> > v (max1, vector<in t>(max2) );

int dp[100000];
vector<int>k;
int main() {
	int n;
	cin >>n;

	int tmp, x;
	rep(i, 10) {
		rep(j, 2) {
			x = j ? 6 : 9;
			tmp = pow(x, i);
			if (tmp > n) continue;
			k.pb(tmp);
		}
	}

	rep(i, n+1)dp[i] = INF;
	dp[0] = 0;
	
	int c = SIZE(k);
	rep(i, n+1 ) {
		rep(j, c) {
			if (k[j] + i > n)continue;
			dp[i + k[j]] = min(dp[i] + 1, dp[i + k[j]]);
		}
	}
	
	cout << dp[n] << endl;
	
	int nn;
	cin >> nn;
	
	return 0;
}

Measured memory_bytes: 640
/*
 * 	If you gave me a chance
 * 		I'll take it
 * 			It's a shot in the dark
 * 				But I will make it:D
 */
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifndef rd
#define endl '\n'
#endif
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#endif
#define deb cout<<"Line: "<<__LINE__<<" plz "
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=2e9;
const int mod=1e9+7;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
auto clk=clock();
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

void solve() {
	int n;
	string s;
	cin>>n>>s;
	int r=0;
	for(int i=0; i<n; i++) {
		if(s[i]=='R')
			r++;
		else
			r--;
	}
	if(r>0) {
		cout<<"Yes"<<endl;
	} else
		cout<<"No"<<endl;
}
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cerr<<endl<<endl<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 256