akhauriyash/Code-Regression huggingface dataset:
/***************************************************
 * Problem Name : A.cpp
 * Problem Link :
 * OJ           :
 * Verdict      : Trying
 * Date         : 2020-06-14
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;

#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<int,int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.rbegin(), v.rend())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define F first
#define S second
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007

template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set  = tree<T, null_type, less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

template <typename T> string toString ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template<typename T> int toInt (T str) {
    stringstream ss;
    ss << str;
    int num;
    ss >> num;
    return num;
}
ll lcm ( ll a, ll b ) {
    return ( a / __gcd ( a, b ) ) * b;
}
/************************************ Code Start Here ******************************************************/
int main () {
    //~ __FastIO;
    //~ cout << setprecision (10) << fixed;
    int a, b;
    cin >> a >> b;
    cout << max3(a+b, 2*a-1, 2*b-1) << '\n';
    return 0;
}


Measured memory_bytes: 256
def resolve():
    from collections import deque
    H, W = map(int, input().split())
    H += 2
    W += 2
    maze = '#' * W
    for _ in range(H-2):
        maze += '#' + input() + '#'
    maze += '#' * W

    def bfs(root):
        if maze[root] == '#':
            return -1
        dist = [-1] * (H*W)
        dist[root] = 0
        q = deque([root])
        while q:
            x = q.popleft()
            for d in [1, -1, W, -W]:
                if maze[x+d] == '.' and dist[x+d] == -1:
                    q.append(x+d)
                    dist[x+d] = dist[x] + 1
        return max(dist)

    ans = max(bfs(i) for i in range(H*W))
    print(ans)
resolve()

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

typedef pair<int,int> P;
set<P> s;
vector<P> H(323456),W(323456);
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int h,w,m;cin>>h>>w>>m;
  for(int i=0;i<323456;i++)H[i]=W[i]=P(0,i);
  for(int i=0;i<m;i++){
    int hh,ww;cin>>hh>>ww;
    H[hh].first++;
    W[ww].first++;
    s.insert(P(hh,ww));
  }
  sort(H.rbegin(),H.rend());
  sort(W.rbegin(),W.rend());
  for(int i=0;H[i].first==H[0].first;i++)
    for(int j=0;W[j].first==W[0].first;j++)
      if(!s.count(P(H[i].second,W[j].second)))
        fin(H[0].first+W[0].first);
  fin(H[0].first+W[0].first-1);
}


Measured memory_bytes: 22232
//abc151_e.cpp
//Sun Jan 12 20:59:41 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

const ll MAX = 400000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
ll 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;
}


int main(){
	ll n,k;
	cin >> n >> k;

	COMinit();

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

	if (k==1){
		cout << 0 << endl;
		return 0;
	}

	sort(a,a+n,greater<ll>());

	ll ans = 0;
	for (int i=0;i<=n-k;i++){
		ll temp = (a[i]*COM(n-i-1,k-1)%MOD+MOD)%MOD;
		ans = ((ans+temp)%MOD+MOD)%MOD;
	}

	sort(a,a+n);

	for (int i=0;i<=n-k;i++){
		ll temp = (a[i]*COM(n-i-1,k-1)%MOD+MOD)%MOD;
		ans = ((ans-temp)%MOD+MOD)%MOD;
	}


	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    ll n,m;
    cin >> n >> m;
    if(abs(n-m) > 1){
        cout << 0 << endl;
        return 0;
    }

    ll a=1,b=1;
    for(ll i = n;i >= 1;i --){
        a *= i;
        a %= 1000000007;
    }
    for(ll i = m;i >= 1;i --){
        b *= i;
        b %= 1000000007;
    }

    ll ans = a * b;
    if(a == b){
        ans *= 2;
    }

    ans %= 1000000007;

    cout << ans << endl;
}

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

//a文字目からb文字目までを出力する関数
void print( int a, int b, string& s )
{
    for( int i = a; i <= b; i++ )
        cout << s[i];
    cout << endl;
}

//a文字目からb文字目までを反対にする関数
void reverse( int a, int b, string& s )
{
    for( int i = a, j = b, k = 0; k < (b - a + 1) / 2; i++, j--, k++ )
    {
        char temp;
        temp = s[i];
        s[i] = s[j];
        s[j] = temp;
    }
}

//a文字目からb文字目までをpに置き換える関数
void replace( int a, int b, string& s, string p )
{
    for( int i = a, j = 0; i <= b; i++, j++ )
        s[i] = p[j];
}

