akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        int h[] = new int[n + 1];
        int m[] = new int[n + 1];
        
        for(int i = 0; i < n; i++){
            h[i] = sc.nextInt();
            m[i] = 0;
        }
        
        int innCounter = 0;
        
        for(int idx = 0; idx < n; idx++){
                for(int k = 0; k < idx; k++){
                    if(h[idx] < h[k]){
                        m[idx]++;
                    }else{
                        
                    }
                }
                if(m[idx] == 0){
                    innCounter++;
                }
        } 
        System.out.println(innCounter);
        
    }
}


Measured memory_bytes: 21716
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include <assert.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
#include<set>
#include <climits>
using namespace std;
typedef unsigned long long ull;
#define ll long long int
static const double PI = 3.141592653589793;
const ll INF = 100000000000000;
ll mod = 1000000007;
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;



int main() {
	long long int n,y=0;
	cin >> n;
	for (long long int i = 1; i < n; i++) {
		y += i;
	}
	cout << y << endl;
}


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

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

int main()
{
	string s;
	cin >> s;
	bool isBad = false;

	for (int i = 0; i < s.size() - 1; i++)
	{
		if (s.at(i) == s.at(i + 1))
		{
			isBad = true;
		}
	}
	if (isBad)
	{
		cout << "Bad" << endl;
	}
	else
	{
		cout << "Good" << endl;
	}
}


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

using namespace std;

int N, M, a[51], b[51];
bool graph[55][55];
bool visited[55];

void dfs(int v){
    
    for(int i = 0; i < N; i++){
        if(graph[v][i] == true && visited[i] == false){
            visited[i] = true;
            dfs(i);
        }
    }
}

