akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int t, N, K, num;
const int max1 = (10e+5) + 1;
vector<int> h(max1), range(max1);
int ans;


int main() {
  cin >> t ;
  for(int p = 0; p < t; p++) {
    cin >> N >> K;
    for(int i = 0; i < max1; i++) {
      h.at(i) = 0;
      range.at(i) = 0;
    }
    for(int i = 0; i < N; i++) {
      cin >> h.at(i);
    }
    for(int i = 0; i < N-1; i++) {
      range.at(i) = h.at(i+1) - h.at(i);
    }
    sort(range.begin(),range.end());
    reverse(range.begin(),range.end());
    num = N - K;
    if(num <= 0) {
      cout << 0 << endl;
      continue;
    }
    ans = h.at(N-1) - h.at(0);
    for(int i = 0; i < K-1; i++) {
      ans -= range.at(i);
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 10568
H, W=map(int, input().split())
graph=[]
road=0
for i in range(H):
    s=list(input())
    road=road+s.count(".")
    graph.append(s)

not_visited=[]
not_visited=[[True for i in range(W)] for j in range(H)]
need_visited=[]
need_visited=[[0 for i in range(W)] for j in range(H)]
need_visited[H-1][W-1]=True
queue=[]

dx=[1, -1, 0, 0]
dy=[0, 0, 1, -1]

start_point=[0, 0]
queue.append(start_point)
while len(queue)!=0:
    now_point=queue.pop(0)
    for i in range(4):
        search_point=[now_point[0]+dx[i], now_point[1]+dy[i]]
        if 0<=search_point[0]<H and 0<=search_point[1]<W:
            if graph[search_point[0]][search_point[1]]!="#" and not_visited[search_point[0]][search_point[1]]:
                not_visited[search_point[0]][search_point[1]]=False
                queue.append(search_point)
                need_visited[search_point[0]][search_point[1]]=need_visited[now_point[0]][now_point[1]]+1

if need_visited[H-1][W-1]==True:
    print(-1)
else:
    print(road-need_visited[H-1][W-1]-1)


Measured memory_bytes: 40944
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))

for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]

ans = 0
b_cnt = m

for a_cnt in range(n+1):
    if a[a_cnt] > k:
        break
    while a[a_cnt] + b[b_cnt] > k:
        b_cnt -= 1
    ans = max(ans, a_cnt + b_cnt)

print(ans)


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