int main() 
{
    string str, order,rep;
    int q;
    int _a, _b;

    cin >> str;
    cin >> q;

    for( int t = 0; t < q; t++ )
    {
        cin >> order;

        if( order == "replace" )
        {
            cin >> _a >> _b >> rep;
            replace( _a, _b, str, rep );
        }
        else if( order == "reverse" )
        {
            cin >> _a >> _b;
            reverse( _a, _b, str );
        }
        else
        {
            cin >> _a >> _b;
            print( _a, _b, str );
        }
    }

    return 0;
}


Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
int main(){
    string A, B, C;
    cin >> A >> B >> C;
    cout << A[0] << B[0] << C[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

int main() {
    ll n, k, ans = 0;
    cin >> n >> k;
    vector<ll> a(n);
    map<ll, ll> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] > a[j]) ans++;
        }
    }
    ans *= k;
    ans %= mod;

    ll cnt = 0, s = 0;
    for (auto ite = mp.begin(); ite != mp.end(); ++ite) {
        if (ite == mp.begin()) {
            cnt = ite->second;
            continue;
        }
        s += cnt * ite->second;
        cnt += ite->second;
    }
    ans = (ans + k * (k - 1) / 2 % mod * s) % mod;
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int n, k, q;
    std::cin >> n >> k >> q;
    std::vector<int> a(q);
    std::vector<int> p(n);

    for (int i = 0; i < q; i++)
    {
        std::cin >> a[i];
        p[a[i] - 1]++;
    }

    for (int i = 0; i < n; i++) {
        if(k - (q - p[i]) > 0 ) {
            std::cout << "Yes"
                      << "\n";
        } else {
            std::cout << "No"
                      << "\n";
        }
    }

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main(){
  int a, b, c; cin >> a >> b >> c;
  cout << a * b / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
ABCD  = list(input())
n = len(ABCD)
ans = 0

for i in range(2 ** (n-1)):

    list = ABCD[0]

    # iをj-1ビット右シフトして1だったら+を入れるのを繰り返す
    # 1の数が+の数になる
    for j in range(1, n):

        if (i >> (j - 1)) & 1:

            list = list + "+" + ABCD[j]
            # print(i >> (j-1))

        else:
            list = list + "-" + ABCD[j]


    if eval(list) == 7:
        print(list,"=7",sep='')
        exit()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int inf = 2e18;
const int mod = 1e9 + 7;

signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    cin >> A;
    sort(A.begin(), A.end());
    int left = 0, right = 1<<30;
    while(abs(right - left) > 1) {
        int middle = (right + left) / 2;
        int count = 0;
        for (int i = 0; i < N; i++) {
            count += N - distance(A.begin(), lower_bound(A.begin(), A.end(), middle - A[i]));
        }
        (count >= M ? left : right) = middle;
        // cout << middle << endl;
    }
    vector<int> sumA(N + 1);
    sumA[0] = 0;
    for (int i = 1; i <= N; i++) {
        sumA[i] = sumA[i - 1] + A[i - 1];
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int d = distance(A.begin(), lower_bound(A.begin(), A.end(), left - A[i]));
        ans += (A[i] * (N - d)) - ((left * (N - d)) - (sumA[N] - sumA[d]));
        // cout << (A[i] * (N - d)) << " " << (sumA[N] - sumA[d]) << endl;
    }
    cout << ans + (left * M) << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define usecppio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const ll mod = 1e9+7;
ll factorial(ll a)
{
    ll x = 1;
    for (ll i = 1; i<=a; i++)
    {
        x*= i;
        x%= mod;
    }
    return x%mod;
}
int main()
{
    ll n, m;
    cin >> n >> m;
    if (abs(n-m)>1)
    {
        cout << 0;
        return 0;
    }
    ll res = 1;
    if (n!=m)
    {
        res *= factorial(n);
        res %= mod;
        res *= factorial(m);
        res %= mod;
    }
    else
    {
        res *= factorial(n);
        res %= mod;
        res *= factorial(m);
        res %= mod;
        res *= 2;
        res %= mod;
    }
    cout << res;
}

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

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9

using namespace std;
typedef long long ll;

int main(){
	int x, y;
	cin >> x >> y;
	cout << x+(y/2) << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int K = scan.nextInt();
		String S = scan.next();
		char[] X = S.toCharArray();
		if(X.length<=K) {
			System.out.println(S);
			
		}else {
			for(int i=0;i<K;i++) {
				System.out.print(X[i]);
				
			}
			System.out.print("...");
		}
	}

}


Measured memory_bytes: 35736
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define int long long int
using namespace std;
#define pii pair <int, int>
#define mii map<int, int>
#define pb push_back
#define deb(x) cout << #x << " " << x << endl
#define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl
#define Loop(s, e, itr) for (int itr = s; itr < e; itr++)
#define loop(n) for(int i = 0; i < n; i++)
#define vin vector<int>
#define w(t) int tc; cin >> tc; for(int t = 1; t <= tc; t++)
#define vec vector
#define mod 1000000007
#define all(x) x.begin(), x.end()

int n;
int a[100005], b[100005], c[100005];



