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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
int L[1010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>L[i];
	sort(L,L+N);
	int ret=0;
	FOR(r,N) FOR(y,r) FOR(x,y) if(L[x]+L[y]>L[r]&&L[x]<L[y]&&L[y]<L[r]) ret++;
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3528
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

int main(){
    int n;
    string s;

    cin>>n >> s;

   vector<int> sum(n);//s[i]:i番目までの#の個数
   sum[0]=(s[0]=='#'?1:0);
   for(int i=1;i<n;i++){
       sum[i]=sum[i-1]+(s[i]=='#'?1:0);
   } 
   int ans=n-sum[n-1];
//   cout << ans << endl;
   for(int i=0;i<n;i++){
       int num1=sum[i],num2=n-i-1-(sum[n-1]-sum[i]);//num1が # の 個数
//       cout << num1 << " " << num2 << endl;
        ans=min(ans,num1+num2);
   }
   cout << ans << endl;

    return 0;
}


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

const int INF = 1001001001;

int main() {
    int h, w;
    cin >> h >> w;
    int ch, dh, cw, dw;
    cin >> ch >> cw >> dh >> dw;
    ch--; cw--; dh--; dw--;
    vector<string> s(h);
    for (int i = 0; i < h; ++i) cin >> s[i];
    vector<vector<int>> dist(h, vector<int>(w, INF));
    
    deque<pair<int, pair<int, int>>> q;
    q.emplace_back(0, make_pair(cw, ch));
    dist[ch][cw] = 0;
    while (!q.empty()) {
        auto p = q.front();
        q.pop_front();
        if (dist[p.second.second][p.second.first] < p.first) continue;
        for (int i = -2; i <= 2; ++i) {
            for (int j = -2; j <= 2; ++j) {
                if (i == 0 && j == 0) continue;
                int x = p.second.first;
                int y = p.second.second;
                int nx = x + i;
                int ny = y + j;
                if (nx >= 0 && nx < w && ny >= 0 && ny < h && s[ny][nx] == '.') {
                    int cost = 0;
                    if (abs(i) + abs(j) > 1) cost = 1;
                    if (dist[ny][nx] > dist[y][x] + cost) {
                        dist[ny][nx] = dist[y][x] + cost;
                        if (cost == 0) q.emplace_front(dist[ny][nx], make_pair(nx, ny));
                        else q.emplace_back(dist[ny][nx], make_pair(nx, ny));
                    }
                }
            }
        }
    }
    if (dist[dh][dw] == INF) cout << -1 << endl;
    else cout << dist[dh][dw] << endl;
}

Measured memory_bytes: 9500
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

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



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
using namespace std;
const int MAX = 100000;

int n, m;
vector<int> p;
vector<vector<int>> g;
int seen[MAX];

void dfs(int v, set<int> &a, set<int> &b) {
	seen[v] = 1;
	a.insert(v);
	b.insert(p[v]);
	for (int nv : g[v]) {
		if (seen[nv] != 0) continue;
		dfs(nv, a, b);
	}
}

int main() {
	cin >> n >> m;
	g.assign(n, vector<int>());
	p.assign(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (seen[i] != 0) continue;
		set<int> a, b;
		vector<int> v;
		dfs(i, a, b);
		set_intersection(a.begin(), a.end(), b.begin(), b.end(), inserter(v, v.end()));
		ans += v.size();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 23000
nxt = input().split()
#print(nxt)
N = int(nxt[0]) 
X = int(nxt[1])
T = int(nxt[2])
#print(N,X,T)
tmp = N/X - int(N/X)
if tmp == 0:
    counter = int(N/X)
else:
    counter = int(N/X) + 1
#print(counter)
print(counter * T)

Measured memory_bytes: 61760
#include<bits/stdc++.h>
using namespace std;
const int N=100;

int a,b,Map[N+5][N+5];

int main() {
//	freopen("data.out","w",stdout);
	cin>>a>>b;
	for (int i=1;i<=N;i++) {
		if (i&1) {
			for (int j=1;j<N;j++) Map[i][j]=1;
			Map[i][N]=0;
		}
		else {
			Map[i][1]=1;
			for (int j=2;j<=N;j++) Map[i][j]=0;
		}
	}
	a--;  b--;
	for (int x=1,y=N-2;a;a--) {
		Map[x][y]=0;
		if (y-2>1) y-=2;
		else x+=2,y=N-2;
	}
	for (int x=N,y=3;b;b--) {
		Map[x][y]=1;
		if (y+2<N) y+=2;
		else x-=2,y=3;
	}
	cout<<N<<' '<<N<<endl;
	for (int i=1;i<=N;i++) {
		for (int j=1;j<=N;j++) {
			if (Map[i][j]) putchar('.');
			else putchar('#');
		}
		cout<<endl;
	}
	return 0;
}

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

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    int n = (int) s.size();

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        ans += (s[i] != t[i]);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
#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 long double ldb;
typedef pair<ll,ll> pll;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define V vector
#define endl "\n"
#define CLEAR(a) memset(a,0,sizeof(a))
#define all(x) x.begin(),x.end()
#define sz(x) ((ll)x.size())
#define rep0(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ios_tie() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(nullptr)
#define trace1(a)             cout <<#a<<":"<<a<< endl;
#define trace2(a,b)           cout <<#a<<":"<<a<<" | "<<#b<<":"<<b<< endl;
#define trace3(a,b,c)         cout <<#a<<":"<<a<<" | "<<#b<<":"<<b<<" | "<<#c<<":"<<c<<endl;
#define trace4(a,b,c,d)       cout <<#a<<":"<<a<<" | "<<#b<<":"<<b<<" | "<<#c<<":"<<c<<" | "<<#d<<":"<<d<<endl;

const ll inf = (ll)1e18;
const ll maxn = 1e9+1;
const ldb PI = acos(-1);

void lol(ll s) {cerr<<"check........................................... "<<s<<endl;}
ll power(ll x, ll y, ll mod) {ll res=1; x%=mod; while(y) {if(y&1) res=(res*x)%mod; y>>=1LL; x=(x*x)%mod; }return res;}
ll inv(ll x, ll mod) {return power(x,mod-2,mod);}//(1/x)%y = x^(y-2) % y;   // pow(x,y)%m = pow(x,y%(m-1))%m
mt19937 rng((ll)chrono::steady_clock::now().time_since_epoch().count());

// I can solve mirror cube in 2 mins but can't solve div2 C in 1hr.
void solve()
{
    ll n;
    cin>>n;
    map<ll,ll> mm;
    ll a[n];
    ll sum = 0;
    rep0(i,n) {
        cin>>a[i];
        mm[a[i]]++;
        sum += a[i];
    }
    ll q;
    cin>>q;
    while(q--) {
        ll b, c;
        cin>>b>>c;
        sum -= b*mm[b];
        sum += c*mm[b];
        mm[c] += mm[b];
        mm.erase(b);
        cout<<sum<<endl;
    }
}
int main()
{
    ios_tie();
    // freopen("input.txt", "r", stdin);
    // freopen("myOut.txt", "w", stdout);
    ll _ = 1;
    // cin>>_;
    rep1(i,_)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 8388
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n,a,b; cin >> n >> a >> b;
	vi s(2,0);
	vector<string> ans(n);
	string S; cin >> S;
	rep(i,n){
		char c = S[i];
		int j = c-'a';
		if(j==0){
			if(s[0]+s[1]<a+b){
				ans[i] = "Yes";
				s[j]++;
			}else ans[i] = "No";
		}else if(j==1){
			if(s[0]+s[1]<a+b && s[1]<b){
				ans[i] = "Yes";
				s[j]++;
			}else ans[i] = "No";
		}else ans[i] = "No";
	}
	rep(i,n) cout << ans[i] << endl;
}




Measured memory_bytes: 6144
import java.util.*;

class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = Integer.parseInt(sc.next());
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    
    int res = (X-A)%B;
    System.out.println(res);
  }
}

Measured memory_bytes: 21844
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    double d = 0;
    for(int i = 0; i < N; i++){
      int n = Integer.parseInt(sc.next());
      d += (double)1/n;
    }
    System.out.println(1/d);
  }
}

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

