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

int main() {
  string S;
  cin >> S;
  int rain = 0;
  int ans = 0;
  for(int i = 0; i < 3; i++) {
    if(S[i] == 'R') rain++;
    else {
      ans = max(ans, rain);
      rain = 0;
    }
  }
  cout << max(ans, rain) << endl;
  return 0;
}


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

int main(){
	int n, k;
	cin >> n >> k;
	set<int> hash;
	while(k--){
		int d;
		cin >> d;
		while(d--){
			int a;
			cin >> a;
			hash.insert(a);
		}
	}
	int res = 0;
	for(int i=1; i<=n; i++){
		if(hash.find(i) == hash.end()){
			res++;
		}
	}
	cout << res << "\n";
}

Measured memory_bytes: 3612
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-10-29 17:48:30
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

ll A, B, K;

int main()
{
  cin >> A >> B >> K;
  for (auto i = 0; i < K; i++)
  {
    if (i % 2 == 0)
    {
      if (A % 2 == 1)
      {
        A--;
      }
      A = A / 2;
      B = B + A;
    }
    else
    {
      if (B % 2 == 1)
      {
        B--;
      }
      B = B / 2;
      A = A + B;
    }
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int n;
int arr[200100];

struct idxtree {
    int tree[530000];
    const int key = 262144;
    void init (){
        for (int i=0;i<key*2;i++) tree[i] = -INF;
    }
    void upd(int idx, int val) {
        idx+=key;
        tree[idx] = val;
        idx/=2;
        while(idx) {
            tree[idx] = max(tree[idx*2],tree[idx*2+1]);
            idx/=2;
        }
    }
    int getv(int s, int e) {
        s+=key; e+=key;
        int ans = -INF;
        while(s<=e){
            if (s&1) ans = max(ans,tree[s++]);
            if (~e&1) ans = max(ans,tree[e--]);
            s/=2;e/=2;
        }
        return ans;
    }
} it1, it2;
int k;
int big[200100];

int main() {
    scanf("%d%d",&n,&k);
    for (int i=0;i<n;i++) scanf("%d",&arr[i]);
    for (int i=0;i+1<n;i++)big[i+1] = (arr[i]<arr[i+1]);
    for (int i=1;i<n;i++)big[i]+=big[i-1];
    it1.init(); it2.init();
    for (int i=0;i<n;i++){
        it1.upd(i,arr[i]);
        it2.upd(i,-arr[i]);
    }
    int ans = n-k+1;
    vector<int> ed;
    for (int i=0;i<n-k;i++) {
        if (-it2.getv(i,i+k-1)==arr[i]&&it1.getv(i+1,i+k)==arr[i+k]) {
            ans--;
        }
        else ed.push_back(i);
    }
    ed.push_back(n-k);
    int c = -1;
    for (int &v : ed) {
        if (big[v+k-1]-big[v]==k-1) c++;
    }
    printf("%d\n",ans-max(c,0));

	return 0;
}


Measured memory_bytes: 7032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T>
inline T read(T&x){
	x=0;int f=0;char ch=getchar();
	while (ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x=f?-x:x;
}
const int N=1e5+10;
string s,t;
int main(){
	cin>>s>>t;
	s=s+s;
	if (s.find(t)!=string::npos) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cfloat>

using namespace std;

int main(int argc, char const *argv[])
{
    long long N;
    cin >> N;
    vector<long long> L;
    long long pre = 0;
    long long in;
    for (int i = 0; i < N; i++)
    {
        cin >> in;
        L.emplace_back(in + pre);
        pre = L[i];
    }

    double min = DBL_MAX;
    double d;
    for (int i = 0; i < N; i++)
    {
        d = abs((double)L[i] -  (double)L[N - 1] / 2.0);
        if (d < min) min = d;
    }
    
    cout << (long long)(min / 0.5) << endl;
    
    return 0;
}

Measured memory_bytes: 2420
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)


int main() {
    string s;
    cin >> s;
    ll sizeS = s.size();

    ll sentou=0;
    rep(i,sizeS){
        if(s[i] == 'A'){
            sentou = i;
            break;
        }
    }

    ll matubi=0;
    for(ll i=sizeS-1;i>=0;i--){
        if(s[i] == 'Z'){
            matubi = i;
            break;
        }
    }

    ll ans = matubi - sentou + 1;

    cout << ans << endl;
    
}



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

int main(){
 int s; cin >> s;
  if(s%3==0){
    if(s ==000){
      cout << 0 << endl;
    }
    else{
      cout << 3 << endl;
    }
  }
  if(s%3==1){
    cout << 1 << endl;
  }
  if(s%3==2){
    cout << 2 <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 2000000
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
//cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);

int H,a[MAX+1];

void maxheapify(int i){
    int l=2*i,r=2*i+1,largest;
    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 main() {
    cin>>H;
    for(int i=1;i<=H;i++) cin>>a[i];
    for(int i=H/2;i>=1;i--) maxheapify(i);
    for(int i=1;i<=H;i++){
        cout<<" "<<a[i];
    }
    cout<<endl;
    return 0;
}






Measured memory_bytes: 5032
#include <bits/stdc++.h>
#define pb push_back
#define mkp make_pair
#define llu unsigned long long int
#define ll long long
#define ld long double
#define foi(a,n) for(int i = a; i < n; i++)
#define foj(a,n) for(int j = a; j < n; j++)
#define foin(a,n) for(int i = n; i >= a; i--)
#define fojn(a,n) for(int j = n; j >= a; j--)
#define isp2(x) x&&(!(x&(x-1)))
#define ee 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define cases long long t;cin>>t;while(t--)

using namespace std;

int n;
int a[100002][3];
int dp[100002][3];


int main() {
    ll q, m, x, y, d;
    string s, h;
	cin >> n; 
	foi(0, n) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	foi(1, n){
		dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = a[i][2] + max(dp[i-1][1], dp[i-1][0]);
	}
	
	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));

}




Measured memory_bytes: 5928
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;


ve<vl> combination(51,vl(51,-1));

ll comb(int a, int b){
    
    if(combination[a][b] > 0) return combination[a][b];
    else if(a == 0 || b == 0 || a == b) return combination[a][b] = 1;
    else return combination[a][b] = comb(a-1,b-1) + comb(a-1,b);

    
}


int main()
{
    int N,P;
    cin >> N >> P;
    vi A(N);
    in(N,A);
    
    int a = 0,b = 0;
    ll ans = 0;
    
    
    rep(i,N){
        if(A[i]%2==0) a++;
        else b++;
    }
    
    
    rep(i,b+1){
        if(i%2 == P){
            rep(j,a+1){
                ans += comb(b,i)*comb(a,j);
            }
            
        }
    }
    
    cout << ans << endl;
    
    

    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll a, b;
  cin >> a >> b;
  for (ll i = 1; i < 10100; ++i) {
    if (i*8/100 == a && i*10/100 == b) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    string  s;
    cin >> s;    

if(s == "AAA" || s == "BBB"){
    cout << "No" << endl;
}else{
    cout << "Yes" << endl;
}

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[3];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        int[] l = new int[n];
        for (int i = 0; i < l.length; i++) {
            l[i] = sc.nextInt();
        }
        int[] bit = new int[3];
        int result = (int)Math.pow(10, 9);
        for (bit[0] = 1; bit[0] < (1 << n); bit[0]++) {
            for (bit[1] = 1; bit[1] < (1 << n); bit[1]++) {
                if ((bit[1] & bit[0]) != 0) {
                    continue;
                }
                for (bit[2] = 1; bit[2] < (1 << n); bit[2]++) {
                    if ((bit[2] & bit[0]) != 0 || (bit[2] & bit[1]) != 0) {
                        continue;
                    }
                    int[] len = new int[3];
                    int[] num = new int[3];
                    for (int i = 0; i < bit.length; i++) {
                        for (int j = 0; j < n; j++) {
                            if ((bit[i] & (1 << j)) != 0) {
                                len[i] += l[j];
                                num[i]++;
                            }
                        }
                    }
                    int score = 0;
                    for (int i = 0; i < num.length; i++) {
                        score += Math.abs(len[i] - a[i]) + (num[i] - 1) * 10;
                    }
                    result = Math.min(result, score);
                }   
            }
        }
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 26536
#include <cstdio>
#include <bitset>
using namespace std;
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
bitset<1008> f;
int e[702][702], vis[702], q[702], cnt[3];
int main(){
	register int n, m, i, j, u, v, qh, qt, ans;
	scanf("%d %d", &n, &m);
	for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) if (i != j) e[i][j] = 1;
	for (i = 1; i <= m; ++i) {
		scanf("%d %d", &u, &v);
		e[u][v] = e[v][u] = 0;
	}
	f.set(0);
	for (i = 1; i <= n; ++i) if (vis[i] == 0) {
		q[qh = qt = 0] = i;
		vis[i] = 1;
		cnt[1] = cnt[2] = 0;
		while (qh <= qt) {
			u = q[qh];
			++qh;
			++cnt[vis[u]];
			for (v = 1; v <= n; ++v) if (e[u][v]) {
				if (vis[v]) {
					if ((vis[u] ^ vis[v]) != 3) {
						puts("-1");
						return 0;
					}
				}
				else {
					vis[v] = vis[u] ^ 3;
					q[++qt] = v;
				}
			}
		}
		f = f << cnt[1] | f << cnt[2];
	}
	ans = n * n;
	for (i = 1; i <= n; ++i) if (f[i]) {
		cmin(ans, i * (i - 1) + (n - i) * (n - i - 1) >> 1);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

string S, T;
int ssize, tsize;
vector<vector<int>> pos;

//にぶたん
//右にあるもののうち一番左を求める
int searchRight(char c, int nowPos){
	int l = 0, m, r = pos[c-'a'].size() - 1;
	//isTrue()はbool型関数, 右側ならtrue, 左側ならfalse
	if(pos[c-'a'][l] > nowPos/*isTrue(l)*/)return pos[c-'a'][l];//全部右にある
	if(pos[c-'a'][r] <= nowPos/*!isTrue(r)*/)return -1;//ひとつも右にない
	while(true){
		m = (l + r) / 2;
		if(pos[c-'a'][m] > nowPos/*isTrue(m)*/){
			if(pos[c-'a'][m-1] <= nowPos/*!isTrue(m - 1)*/){
				return pos[c-'a'][m];
			}
			r = m - 1;
		}
		else{
			l = m + 1;
		}
	}
}

int main(){

    cin >> S >> T;
    ssize = S.size();
    tsize = T.size();
    pos = vector<vector<int>>(26);
    for(int i = 0; i < ssize; i++){
        pos[S[i]-'a'].pb(i);
    }
    for(int i = 0; i < tsize; i++){
        if(pos[T[i]-'a'].size() == 0){
            cout << "-1" << endl;
            return 0;
        }
    }

    int nowPos = -1, nextpos;
    ll ans = 0;
    for(int i = 0; i < tsize; i++){
        nextpos = searchRight(T[i], nowPos);
        //cout << nextpos << endl;
        if(nextpos == -1){
            nextpos = pos[T[i]-'a'][0];
            ans += ssize - nowPos + nextpos;
        }
        else{
            ans += nextpos - nowPos;
        }
        nowPos = nextpos;
        //cout << i << SPACE << ans << endl;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1344
/* ex3-4
    kas056 */
#include <stdio.h>
int main(void){
    //積cross,フラグflagの設定
    int N,cross,flag;
    scanf("%d",&N);

    //flagの初期値設定
    flag = 0;
    /*1<=i<=9の範囲内のiと、1<=j<=9の範囲内のjで
    九九を全て表すことが出来る。ループを用いて積を出す。*/
    for(int i = 1; i < 10 ; i ++){
        for (int j = 1; j<10; j++){
            cross = i * j;
            if (N == cross){//Nとcrossが一致したら
                flag = 1;//フラグを立てる
            }
        }
    }
    if (flag == 1){//フラグがたっていたら
        printf("%s\n","Yes");//Yesを出力
    }
        
    else{//立ってなかったら
        printf("%s\n","No");//Noを出力
    }

    return 0;
}


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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int N, x; cin >> N >> x;
  int K = 2 * N - 1;
  if (x == 1 || x == K) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes\n";
  if (N == 2) {
    cout << "1\n2\n3\n";
    return 0;
  }
  vector<int> p(K);
  int lmin = N-2;
  int lmax = N;
  if (x+2 <= K) {
    p.at(N-3) = x+2;
    lmin = N-3;
  }
  p.at(N-2) = x-1;
  p.at(N-1) = x;
  p.at(N)   = x+1;
  if (x-2 >= 1) {
    p.at(N+1) = x-2;
    lmax = N+1;
  }
  int y = 1;
  int i = 0;
  while (i < K) {
    if (i == lmin) {
      i = lmax + 1;
      continue;
    }
    if (x-2 <= y && y <= x+2) {
      y = x + 3;
    }
    p.at(i) = y;
    i++;
    y++;
  }
  for (int j = 0; j < K; j++) cout << p.at(j) << "\n";

  return 0;
}



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  for (int i = 0; i < n; i++)
    cin >> h.at(i);
  
  vector<bool> good(n, true);
  for (int i = 0; i < m; i++) {
    int a0, b0;
    cin >> a0 >> b0;
    int a1 = a0 - 1, b1 = b0 - 1;
    if (h.at(a1) < h.at(b1))
      good.at(a1) = false;
    else if (h.at(a1) > h.at(b1))
      good.at(b1) = false;
    else {
      good.at(a1) = false;
      good.at(b1) = false;
    }
  }
  
  int res = 0;  
  for (int i = 0; i < n; i++) {
    if (good.at(i))
      res++;
  }
  
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3728
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

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

// ?´??????°????§£(????????????)
vector<int> factor(int n)
{
    vector<int> facs;
    int sqrtn = static_cast<int>(sqrt(n));

    // 2????????°
    if(n % 2 == 0) {
        facs.push_back(2);
        while(n % 2 == 0) n /= 2;
    }
    // 3????????°
    if(n % 3 == 0) {
        facs.push_back(3);
        while(n % 3 == 0) n /= 3;
    }

    // 6n?±1
    for(int i = 6; i-1 <= sqrtn; i += 6) {
        if(n % (i-1) == 0) {
            facs.push_back(i-1);
            while(n % (i-1) == 0) n /= i-1;
        }
        if(n % (i+1) == 0) {
            facs.push_back(i+1);
            while(n % (i+1) == 0) n /= i+1;
        }
    }

    if(n != 1)
        facs.push_back(n);

    return facs;
}

int main()
{
    int n;
    scanf("%d\n", &n);

    vector<int> facs = factor(n);
#if 0
    for(unsigned int i = 0; i < facs.size(); ++i) {
        printf("%d ", facs[i]);
    }
    puts("");
#endif

    // ??¬????????¨
    int cnt = n;
    for(int p : facs) {
        cnt /= p;
        cnt *= p-1;
    }

    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 2724
from collections import deque
s = deque(input())
q_num = int(input())
d = 0
for _ in range(q_num):
    q = input().split()
    if q[0] == '1':
        d = 1 - d
    else:
        if d == 0 and q[1] == '1' or d == 1 and q[1] == '2':
            s.appendleft(q[2])
        else:
            s.append(q[2])

s = ''.join(s)
if d == 1:
    s = s[::-1]
print(s)



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

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

  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int mini = i;

    for (int j = i; j < n; ++j)
      if (seq[j] < seq[mini])
        mini = j;

    if (mini != i) {
      int tmp = seq[i];
      seq[i] = seq[mini];
      seq[mini] = tmp;
      ++cnt;
    }
  }

  cout << seq[0];
  for (int i = 1; i < n; ++i)
    cout << " " << seq[i];
  cout << endl << cnt << endl;


  return EXIT_SUCCESS;
}


Measured memory_bytes: 3084
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] a_asArgs)
        {
			for (int l_iBuf = 0; l_iBuf < 3; l_iBuf++)
			{
				Console.Write(Console.ReadLine()[l_iBuf]);
			}
			Console.WriteLine();
		}
	}
}


Measured memory_bytes: 13140
N,T = map(int,input().split())

list_c_t = []
for i in range(N):
  list_c_t.append(list(map(int,input().split())))


list_cut = [i[0] for i in list_c_t if i[1] <= T]
if len(list_cut) == 0:
  print('TLE')
else:
  print(min(list_cut))

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS


#define	Rd(s) scanf("%d", &s)
#define	Rs(s) scanf("%s", &s)
#define	Rf(s) scanf("%f", &s)

#define RTNd(n, s, i) for (int i = 0;(i<n) ? scanf("%d", &s), true : false;i++)
#define RTNf(n, s, i) for (int i = 0;(i<n) ? scanf("%lf", &s), true : false;i++)

#define RTEs(s) while (fgets(s, sizeof(s), stdin) != NULL)
#define RTEc(s) while ((s = scanf("%c")) != EOF)

#define Pd(s) printf("%d", s);
#define Pf(s) printf("%f", s);

#define Pn printf("\n");

#define SORTV(v) sort(v.begin(), v.end())
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long lli;
using namespace std;

int main() {
	int C=0, F=0;
	char c;

	while (scanf("%c", &c), c != '\n') {
		if ((C==0) &&( c == 'C'))C=1;
		if ((F == 0) && (C == 1) && (c == 'F'))F = 1;
	}
	if (F == 1) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}
//改行注意



Measured memory_bytes: 256
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <bits/stdc++.h>  
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vl vector<ll>
#define N 100005
#define mod 1000000007


int main()
{
    ll n;cin>>n;
    while(n)
    {
        ll x=n%10;
        if(x==9)
        {
            cout<<"Yes"<<"\n";return 0;
        }
        n/=10;
    }
    cout<<"No"<<"\n";
    return 0;
}

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

int main() {
    string S;
    cin >> S;
    ll N = S.size();
    ll sum = 0;
    for (ll bit = 0; bit < (1 << (N-1)); bit++) {
        ll t = S[0]-'0';
        for (ll i = 0; i < N-1; i++) {
            if (bit & (1 << i)) {
                sum += t;
                t = S[i+1]-'0';
            }
            else {
                t *= 10;
                t += S[i+1]-'0';
            }
        }
        sum += t;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut count = 0;
    let mut ans = false;
    for i in 0..n {
        let v = read_vec::<usize>();
        if v[0] == v[1] {
            count += 1;
        } else {
            count = 0;
        }
        if count >= 3 {
            ans = true;
        }
    }
    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2136
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
int n; 
char s;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		printf("ACL"); 
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl


void solve(long long N, std::vector<long long> P){
  int ans = 1;
  int minN = P.at(0);
  FOR(x, 1, N) {
    if (minN > P.at(x)){
      ++ans;
      minN = P.at(x);
    }
  }
  
  cout << ans << endl;
}

signed main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> P(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&P[i]);
  }
  solve(N, std::move(P));
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;


        int n,m;
        cin>>n>>m;
        if(n==m)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;


return 0;
}







Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main()
{
    int a,b,z;
    
    cin >> a >> b;
   z=a-b;
   
    if (z > 0)
      cout << "a"<<" " <<">"<<" "<<"b"<< endl;
    else if (z < 0)
        cout << "a"<<" " <<"<"<<" "<<"b"<< endl;
    else
      cout << "a == b" << endl;
   
    return 0;
}


Measured memory_bytes: 3092
package main

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

func main() {
	fsc := NewFastScanner()
	S := fsc.Next()
	N := len(S)
	if N < 4 || S[0:4] != "YAKI" {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

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

	return result
}

func (s *FastScanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

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

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 640
def d_islands_war(N, M, Demands):
    demands = sorted(Demands, key=lambda x: x[1])
    _, previous_cut = demands[0]  # previous_cut番目の島のすぐ西の橋を切る
    ans = 1
    for a, b in demands[1:]:
        if a >= previous_cut:
            # 要望を満たすためにb番目の島のすぐ西の橋を切らねばならない
            ans += 1
            previous_cut = b
    return ans

N, M = [int(i) for i in input().split()]
Demands = [[int(i) for i in input().split()] for j in range(M)]
print(d_islands_war(N, M, Demands))

Measured memory_bytes: 23700
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 998244353; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


void solve() {
	int N; cin >> N;
	int ans = 0;
	string S; cin >> S;
	REP(i, N - 2) {
		if (S.substr(i, 3) == "ABC")ans++;
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 256
n = gets.to_i


def prime?(n)
  return false if n < 2
  return true  if n == 2 or n == 3
  return false if (n % 2).zero?
  3.step(Math.sqrt(n).to_i, 2) {|i| return false if (n % i).zero?}
  true
end
flag = 0
while flag == 0
  if prime?(n)
    flag = 1
  else
    n+=1
  end
end
puts n

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  int n;
  cin>>n;
  ll sum=0;
  rrep(i,n){
    if(i%3==0||i%5==0) continue;
    sum+=i;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
		int p[]=new int[n];
		for(int i=0;i<n;i++) {
			p[i]=scan.nextInt()+1;
		}
		scan.close();


		double max=0;
		double ans=0;
		for(int i=0;i<n;i++) {
			if(i<k)ans+=p[i];
			else ans+=p[i]-p[i-k];

			if(ans>max)max=ans;
		}

		System.out.println(max/2);
	}
}

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

int main () {
    int h, w; cin >> h >> w;
    rep(i, 0, w + 2) cout << '#';
    cout << endl;
    rep(i, 0, h) {
        string s;
        cin >> s;
        cout << '#' << s << '#' << endl;
    }
    rep(i, 0, w + 2) cout << '#';
    cout << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from collections import deque
def inpl(): return tuple(map(int, input().split()))

H, W = inpl()

S = []
for _ in range(H):
    S.append(input())

M = [[50*50*10 if S[h][w]=="." else -1 for w in range(W)] for h in range(H)]

Q = deque() #step, H, W
Q.append([1, 0, 0])

ok = False
while Q:
    s, h, w = Q.popleft()
    if h == H-1 and w == W-1:
        ok = True
        break
    
    if h > 0:
        if M[h-1][w] > s+1:
            M[h-1][w] = s+1
            Q.append([s+1, h-1, w])
    
    if h < H-1:
        if M[h+1][w] > s+1:
            M[h+1][w] = s+1
            Q.append([s+1, h+1, w])

    if w > 0:
        if M[h][w-1] > s+1:
            M[h][w-1] = s+1
            Q.append([s+1, h, w-1])
    
    if w < W-1:
        if M[h][w+1] > s+1:
            M[h][w+1] = s+1
            Q.append([s+1, h, w+1])

if ok:
    b = sum([s.count("#") for s in S])
    print(H*W - b - s)
else:
    print(-1)

Measured memory_bytes: 3316
import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit = {
    val a = sc.nextInt
    val b = sc.nextInt
    val k = sc.nextInt

    val d = gcd(a,b)
    val r = (d to 1 by -1).filter(d % _ == 0)(k - 1)

    println(r)
  }

  def gcd(a: Int , b: Int): Int ={
    if(b == 0) a
    else
    if(a < b) gcd(b,a)
    else gcd(a % b,b)
  }

}

Measured memory_bytes: 25544
#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;

ll solve(void);

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

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

	ll ans = inf;
	for (ll i = 1; i * i <= n ; i++)
	{
		if (n % i == 0)
			ans = min(ans, abs(i - 1) + abs(n/i - 1));
	}
	cout << ans << endl;

	return 0;
}



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

int main() {
  long long N,K;
  cin >> N>>K;
  vector<long long>H(N);
  for(long long i=0;i<N;i++){
    cin>>H[i];
  }
  long long ans=0;
  int long C=0;
  sort(H.begin(), H.end());
  reverse(H.begin(), H.end());
  for(long long i=0+K;i<N;i++){
    ans+=H[i];
  }
  cout<<ans<<endl;
}

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

ll h,w,k,a,b,m,n;

int main(){
    cin>>h>>w>>k;
    cin>>a>>b>>m>>n;
    char c[h+1][w+1];
    
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>c[i][j];
        }
    }
    
    queue<pair<ll,ll> > q;
    ll vis[h+1][w+1];
    memset(vis,-1,sizeof(vis));
    
    vis[a][b]=0;
    q.push(make_pair(a,b));
    
    while(!q.empty()){
        ll x=q.front().first,y=q.front().second;
        q.pop();
        
        for(int i=1;i<=k;i++){
            if(y+i<=w){
                if(c[x][y+i]=='.' && (vis[x][y+i]==-1 || vis[x][y+i]==vis[x][y]+1)){
                    if(vis[x][y+i]==-1){
                        vis[x][y+i]=vis[x][y]+1;
                        q.push(make_pair(x,y+i));
                    }
                }
                else
                    break;
            }
        }
        
        for(int i=1;i<=k;i++){
            if(y-i>0){
                if(c[x][y-i]=='.' && (vis[x][y-i]==-1 || vis[x][y-i]==vis[x][y]+1)){
                    if(vis[x][y-i]==-1){
                        vis[x][y-i]=vis[x][y]+1;
                        q.push(make_pair(x,y-i));
                    }
                }
                else
                    break;
            }
        }
        
        for(int i=1;i<=k;i++){
			if(x+i<=h){
				if(c[x+i][y]=='.' && (vis[x+i][y]==-1 || vis[x+i][y]==vis[x][y]+1)){
					if(vis[x+i][y]==-1){
						vis[x+i][y]=vis[x][y]+1;
						q.push(make_pair(x+i,y));
					}
				}
				else 
                    break;
			}
		}
		
		for(int i=1;i<=k;i++){
			if(x-i>0){
				if(c[x-i][y]=='.' && (vis[x-i][y]==-1 || vis[x-i][y]==vis[x][y]+1)){
					if (vis[x-i][y]==-1) {
						vis[x-i][y]=vis[x][y]+1;
						q.push(make_pair(x-i,y));
					}
				}
				else 
                    break;
			}
		}
    }
    
    cout<<vis[m][n]<<endl;
    return 0;
}

Measured memory_bytes: 20184
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define VAR(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    VAR(int, N);

    vector<int> a(N);
    read(a);

    if (a.front() > 0) {
        return print(-1), 0;
    }

    i64 ans = 0;
    a.push_back(0);
    rep(i, 0, N) {
        if (a[i] < a[i+1] - 1) {
            return print(-1), 0;
        }
        if (a[i] >= a[i+1]) {
            dump(i, a[i]);
            ans += a[i];
        }
    }

    print(ans);

    return 0;
}


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

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

    string s;
    cin >> s;
    ll a = 0,b = 0,c = 0;
    for (ll i = 0; i < s.size(); i++){
        if (s[i] == 'a'){
            a++;
        }
        else if (s[i] == 'b'){
            b++;
        }
        else{
            c++;
        }
    }
    if (max(max(a,b),c) - min(min(a,b),c) <= 1){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> b(n - 1);
    rep(i, n - 1)cin >> b[i];
    int ans = b[0] + b[n - 2];
    for(int i = 0; i < n - 2; i++){
        ans += min(b[i], b[i + 1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;

int main(){
    int a, b;
    cin >> a >> b;
    int time = a+b;
    if(time<24) out(time);
    else out(time-24);
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
flag = False
price = 10 ** 7
for i in range(2 ** n):
    num = bin(2 ** n + i)
    flag2 = True
    temp_price = 0
    a = [0] * m
    for j in range(n):
        if num[-j-1] == "1":
            temp = data[j][1:]
            temp2 = data[j][0]
            temp_price += temp2
            for k in range(m):
                a[k] += temp[k]
    for j in range(m):
        if a[j] < x:
            flag2 = False
            break
    if flag2 == True:
        flag = True
        price = min(price, temp_price)
if flag == True:
    print(price)
else:
    print(-1)

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

typedef unsigned long long ull;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	if(N%2) cout << (N+1)/2 << endl;
	else cout <<N/2 <<endl;


    return 0;
}

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


int main()
{	
	int a,b;
	while(cin>>a>>b)
	{
		if(a==0&&b==0)break;
		for(int i=0;i<a;i++)
		{
			for(int j=0;j<b;j++)
			{
				if(i==0||j==0||i==a-1||j==b-1)cout<<"#";
				else cout<<".";
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;	
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,cnt=0,ans=-10000;
	string s[100],t[100];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>t[i];
	}
	string f;
	for(int i=0;i<n;i++){
		f=s[i];
		cnt++;
		for(int j=i+1;j<n;j++){
			if(s[j]==f){
				cnt++;
			}
		}
		for(int j=0;j<m;j++){
			if(t[j]==f){
				cnt--;
			}
		}
		if(cnt>ans){
			ans=cnt;
		}
		cnt=0;
	}
	if(ans<0){
		cout<<0<<endl;
		return 0;
	}
	cout<<ans<<endl;
	return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int main() {
    int x,a,b;
    cin >> x >> a >> b;

    int tmp = x-a;
    tmp = tmp % b;
    cout << tmp << endl;
}


Measured memory_bytes: 256
#while 1:
    #n=map(int,raw_input().split())

otehon = [[1,2,6,7,15,16,28,29,45],
          [3,5,8,14,17,27,30,44],
          [4,9,13,18,26,31,43],
          [10,12,19,25,32,42],
          [11,20,24,33,41],
          [21,23,34,40],
          [22,35,39],
          [36,38],
          [37]]


def xyz(num):
    num = str(num)
    if(len(num)==1):
        return "  "+num
    return " "+num


n = 0
while 1:
    N = int(raw_input())
    if(N==0):break
    n +=1
    hairetu = [[0 for i in range(N)] for j in range(N)]
    for i in range(N):
        for j in range(N):
            if(i+j<N):hairetu[i][j]=otehon[i][j]
    #
    for i in range(N):
        for j in range(N):
            if(i+j>=N):hairetu[i][j]=N*N +1 - hairetu[N-1-i][N-1-j]
    #
    print "Case "+str(n)+":"
    for i in range(N):
            strn = ""
            for j in range(N):
                strn += xyz(hairetu[i][j])
            print strn
    
    
            

Measured memory_bytes: 6376
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
//map<key,value>

int main(){
  int n,r=0,b=0;
  string s;
  cin >> n;
  cin >> s;
  for(int i=0;i<n;i++){
    if(s[i]=='R')r++;
    else b++;
  }
  if(r>b)cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256