void solve_itr(){
    int dp[n+5][3];
    memset(dp, -1, sizeof(dp));
    dp[n-1][0] = a[n-1];
    dp[n-1][1] = b[n-1];
    dp[n-1][2] = c[n-1];
    for(int i = n-2; i >= 0; i--){
        dp[i][0] = a[i] + max(dp[i+1][1], dp[i+1][2]);
        dp[i][1] = b[i] + max(dp[i+1][0], dp[i+1][2]);
        dp[i][2] = c[i] + max(dp[i+1][0], dp[i+1][1]);
    }
    int ans = max(dp[0][0], max(dp[0][1], dp[0][2]));
    
    cout << ans << endl;
}

int32_t main(){
    cin >> n;
    loop(n) cin >> a[i] >> b[i] >> c[i];

    solve_itr();
}

Measured memory_bytes: 8192
float p=atan(1)*4/9,X[100],Y[100],x,y;main(n,i,j,k,a,b,c){
	for(;scanf("%d",&n),n;printf("%d\n",a)){
		for(i=0;i<n;i++)scanf("%f,%f",X+i,Y+i);
		for(a=i=0;i<n;a=a>b?a:b,i++)for(b=k=0;k<9;b=b>c?b:c,k++)for(x=X[i]+cos(p*k),y=Y[i]+sin(p*k),c=j=0;j<n;j++)if(hypot(X[j]-x,Y[j]-y)<1+1e-3)c++;
	}
exit(0);}

Measured memory_bytes: 652
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <cstring>
#include <cinttypes>
using namespace std;
 
using ll=int64_t;
#define int ll
 
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;
 
void printSpace(){
	printf(" ");
}
 
void printEoln(){
	printf("\n");
}

int read(){
	int i;
	scanf("%" SCNd64,&i);
	return i;
}
void print(const string& s) {
	printf("%s", s.c_str());
}
void println(const string& s) {
	printf("%s\n", s.c_str());
}
void print(int x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}
 
string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}
 
char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template <typename T>
vector<T> readVec(int size) {
	using namespace std;
	vector<T> vec(size);
	for (int i = 0; i < size; ++i) {
		cin >> vec[i];
	}
	return vec;
}
template <typename T>
void printVec(const vector<T> &vec, int size, const string &sep = " ") {
	using namespace std;
	if (vec.empty()) return;
	cout << vec[0];
	for (int i = 1; i < size; ++i) {
		cout << sep << vec[i];
	}
	cout << endl;
	return;
}
#define printAll(vec) PrintSize(vec, vec.size())

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

	auto a = readVec<int>(4);
	if (a[0] + a[1] > a[2] + a[3]) {
		println("Left");
	} else 	if (a[0] + a[1] < a[2] + a[3]) {
		println("Right");
	} else {
		println("Balanced");
	}
	return 0;
}

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

#define SZ(v) ((int)(v).size())
using ll = long long;

const int MAXD = 4;
const pair<int, int>DELT[] =  {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

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

	int nb_cases;
	cin >> nb_cases;
	vector<vector<int>> dis(nb_cases, vector<int>(nb_cases));
	for (int lig(0); lig < nb_cases; ++lig)
		for (int col(0); col < nb_cases; ++col)
			dis[lig][col] = min({lig, col, nb_cases - lig - 1, nb_cases - col - 1});

	ll ans(0);
	vector<vector<bool>> erased(nb_cases, vector<bool>(nb_cases));
	for (int i(0); i < nb_cases*nb_cases; ++i)
	{
		int pos;
		cin >> pos;
		int lig = (pos-1)/nb_cases;
		int col = (pos-1)%nb_cases;
		ans += dis[lig][col];
		erased[lig][col] = true;
		queue<pair<int, int>> q;
		q.push({lig, col});
		while (SZ(q))
		{
			auto [y, x] = q.front(); q.pop();
			for (auto [dy, dx] : DELT)
			{
				int yy = y + dy, xx = x + dx;
				if (yy < 0 or yy >= nb_cases or xx < 0 or xx >= nb_cases) continue;
				if (dis[yy][xx] > !erased[y][x] + dis[y][x])
				{
					dis[yy][xx] = !erased[y][x] + dis[y][x];
					q.push({yy, xx});
				}
			}
		}

	}
	cout << ans << endl;
}


Measured memory_bytes: 4684
#include <iostream>
#include <queue>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main(void){
    ull mod = 1000000007;
    
    uint N, M;
    cin >> N >> M;
    
    queue<uint> aq;
    for(uint i=0; i<M; i++) {
        uint a;
        cin >> a;
        if(!aq.empty() && (a - 1) == aq.back()) {
            cout << 0;
            return 0;
        } else {
            aq.push(a);
        }
    }
    
    ull dp_2 = 1;
    
    ull dp_1;
    if(!aq.empty() && aq.front() == 1) {
        dp_1 = 0;
        aq.pop();
    } else { 
        dp_1 = 1;
    }
    
    ull dp = dp_1;
    
    for(uint i=2; i<=N; i++) {
        if(!aq.empty() && aq.front() == i) {
            dp = 0;
            aq.pop();
        } else {
            dp = (dp_1 + dp_2) % mod;
        }
        
        dp_2 = dp_1;
        dp_1 = dp;
    }
    
    cout << dp;
    return 0;
    
}