int  main(){

    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    int ans = 0;
    for(int i = 0; i < M; i++){
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        for(int j = 0; j < N; j++) visited[j] = false;

        visited[0] = true;

        dfs(0);

        for(int j = 1; j < N; j++){
            if(visited[j] == false){
                ans++;
                break;
            }
        }

        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
s = input()
count1 = 0
count2 = 0
if s[0] == 'A'and s[1].islower() == True and s[len(s)-1].islower() == True:
    count1 += 1
for i in range(2, len(s) - 1):
    if s[i] == 'C':
        count2 += 1
    elif s[i].islower == False:
        print('WA')
        break
if count1 != 1 or count2 != 1:
    print('WA')
else:
    print('AC')



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
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;
}

int main(){
  
  int m;
  cin>>m;
  long long d[m],c[m];
  long long n = 0;
  long long s = 0;
  REP(i,m){
    cin>>d[i]>>c[i];
    n += c[i];
    s += d[i]*c[i];
  }
  long long temp = 9*n + s;
  long long last_;
  if(s%9 == 0){
    last_ = 9;
  }else{
    last_ = s%9;
  }
  last_ = 9*1 + last_;
  long long ans = (temp - last_)/9;
  cout<<ans<<endl;
  return 0; 
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
using namespace std;
const int maxd = 2e5+10;
typedef pair<int,int> P;
void solve()
{
    int a,b;scanf("%d %d",&a,&b);
    printf("%d",a^b);
}
int main()
{
//    freopen("a.in","r",stdin);
//    freopen("k.out","w",stdout);
    //int t;scanf("%d",t);
    int t = 1;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 128
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A, B = MAP()

print(max(A+B, A-B, A*B))


Measured memory_bytes: 3884
# ABC148D - Brick Break
import sys

read = sys.stdin.buffer.read


def main():
    N, *A = map(int, read().split())
    remaining = 0
    target = 1
    for i in A:
        if i == target:
            remaining += 1
            target += 1
    print(N - remaining if remaining else -1)


if __name__ == "__main__":
    main()


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

int main(){
  int N;
  cin >>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int sum=1;
  for(int i=1;i<N;i++){
    if(vec.at(i-1)<vec.at(i)){
    sum++;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
c = [ list(map(int, input().split())) for _ in range(10) ]
A = [ list(map(int, input().split())) for _ in range(H) ]
for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j] = min(c[i][j], c[i][k] + c[k][j])
ans = 0
for i in range(H):
  for j in range(W):
    if A[i][j] >= 0:
      ans += c[A[i][j]][1]
print(ans)


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


int main(){
    long double a,b;
    cin>>a>>b;
    ll c=a*b;
    cout<<c<<endl;
}

    









Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
const int mod=1e9+7;
typedef long long LL;
int n,m;
string str;
int dp[maxn][13];

int main()
{
    cin>>str;
    int n=str.length();
    if(str[0]=='?')
        for(int i=0;i<10;i++)
            dp[0][i]=1;
    else
        dp[0][str[0]-'0']=1;
    for(int i=0;i<n-1;i++)
    {
        if(str[i+1]=='?')
            for(int j=0;j<13;j++)
                for(int k=0;k<10;k++)
                {
                    int id=(j*10+k)%13;
                    dp[i+1][id]=(1LL*dp[i+1][id]+dp[i][j])%mod;
                }
        else
        {
            int k=str[i+1]-'0';
            for(int j=0;j<13;j++)
            {
                int id=(j*10+k)%13;
                dp[i+1][id]=(1LL*dp[i+1][id]+dp[i][j])%mod;
            }
        }
    }
    cout<<dp[n-1][5]<<endl;
}


Measured memory_bytes: 5504
let init n f =
  let rec g i ns = if i = 0 then 0 :: ns else g (i - 1) (i :: ns) in
  List.map f (g (n - 1) [])

let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let s = if n mod 2 = 0 then n + 1 else n

let e = List.flatten @@ init (n - 1) (fun i -> init (n - i - 1) (fun j -> (i + 1, i + j + 2)))

let () = 
  let e = e |> List.filter (fun (a, b) -> a + b <> s) in
  Printf.printf "%d\n" (List.length e);
  List.iter (fun (a, b) -> Printf.printf "%d %d\n" a b) e

Measured memory_bytes: 4864
#include <stdio.h>

static const char *days[7]=
{
    "Sunday",
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    
};

int main(void)
{
    int base=4;
    int monthbase[12]=
    {0,3,4,0,2,5,0,3,6,1,4,6,};
    while(1)
    {
        int m,d;
        scanf("%d%d",&m,&d);
        if(m==0)
            break;
        puts(days[(base+monthbase[m-1]+d-1)%7]);
    }
    return 0;
}

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

const int INF = 3000;
int cnt[15][1005];

int main () {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  
  int h, w, k, ans = INF;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, 0, h) cin >> s[i];
  rep(div, 0, 1<<(h-1)) {
    int g = 0;
    vector<int> gid(h);
    rep(i, 0, h) {
      gid[i] = g;
      if (div>>i & 1) ++g;
    }
    ++g;
    rep(i, 0, g) rep(j, 0, w) cnt[i][j] = 0;
    rep(i, 0, h) rep(j, 0, w) cnt[gid[i]][j] += (s[i][j] - '0');
    // rep(i, 0, g) rep(j, 0, w) if (cnt[i][j] > k) continue;
    
    int num = g-1;
    vector<int> now(g);
    auto add = [&] (int t) {
      rep(id, 0, g) now[id] += cnt[id][t];
      rep(id, 0, g) if (now[id] > k) return false;
      return true;
    };
    rep(i, 0, w) {
      if (!add(i)) {
        num++;
        now = vector<int>(g);
        if (!add(i)) {
          num = INF;
          break;
        }
        // add(i);
      }
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
void sort(int p[],int n){
  int i,j,tmp;
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(p[j-1]>p[j]){
        tmp=p[j-1];
        p[j-1]=p[j];
        p[j]=tmp;
        }
    }
  }
}
int main(void){
  int k,n,i,a;
  int p[1000];
  scanf("%d",&n);
  scanf("%d",&k);

  for(i=0;i<n;i++){
    scanf("%d",&a);
    p[i]=a;
  }
  sort(p,n);  //小さいジュん
  n=0;
  for(i=0;i<k;i++){
    n=n+p[i];
  }
  printf("%d",n);
  return 0;
  }

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

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;
}

const long long INF = 1LL << 60;


int main() {
  int N;
  cin >> N;
 
  vector<int64_t> dp(100010);
  for (int i = 0; i < 100010; ++i) dp.at(i) = INF;

  vector<int> h(N+2);
  for (int i=0; i<N; i++) {
    cin >> h.at(i);
  }
  dp.at(0) = 0;
  for (int i=0; i<N; i++) {
    chmin(dp.at(i+1), dp.at(i) + abs(h.at(i) - h.at(i+1)));
    chmin(dp.at(i+2), dp.at(i) + abs(h.at(i) - h.at(i+2)));
  }
  cout << dp.at(N-1) << endl;
}

Measured memory_bytes: 1408
S = list(input())

ACGT = ["A", "C", "G", "T"]

Max = 0
s = []
t = 0
for i in range(len(S)):
  if S[i] in ACGT:
    t += 1
    if t > Max:
      Max = t
  else:
    t = 0
print(Max)

Measured memory_bytes: 3060
from collections import defaultdict
from bisect import bisect_right

N = int(input())
arr = list(map(int, input().split()))
val2idx = defaultdict(list)
for j, aj in enumerate(arr):
    val2idx[j - aj].append(j)

ans = 0
for i, ai in enumerate(arr):
    if ai + i in val2idx:
        res = bisect_right(val2idx[ai + i], i)
        ans += len(val2idx[ai + i]) - res
print(ans)
 




Measured memory_bytes: 124092
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N];
int main(){
	int n,k,sum=0,ans=0;scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	for(int i=0;i<k;i++)sum+=a[i];
	ans=sum;for(int i=k;i<n;i++)sum+=a[i]-a[i-k],ans=max(ans,sum);
	printf("%.10lf",(ans+k)/2.0);
	return 0;
}

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

using namespace std;

#define EPS 1e-10

struct Point{
    double x,y;

    Point(){}
    Point(double x,double y) : x(x),y(y) {}

    Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
};

double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double norm(const Point &p){ return dot(p,p); }

#define prev(G,i) (G[(i-1+G.size())%G.size()])
#define curr(G,i) (G[i%G.size()])
#define next(G,i) (G[(i+1)%G.size()])

typedef vector<Point> Polygon;

int containPP(const Polygon &pg,const Point &p){
    int N = pg.size();
    bool in = false;
    for(int i = 0 ; i < N ; i++){
        Point a = curr(pg,i)-p, b = next(pg,i)-p;
        if(a.y > b.y) swap(a,b);
        if(a.y <= 0 && 0 < b.y && cross(a,b) < 0) in = !in;
        if(cross(a,b) == 0 && dot(a,b) <= 0) return 1;
    }
    return (in ? 2 : 0); 
}


int main(){
    int N,Q;
    cin >> N;
    Polygon pg(N);
    for(int i = 0 ; i < N ; i++){
        cin >> pg[i].x >> pg[i].y;
    }
    cin >> Q;
    while(Q--){
        Point p;
        cin >> p.x >> p.y;
        cout << containPP(pg,p) << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
#include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
#include<string>
#include<set>
#include<numeric>
#include<functional>
#include<unordered_map>
#include<cmath>
#include<cstdlib>
#include<cassert>
#include<climits>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<string> A(N), B(M);
	for (int i = 0; i < N; i++)
		cin >> A[i];
	for (int i = 0; i < M; i++)
		cin >> B[i];

	for (int i = 0; i < N - M + 1; i++) {
		for (int j = 0; j < N - M + 1; j++) {
			bool flag = true;
			for (int k = 0; k < M; k++) {
				for (int l =0; l < M; l++) {
					if (A[i + k][j + l] != B[k][l]) {
						flag = false;
						break;
					}
				}
				if (!flag)
					break;
			}
			if (flag) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  int ans = 0;
  for (int i = a; i <= b; i++) {
    string s = to_string(i);
    bool flag = true;
    rep(i, s.size()/2) {
      if (s[i] != s[s.size()-1-i])
        flag = false;
    }
    if (flag)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
using namespace std;
const ll inf=1e18; 
ll t,a,b,c,d,k,n;
map<pair<ll,ll>,ll> m;
ll cal(ll x){
	if(x>=1e18/d) return inf;
	return x*d;
}
ll solve(ll x,ll add){
	if(x<0) return inf;
	if(x==0) return 0;
	if(x==1) return d;
	if(m[make_pair(x,add)]) return m[make_pair(x,add)];
	ll res=cal(x);
	if(res>a&&x%2==0) res=min(res,solve(x/2,0)+a);
	if(res>b&&x%3==0) res=min(res,solve(x/3,0)+b);
	if(res>c&&x%5==0) res=min(res,solve(x/5,0)+c);
	if(!add){
		inc(i,max(-4LL,-x/2),min(4LL,x/2)){
			if(i==0) continue;
			res=min(res,solve(x+i,1)+abs(i)*d);
		}
	}
	return m[make_pair(x,add)]=res;
}
int main(){
	scanf("%d",&t);
	while(t--){
		m.clear();
		scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
		printf("%lld\n",solve(n,0));	
	}
}

Measured memory_bytes: 12308
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X, Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%(m))
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_S = 200000;
const ll M = 2019;
ll memo[M];
ll sSize;
string S;


//x^nをmodのもとで計算する
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() {
    cin >> S;
    sSize = len(S);
    int zeroPos = 0;
    ll ans = 0;

    for (ll i = sSize - 1; i >= 0; --i) {
        ll newNum = S[i] - '0';
        newNum = mod(newNum * mod_pow(10, sSize - i - 1, M), M);
        ll matchNum = mod(M - newNum, M);
        ll idx = mod(zeroPos + matchNum, M);
        ans += memo[idx];
        zeroPos = idx;
        ++memo[mod(zeroPos + newNum, M)];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3736
def fib n
  res = Array.new(n + 1, 0)
  res[0] = 1
  res[1] = 1
  (2..n).each do |i|
    res[i] = res[i - 1] + res[i - 2]
  end
  res
end

def main
  fibs = fib 44
  n = gets.chomp.to_i
  puts fibs[n]
end

main

Measured memory_bytes: 6092
N = int(input())
plan = [[0, 0, 0]] + [list(map(int, input().split())) for _ in range(N)]
diff = [[plan[i + 1][j] - plan[i][j] for j in range(3)] for i in range(N)]

def is_possible(t, x, y):
    if (t + x + y) % 2 == 0 and abs(x) + abs(y) <= t:
        return True
    else:
        return False

for i in range(N):
    ti, xi, yi = diff[i]
    if not is_possible(ti, xi, yi):
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 36444
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000

int A[MAX];

int insertionSort(int n, int g){
	int cnt = 0;
	for(int i=g; i<n; i++){
		int t = A[i];
		int j;
		for(j=i-g; j>=0 && A[j]>t; j-=g){
			A[j+g] = A[j];
			cnt++;
		}
		A[j+g] = t;
	}
	return cnt;
}

int shellSort(int n){
	int cnt = 0;
	int m = 13;
	int g[13];
	
	for(int i=0; i<13; i++){
		g[i] = (pow(3, i+1) - 1 ) / 2;
		if(g[i] > n){
			m = i;
			break;
		}
	}
	
	for(int i=0; i<m; i++){
		cnt += insertionSort(n, g[m-1-i]);
	}
	
	cout << m << "\n";
	cout << g[m-1]; for(int i=m-2; i>=0; i--) cout << " " << g[i]; cout << "\n";
	cout << cnt << "\n";
	for(int i=0; i<n; i++) cout << A[i] << "\n";
	cout << flush;
	
	return 0;
}

int main(){
	int n;
	cin >> n;
	for(int i=0; i<n; i++) cin >> A[i];
	
	shellSort(n);
	
	return 0;
}


Measured memory_bytes: 7040
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

int main()
{
    string s;
    cin >> s;

    int index = 0;
    int count = 0;
    string prev_s = "";
    for (int i = 0; i < s.size(); i++)
    {
        auto token = s.substr(index, i - index + 1);
        if (prev_s != token)
        {
            prev_s = token;
            count++;
            index = i + 1;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 640
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    N = II()
    A = [0]*N
    pushed = [False]*N
    for i in range(N):
        A[i] = II()
    count = 0
    n = 1
    while True:
        pushed[n-1] = True
        n = A[n-1]
        count += 1
        if n == 2:
            print(count)
            return
        elif pushed[n-1]:
            print(-1)
            return


    

if __name__ == '__main__':
    main()

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  if(!(n % 2)) {
    char s1[n / 2 + 1] = {}, s2[n / 2 + 1] = {};
    s.copy(s1, n / 2);
    s.copy(s2, n / 2, n / 2);
    if(!strcmp(s1, s2)) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


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

int main()
{
	char stack[105], tmp;
	int N, pos;
	while (cin >> N)
	{
		string p = "";
		string t = "";
		pos = 0;
		for (int i = 1; i <= N; i++)
		{
			cin >> tmp;
			p += tmp;
			if (pos == 0)
			{
				stack[pos++] = tmp;	continue;
			}
			if (tmp == ')'&&stack[pos - 1] == '(')
				pos--;
			else
				stack[pos++] = tmp;
		}
		if (pos == 0)
		{
			cout << p << endl;	continue;
		}
		while (pos > 0)
		{
			if (stack[pos - 1] == '(')
			{
				p += ')';
				pos--;
			}
			if (stack[pos - 1] == ')')
			{
				t += '(';
				pos--;
			}
		}
		t += p;
		cout << t << endl;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <ctype.h>
using namespace std;

int main(){
    int count[26]={0};
    string w; cin >> w;
    for (int i=0;i<w.size();i++){
        int tmp = int(w[i])-int('a');
        count[tmp]++; 
    }
    for (int i=0;i<26;i++){
        if (count[i]%2 != 0) {
            cout << "No" << endl;
            return 0;
        }
        else if (i==25) {
            cout << "Yes" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
package main

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

var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}

func main() {
	nextReader = newScanner()

	N := nextInt()
	ai := nextInts(N)

	num := 0
	for _, v := range ai {
		if v == num+1 {
			num++
		}
	}
	cnt := -1
	if num != 0 {
		cnt = N - num
	}
	fmt.Println(cnt)
}

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

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

int main() {
  int n; cin >>n;
  int bufa; cin >>bufa;
  int bufb;
  int ans = bufa;
  for (int i=0; i<n-1; i++){
    bufb = bufa; cin >>bufa;
    ans = min(ans, gcd(bufa,bufb));
  }
  cout <<ans;
  cout <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli n;
	cin >> n;
	cout << n*(n-1)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<int> a(n);rep(i,n)cin>>a[i];
  int four = 0;
  int odd = 0;
  rep(i,n){
    if(a[i] % 4 == 0)four++;
    if(a[i]%2)odd++;
  }
  int even = n - odd - four;
  if(n/2 <= four || odd <= four)print("Yes");
  else print("No");
  return 0;
}

Measured memory_bytes: 640
N,M = map(int,input().split())
x = [0 for i in range(N+2)]
for m in range(M):
    L,R = map(int,input().split())
    x[L] += 1
    x[R+1] -=1

c = 0
cnt = 0
for i in range(N+2):
    c += x[i]
    if c == M:
        cnt += 1


print(cnt)

Measured memory_bytes: 4136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];

        for(int i = 0; i < n; i++)
        	a[i] = sc.nextInt();

        int q = sc.nextInt();
        for(int i = 0; i < q; i++) {
        	if(solve(a, sc.nextInt(), 0))
        		System.out.println("yes");
        	else
        		System.out.println("no");
        }
        sc.close();
	}

	static boolean solve(int[] a, int ans, int i) {
		if(ans == 0)
			return true;

		if(i >= a.length)
			return false;

		return solve(a, ans, i + 1) || solve(a, ans - a[i], i + 1);
	}
}



Measured memory_bytes: 26884
#include<cstdio>
using namespace std;
int n,a[100010],minn,maxx,i;
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	minn=maxx=a[1];
	for (i=2;i<=n;i++)
	{
		if (a[i]<minn) minn=a[i];
		if (a[i]>maxx) maxx=a[i];
	}
	if (maxx-minn>=2) 
	{
		printf("No\n");
		return 0;
	}
	if (maxx==minn)//no unique color  >=2*c   OR all are unique 
	{
		if (n==maxx+1)
		{
			printf("Yes\n");
			return 0;
		}
		if (n>=2*maxx)
		{
			printf("Yes\n");
			return 0;
		}
		printf("No\n");
		return 0;
	}
	//maxx=minn+1
	//some are unique,some are not
	int cnt=0;
	for (i=1;i<=n;i++) if (a[i]==minn) cnt++;//unique
	maxx-=cnt;//not unique
	if (maxx<=0) {printf("No\n");return 0;}
	if (n-cnt>=2*maxx)
	{
			printf("Yes\n");
			return 0;
	}
	printf("No\n");
	return 0;
}
//in total?
//unqiue color?

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long int t[100001];
long int solve(long int a[],long int n)
{
    if(n==0)
    {
        return 0;
    }
    if(n<0)
    {
        return INT_MAX-11;
    }
    if(t[n]!=-1)
    {
        return t[n];
    }
    else
    {
        if(n-3>=0)
        {
        return t[n]=min(abs(a[n-1]-a[n-2])+solve(a,n-1),abs(a[n-1]-a[n-3])+solve(a,n-2) );
        }
        else if(n-2>=0)
        {
            return t[n]=abs(a[n-1]-a[n-2])+solve(a,n-1);
        }
        else
        {
            return t[n]=solve(a,n-1);
        }
    }
}
int main ()
{
    memset(t,-1,sizeof(t));
    long int n;
    cin>>n;
    long int a[n];
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
    }
    
    long int p= solve(a,n);
    cout<<p<<endl;
    
    return 0;
}


Measured memory_bytes: 8992
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   string S;
   cin>>S;
   int fee=700;
   rep(i,3){
       if(S[i]=='o'){
           fee+=100;
       }
   }
   cout<<fee<<endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int n ; 
ll inf = 1e18+7; 
long int arr[401]; 
vector< vector<ll> > memo(401 , vector<ll> (401,-1) );

ll find(int i ,int j )
{
     if( i == j ) return 0 ;

     if(memo[i][j] != -1 ) return memo[i][j];
     
     ll res = inf;
     ll sum = accumulate(begin(arr)+i, begin(arr)+ (j+1), 0ll ) ;  
     for(int k = i+1 ; k <= j ; k ++)
     {
     	
         res = min ( res , sum + find(i,k-1) + find(k,j));
     	
     }

     return memo[i][j] = res; 

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

       	cout << find(0,n-1); 
       


}

int main()
{

	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);

	 
	 int test = 0, t = 1;
	 if(test) cin >> t;
	 for(int i = 0 ; i < t ; i ++)
	 {
         solve(); 
	 }

	return 0;
}


Measured memory_bytes: 4956
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repeat(i,a,b) for(int i=(a),i##__end=(b);i<i##__end;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,i##__end=(a);i>=i##__end;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define pii pair<int,int>
#define N 100010
#define mod 1000000007
#define int ll
char s[310][310];
int ans[310][310];
int n,m,k;
int find(){
	repeat(i,0,n)
	repeat(j,0,m)
	if(s[i][j]=='#')
		return i;
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>m>>k;
	repeat(i,0,n)cin>>s[i];
	int f=find();//cout<<f<<endl;
	repeat(i,f,n){
		int cnt=0;
		repeat(j,0,m)
			cnt+=s[i][j]=='#';
		if(cnt==0){
			if(i==f)
				repeat(j,0,m)ans[i][j]=1;
			else
				repeat(j,0,m)ans[i][j]=ans[i-1][j];
		}
		else{
			int co;
			if(i==f)co=0;
			else co=ans[i-1][m-1];
			co++;
			repeat(j,0,m){
				ans[i][j]=co;
				cnt-=s[i][j]=='#';
				if(s[i][j]=='#' && cnt>0)
					co++;
			}
		}
	}
	repeat(i,0,f){
		repeat(j,0,m)cout<<ans[f][j]<<' ';
		cout<<endl;
	}
	repeat(i,f,n){
		repeat(j,0,m)cout<<ans[i][j]<<' ';
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = 1e9;
  for (int i = 1; i <= 100; i ++) {
    int sum = 0;
    for (int j = 0; j < n; j ++) {
      sum += (a[j] - i) * (a[j] - i);
    }
    ans = min(ans, sum);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
const log = console.log;

const parseLines = (s: string) => s.trim().split("\n");
const parseSpaceSeparated = (line: string) => line.trim().split(" ");
const parseDecimalInt = (s: string) => parseInt(s);
const parseSpaceSeparatedDecimalInt = (line: string) =>
  parseSpaceSeparated(line).map(parseDecimalInt);

const descendingSorter = (a: number, b: number) => b - a;

const sumReducer = (accumulator: number, currentValue: number) =>
  accumulator + currentValue;
const sum = (numbers: number[]) => numbers.reduce(sumReducer, 0);

// ----

function Main(input: string): void {
  const [head, body] = parseLines(input);
  const [n, k] = parseSpaceSeparatedDecimalInt(head);
  const l = parseSpaceSeparatedDecimalInt(body);

  l.sort(descendingSorter);

  log(sum(l.slice(0, k)));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    long long n,p,q;
    cin >> n >> p >> q;
    vector<long long> a(n);
    long long sum = 0;
    for(int i = 0; i < n; i++){
        long long c;
        cin >> c;
        sum += c;
        a[i] = p*i + c;
    }
    sort(a.begin(),a.end());
    for(int i = 0; i < n-1; i++)a[i+1] += a[i];
    long long ans = sum;
    for(int i = 1; i <= n; i++){
        ans = max(ans, sum + i*p*q+p*i*(i-1) - a[i-1]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 6792
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i)  
#else
  #define DUMP(i)  
#endif

#define GETTYPE(i) 
#define TOSTRING(x) #x
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a):i<(b);i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,n;
  while(cin >> a >> b >> n){
    int ans = 0;
    REP(i,n){
      int ia,ib;
      cin >> ia >> ib;
      DUMP(ia < a && a < ib);
      DUMP(ia < b && b < ib);
      if((ia < a && a < ib) || (ia < b && b < ib) || ia == a || ib == b || a < ia && ib < b) ans = 1;
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3116
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        ArrayList<Integer> x = new ArrayList<>();
        ArrayList<Integer> l = new ArrayList<>();

        int ans = 0;

        for (int i = 0; i < m; i++) {
            x.add(sc.nextInt());
        }
        Collections.sort(x);

        for (int i = 1; i < m; i++) {
            l.add(Math.abs(x.get(i-1) - x.get(i)));
        }
        Collections.sort(l);

        for (int i = 0; i < m - n; i++) {
            ans += l.get(i);
        }
        System.out.println(ans);

//        for (int i = 0; i < m; i++) {
//            System.out.println(l.get(i));
//        }



    }
}


Measured memory_bytes: 54464
n=int(input())
h=[int(i) for i in input().split()]
c=0
d=c
for i in range(n-1):
    if h[i]>=h[i+1]:
        c+=1
    else:
        if c>d:
            d=c
        c=0
    if i==n-2 and c>d:
        d=c
    
print(d)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll N;
  cin >> N;
  ll sum = 0;
  ll ex = 10;
  if(N%2==1)
  {
    cout << 0 << endl;
  }
  else
  {
    while(N/ex>0)
    {
      sum += N/ex;
      ex *= 5;
    }
    cout << sum << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3592
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let a:i32 = read();
    let b:i32 = read();

    let d:i32 = b-a;
    println!("{}", d*(d-1)/2-a);

}


Measured memory_bytes: 4352
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<vector<vector<vector<int>>>> vvvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<vector<vector<vector<ll>>>> vvvvl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;

int N;

char change(char X){
  string A = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int aPos = A.find_first_of(X);
  aPos += N;
  return A[aPos];
}

int main() {
  string S;
  cin >> N >> S;
  string ans;
  for(int i = 0; i < S.size(); i++){
    ans.push_back(change(S[i]));
  }
  cout << ans <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int getint()
{
    int i=0,f=1;char c;
    for(c=getchar();(c!='-')&&(c<'0'||c>'9');c=getchar());
    if(c=='-')c=getchar(),f=-1;
    for(;c>='0'&&c<='9';c=getchar())i=(i<<3)+(i<<1)+c-'0';
    return i*f;
}
const int N=200005,mod=1e9+7;
const ll INF=1e18;
int n,m,A,B,q[N];
ll f[N<<2],g[N<<2],h[N<<2],tag[N<<2];
void add(int k,ll v){if(f[k]!=INF)f[k]+=v,g[k]+=v,h[k]+=v,tag[k]+=v;}
void pushdown(int k){add(k<<1,tag[k]),add(k<<1|1,tag[k]);tag[k]=0;}
void update(int k)
{
	f[k]=min(f[k<<1],f[k<<1|1]);
	g[k]=min(g[k<<1],g[k<<1|1]);
	h[k]=min(h[k<<1],h[k<<1|1]);
}
void build(int k,int l,int r)
{
	f[k]=g[k]=h[k]=INF;
	if(l==r)return;
	int mid=l+r>>1;
	build(k<<1,l,mid),build(k<<1|1,mid+1,r);
}
void chkmin(int k,int l,int r,int p,ll v)
{
	if(l==r)
	{	
		if(v<f[k])f[k]=v,g[k]=v-l,h[k]=v+l;
		return;
	}
	if(tag[k])pushdown(k);
	int mid=l+r>>1;
	p<=mid?chkmin(k<<1,l,mid,p,v):chkmin(k<<1|1,mid+1,r,p,v);
	update(k);
}
ll query(int k,int l,int r,int x,int y,int op)
{
	if(x>y)return INF;
	if(x<=l&&r<=y)return op?h[k]:g[k];
	if(tag[k])pushdown(k);
	int mid=l+r>>1;
	if(y<=mid)return query(k<<1,l,mid,x,y,op);
	else if(x>mid)return query(k<<1|1,mid+1,r,x,y,op);
	else return min(query(k<<1,l,mid,x,mid,op),query(k<<1|1,mid+1,r,mid+1,y,op));
}
int main()
{
	//freopen("lx.in","r",stdin);
	n=getint(),m=getint(),A=getint(),B=getint();
	build(1,1,n);
	for(int i=1;i<=m;i++)q[i]=getint();
	q[0]=B;chkmin(1,1,n,A,0);
	for(int i=1;i<=m;i++)
	{
		ll tmp=min(query(1,1,n,1,q[i],0)+q[i],query(1,1,n,q[i]+1,n,1)-q[i]);
		add(1,abs(q[i]-q[i-1]));chkmin(1,1,n,q[i-1],tmp);
	}
	cout<<f[1]<<'\n';
	return 0;
}


Measured memory_bytes: 25600
/* CODE BY NITIN 
	ON 5 April 2020--------------
	*/
	
	#include <bits/stdc++.h>
	//#include<boost/multiprecision/cpp_int.hpp>
	#define mod 1000000007
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
	#define REP(i, n) for (int i = 0; i < (n); i++)
	#define REPN(i, n) for (int i = 1; i <=(n); i++)
	#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
	#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
	#define T(a) ll a;  cin >> a;
	#define TT(t) T(t); while (t--)
	#define pb push_back
	#define mp make_pair
	 #define ll long long int
	using namespace std;
 
 
	void solve()
	{
	
		T(n)T(m)
		ll a[m];
		REP(i,m)
		cin>>a[i];
		ll sum =0;
		REP(i,m)
		sum=sum+a[i];
		if(sum>n)
		cout<<"-1"<<endl;
		else
		cout<<n-sum<<endl;
				
		
	}
	int main()
	{
		
		
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
		solve();
		return 0;
		
	}


Measured memory_bytes: 3720
eval"H,W,*A="+`dd`.split*?,
a=A.pop(H*W).zip(A).map{|a,b|(a-b).abs}
d=[1<<t=10**4]+[0]*~-W
a.map{|a|d.size%W<1&&N=0;N|=d[-W];d<<N=N<<a|N>>a}
p (0..2*t).map{|i|(t-i*N[i]).abs}.min

Measured memory_bytes: 35716
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int N = 100010;

int x[N], a[N];
ll p[N];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, s;
  cin >> n >> s;
  for (int i = 1; i <= n; ++i) cin >> x[i] >> p[i];
  int div = lower_bound(x + 1, x + n + 1, s) - x;
  int l = 1, r = n, c = 0;
  while (l <= r) {
    bool f = false;
    if (l < div) {
      if (r >= div) {
        if (p[l] >= p[r])
          f = true;
      }
    } else
      f = true;
    if (f) {
      a[++c] = x[r];
      p[l] += p[r--];
    } else {
      a[++c] = x[l];
      p[r] += p[l++];
    }
  }
  ll ans = 0;
  a[++c] = s;
  for (int i = n; i; --i)
    ans += abs(a[i] - a[i + 1]);
  cout << ans << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 1792
y, m, d = gets.chomp.split('/').map(&:to_i)

def heisei?(y, m, d)
  return false if y > 2019
  return true if y < 2019
  return false if m > 4
  true
end

puts heisei?(y, m, d) ? 'Heisei' : 'TBD'



Measured memory_bytes: 1788
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define N 2005
using namespace std;
int l[N],n,a[N],r[N],w[N],pr[5000005],f[N],a1[N][N];
bool bz[20000005],bp[N];
void prp()
{
	bz[1]=1;
	bz[0]=1;
	fo(i,2,20000000)
	{
		if(!bz[i]) pr[++pr[0]]=i;
		for(int j=1;j<=pr[0]&&i*pr[j]<=20000000;j++)
		{
			bz[i*pr[j]]=1;
			if(i%pr[j]==0) break;
		}
	}
	bz[2]=1;
}
bool find(int k)
{
	fo(i,1,a1[k][0])
	{
		int p=a1[k][i];
		if(!bp[p])
		{
			bp[p]=1;
			if(!f[p]||find(f[p])) 
			{
				f[p]=k;
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	cin>>n;
	prp();
	fo(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	fo(i,1,n) 
	{
		if(i==1||a[i-1]!=a[i]-1) w[++w[0]]=a[i];
		if(a[i+1]!=a[i]+1) w[++w[0]]=a[i]+1;
	}
	sort(w+1,w+w[0]+1);
	fo(i,1,w[0]) 
		if(w[i]%2==0) l[++l[0]]=w[i];
		else r[++r[0]]=w[i];
	fo(i,1,l[0])
	{
		fo(j,1,r[0])
		{
			if(!bz[abs(l[i]-r[j])]) a1[i][++a1[i][0]]=j;
		}
	}
	long long s=0;
	fo(i,1,l[0]) 
	{
		memset(bp,0,sizeof(bp));
		if(find(i)) s++;
	}
	printf("%lld",s+2*(long long)((l[0]-s)/2)+2*(long long)((r[0]-s)/2)+3*(long long)((l[0]-s)%2));
}

Measured memory_bytes: 27008
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> A;
  double a;
  double sum=0;
  for(int i=0;i<N;i++){
    cin >>a;
    A.push_back(a);
    sum+=a;
  }
  sort(A.begin(), A.end());
  int hantei=1;
  for(int i=N-1;i>N-M-1;i--){
    if(A[i]>=sum/4/M){
      hantei*=1;
    }
    else{
      hantei*=0;
    }
    //cout << A[i];
  }
  if(hantei==1){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
 
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}
 
void init_global() {}

int main_() {
	int W, a, b;
	cin >> W >> a >> b;
 
	int ans = 0;
	if (b + W < a) ans = a - (b + W);
	else if (a + W < b) ans = b - (a + W);
 
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//aとbの大きい方

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//aとbの小さい方

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//aとbの差の絶対値

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

int main() {

	ll N, a = 2;

	cin >> N;

	while (1) {

		if (a*a > N) {

			cout << (a - 1)*(a - 1) << endl;
			break;

		}
		a++;

	}

	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from collections import deque

N, M = map(int, input().split())

D = defaultdict(list)
for i in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  D[a].append(b)
  D[b].append(a)

q = deque([])
q.append(0)

ans = 0
def dfs(n, q):
  global ans
  q.append(n)
  if len(q) == N:
    ans += 1
  else:
    for b in D[n]:
      if b not in q:
        dfs(b, q)
        q.pop()

dfs(0, [])
print (ans)

Measured memory_bytes: 3316