const int N=2010,mod=1000000007;
inline void reduce(int&x){x+=x>>31&mod;}
int f[N],n,K,ans;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>K;
	f[0]=1;
	for(int i=1;i<=K;++i)
		for(int j=i;j<n;++j)reduce(f[j]+=f[j-1]-mod);
	ans=f[n-1];
	for(int i=1;i<n-K;++i)reduce(ans+=ans-mod);
	cout<<ans<<'\n';
	return 0;
}


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

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

ll sums[50];
ll patties[50];

ll lv1[5] = {0, 1, 2, 3, 3};
ll lv0[1] = {1};

ll dfs(ll N, ll X) {
    if (X <= 0) return 0;
    if (N==0) {
        return lv0[X-1];
    }
    if (N==1) {
        return lv1[X-1];
    }
    if (sums[N-1] - 1 <= X) {
        return patties[N-1];
    }

    ll ret = 0;
    ll mid_ind = sums[N-1] / 2 + 1;
    if (X < mid_ind - 1) {
        ret = dfs(N-1, X-1);
    }
    if (X == mid_ind - 1) {
        ret = patties[N-2];
    }
    if (X == mid_ind) {
        ret = 1 + patties[N-2];
    }
    if (X  == mid_ind + 1) {
        ret = 1 + patties[N-2];
    }
    if (mid_ind + 1 < X) {
        ret = patties[N-2] + 1 + dfs(N-1, X-mid_ind);
    }

    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    ll N;
    ll X;
    cin >> N >> X;

    ll sum = 1;
    ll patty = 1;
    
    REP(i, 50) {
        sum = 1 + sum + 1 + sum + 1;
        sums[i] = sum;
        patty = patty + 1 + patty;
        patties[i] = patty;
    }
    cout << dfs(N, X) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll a,b;
  cin>>a>>b;
  rep(i,1,10010){
    ll a1 = i*8;
    ll b1 = i*10;
    if(a*100<=a1&&a1<(a+1)*100){
      if(b*100<=b1&&b1<(b+1)*100){
        cout << i << endl;
        return 0;
      }      
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload '(:cl-debug-print :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((l (read))
         (k (- (integer-length l) 1))
         (out (make-string-output-stream :element-type 'base-char))
         (n (+ k 1))
         (m 0))
    (dotimes (i k)
      (format out "~D ~D ~D~%" (+ i 1) (+ i 2) 0)
      (format out "~D ~D ~D~%" (+ i 1) (+ i 2) (ash 1 i))
      (incf m 2))
    (loop for v from (- k 1) downto 0
          do ;; (format out "~D ~D ~D~%" (+ v 1) n (+ (- l (ash 1 v)) 1))
             (when (>= (- l (ash 1 v)) (ash 1 k))
               (format out "~D ~D ~D~%" (+ v 1) n (- l (ash 1 v)))
               (decf l (ash 1 v))
               (incf m)))
    (format t "~D ~D~%" n m)
    (write-string (get-output-stream-string out))))

#-swank (main)


Measured memory_bytes: 18020
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main(){
  int k;
  cin >> k;
  if(k%2==0)cout << (k/2)*(k/2) << endl;
  else cout << (k/2)*(k/2+1)<< endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
pair<vl,vb> eratosthenes_sieve(ll n){
  vb is_prime(n+1,true);
  vl prime;
  is_prime[0] = false;
  is_prime[1] = false;
  FOR(i,2,sqrt(n)+1){
    if(!is_prime[i]) continue;
    for(ll j=2*i;j<=n;j+=i) is_prime[j] = false;
    prime.eb(i);
  }
  return {prime,is_prime};
}
signed main(){
  int n;
  int ans = 0;
  cin >> n;
  vi a(n);
  REP(i,n) cin >> a[i];
  REP(i,n-1)REP(j,n-i-1){
    if(a[j]>a[j+1]){
      ++ans;
      swap(a[j],a[j+1]);
    }
  }
  REP(i,n-1) cout << a[i] << " ";
  cout << a[n-1] << endl;
  cout << ans << endl;
}



Measured memory_bytes: 3100
short len[3], used[3], s[3][100], d, i;

void rec(t){
        if(used[t]++>=len[t]) putchar('A'+t);
        else rec(s[t][used[t]-1]);
}

main(){
        for(i=0; i<3; i++){
                while((d=getchar())!='\n'){
                        s[i][len[i]++] = d-'a';
                }
        }
        rec(0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int main(){
  string S; cin>>S;
  ll K; cin>>K;
  int l=0;
  while(S[l]=='1') l++;
  if(K<=l) cout<<S[0]<<endl;
  else cout<<S[l]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main(){
  int n; cin >> n;
  vector<int> a(n);
  vector<vector<int>> x(n, vector<int>(n));
  vector<vector<int>> y(n, vector<int>(n));
  for(int i=0; i<n; i++) {
    cin >> a[i];
    for(int j=0; j<a[i]; j++) {
      cin >> x[i][j] >> y[i][j];
    }
  }

  int ans = 0;
  for(int d=0; d<(1 << n); d++) {
    bool f = true;
    for(int i=0; i<n; i++) {
      if ((d & (1 << i)) == 0) continue;
      for(int j=0; j<a[i]; j++) {
        if (((d >> (x[i][j]-1)) & 1) ^ y[i][j]) f = false;
      }
    }
    if (f) {
      ans = max(ans, (int) bitset<32>(d).count());
    }
  }
  cout << ans << endl;


}

// EOF

Measured memory_bytes: 256
#include <stdio.h>

int cmp(char[],char[]);

int main() {
  int n,i,j,k,m;
  char a[101][2],b[101][2],tmp[2];
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%s",a[i]);
    for(k=0; k<2; k++) b[i][k]=a[i][k];
  }
  for(i=0; i<n; i++) {
    for(j=n-1; j>i; j--) {
      if(a[j][1]<a[j-1][1]) {
	for(k=0; k<2; k++) tmp[k]=a[j][k];
	for(k=0; k<2; k++) a[j][k]=a[j-1][k];
	for(k=0; k<2; k++) a[j-1][k]=tmp[k];
      }
    }
  }
  for(i=0; i<n; i++) {
    m=i;
    for(j=i+1; j<n; j++) {
      if(b[j][1]<b[m][1]) m=j;
    }
    if(b[m][1]<b[i][1]) {
      for(k=0; k<2; k++) tmp[k]=b[i][k];
      for(k=0; k<2; k++) b[i][k]=b[m][k];
      for(k=0; k<2; k++) b[m][k]=tmp[k];
    }
  }
  int ck=1;
  for(i=0; i<n; i++) {
    if(a[i][0]!=b[i][0]) ck=0;
  }    
  for(i=0; i<n; i++) {
    if(i) printf(" ");
    printf("%c%c",a[i][0],a[i][1]);
  }
  printf("\nStable\n");
  for(i=0; i<n; i++) {
    if(i) printf(" ");
    printf("%c%c",b[i][0],b[i][1]);
  }
  if(ck) printf("\nStable\n");
  else printf("\nNot stable\n");
  return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const static int MOD = 1000000007;

int main(){
    string S;
    cin >> S;
    int initial = 0;
    while(initial < S.size()){
        if(initial + 4 >= S.size() || (S[initial] != 'd' && S[initial] != 'e')){
            printf("NO\n");
            return 0;
        }
        if(S[initial] == 'd'){
            if(S[initial+1] != 'r' || S[initial+2] != 'e' || S[initial+3] != 'a' || S[initial+4] != 'm'){
                printf("NO\n");
                return 0;
            }
            if(initial + 5 == S.size()){
                printf("YES\n");
                return 0;
            }
            if(S[initial+5] == 'd'){
                initial += 5;
                continue;
            }
            if(initial + 6 >= S.size() || S[initial+5] != 'e' || S[initial+6] != 'r'){
                printf("NO\n");
                return 0;
            }
            if(initial + 7 == S.size()){
                printf("YES\n");
                return 0;
            }
            if(S[initial+7] == 'a'){
                initial += 5;
                continue;
            }
            initial += 7;
        }else{
            if(S[initial+1] != 'r' || S[initial+2] != 'a' || S[initial+3] != 's' || S[initial+4] != 'e'){
                printf("NO\n");
                return 0;
            }
            if(initial+5 == S.size()){
                printf("YES\n");
                return 0;
            }
            if(S[initial+5] == 'r'){
                initial += 6;
                continue;
            }
            initial += 5;
        }
    }
    printf("YES\n");
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>

const int MAX = (1<<30);

using namespace std;

int minnode;

int main(){
  int c, city, bus, from, to;
  while(cin >> c >> city >> bus >> from >> to && c && city && bus && from && to){

    int price[city+1][city+1];

    for(int i = 0; i < city+1; i++){
      for(int j = 0; j < city+1; j++){	
	price[i][j] = 0;	
      }
    }

    for(int i = 0; i < bus; i++){
      int start, end, pri;
      cin >> start >> end >> pri;

      price[start][end] = pri;
      price[end][start] = pri;
    }

    int node[city+1][c+1];
    int visited[city+1][c+1];

    for(int i = 0; i < city+1; i++){
      for(int j = 0; j < c+1; j++){	
	node[i][j] = MAX;
	visited[i][j] = 0;
      }
    }

    minnode = from;
    int ticket = c;
    node[from][c] = 0;
    int nownode = MAX;
    int minpos, mintic;
    
    while(1){
      for(int i = 1; i < city+1; i++){
	for(int j = 0; j < c+1; j++){
	  if(visited[i][j]) continue;
	  if(node[i][j] < nownode){
	    nownode = node[i][j];
	    minpos = i;
	    mintic = j;
	  }
	}
      }
      visited[minpos][mintic] = 1;
      if(nownode == MAX) break;
      
      nownode = MAX;
      
      for(int i = 1; i < city+1; i++){
	if(price[minpos][i]){
	  node[i][mintic] = min(node[i][mintic],node[minpos][mintic]+price[minpos][i]);
	  if(mintic){
	    node[i][mintic-1] = min(node[i][mintic-1],node[minpos][mintic] + price[minpos][i]/2);
	  }
	}
      }
    }

    for(int i = 1; i <= ticket; i++){
      if(node[to][0] > node[to][i]) node[to][0] = node[to][i];
    }
    cout << node[to][0] << endl;
  }
  return 0;
}

Measured memory_bytes: 912
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  string w;
    cin >> w;
  
  if(w == "SSS"){cout << '0' << endl;}
  else if(w == "SSR" || w == "RSS" || w == "SRS"|| w == "RSR"){cout << '1' << endl;}
  else if(w == "RRS" || w == "SRR"){cout << '2' << endl;}
  else {cout << '3' << endl;}
  
}

Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int a, b;
long long int s[100001], t[100001];

long long int solve(long long int x)
{
	int si = lower_bound(s, s + a, x) - s;
	int ti = lower_bound(t, t + b, x) - t;
	long long int ans = (long long int)mod * 100;
	if(si < a && ti < b) ans = min(ans, max(s[si], t[ti]) - x);
	if(si < a && ti > 0) ans = min(ans, s[si] - x + x - t[ti - 1] + min(s[si] - x, x - t[ti - 1]));
	if(si > 0 && ti < b) ans = min(ans, t[ti] - x + x - s[si - 1] + min(t[ti] - x, x - s[si - 1]));
	if(si > 0 && ti > 0) ans = min(ans, x - min(s[si - 1], t[ti - 1]));
	return ans;
}

int main()
{
	int q;
	cin >> a >> b >> q;
	for(int i = 0; i < a; i++){
		cin >> s[i];
	}
	for(int i = 0; i < b; i++){
		cin >> t[i];
	}
	sort(s, s + a);
	sort(t, t + b);
	for(int i = 0; i < q; i++){
		long long int x;
		cin >> x;
		cout << solve(x) << endl;
	}
}

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


int main(){
  int N, K;
  cin >> N >> K;
  vector<long long> V(N);
  
  for(int i=0; i<N; i++) cin >> V[i];
  
  int ans=0;
  
  for(int i=0; i<=K; i++){
    for(int j=0; j<=K-i; j++){
      if(i+j>N) continue;
      vector<long long> S;
      int res=0;
      
      for(int k=0; k<i; k++){
        res += V[k];
        S.push_back(V[k]);
      }
      for(int l=0; l<j; l++){
        res += V[N-l-1];
        S.push_back(V[N-l-1]);
      }
      
      sort(S.begin(), S.end());
          
      for(int k=0; k<(K-i-j); k++){
        if(k>=S.size()) break;
        if(S[k]>0) break;
        res -= S[k];
      }
     
      
      ans = max(ans, res);
    
    }
  }
  
  cout << ans << endl;
  
  return 0;

}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 1e-8;

int C(int* book,int n,int m,int w){
	int j=0;
	for(int i=0;i<m;i++){
		int tmp = w;
		for(;j<n;){
			tmp-= book[j];
			if(tmp >= 0) j++;
			else {
				break;
			}
		}
	}

	if(j<n) return false;
	else return true;

}

int main(){
	int m,n;
	while(~scanf("%d %d",&m,&n)){
		if(m==n && n==0) break;

		int *book = new int[n]();
		for(int i=0;i<n;i++){
			scanf("%d",book+i);
		}

		int lb = 1;
		int ub = 1500000;
		int md;

		for(int i=0;i<100;i++){
			md = (lb+ub)/2;
			if(C(book,n,m,md)) ub = md;
			else lb = md;
		}

		printf("%d\n",ub);
		delete[] book;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"
	

const int N = 5e5 + 5;
const int M = 1e9 + 7;
int mod(int m){
   m%=M;
   return (m+M)%M;
}

int power(int x,int y) {
   int res = 1;
   x = mod(x);
   while (y > 0) {
      if (y & 1)
         res =mod(res*x);
      y = y>>1;
      x = mod(x*x);
   }
   return mod(res);
}

int f[N],invf[N];
void fact(){
   f[0]=f[1]=1;
   for(int i=2;i<N;i++)
      f[i]=mod(f[i-1]*i);

   invf[N-1]=power(f[N-1],M-2);
   for(int i=N-1;i>0;i--)
      invf[i-1]=mod(invf[i]*i);

}

int nCr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   ans = mod(ans*invf[r]);
   return ans;
}

int nPr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   return ans;
}

int32_t main(){
	boost;
	string s;
	cin>>s;
	int n = s.size();
	int ans = power(3,n);
	int pf = 1;
	for(int i=0;i<s.size();i++){
		if(s[i] == '0'){
			int tt = power(3,n-i-1);
			tt = mod(tt*2*pf);
			ans = mod(ans - tt);
		}
		else
			pf = mod(pf*2);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3756
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    REP(i, N / R + 1) {
        REP(j, N / G + 1) {
            int k = N - (R * i + G * j);

            if (k % B == 0 && k >= 0)
                ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            FastScanner fs = new FastScanner();

            final int N = fs.nextInt();
            final int X = fs.nextInt();

            int mn = 1001;
            int sm = 0;
            for (int i = 0; i < N; i++) {
                int m = fs.nextInt();
                sm += m;
                if (m < mn) mn = m;
            }

            System.out.println(N + (X - sm) / mn);
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int n = in.nextInt();
			if (n == 0) {
				break;
			} else {
				int[] ageCounter = new int[7];
				for (int i = 0; i < n; i++) {
					String age = in.next().trim();
					if (age.length() == 1) {
						ageCounter[0]++;
					} else if (age.length() == 2) {
						if (age.startsWith("1")) {
							ageCounter[1]++;
						} else if (age.startsWith("2")) {
							ageCounter[2]++;
						} else if (age.startsWith("3")) {
							ageCounter[3]++;
						} else if (age.startsWith("4")) {
							ageCounter[4]++;
						} else if (age.startsWith("5")) {
							ageCounter[5]++;
						} else {
							ageCounter[6]++;
						}
					} else {
						ageCounter[6]++;
					}
				}
				for (int count : ageCounter) {
					System.out.println(count);
				}
			}
		}
	}
}

Measured memory_bytes: 12000
c=Array.new(3)
c[0]=gets.split.map(&:to_i)
c[1]=gets.split.map(&:to_i)
c[2]=gets.split.map(&:to_i)
if 0 == c[0][0]+c[1][1]+c[2][2]-c[0][1]-c[1][2]-c[2][0] && 0 == c[0][0]+c[1][1]+c[2][2]-c[0][2]-c[1][0]-c[2][1]   then
    print "Yes\n"
  else
    print "No\n"
end


Measured memory_bytes: 1916
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

int main(){
	ll n;
	scanf("%lld",&n);
	puts(n<1200?"ABC":n<2800?"ARC":"AGC");
}

Measured memory_bytes: 128
from math import ceil
def f(x,hp):
  hp=[hh-(b*x) for hh in hp]
  c=0
  for p in hp:
    if p<=0:continue
    c+=ceil(p/(a-b))
  return c<=x

n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
ng=0
ok=10**9
while ok-ng>1:
  mid=(ok+ng)//2
  if f(mid,h):
    ok=mid
  else:
    ng=mid
print(ok)






Measured memory_bytes: 11080
#include <stdio.h>
#include <string.h>

int main(void){

	int i;
	char str[1000];
	scanf("%s",str);
	for(i = 0;i < strlen(str);i++){
		str[i] = (str[i] - 16) % 26 + 65;
	}
	printf("%s\n",str);
	return 0;
}


Measured memory_bytes: 524
n,*a=map(int,open(0).read().split())
a=[0]+a+[0]
b=sum(abs(i-j) for i,j in zip(a,a[1:]))
for i,j,k in zip(a,a[1:],a[2:]):
    if i<=j<=k or i>=j>=k:
        print(b)
    elif min(i,j,k)==j:
        print(b-2*(min(i,k)-j))
    else:
        print(b-2*(j-max(i,k))) 

Measured memory_bytes: 13932
#!/usr/bin/env python3
#AGC29 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
ans,cnt = 0,0
for i in range(n):
    if s[i] == 'B':
        cnt += 1
    else:
        ans += cnt
print(ans)


Measured memory_bytes: 40176
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
 
int main() {
  ios_base::sync_with_stdio(false);
  int X, A, B;
  cin >> X >> A >> B;
  cout << min(X * A, B);
}


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

int main(){
  long int n,m,sum=0,a[10000];
  cin >> n >> m;
  
  for(long int i=0; i< m; i++){
    cin >> a[i];
    sum += a[i];
  }
  
  if(sum <= n)
    cout << n-sum << endl;
  else
    cout << "-1" << endl;
  
  return 0;
}

Measured memory_bytes: 3612
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  int hn = N / 2;
  vector<int> ds(N);
  F0R(i, N) {
    cin >> ds[i];
  }
  sort(rng(ds));
  cout << (ds[hn] - ds[hn - 1]);
}
#endif


Measured memory_bytes: 3720
/* Count characters */
#include <stdio.h>
 
int main(void){
/* Parameters */
int count[26];
int num;
int i;
char ch;
 
/* Initialize */
for (i = 0; i < 26; i++){
        count[i] = 0;
}
 
/* Read Files */
while (scanf("%c", &ch) != EOF){
        /* Small Capital */
        num = ch - 'a';
        if ( num >= 0 && num <= 25) count[num]++;
        /* Large Capital */
        num = ch - 'A';
        if ( num >= 0 && num <= 25) count[num]++;
}
 
/* Print statistics */
ch = 'a';
for (i = 0; i < 26; i++){
        printf("%c : %d\n", ch + i, count[i]);
}
 
/* RC */
return 0;}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n,m;
  cin>>n>>m;
  int s[n+1],t[m+1];
  REPP(i,n){
    cin>>s[i];
  }
  REPP(i,m){
    cin>>t[i];
  }
  vector<vector<long long>> dp(n+1,vector<long long>(m+1,0));
  dp[0][0]=1;
  REP(i,n+1){
    dp[i][0]=1;
  }
  REP(i,m+1){
    dp[0][i]=1;
  }
  REPP(i,n){
    REPP(j,m){
      if(s[i]==t[j]){
        dp[i][j] = mod(2*dp[i-1][j-1]);
        dp[i][j] = mod(mod(dp[i][j]+mod(dp[i-1][j]-dp[i-1][j-1]))+mod(dp[i][j-1]-dp[i-1][j-1]));
      }else{
        dp[i][j] = dp[i-1][j-1];
        dp[i][j] = mod(mod(dp[i][j]+mod(dp[i-1][j]-dp[i-1][j-1]))+mod(dp[i][j-1]-dp[i-1][j-1]));
      }
    }
  }
  long long ans;
  ans = dp[n][m];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 31616
use std::io::*;
use std::str::FromStr;

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

fn parse_line_vec<T: FromStr>() -> Vec<T> {
    let line = parse_line::<String>();
    line.split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn println<T: ToString>(s: T) {
    println!("{}", s.to_string());
}

// ------------------------------------------------------------------------

fn is_sorted(p: &Vec<u32>) -> bool {
    for p_sub in p.windows(2) {
        if p_sub[0] >= p_sub[1] {
            return false;
        }
    }
    true
}

fn main() {
    let n = parse_line::<usize>();

    let p = parse_line_vec::<u32>();

    if is_sorted(&p) {
        println("YES");
        return;
    }

    for i in 0..n - 1 {
        for k in i + 1..n {
            let mut p2 = p.clone();
            p2.swap(i, k);
            if is_sorted(&p2) {
                println("YES");
                return;
            }
        }
    }
    
    println("NO");
}


Measured memory_bytes: 4352
#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 = 2e17;
const int mod = 1e9 + 7;

struct aaa {
    int first, second, count;
};

signed main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> mass(H, vector<char>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> mass[i][j];
        }
    }
    int ans = 0;
    for (int a = 0; a < H; a++) {
        for(int b = 0; b < W; b++) {
            vector<vector<int>> temp(H, vector<int>(W, inf));
            if (mass[a][b] == '#') continue;
            queue<aaa> q;
            q.push({a, b, 0});
            while (!q.empty()) {
                aaa take = q.front();
                int i = take.first;
                int j = take.second;
                q.pop();
                if (mass[i][j] == '#') continue;
                if (temp[i][j] <= take.count) continue;
                temp[i][j] = take.count;
                ans = max(ans, take.count);
                // cout << 1 << endl;
                if (i != 0) q.push({i - 1, j, take.count + 1});
                if (i != H - 1) q.push({i + 1, j, take.count + 1});
                if (j != 0) q.push({i, j - 1, take.count + 1});
                if (j != W - 1) q.push({i, j + 1, take.count + 1});
                // cout << i << " " << j << endl;
            }
        }
    }
    cout << ans << endl;

}

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

#define long long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,v) memset(a,v,sizeof(a))
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define INF 0x3f3f3f3f//infinity for integers
#define JJ ios_base::sync_with_stdio(0); cin.tie(0)//input fast
#define MOD 1000000007
#define hash(n) unordered_map<int,int>mp(n)

int main()
{
	JJ;
	int a; cin>>a;
	cout<<(a+a*a+a*a*a)<<endl;
	


	return 0;
}


Measured memory_bytes: 3608
K = int(input())
import collections
d = [float('inf')]*(K)
d[1] = 1
path = [[] for _ in range(K)]
for i in range(K-1):
    path[i].append((i+1,1))

path[-1].append((0,1))
for i in range(K):
    path[i].append(((i*10)%K,0))
deque = collections.deque([1])
while deque:
    s = deque.popleft()
    for e,cost in path[s]:
        if d[s] + cost < d[e]:
            d[e] = d[s]+cost
            if cost ==0: deque.appendleft(e)
            else: deque.append(e)
print(d[0])
#1から10倍（コスト0）か1足す（コスト1）で任意の整数を作成可能
#上記を満たすグラフを考えれば題意とイコール
#1から0への最小経路こそが各桁の最小和


Measured memory_bytes: 87124
#include <iostream>

int main(void)
{
    int a, b;
    std::cin >> a >> b;
    bool result = false;
    for (int c = 1; c <= 3; ++c) {
        if ((a * b * c) % 2) {
            result = true;
            break;
        }
    }
    std::cout << (result? "Yes": "No");
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int digsum(int a) {
    int res = 0;
    while (a > 0) {
        res += a % 10;
        a /= 10;
    }
    return res;
}

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

    int minsum = 99999;
    for (int n = 1; n <= N / 2; n++) {
        int m = N - n;
        int tmp = digsum(n) + digsum(m);
        if (minsum >= tmp) minsum = tmp;
    }

    cout << minsum << endl;

    return 0;
}


Measured memory_bytes: 256
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
H,W,M = ma()
hw = []
coh = collections.Counter()
cow = collections.Counter()
se=set()
for i in range(M):
    h,w = ma()
    coh[h]+=1
    cow[w] +=1
    se.add((h,w))

lh =  list(coh.items())
lw =  list(cow.items())
#print(lh,lw)
lh.sort(key=lambda x:x[1],reverse=True)
lw.sort(key=lambda x:x[1],reverse=True)
mah = lh[0][1]
maw = lw[0][1]
lhh = [num for num,cnt in lh if cnt==mah]
lww = [num for num,cnt in lw if cnt==maw]
ans = mah+maw

f=False
if len(lhh)*len(lww)<=M:
    for h in lhh:
        for w in lww:
            if not (h,w) in se:
                f=True
    if f:
        print(ans)
    else:
        print(ans-1)
else:
    print(ans)


Measured memory_bytes: 188084
#include<stdio.h>
int main(void)
{
	int x, y, k;
	scanf("%d %d", &x, &y);
	printf("\n");

	k = (x + y) / 2;
	if ((x+y) % 2 == 0)
	{
		printf("%d", k);
	}
	else
	{
		printf("IMPOSSIBLE");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
constexpr ll mod[2] = {1000000007,998244353};
struct rolling_hash{
	ll z = 100,ex[2][100010];
	vector<ll> v,w[2];
	rolling_hash(string &s){
		int i,j,n = s.size();
		for(i=0;i<n;i++){
			v.push_back(s[i] - 'a' + 1);
		}
		w[0].assign(n + 1,0),w[1].assign(n + 1,0);
		ex[0][0] = 1,ex[1][0] = 1;
		for(i=0;i<n;i++){
			for(j=0;j<2;j++){
				w[j][i + 1] = (w[j][i]*z + v[i])%mod[j];
				ex[j][i + 1] = ex[j][i]*z%mod[j];
			}
		}
	}
	inline pll get(int l, int r){//[l,r)
		ll x = (w[0][r] - ex[0][r - l]*w[0][l]%mod[0] + mod[0])%mod[0];
		ll y = (w[1][r] - ex[1][r - l]*w[1][l]%mod[1] + mod[1])%mod[1];
		return {x,y};
	}
};

string s;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,j,n,ans = 0;
	cin >> n >> s;
	rolling_hash rh(s);
	for(i=0;i<n;i++){
		for(j=i + 1;j<n;j++){
			if(s[i]!=s[j]) continue;
			int l = 0,r = min(j - i,n - j);
			if(rh.get(i,i + r)==rh.get(j,j + r)){
				ans = max(ans,r);
				continue;
			}
			while(r - l>1){
				int mid = (l + r)/2;
				if(rh.get(i,i + mid)==rh.get(j,j + mid)) l = mid;
				else r = mid;
			}
			ans = max(ans,l);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define s second
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
using namespace std;


int main(){
    faster
    int T = 1;
    while(T--){
        string str;
        int n;
        cin>>str;
        n = str.size();
        
        string ans = "";
        for(int i=0; i<n; i++){
            if(str[i] != 'B') ans+=str[i];
            else{
                if(ans.size()!=0) ans.pop_back();
            }
        }
        
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define in(e,l) (std::find(l.begin(), l.end(), e) != l.end())
#define asort(l) (std::sort(l.begin(), l.end()))
#define dsort(l) (std::sort(l.rbegin(), l.rend()))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;

int main() {
  string S, T;
  cin >> S >> T;
  ll ans = 0;
  rep(i, 3) {
    if (S[i] == T[i]) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256