Measured memory_bytes: 512
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int a = 0, b = 0, c = 0, d = 0, e = 0, k = 0, greater = 0, smaller = 200, coords[6];

    scanf("%d", &coords[0]);
    scanf("%d", &coords[1]);
    scanf("%d", &coords[2]);
    scanf("%d", &coords[3]);
    scanf("%d", &coords[4]);
    scanf("%d", &k);

    for (int i = 0; i < 5; i++) {
        greater = (greater > coords[i]) ? greater : coords[i];
        smaller = (smaller < coords[i]) ? smaller : coords[i];
    }

    if (greater-smaller > k) printf(":(\n");
    else printf("Yay!\n");

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

int main() {
    int data[ 4 ] [ 3 ] [ 10 ] = {} ;
    int n ;
    std::cin >> n ;
    for( int i = 0 ; i < n ; i++ ) {
        int b , f , r , v ;
        std::cin >> b >> f >> r >> v ;
        data[ b - 1 ] [ f - 1 ] [ r - 1 ] += v ;
    }
    
    for( int b = 0 ; b < 4 ; b++ ) {
        for( int f = 0 ; f < 3 ; f++ ) {
            for( int r = 0 ; r < 10 ; r++ ) {
                std::cout << " " << data[ b ] [ f ] [ r ] ;
            }
            std::cout << std::endl ;
        }
        if( b != 3 ) {
            std::cout << "####################" << std::endl ;
        }
    }
            
}



Measured memory_bytes: 3104
S = input().replace('dream', 'A').replace('erase', 'B').replace('er', 'C').replace('r', 'D')
N = len(S)

for i in range(N):
    if S[i] in 'AB':
        continue
    elif S[i] == 'C':
        if i == 0 or S[i-1] != 'A':
            print('NO')
            exit()
    elif S[i] == 'D':
        if i == 0 or S[i-1] != 'B':
            print('NO')
            exit()
    else:
        print('NO')
        exit()
print('YES')



Measured memory_bytes: 40176
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N; cin >> N;
    ll ans = 0;
    for(ll i = 1; i < N; i++) ans += i;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register int i=(a);i<=(b);i++)