int main() {
  // ここにプログラムを追記
  int intA;
  int intB;

  cin >> intA >> intB;
  
  cout << (intA + intB) / 2 + (intA + intB) % 2 << endl;
  
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;

  for (int64_t i = 1; i <= n; i++) {
    for (int64_t j = i + 1; j <= n; j++) {
      auto p = i;
      auto q = j;
      auto c = 1;
      while ((p % 2) == (q % 2)) {
        if (p % 2 == 1) {
          p += 1;
          q += 1;
        }
        p /= 2;
        q /= 2;
        c++;
      }
      std::cout << c;
      if (j != n) {
        std::cout << " ";
      } else {
        std::cout << "\n";
      }
    }
  }
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector <char> v(n);
  vector <char> u(n);
  rep(i, n) cin >> v.at(i);
  rep(i, n) cin >> u.at(i);
  vector <bool> flag(n);
  rep(i, n) {
    if (v.at(i) == u.at(i)) flag.at(i) = 1;
    else flag.at(i) = 0;
  }
  ll res;
  if (flag.at(0)) {
    res = 3;
    for (ll i = 1; i < n; i++) {
      if (flag.at(i)) {
        if (flag.at(i-1)) {
          res *= 2;
        } else {
          res *= 1;
        }
      } else {
        if (flag.at(i-1)) {
          res *= 2;
        } else {
          res *= 3;
        }
        i++;
      }
      res %= mod;
    }
  } else {
    res = 6;
    for (ll i = 2; i < n; i++) {
      if (flag.at(i)) {
        if (flag.at(i-1)) {
          res *= 2;
        } else {
          res *= 1;
        }
      } else {
        if (flag.at(i-1)) {
          res *= 2;
        } else {
          res *= 3;
        }
        i++;
      }
      res %= mod;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, pre[45], in[45];
int solve(int i, int s, int e){
    //cout << i << " " << s << " " << e << endl;
    if(s == e){
        if(in[s] == pre[0]){
            cout << in[s];
        }
        else{
            cout << in[s] << " ";
        }
        return i;
    }
    for(int j = s; j <= e; j++){
        if(pre[i] == in[j]){
            if(j - 1 >= s)
                i = solve(i + 1, s, j - 1);
            if(j + 1 <= e)
                i = solve(i + 1, j + 1, e);
            if(in[j] == pre[0]){
                cout << in[j];
            }
            else{
                cout << in[j] << " ";
            }
            break;
        }
    }
    return i;
}
int main(){

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> pre[i];
    }
    for(int i = 0; i < n; i++){
        cin >> in[i];
    }
    solve(0, 0, n - 1);
    cout << endl;
}


Measured memory_bytes: 3100
h, w = map(int, input().split())

A = []
B = ["."] * (w + 2)
A.append(B)
temp = 0
for i in range(h):
    T = ['.'] + list(input()) + ['.']
    A.append(T)
    temp += T.count('#')
A.append(B)

t = 1
x = 1
y = 1
ans = 0
while t:
    if A[x][y] == '#':
        C = []
        C.append(A[x][y + 1])
        C.append(A[x+1][y])
        if C.count('#') > 1:
            t = 0
        else:
            A[x][y] = '?'
            if A[x][y+1] == '#':
                y = y + 1
            else:
                x = x + 1
            ans += 1
    else:
        t = 0

print("Possible" if ans == temp else "Impossible")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

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

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(d==1)<<endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


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

    cout << (x-a)%b << endl;

    return 0;
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////


 #define N 305

ll n,m,l;
struct edge{
    ll to,c;
};
vector<edge>e[N];
ll ans[N][N];
 
void dijk(ll s){
    l_l cost[n+1];
    rep(i,1,n){
        cost[i]=l_l(inf,inf);
    }
    cost[s]=l_l(0,0);
    bool used[n+1];memset(used,false,sizeof(used));
    rep(xx,1,n){
        ll t=0;
        l_l mi=l_l(inf,inf);
        rep(j,1,n){
            if(used[j]==false&&mi>=cost[j]){
                mi=cost[j];
                t=j;
            }
        }
        used[t]=true;
        for(auto x:e[t]){
            if(x.c>l)continue;
            l_l nc;
            if(cost[t].second+x.c<=l){
                nc=l_l(cost[t].first,cost[t].second+x.c);
            }else{
                nc=l_l(cost[t].first+1,x.c);
            }
            if(cost[x.to]>nc)cost[x.to]=nc;
        }
    }
    rep(i,1,n){
        if(cost[i].first>=inf)ans[s][i]=-1;
        else ans[s][i]=cost[i].first;
    }
}
int main(){
    cin>>n>>m>>l;
    rep(i,1,m){
        edge x;
        ll a;cin>>a>>x.to>>x.c;
        e[a].pb(x);
        swap(x.to,a);
        e[a].pb(x);
    }
    rep(i,1,n){
        dijk(i);
    }
    /*
    rep(i,1,n){
        rep(j,1,n){
            cout<<ans[i][j]<<" ";
        }cout<<endl;
    }cout<<endl;
    */
    ll q;cin>>q;
    while(q--){
        ll a,b;cin>>a>>b;
        cout<<ans[a][b]<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3584
module Factwithmod
  implicit none
  integer(16),allocatable,dimension(:)::Kaijo
  contains
subroutine initiationFactorial(maxnum,mo)
  implicit none
  integer(16)::maxnum
  integer(16)::mo
  integer(16)::i

  allocate(Kaijo(0:maxnum))
  Kaijo(0)=1
  do i=1,maxnum
    Kaijo(i)=mod(Kaijo(i-1)*i,mo)
  end do
end subroutine

function combination(n,k,l)
implicit none
integer(16),intent(in)::n,k,l
integer combination

combination=mod(Kaijo(N)*inv(Kaijo(K),l)*inv(Kaijo(N-K),l),l)

end function

function inv(K,L)
integer(16),intent(in)::k,l
integer(16) l2,y
integer(16) inv
inv=1
l2=l-2
y=k
do
  if(mod(l2,2)==1)inv=mod(inv*y,l)
  y=mod(y*y,l)
  l2=l2/2
  if(l2==0)exit
end do
end function

function permutation(n,k,mo)
implicit none
  integer(16)::n,k
  integer(16)::mo,permutation
  permutation=mod(Kaijo(N)*inv(Kaijo(N-K),mo),mo)
end function
end module

use Factwithmod
integer(16) N
character(200000) S
integer(16) match,cntmatch
integer(16)ans,mo,i
mo=10**9+7
read*,N
read*,S
call initiationFactorial(N,mo)
match=0
cntmatch=0
ans=1
do i=1,2*N
  if(mod(I,2)==1)then
    if(S(I:I)=="B")then
      match=match+1
      cntmatch=cntmatch+1
    else
      ans=mod(ans*match,mo)
      match=match-1
    endif
  else
    if(S(I:I)=="W")then
      match=match+1
      cntmatch=cntmatch+1
    else
      ans=mod(ans*match,mo)
      match=match-1
    endif
  end if
end do
if(cntmatch/=N)ans=0
ans=mod(ans*kaijo(N),mo)
print"(I0)",ans
end


Measured memory_bytes: 2316
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>


using std::cout;
using std::cin;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


ll gcd(ll a, ll b) {
    while (b != 0) {
        auto tmp = a;
        a = b;
        b = tmp % a;
    }
    return a;
}

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


void oneCase () {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for (int i = 0; i < ty - sy; ++i) {
        cout << "U";
    }
    for (int i = 0; i < tx - sx; ++i) {
        cout << "R";
    }
    for (int i = 0; i < ty - sy; ++i) {
        cout << "D";
    }
    for (int i = 0; i < tx - sx; ++i) {
        cout << "L";
    }
    cout << "L";
    for (int i = 0; i <= ty - sy; ++i) {
        cout << "U";
    }
    for (int i = 0; i <= tx - sx; ++i) {
        cout << "R";
    }
    cout << "D";
    cout << "R";
    for (int i = 0; i <= ty - sy; ++i) {
        cout << "D";
    }
    for (int i = 0; i <= tx - sx; ++i) {
        cout << "L";
    }
    cout << "U";



}





int main() {
    int t = 1;
//    cin >> t;
    while (t > 0) {
        oneCase();
        --t;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define int int64_t
signed main() {
	int A, B, K;
	cin >> A >> B >> K;
	if (A >= K) {
		cout << A - K << " " << B;
	}
	else if(B>=(K-A)){
		cout << 0 << " " << B - (K - A);
	}
	else {
		cout << 0 <<" "<< 0;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    string s;cin >> s;
    vector<int> pre(n+1),suf(n+1);
    rep(i,n)pre[i+1] = pre[i] + (s[i] == 'W');//[0,i)のWの個数
    for(int i = n-1;i >= 0;i--)suf[i] = suf[i+1] + (s[i] == 'E');   //[i,n)のEの個数
    int ret = 1001001001;
    rep(i,n){
        int tmp = pre[i] + suf[i];
        tmp -= (int)(s[i] == 'E');
        ret = min(ret,tmp);
    }
    //trace(pre,suf);
    cout << ret << endl;
    return 0;
}

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

int INF = 1e9 + 1;

int main()
{
    int N, M, L;
    cin >> N >> M >> L;
    vector<vector<int>> dp(N, vector<int>(N, INF));
    for (int i = 0; i < M; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        dp.at(a).at(b) = c;
        dp.at(b).at(a) = c;
    }
    for(int i = 0; i < N; i++)
    {
        dp.at(i).at(i) = 0;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    vector<vector<int>> chargeDp(N, vector<int>(N, INF));
    for(int i = 0; i < N; i++)
    {
        chargeDp.at(i).at(i) = 0;
    }
    for (int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(dp[i][j] <= L){
                chargeDp[i][j] = 1;
            }
        }
    }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                chargeDp[i][j] = min(chargeDp[i][j], chargeDp[i][k] + chargeDp[k][j]);
            }
        }
    }

    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        if(chargeDp.at(s).at(t) == INF){
            cout << -1 << endl;
        }else{
            cout << chargeDp.at(s).at(t) - 1 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 1280
#include <iostream>

using namespace std;

int main()
{

    int X, Y;
    cin >> X >> Y;

    for (int i = 0; i <= X; i++){

        if(2 * i + 4 * (X - i) == Y){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
import itertools

[n,a,b,c] = list(map(int, input().strip().split(' ')))
lst = []
for i in range(n):
    lst.append(int(input().strip()))

x = [0,1,2,3]
y = list(itertools.product(x,x,x,x,x,x,x,x))
minimum = 1000000
for pattern in y:
    aa = 0
    bb = 0
    cc = 0
    mp = 0
    for i,num in enumerate(pattern):
        if i > n - 1:
            break
        if num == 1:
            if aa != 0:
                mp += 10
            aa += lst[i]
        if num == 2:
            if bb != 0:
                mp += 10
            bb += lst[i]
        if num == 3:
            if cc!= 0:
                mp += 10
            cc += lst[i]
    if aa == 0 or bb == 0 or cc == 0:
        continue
    mp += abs(a-aa) + abs(b-bb) + abs(c-cc)
    if minimum > mp:
        minimum = mp
print(minimum)



Measured memory_bytes: 10996
#include "bits/stdc++.h"

using namespace std;

using i64 = long long;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


template <typename T = i64>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template <typename T = i64>
bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}


signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(auto& x : a)
        cin >> x;
    vector<int> flag(1 << n, 0);
    for(int i = 0; i < (1 << n); ++i){
        int sum = 0;
        for(int j = 0; j < n; ++j)
            if(i & (1 << j))
                sum += a[j];
        if(sum == k)
            flag[i] = 1;
    }
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < (1 << n); ++j)
            if(j & (1 << i))
                flag[j] |= flag[j ^ (1 << i)];
    int ans = n;
    for(int i = 0; i < (1 << n); ++i)
        if(flag[i] == 0)
            chmin(ans, n - __builtin_popcount(i));
    cout << ans << endl;
}




Measured memory_bytes: 7064
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#include <sstream>
#include <iterator>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

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

    vector<int> arr(n);

    for (int i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    vector<int> len(n + 1);
    int maxLen = 0;

    for (int i = 0; i < n; i++)
    {
        len[arr[i]] = len[arr[i] - 1] + 1;
        maxLen = max(maxLen, len[arr[i]]);
    }

    printf("%d\n", n - maxLen);
   
    return 0;
}

Measured memory_bytes: 1920
#include <cstdio>
#include <cstring>
char a[1005];bool N=0,S=0,W=0,E=0;
int main (){
	scanf ("%s",a+1);int n=strlen(a+1);
    for (int i=1;i<=n;i++) 
        if (a[i]=='N') N=1;
    	else if (a[i]=='S') S=1;
    	else if (a[i]=='W') W=1;
    	else E=1;
    if ((N^S)||(W^E)) puts("No");
    else puts("Yes");
	return 0;
}

Measured memory_bytes: 128
N=int(input())
A=list(map(int,input().split()))
C=[0]*100001
cnt=0
for i in range(N):
  if A[i]>10**5:
    cnt +=1
  else:
    C[A[i]] += 1
for j in range(100001):
  if C[j]<j:
    cnt=cnt+C[j]
  elif C[j]>j:
    cnt=cnt+C[j]-j
print(cnt)

Measured memory_bytes: 14268
s = input()

l = 0
r = len(s)-1

rlt = 0

while l<=r:
  if s[l] == 'x':
    if s[r] != 'x':
      rlt += 1
      l += 1
    else:
      l += 1
      r -= 1
  elif s[r] == 'x':
    rlt += 1
    r -= 1
  else:
    if s[l] != s[r]:
      print(-1)
      exit()
    else:
      l += 1
      r -= 1
      
print(rlt)

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

int main(){
    string s;
    cin>>s;
    if(s[0]=='S')cout<<"Cloudy"<<endl;
    else if(s[0]=='C')cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;
template <class Monoid>
class SegmentTree
{
public:
  using Func = function<Monoid(Monoid, Monoid)>;
  const Func F;
  const Monoid M1;
  int sz;
  vector<Monoid> seg;

  SegmentTree(int n,const Func fu, const Monoid &m1): F(fu) , M1(m1) {init(n);}
  void init(int n)
  {
      sz= 1;
      while (sz < n) sz *= 2;
      seg.assign(sz * 2, M1);
  }
  void update(int k,const Monoid &x)
  {
    k+=sz;
    seg[k]=x;
    while(k>>=1)
    {
      seg[k]=F(seg[k*2],seg[k*2+1]);
    }
  }
  Monoid query(int l,int r)
  {
    Monoid L=M1,R=M1;
    l+=sz;r+=sz;
    for(;l<r;l>>=1,r>>=1)
    {
      if(l&1)L=F(L,seg[l++]);
      if(r&1)R=F(seg[--r],R);
    }
    return F(L,R);
  }
};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,t;
  cin>>n>>t;
  SegmentTree<int> st(n,[](int a,int b){return max(a,b);},0);
  rep(i,n){int a;cin>>a;st.update(i,a);}
  rep(i,n)
  {
    st.update(i,max(0,st.query(i+1,n)-st.query(i,i+1)));
  }
  int cnt=0,maxd=st.query(0,n);
  rep(i,n)
  {
    if(st.query(i,i+1)==maxd)cnt++;
  }
  cout<<cnt<<endl;

  return 0;

}


Measured memory_bytes: 1280
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from itertools import accumulate

def sum_max(line,n_min,n_max):
    n = len(line)
    ac = list(accumulate([0]+line))
    l = 0
    r = n_min
    ans = ac[r]-ac[l]
    i  = 0
    if n_min==n_max:
        for i in range(n-n_min+1):
            ans = max(ans,ac[i+n_min]-ac[i])
    else:
        while r!=n or i%2==1:
            if i%2==0:
                r = ac[r+1:l+n_max+1].index(max(ac[r+1:l+n_max+1])) + r+1
            else:
                l = ac[l+1:r-n_min+1].index(min(ac[l+1:r-n_min+1])) + l+1
            i+=1
            ans = max(ans,ac[r]-ac[l])
    return ans

def sum_min(line,n_min,n_max):
    n = len(line)
    ac = list(accumulate([0]+line))
    l = 0
    r = n_min
    ans = ac[r]-ac[l]
    i  = 0
    if n_min==n_max:
        for i in range(n-n_min+1):
            ans = min(ans,ac[i+n_min]-ac[i])
    else:
        while r!=n or i%2==1:
            if i%2==0:
                r = ac[r+1:l+n_max+1].index(min(ac[r+1:l+n_max+1])) + r+1
            else:
                l = ac[l+1:r-n_min+1].index(max(ac[l+1:r-n_min+1])) + l+1
            i+=1
            ans = min(ans,ac[r]-ac[l])
    return ans

def circle_sum_max(circle,num):
    n = len(circle)
    s = sum(circle)
    if num == 0:
        ans = 0
    else:
        ans = max(sum_max(circle,1,num), s-sum_min(circle,n-num,n-1))
    return ans
 
n,k = readints()
p = [x-1 for x in readints()]
c = readints()

circles = []
used = [0]*n

for i in range(n):
    if not used[i]:
        circles.append([c[i]])
        used[i] = 1
        j = p[i]
        while not used[j]:
            circles[-1].append(c[j])
            used[j] = 1
            j = p[j]

score = -10**20

for cir in circles:
    m = len(cir)
    a = sum(cir)
    if k>m:
        if a>0:
            score = max(score, (k//m)*a + circle_sum_max(cir,k%m), (k//m-1)*a + circle_sum_max(cir,m))
        else:
            score = max(score,circle_sum_max(cir,m))
    else:
        score = max(score,circle_sum_max(cir,k))

print(score)










Measured memory_bytes: 10064
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};
int main(){
	int N;
	ll A[100001],B[100001];
	vpll BAi;
	vpll BA;
	vll SA;
	vll SB;
	int Amplus[100001]={};
	scan(N);
	UnionFind uf(N);
	rep(i,N){
		scan(A[i]);
		SA.push_back(A[i]);
	}
	rep(i,N){
		scan(B[i]);
		SB.push_back(B[i]);
		BA.push_back({B[i],A[i]});
	}
	sort(ALL(SA));
	sort(ALL(SB));
	sort(ALL(BA));

	int flag=1;
	rep(i,N){
		if(SA[i]>SB[i]){
			flag=0;
			break;
		}
	}
	if(flag==0){
		prin("No");
		return 0;
	}

	/*rep(i,N){
		printf("%lld ",BA[i].second);
	}
	kaigyo;
	rep(i,N){
		printf("%lld ",BA[i].first);
	}
	kaigyo;*/
	rep(i,N){
		int m=lower_bound(SA.begin(),SA.end(),BA[i].second)-SA.begin();
		int oldm=m;
		m+=Amplus[m];
		Amplus[oldm]++;
		uf.unite(i,m);
	}

	flag=0;
	rep(i,N-1){
		if(SB[i]>=SA[i+1]){
			flag=1;
			break;
		}
	}
	
	if(uf.size(0)==N&&flag==0){
		prin("No");
	}
	else{
		prin("Yes");
	}

	return 0;
}


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

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//const string YES = "Yes";
const string NO = "No";

void solve(long long H, long long N, std::vector<long long> A){
    ll sum=0;
    rep(i,N){
        sum+=A[i];
    }
    if(sum>=H){
        opY;
        return;
    }
    opN;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long H;
    scanf("%lld",&H);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(H, N, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())
c = [input().split() for i in range(m)]
for i in range(m):
    c[i][0] = int(c[i][0])
AC, WA = 0, 0
acwa = [[0, 0] for i in range(n)]
for i in range(m):
    if acwa[c[i][0] - 1][0] == 0:
        if c[i][1] == 'AC':
            acwa[c[i][0] - 1][0] += 1
            AC += 1
            WA += acwa[c[i][0] - 1][1]
        else:
            acwa[c[i][0] - 1][1] += 1

print(AC, WA)

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

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define ll unsigned long long
#define int long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

const int Maxn = (int)1e6;
const ld pi = acos(-1);
const int mod = (int)1e9 + 7;
const int inf = (int)1e18;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A) {
    fr(i, 0, (int)A.size()) out << A[i] << " ";
    return out;
}

template <class T1, class T2>
ostream &operator<<(ostream &out, map<T1, T2> &A) {
    for (auto x : A) cout << x.ff << " # " << x.ss << endl;
    return out;
}

int32_t main() {IOS
    int n, sum = 0;  cin>>n;
    map<int, int> my;
    vector<int>A(n);    fr(i,0,n){
        cin>>A[i];
        sum += A[i];
        my[A[i]]++;
    }
    int Q;  cin>>Q;
    while(Q--){
        int x,y;    cin>>x>>y;
        sum -= x*my[x];
        sum += y * my[x];
        my[y] += my[x];
        my[x] = 0;
        cout << sum << endl;
        //cout << my << endl;
    }
    return 0;
}

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

int main(){
	int r,g,b;
	cin>>r>>g>>b;
	
	int sum;
	sum=100*r+10*g+b;
	
	if(sum%4==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    vector<vector<int>> isOpen(n, vector<int>(10));
    rep(i, n) rep(j, 10) cin >> isOpen[i][j];
    vector<vector<int>> profit(n, vector<int>(11, 0));
    rep(i, n) rep(j, 11) cin >> profit[i][j];

    ll ans = -LONG_LONG_MAX;
    rep(bit, 1<<10) {
        ll tmp = 0;
        bool ok = false;
        vector<int> bothOpen(n, 0);
        rep(i, 10) {
            if (bit & 1<<i) {
                ok = true;
                rep(j, n) {
                    if (isOpen[j][i]==1) bothOpen[j]++;
                }
            }
        }
        if (ok) {
            rep(i, n) tmp += profit[i][bothOpen[i]];
            if (chmax(ans, tmp)) debug(ans, bothOpen, tmp);
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const ll INF = (1LL << 31) - 1;
const double pi=acos(-1);

int main(){
  ll n;
  cin >> n;
  vector<ll>vec(n+1);
  map<ll,ll>mp;
  ll ans=0;
  vec[0]=0;
  rep(i,n){
    ll a;
    cin >> a;
    vec[i+1]=vec[i]+a;
  }
  sort(vec.begin(),vec.end());
  
  rep(i,n+1){
    mp[vec[i]]++;
  } 
  for(auto p:mp){
    ans+=(p.second)*(p.second-1)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 14336
// AtCoder Beginner Contest 075
// B - Minesweeper
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
  int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

  int h, w;
  cin >> h >> w;

  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s.at(i);
  }

  vector<string> ans(h);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {

      string mine;
      if (s.at(i).at(j) == '#') {
        mine = '#';
      } else {
        int cnt = 0;
        for (int k = 0; k < 8; k++) {
          if (j + dx[k] >= 0 && j + dx[k] < w 
              && i + dy[k] >= 0 && i + dy[k] < h) {
            if (s.at(i + dy[k]).at(j + dx[k]) == '#') {
              cnt++;
            }
          }
        }
        mine = '0' + cnt;
      }

      if (ans.at(i) == "") {
        ans.at(i) = mine;
      } else {
        ans.at(i) += mine;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
#define inf (llg)1e16
using namespace std;
#define maxn 500100
#define llg long long 
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,a[maxn],f[maxn][10];

inline int getint()
{
       int w=0,q=0; char c=getchar();
       while((c<'0' || c>'9') && c!='-') c=getchar(); if(c=='-') q=1,c=getchar(); 
       while (c>='0' && c<='9') w=w*10+c-'0', c=getchar(); return q ? -w : w;
}

bool cmp(llg a,llg b){return a>b;}

int main()
{
	//yyj("A");
	cin>>n;
	n*=3;
	for (llg i=1;i<=n;i++) a[i]=getint();
	sort(a+1,a+n+1,cmp);
	n/=3;
	n*=2;
	for (llg i=1;i<=n;i++)
		for (llg j=0;j<10;j++)
			f[i][j]=-inf;
	f[1][0]=0;
	for (llg i=1;i<=n;i++)
	{
		for (llg j=0;j<=3;j++)
			f[i+1][j+1]=max(f[i][j],f[i+1][j+1]);
		for (llg j=1;j<=4;j++) f[i+1][j-1]=max(f[i+1][j-1],f[i][j]+a[i]);
	}
	cout<<f[n+1][0];
	return 0;
}


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

int main(){
  string s;
  cin>>s;
  if(s=="ABC"){
    cout<<"ARC";}
  else{cout<<"ABC";}
  

  return 0;
}

Measured memory_bytes: 3624
A = [list(map(int, input().split(' '))) for i in range(3)]
N = int(input())
B = set([int(input()) for i in range(N)])

X = []
X += [set(A[i]) for i in range(3)]
X += [set([A[j][i] for j in range(3)]) for i in range(3)]
X += [set([A[0][2], A[1][1], A[2][0]]), set([A[2][2], A[1][1], A[0][0]])]

for x in X:
    if x <= B: #setの場合は、順不同で比較する。　<=は部分重合
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()



class Doubling():
    def __init__(self, a0, m):
        """
        a0 is an array-like object which contains ai, 0 <= i < N.
        ai is the next value of i.
        """
        N = len(a0)
        self.N = N
        self.nt = [[None] * N for i in range(m.bit_length()+1)]
        for i, a in enumerate(a0):
            self.nt[0][i] = a

        for i in range(1, len(self.nt)):
            for j in range(N):
                if self.nt[i-1][j] is None:
                    self.nt[i][j] = None
                else:
                    self.nt[i][j] = self.nt[i-1][self.nt[i-1][j]]

    def apply(self, i, n):
        """
        Apply n times from i
        """
        j = i
        for k in range(n.bit_length()):
            m = 1 << k
            if m & n:
                j = self.nt[k][j]
            if j is None:
                break
        return j

def slv(N, K, A):
    A = [a-1 for a in A]
    d = Doubling(A, 10**18+1)
    return d.apply(0, K) + 1


def main():
    N, K = read_int_n()
    A = read_int_n()
    print(slv(N, K, A))


if __name__ == '__main__':
    main()


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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }

int main(){
  string s;
  cin >> s;
  bool bus[2] = {false,false};
  string ans = "No";
  rep(i,3){
    if(s[i] == 'A' and bus[1] == false)bus[0] = true;
    else if(s[i] == 'A' and bus[1] == true)ans = "Yes";
    else if(s[i] == 'B' and bus[0] == false)bus[1] = true;
    else if(s[i] == 'B' and bus[0] == true)ans = "Yes";
  }
  cout << ans << endl;
}


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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 2005;

int n, cnt, a[N], d[N], e[N], p[N], r[N];
vector <int> ans, seq, adj[N];
bool v[N];

inline void Rotate(int x) {
  int t = a[x];
  ans.pb(x), a[x] = a[0];
  for (int i = p[x]; ~i; swap(a[i], t), i = p[i]);
}

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n), p[0] = -1;
  for (int i = 1; i < n; ++i) {
    Read(p[i]), adj[p[i]].pb(i), d[i] = d[p[i]] + 1;
  }
  for (int i = 0; i < n; ++i) {
    Read(a[i]);
  }
  while (cnt < n) {
    seq.clear();
    for (int i = n - 1; ~i; --i) {
      if (!v[i]) {
        int t = 0, son = -1;
        seq.pb(i);
        for (auto j : adj[i]) {
          if (!v[j]) {
            ++t, son = j;
          }
        }
        if (!t) {
          r[i] = e[i] = i;
        } else if (t == 1 && ~r[son]) {
          r[i] = r[son];
        } else {
          r[i] = -1;
        }
      }
    }
    sort(seq.begin(), seq.end(), [&](const int &x, const int &y) {
      return mp(r[x], d[x]) > mp(r[y], d[y]);
    });
    for (int i = 0; i < seq.size(); ) {
      if (~r[a[0]]) {
        int x = a[0], y = r[x];
        for (; v[y] && a[y] > x; y = p[y]);
        Rotate(y), y = r[x], v[e[y]] = true, e[y] = p[e[y]], ++cnt;
      } else {
        Rotate(seq[i++]);
      }
      for (; i < seq.size() && v[seq[i]]; ++i);
    }
  }
  for (int i = 0; i < n; ++i) {
    assert(a[i] == i);
  }
  printf("%d\n", ans.size());
  for (auto x : ans) {
    printf("%d\n", x);
  }
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


Measured memory_bytes: 512
if __name__ == '__main__':
    opcode = []                 # ?????????????¨???¶??¨
    operand = []                # ?????´????¢??????????????¨???¶??¨

    # ??????????????\???
    while True:
        data = input()
        if data == '=':
            break
        elif data in '+-*/':
            opcode.append(data)
        else:
            if len(operand) == 0:
                operand.append(int(data))
            else:
                op = opcode.pop()
                operand1 = operand.pop()
                operand2 = int(data)
                if op == '+':
                    operand.append(operand1 + operand2)
                elif op == '-':
                    operand.append(operand1 - operand2)
                elif op == '*':
                    operand.append(operand1 * operand2)
                elif op == '/':
                    operand.append(operand1 // operand2)

    # ???????????¨???
    print('{0}'.format(operand.pop()))

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

const string d[]{"U", "R", "D", "L"};

void calc(int sd, int len1, int len2) {
    for(int i = 0; i < len1; i++) {
        cout << d[sd];
    }
    for(int i = 0; i < len2; i++) {
        cout << d[(sd+1)%4];
    }
    for(int i = 0; i < len1; i++) {
        cout << d[(sd+2)%4];
    }
    for(int i = 0; i < len2; i++) {
        cout << d[(sd+3)%4];
    }
    
    cout << d[(sd+3)%4];
    
    for(int i = 0; i < len1 + 1; i++) {
        cout << d[sd];
    }
    for(int i = 0; i < len2 + 1; i++) {
        cout << d[(sd+1)%4];
    }
        
    cout << d[(sd+2)%4];
    cout << d[(sd+1)%4];

    for(int i = 0; i < len1 + 1; i++) {
        cout << d[(sd+2)%4];
    }
    for(int i = 0; i < len2 + 1; i++) {
        cout << d[(sd+3)%4];
    }
    
    cout << d[sd] << endl;
}

int main() {
    int sx, sy, ex, ey;
    cin >> sx >> sy >> ex >> ey;

    if (sx > ex && sy > ey) {
        calc(2, sy - ey, sx - ex);
    } else if (sx > ex && sy < ey) {
        calc(3, sx - ex, ey - sy);
    } else if (sx < ex && sy > ey) {
        calc(1, ex - sx, sy - ey);
    } else if (sx < ex && sy < ey) {
        calc(0, ey - sy, ex - sx);
    }
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Range Flip Find Route
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 100;
const int MAX_W = 100;
const int INF = 1 << 30;

/* typedef */

inline void setmin(int &a, int b) { if (a > b) a = b; }

/* global variables */

char fs[MAX_H][MAX_W + 4];
int dp[MAX_H][MAX_W];

/* subroutines */

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);

  for (int y = 0; y < h; y++) {
    scanf("%s", fs[y]);
    fill(dp[y], dp[y] + w, INF);
  }

  dp[0][0] = 0;
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++) {
      if (y + 1 < h)
	setmin(dp[y + 1][x],
	       dp[y][x] + ((fs[y + 1][x] == fs[y][x]) ? 0 : 1));
      if (x + 1 < w)
	setmin(dp[y][x + 1],
	       dp[y][x] + ((fs[y][x + 1] == fs[y][x]) ? 0 : 1));
    }

  //printf("%d\n", dp[h - 1][w - 1]);

  int d = dp[h - 1][w - 1], c = 0;
  if (fs[0][0] == '#') d--, c++;
  if (fs[h - 1][w - 1] == '#') d--, c++;

  printf("%d\n", c + d / 2);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <map>
#include <memory.h>
#include <queue>
#include <string.h>
#include <set>
#include <bitset>
using namespace std;

#define ll long long
#define N 300005
#define EDGE 200005

int in[N];
ll pos[N],neg[N];
void solve() {
  int n;scanf("%d ", &n);
  for(int i=1;i<=n*3;++i) {
    scanf("%d ", &in[i]);
  }
  priority_queue<int ,vector<int>,greater<int>> pq;
  ll sum = 0;
  for(int i=1;i<=n*3;++i) {
    pq.push(in[i]);
    sum += in[i];
    if(pq.size()>n) {
      sum -= pq.top();
      pq.pop();
    }
    if(pq.size()==n) {
      pos[i] += sum;
    }
  }
  priority_queue<int> q;
  sum = 0;
  for(int i=n*3;i;--i) {
    sum += in[i];
    q.push(in[i]);
    if(q.size()>n) {
      sum -= q.top();
      q.pop();
    }
    if(q.size()==n) {
      neg[i] += sum;
    }
  }
  ll ret = -1e18;
  for(int i=1;i<=n*3;++i) {
    if(i>=n && 3*n-i>=n) {
      ret = max(ret, pos[i] - neg[i+1]);
    }
  }
  printf("%lld\n", ret);
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void Main(){
    int L,R,d; cin >> L >> R >> d;
    int ans = 0;
    FOR(i,L,R+1){
        if(i%d == 0) ans++;
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3608