#define For(i,a,b) for (register int i=(a);i>=(b);i--)
#define mem(i,j) memset(i,j,sizeof(i))
#define GO(u) for (register int j=f[u];j!=-1;j=nxt[j])
using namespace std;
typedef long long ll;
const int N=1010;
int n,m,a,b,ans[N][N];
int main()
{
    cin>>n>>m>>a>>b;
    FOR(i,1,n)
    {
        FOR(j,1,m)
        {
            if (i<=b&&j<=a) ans[i][j]=1;
            else if (i>b&&j>a) ans[i][j]=1;
            
        }
    }
    FOR(i,1,n)
    {
        FOR(j,1,m) printf("%d",ans[i][j]);
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  21
ll dp[N][1<<21];
ll n;
ll arr[N][N];
ll dps(ll ind,ll rem)
{
    // cout<<ind<<" "<<rem<<endl;
    if(rem==0)
        return 1;
    if(ind==0)
    {
        rep(i,0,n)
        {
            if(((1<<i)==rem)&&arr[0][i]==1)
                return 1;
        }
        return 0;
    }
    if(dp[ind][rem]!=-1)
        return dp[ind][rem];
    dp[ind][rem]=0;
    rep(i,0,n)
    {
        if((rem&(1ll<<i))&&arr[ind][i]==1)
        {
            dp[ind][rem]=(dp[ind][rem]+dps(ind-1,rem-(1<<i)))%hell;
        }
    }
    return dp[ind][rem];
}
void solve()
{
    cin>>n;
    rep(i,0,n)rep(j,0,n)cin>>arr[i][j];
    memset(dp,-1,sizeof(dp));
    cout<<dps(n-1,(1<<n)-1);
    // rep(i,0,n)
    // {
    //     rep(j,0,8)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 347684
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;
using namespace std;

int main() {
	ll n,m,s,t,a,b,c;
	vector<ll>vec;

	cin >> n >> m;
	for (ll i = 0; i < n; i++) {
		cin >> a;
		vec.push_back(a);
	}
	sort(vec.begin(), vec.end());

	vector<pair<ll, ll> > pairs(m);

	for (ll i = 0; i < m; i++) {
		cin >> b >> c;
		pairs[i] = make_pair(c,b);
	}

	// firstが小さい順、secondが小さい順にソート
	sort(pairs.begin(), pairs.end());


	ll flag = 1,index=0,index2=m-1;
	while (index2!=-1) {
		if (vec[index] > pairs[index2].first || index >= n ) {
			break;
		}
		if (vec[index] < pairs[index2].first) {
			vec[index] = pairs[index2].first;
			index++;	
			pairs[index2].second--;
		}
		else {
			break;
		}
		if (pairs[index2].second <= 0)index2--;
	}
	ll sum = 0;
	for (ll i = 0; i < n; i++) {
		sum += vec[i];
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 2676
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	string s;
	cin>>s;
	if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3])cout<<"Bad"<<endl;
	else cout<<"Good"<<endl;

	return 0;
}


Measured memory_bytes: 256
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

char w[9][5] = {
  {'.', ',', '!', '?', ' '},
  {'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 n;
char c[1030];
int t;
P s[80];
char o[80];
int l;

void input(){
  cin>>c;
  l = strlen(c);
  REP(i, 80)s[i] = mp(0, 0);
}

void solve(){
  t=0;

  REP(i, l) {
    if(c[i]=='0') {
      if(s[t].ft==0)continue;
      else t++;
    }else {
      if(s[t].ft==0)s[t].ft=c[i]-'0';
      else s[t].sd++;
    }
  }

  REP(i, t) {
    s[i].ft--;
    o[i] = w[s[i].ft][s[i].sd%(s[i].ft==0?5:(s[i].ft==6||s[i].ft==8?4:3))];
  }
  o[t] = '\0';
  cout<<o<<endl;
}

int main(){
  cin.tie(0);
  
  cin>>n;
  REP(i, n) {
    input();
    solve();
  }
  
  return 0;
}

Measured memory_bytes: 3044
#include<cstdio>
#include<map>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>

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

using namespace std;

int main(){
	int a[100000]={},b[100002]={};
	int n;cin>>n;
	REP(i,n){
		cin>>a[i];
		b[a[i]]++;
		b[a[i]+1]++;
		b[a[i]+2]++;
	}

	sort(b,b+100002,greater<int>());
	cout<<b[0]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int a[26];
int main() {
  string s;
  cin>>s;
  int n=s.size();
  for(int i=0;i<n;i++){
    int x=s[i]-'a';
    a[x]++;
  }
  int kotae=n;
  for(int i=0;i<26;i++){
    int tmp=0;
    int nagasa=0;
    if(a[i]==n){
      cout<<0<<endl;
      return 0;
    }
    if(a[i]!=0){
      //cout<<a[i]<<" ";
      for(int k=1;k<=a[i];k++){
        for(int j=0;j<n;j++){
          if(s[j]==(char)(i+'a')){
            if(tmp==0){
              nagasa=max({j,j-tmp-1,nagasa});
            }else{
              nagasa=max(j-tmp-1,nagasa);
            }
            tmp=j;
          }
        }
        nagasa=max(nagasa,n-tmp-1);
        //cout<<nagasa<<" ";
        kotae=min(nagasa,kotae);
      }
    }
  }
  cout<<kotae<<endl;
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);
    
    int extra = 0;
    for(int i = 0; i < n - 1;i++){
        while(a[i + 1] == a[i] ){
            i++;
            extra++;
        }
    }
    if(extra % 2 == 1){
        cout << n - extra - 1;
    }
    else{
        cout << n - extra;
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std; typedef long long ll; const int INF=1e9; typedef pair<ll,ll> P;

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

int main() {
  int n,k; cin>>n>>k;
  int a[n]; int mx=-1e9;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) mx=max(mx,a[i]);
  
  if (mx < k) return puts("IMPOSSIBLE")*0;

  int g=a[0];
  for(int i=1;i<n;i++) g=gcd(g,a[i]);
  if (k%g) return puts("IMPOSSIBLE")*0;
  else return puts("POSSIBLE")*0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };

bool f=false;
int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b==c) f=true;
	if(b+c==a) f=true;
	if(c+a==b) f=true;
	if(f) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    main(){
      int n;
      cin>>n;
      int arr[n];
      for(int i = 0; i < n; i++) cin>>arr[i];
      
      arr[0]--;
      for(int i = 1; i < n; i++){
    	if(arr[i] > arr[i - 1]) arr[i]--;
      }
      for(int i = 1; i < n; i++){
        if(arr[i] < arr[i - 1]){
          cout<<"No";
          return 0;
        }
      }
      cout<<"Yes";
    }

Measured memory_bytes: 640
#include <stdio.h>
 
int main(void)
{
	long long total=0,i;
	int N;
	scanf("%d",&N);
	for(i=1;i<=N;i++){
		if(i%3!=0&&i%5!=0)total=(long long)total+i;
	}
	printf("%lld",total);
	return 0;
}

Measured memory_bytes: 1732
N=int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans=0
j=0
 
for i in range(N):
	ans+=B[A[i]-1]
	if A[i]-j==1 and i>=1:
		ans+=C[j-1]
	j=A[i]

print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;

class Dice
{
  public int[] dice = new[] { 1, 5, 4, 2, 3, 6 };
  public void North() {
    int tmp = dice[0];
    dice[0] = dice[3];
    dice[3] = dice[5];
    dice[5] = dice[1];
    dice[1] = tmp;
  }

  public void East() {
    int tmp = dice[0];
    dice[0] = dice[2];
    dice[2] = dice[5];
    dice[5] = dice[4];
    dice[4] = tmp;
  }

  public void South() {
    int tmp = dice[0];
    dice[0] = dice[1];
    dice[1] = dice[5];
    dice[5] = dice[3];
    dice[3] = tmp;
  }

  public void West() {
    int tmp = dice[0];
    dice[0] = dice[4];
    dice[4] = dice[5];
    dice[5] = dice[2];
    dice[2] = tmp;
  }

  public void Right() {
    int tmp = dice[1];
    dice[1] = dice[2];
    dice[2] = dice[3];
    dice[3] = dice[4];
    dice[4] = tmp;
  }

  public void Left() {
    int tmp = dice[1];
    dice[1] = dice[4];
    dice[4] = dice[3];
    dice[3] = dice[2];
    dice[2] = tmp;
  }
}


class Program
{
  
  public static int Main() {
    Scanner cin = new Scanner();
    while (true)
    {
      int ans = 1, n = cin.nextInt();
      if (n == 0)
      {
        break;
      }
      Dice dice = new Dice();
      for (int i = 0; i < n; i++)
      {
        switch (cin.next())
        {
          case "North":
            dice.North();
            break;
          case "East":
            dice.East();
            break;
          case "South":
            dice.South();
            break;
          case "West":
            dice.West();
            break;
          case "Right":
            dice.Right();
            break;
          case "Left":
            dice.Left();
            break;
        }
        ans += dice.dice[0];
      }
      Console.WriteLine(ans);
    }
    return 0;
  }

  
}

class Scanner {
  string[] s;
  int i;

  char[] cs = new char[] { ' ' };

  public Scanner() {
    s = new string[0];
    i = 0;
  }

  public string next() {
    if (i < s.Length) return s[i++];
    do {
      s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
    } while ((s.Length == 1 && s[0] == "") || s.Length == 0);
    i = 0;
    return s[i++];
  }

  public int nextInt() {
    return int.Parse(next());
  }

  public long nextLong() {
    return long.Parse(next());
  }

  public double nextDouble() {
    return double.Parse(next());
  }

}

Measured memory_bytes: 5856
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n,sum=0,k;
	cin>>n;	
	k=n;
	while(n>0){
		sum+=n%10;
		n=n/10;
	}

	if(k%sum==0) cout<<"Yes"; else cout<<"No";

   return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();
	        Double X = 0.0;
	        String U = "no word";
	        Double ans = 0.0;
	        
		 	for (int i=0; i<N; i++){
		 		X = sc.nextDouble();
		 		U = sc.nextLine();

	        	if(U.equals(" BTC")){
	        		X = X * 380000.0;
	        	}
	        	ans = ans + X;
		 	}
	        System.out.println(ans);
	}
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main() {
    ll n;cin >>n;
    vector<ll>a(n+1);
    vector<ll>b(n);
    for (int i = 0; i < n + 1; ++i) {
        cin >>a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >>b[i];
    }
    ll ans=0;
    for (int i = 0; i < n; ++i) {
        if(a[i]>=b[i]){
            ans+=b[i];
            a[i]-=b[i];
        }
        else if(a[i]+a[i+1]>b[i]){
            ans+=b[i];
            b[i]-=a[i];
            a[i]=0;
            a[i+1]-=b[i];
        }
        else {
            ans+=a[i]+a[i+1];
            a[i]=a[i+1]=0;
        }
//        for (int j = 0; j < n + 1; ++j) {
//            cout <<a[j]<<" ";
//        }
//        cout <<endl;
//        cout <<ans <<endl;
    }
    cout <<ans <<endl;
    return 0;
}



Measured memory_bytes: 1792
H,W,K = map(int,input().split(" "))

C = []
for i in range(H):
    row = list(input())
    C.append(row)

#print(C)

pattern = 0

for markR in range(1<<H):
    for markC in range(1<<W):
        black = 0
        for i in range(H):
            for j in range(W):
                if (markR>>i) & 1 == 0 and (markC>>j) & 1 == 0 and C[i][j] == "#":
                    black += 1
        if black == K:
            pattern += 1

print(pattern)

Measured memory_bytes: 9024
N = int(input())
xl = []
for i in range(N):
  x,l =[int(x) for x in input().split()]
  a = max(x-l,0)
  xl.append([a,x+l])
xl = sorted(xl,key = lambda x:x[1])
#print(xl)
minx=xl[0][0]
maxx=xl[0][1]
cnt=0
for i in range(1,N):
  if maxx<=xl[i][0]:
    maxx=xl[i][1]
  else:
    cnt+=1
print(N-cnt)

Measured memory_bytes: 22144
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[200100];

void solve() {
    deque<int> deq;
    deq.push_back(a[0]);
    for (int i = 1; i < n; i++) {
        if (i%2) {
            deq.push_back(a[i]);
        } else {
            deq.push_front(a[i]);
        }
    }
    if (n%2 == 0) {
        reverse(ALL(deq));
    }

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


Measured memory_bytes: 3840
#include<stdio.h>
 
int main(void) {
	int R, N;
	int x;
    
   scanf("%d %d", &N, &R);
 
	if ((1 <= N) && (N <= 9)) {
		x = R + 100 * (10 - N);
	}
	else if (10 <= N) {
		x = R;
	}
	else return 0;
 
	printf("%d", x);
 
	return 0;
 
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    int N = 0, Q = 0;
    cin >> N >> Q;
   
    string S;
    cin >> S;
    
    int t[S.length()] = {};
    
    for(int i = 0; i < S.length(); i++){
        if(S.substr(i,2) == "AC"){
            t[i+1] = t[i] + 1;
        }else{
            t[i+1] = t[i];
        }
    }
    
    int l[N][2] = {};
    
    for(int i = 0; i < Q; i ++){
        cin >> l[i][0] >> l[i][1];
    }

    for(int i = 0; i < Q; i ++){
        cout << t[l[i][1]-1] - t[l[i][0]-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 2176
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1e9+7;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
llint rui(llint in,int zyo){//inのzyo乗を計算します
	llint ans=1,gen=in;
	for(int h=0;h<30;h++){
		if(zyo&(1<<h)){ans*=gen;ans%=mod;}
		gen*=gen;gen%=mod;
	}
	return ans;
}
int main(void){
	int n,i,j;cin>>n;
	//1～n,晩兵のn+1,さらに晩兵
	vector<int>h(n+3);
	for(i=1;i<=n;i++){cin>>h[i];}h[n+1]=1;
	vector<pair<int,int>>taka(n+1);
	for(i=1;i<=n+1;i++){taka[i-1]=mp(h[i],i);}
	SO(taka);REV(taka);
	vector<bool>mite(n+3);
	vector<int>hi(n+3);//左端を示します
	vector<int>mg(n+3);//左端を示します
	for(i=0;i<n+3;i++){hi[i]=i;mg[i]=i;}
	vector<llint>free(n+3);
	vector<llint>same(n+3);
	vector<llint>when(n+3);//前にいつ見たか
	for(i=0;i<=n;i++){
		int naga=taka[i].fir;
		int ter=taka[i].sec;
		mite[ter]=1;
		
		free[ter]=1;
		same[ter]=0;
		when[ter]=naga;
		if(mite[ter+1]){
			int net=ter+1;
			mg[ter]=mg[net];
			hi[mg[net]]=ter;
			free[net]*=rui(2,when[net]-naga);
			free[net]%=mod;
			llint f=free[ter]*free[net];
			llint s=2*(free[ter]+same[ter])*(free[net]+same[net])-f;
			free[ter]=f%mod;same[ter]=s%mod;when[ter]=naga;
		}
		if(mite[ter-1]){
			//マージします
			int net=hi[ter-1];
			hi[mg[ter]]=net;
			mg[hi[net]]=mg[ter];
			free[net]*=rui(2,when[net]-naga);
			free[net]%=mod;
			llint f=free[ter]*free[net];
			llint s=2*(free[ter]+same[ter])*(free[net]+same[net])-f;
			free[net]=f%mod;same[net]=s%mod;when[net]=naga;
		}
		//cerr<<"free";for(j=1;j<=n+1;j++){cerr<<free[j]<<" ";}cerr<<endl;
		//cerr<<"same";for(j=1;j<=n+1;j++){cerr<<same[j]<<" ";}cerr<<endl;
	}
	cout<<(free[1]+same[1])%mod<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			//例 12=2*2*3=2^2 * 3^1
			//a=2^p * 3^q
			//b=2^t * 3^s
			//p, tが少なくとも一つ2である必要
			//p,tの並びは(2+1)*(2+1)
			//全部2でない並びは 2*2
			//よって少なくとも一つ2であるのは(2+1)*(2+1)-2*2
			//q,sも同様
			while (sc.hasNext()) {
				long L = sc.nextLong();
				if (L == 0) break;
				long ans = 1;
				for(long i=2; i*i<=L; i++) {
					if(L%i != 0) continue;
					L/=i;
					int count=1;
					while(L%i == 0) {
						L/=i;
						count++;
					}
					ans*=(count+1)*(count+1)-count*count;
				}
				if(L!=1) {
					ans*=2*2-1*1;
				}
				System.out.println((ans+1)/2);
			}
			
		}
	}
}


Measured memory_bytes: 50932
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	/** 一行で最大拾うアイテム数+1 */
	private static final int MAX = 4;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int r = scanner.nextInt(), c = scanner.nextInt(), k = scanner.nextInt();
			long[][] v = new long[r][c];
			IntStream.range(0, r).forEach(i -> Arrays.fill(v[i], 0L));
			IntStream.range(0, k).forEach(i -> v[scanner.nextInt() - 1][scanner.nextInt() - 1] = scanner.nextLong());
			long[][][] dp = new long[MAX][r][c];
			dp[0][0][0] = 0L;
			dp[1][0][0] = v[0][0];
			IntStream.range(0, r).forEach(i -> IntStream.range(0, c).forEach(j -> {
				if (i > 0) {
					dp[0][i][j] = max(dp[0][i][j],
							IntStream.range(0, MAX).mapToLong(l -> dp[l][i - 1][j]).max().getAsLong());
					if (v[i][j] > 0) {
						dp[1][i][j] = max(dp[1][i][j],
								IntStream.range(0, MAX).mapToLong(l -> dp[l][i - 1][j]).max().getAsLong() + v[i][j]);
					}
				}
				if (j > 0) {
					if (v[i][j] > 0) {
						dp[0][i][j] = max(dp[0][i][j], dp[0][i][j - 1]);
						IntStream.range(1, MAX).forEach(
								l -> dp[l][i][j] = max(dp[l][i][j], dp[l - 1][i][j - 1] + v[i][j], dp[l][i][j - 1]));
					} else {
						IntStream.range(0, MAX).forEach(l -> dp[l][i][j] = max(dp[l][i][j], dp[l][i][j - 1]));
					}
				}
			}));
			System.out.println(IntStream.range(0, MAX).mapToLong(l -> dp[l][r - 1][c - 1]).max().getAsLong());
		}
	}

	/**
	 * 複数のlongのmaxを取得する
	 * 
	 * @param a 一つ目のlong
	 * @param b 二つ目以降のlong
	 * @return 複数のlongのmax
	 */
	private static long max(long a, long... b) {
		long result = a;
		for (long l : b) {
			result = Math.max(result, l);
		}
		return result;
	}
}


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

int main(){ 
  int x, y, z;
  cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  cout << x << " " << y << " " << z << endl;
  return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {    
    int res = 0;
    int n;
    cin >> n;
    while (n > 0) {
        if (n % 10 == 2) res++;
        n /= 10;
    }
    cout << res << endl;
}




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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL mtr1[100][100], mtr2[100][100], ans[100][100] = {};
    int n, m, l;
    cin >> n >> m >> l;
    REP(i, n) {
        REP(j, m) {
            cin >> mtr1[i][j];
        }
    }
    REP(i, m) {
        REP(j, l) {
            cin >> mtr2[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            for (int k = 0; k < l; k++) {
                ans[i][k] += mtr1[i][j] * mtr2[j][k];
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            if (j) {
                cout << " ";
            }
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3464
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;

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

  long long int sqrtN = sqrt(N);
  long long int count = 0;
  for(int i = 1; i <= sqrtN; i++){
    if(N % i == 0){
      if( N / i - i >= 2)
      	count += (N / i) - 1;
    }
  }
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
a = MAP()

if not 1 in a:
    print(-1)
    exit(0)


serch = 1
ans=0
for i in a:
    if i==serch:
        serch+=1
    else:
        ans+=1
print(ans)

Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B, C; cin >> A >> B >> C;

    int ans = C - (A - B);
    if(ans > 0){
        cout << ans << endl;
    }
    else{
        cout << 0 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
n,m,l = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]
B = [list(map(int,input().split())) for i in range(m)]

ANS = [[0 for i in range(l)]for j in range(n)]
for ni in range(n):
  for li in range(l):
    for mi in range(m):
      ANS[ni][li] += A[ni][mi]*B[mi][li]
    if li!=l-1:
      print(ANS[ni][li],end=' ')
    else:
      print(ANS[ni][li])


Measured memory_bytes: 7048
#include<bits/stdc++.h>
 
using namespace std;
 
#define USE_IOSTREAM \
{\
	ios::sync_with_stdio(false);\
	cin.tie(0);\
	cout.tie(0);\
}
 
#define pii pair<int, int>
#define mp make_pair
 
typedef long long ll;
 
const int N = 550;
 
int ans[N*N];
 
int main()
{
	USE_IOSTREAM;
	int n, i, j, k, num;
	cin >> n;
	vector<int> vec;
	for (i = 1; i <= n; i++)
	{
		cin >> num;
		ans[num] = i;
		vec.push_back(num);
	}
	
	sort(vec.begin(), vec.end());
	
	int curIdx;
	for (i = 0, j = 1; i < n; i++)
	{
		curIdx = vec[i];
		num = ans[curIdx];
		for (k = 0; k < num - 1 && j < curIdx; j++)
		{
			if (ans[j] == 0)
			{
				ans[j] = num;
				k++;
			}
		}
		
		if (k < num - 1)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	
	for (i = vec.size() - 1, j = n*n; i >= 0; i--)
	{
		curIdx = vec[i];
		num = ans[curIdx];
		for (k = 0; k < n - num && j > curIdx; j--)
		{
			if (ans[j] == 0)
			{
				ans[j] = num;
				k++;
			}
		}
		
		if (k <  n - num)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	for (i = 1; i <= n*n; i++)
	{
		cout << ans[i] << " ";
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 2176