akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;
 
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
 
template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}
 
// ------------------------------------------------------------------------------------------

map<vector<int>, int> mp;

void init() {
   vector<int> v(8);
   iota(all(v), 0);
   mp[v] = 0;

   queue<vector<int>> que;
   que.push(v);
   while (que.size()) {
      vector<int> cur = que.front(); que.pop();
      int idx = find(all(cur), 0) - cur.begin();

      rep (i, 4) {
         int ny = (idx / 4) + dy[i];
         int nx = (idx % 4) + dx[i];
         if (ny < 0 || ny >= 2 || nx < 0 || nx >= 4) continue;
         int nc = ny * 4 + nx;
         vector<int> tmp = cur;
         swap(tmp[nc], tmp[idx]);
         if (mp.count(tmp)) continue;
         mp[tmp] = mp[cur] + 1;
         que.push(tmp);
      }
   }
}

int main() {
   init();
   vector<int> vs(8);
   while (cin >> vs[0]) {
      repp (i, 1, 8) cin >> vs[i];
      cout << mp[vs] << endl;
   }

   return 0;
}


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
const ll INFll = 1E+18;

int e() {
    return -INF;
}

int op(int a, int b) {
    return max(a, b);
}
int val;
bool comp(int now) {
    return now<val;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, q;
    cin >> n >> q;
    vi a(n);
    rep(i, n) cin >> a[i];
    segtree<int, op, e> s(a);
    
    rep(qi, q) {
        int t;
        cin >> t;
        if (t==1) {
            int x, v;
            cin >> x >> v;
            x--;
            s.set(x, v);
        }
        if (t==2) {
            int l, r;
            cin >> l >> r;
            l--;
            int ans = s.prod(l, r);
            pr(ans);
        }
        if (t==3) {
            int x;
            cin >> x >> val;
            x--;
            int ans = s.max_right<comp>(x);
            ans++;
            pr(ans);
        }
    }
    return 0;
}


Measured memory_bytes: 6140
a = input()
b = input()
ans = ''
if len(a) == len(b):
  for i in range(len(a)):
    ans = ans + (a[i]+b[i])
else:
  for i in range(len(a)-1):
    ans = ans +(a[i]+b[i])
  ans = ans + (a[-1])
print(ans)

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

int main() {
  string S;
  cin >> S;
  int a = 0;
  for (int i = 0; i < S.size(); i++) {
    if (i%2 == 0 && S.at(i) == 'L')
      a++;
    if (i%2 == 1 && S.at(i) =='R')
      a++;
  }
  if (a == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3576
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
ans=0
pre_x=x[0]
for i in range(1,n):
    xi=x[i]
    if((xi-pre_x)*a >= b):
        ans+=b
    else:
        ans+=(xi-pre_x)*a
    pre_x=xi
print(ans)

Measured memory_bytes: 15020
n=int(input())
a,b=[],[]
for _ in range(n):
    a_,b_=map(int,input().split())
    a.append(a_)
    b.append(b_)
a.sort()
b.sort()
if n%2:
    print(b[n//2]-a[n//2]+1)
else:
    lower=(a[n//2]+a[n//2-1])/2
    upper=(b[n//2]+b[n//2-1])/2
    print(int(upper*2-(lower*2-1)))

Measured memory_bytes: 25300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int n, h[105], ma = 0, ans = 0;
    cin >> n;
    REP(i,n){
        cin >> h[i];
    }
    REP(i,n){
        if(h[i] >= ma) ans++;
        ma = max(ma, h[i]);
    }
    cout << ans << endl;
    return 0;
}

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;

  std::vector<std::set<int64_t>> s(n), t(n);

  for (int64_t i = 0; i < n; i++) {
    int64_t a;
    std::cin >> a;
    for (int64_t j = 0; j < a; j++) {
      int64_t x, y;
      std::cin >> x >> y;
      x--;
      if (y == 1) {
        s[i].insert(x);
      } else {
        t[i].insert(x);
      }
    }
  }

  std::vector<bool> f(n);
  int64_t ans = 0;
  for (int64_t i = 0; i < (1 << n); i++) {
    auto j = i;
    int64_t num = 0;
    bool flag = true;
    for (int64_t k = 0; k < n; k++) {
      f[k] = ((j % 2) == 1);
      if (f[k]) {
        num++;
      }
      j /= 2;
    }

    for (int64_t k = 0; k < n; k++) {
      if (f[k]) {
        for (const auto l : s[k]) {
          if (!f[l]) {
            flag = false;
            break;
          }
        }
        for (const auto l : t[k]) {
          if (f[l]) {
            flag = false;
            break;
          }
        }
      }
    }
    if (flag) {
      ans = std::max(ans, num);
    }
  }
  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}


int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> white;
    vector<int> red;
    int tmp=0;
    REP(i,n){
        if(s[i]=='W'){
            tmp++;
        }
        else{
            if(tmp!=0){
                white.push_back(tmp);
                tmp=0;
            }
        }
    }
    tmp=0;
    REP(i,n){
        if(i==0&&s[i]=='R'){
            tmp=-1;
        }
        if (s[i] == 'R')
        {
            if(tmp==-1){
                continue;
            }
            tmp++;
        }
        else
        {
            if (tmp > 0)
            {
                red.push_back(tmp);
            }
            tmp = 0;
        }
    }
    if(tmp!=0){
        red.push_back(tmp);
    }
    int ans=0;
    int nowr=red.size()-1;
    if(nowr==-1){
        cout << ans << endl;
        return 0;
    }
    int wsize=white.size();
    for(int i=0;i<wsize;i++){
        if(i==nowr){
            ans+=min(white[i],red[nowr]);
            break;
        }
        if(i>nowr){
            break;
        }
        if(red[nowr]<white[i]){
            white[i] -= red[nowr];
            ans+=red[nowr];
            red[nowr] = 0;
            nowr--;
            i--;
        }
        else if(red[nowr]==white[i]){
            ans+=red[nowr];
            red[nowr]=white[i]=0;
            nowr--;
        }
        else{
            ans+=white[i];
            red[nowr]-=white[i];
            white[i]=0;
        }
    }
    cout << ans << endl;
}


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

ll cmd(ll a, ll b){
return b==0?a:cmd(b,a%b);}
ll gcd(ll a , ll b){
    ll k = cmd(a,b);
    return (a/k)*b;
}
ll a[10000]={0};
int main(){
    ll n,num=1;
    cin >>n;
    for(ll i=1;i<=n;i++){
        cin >>a[i];
    }
    for(int i=1;i<=n;i++){
        num=gcd(a[i],num);
    }
    cout<<num<<endl;

}


Measured memory_bytes: 256
A = []
for i in range(3):
    for x in map(int, input().split()):
        A.append(x)
for _ in range(int(input())):
    x = int(input())
    if x in A:
        A[A.index(x)] = 'b'
cds = [
    [0, 1, 2],
    [3, 4, 5],
    [6, 7, 8],
    [0, 3, 6],
    [1, 4, 7],
    [2, 5, 8],
    [0, 4, 8],
    [2, 4, 6]
]
for cd in cds:
    if A[cd[0]] == 'b' and A[cd[1]] == 'b' and A[cd[2]] == 'b':
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
import math

def gai(x1,y1,x2,y2,x3,y3):
    #coordinates

    #length of each side squared and area of the triangle
    a2 = (x2 - x3) **2 + (y2 -y3) ** 2
    b2 = (x1 - x3) **2 + (y1 -y3) ** 2
    c2 = (x2 - x1) **2 + (y2 -y1) ** 2
    area = ((x2 - x1) * (y3 -y1) - (x3 -x1) * (y2- y1)) / 2

    #is_triangle
    if area == 0:
        xmax=max(x1,x2,x3)
        xmin=min(x1,x2,x3)
        x=xmax-xmin
        ymax=max(y1,y2,y3)
        ymin=min(y1,y2,y3)
        y=ymax-ymin
        r=(x*x+y*y)**0.5/2
        gx=(xmax+xmin)/2
        gy=(ymax+ymin)/2
        return gx,gy,r

    #circumcenter coordinate and radius
    x = (a2*(b2+c2-a2)*x1 + b2*(c2+a2-b2)*x2 + c2*(a2+b2-c2)*x3) / (16*area*area)
    y = (a2*(b2+c2-a2)*y1 + b2*(c2+a2-b2)*y2 + c2*(a2+b2-c2)*y3) / (16*area*area)
    r = ((x1-x)**2 + (y1-y)**2)**0.5

    #rounding
    #return the equation
    return x, y, r

def gai2(x1,y1,x2,y2):
    return (x1+x2)/2,(y1+y2)/2,((x1-x2)**2+(y1-y2)**2)**0.5/2

N=int(input())
X=[]
Y=[]
for i in range(N):
    x,y=map(int,input().split())
    X.append(x)
    Y.append(y)
if N==2:
    print(((X[1]-X[0])**2+(Y[1]-Y[0])**2)**0.5/2)
    exit()
#print(X,Y)
dm=float("inf")
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            """gx=(X[i]+X[j]+X[k])/3
            gy=(Y[i]+Y[j]+Y[k])/3
            han=((gx-X[i])**2+(gy-Y[i])**2)"""
            gx,gy,r=gai(X[i],Y[i],X[j],Y[j],X[k],Y[k])
            #print(i,j,k)
            if dm>r:
                flg=True
                for l in range(N):
                    if l==i or l==j or l==k:
                        continue
                    if ((X[l]-gx)**2+(Y[l]-gy)**2)>r**2:
                        flg=False
                if flg:
                    dm=r
for i in range(N-1):
    for j in range(N):
        gx,gy,r=gai2(X[i],Y[i],X[j],Y[j])
        #print(i,j,k)
        if dm>r:
            flg=True
            for l in range(N):
                if l==i or l==j:
                    continue
                if ((X[l]-gx)**2+(Y[l]-gy)**2)>r**2:
                    flg=False
            if flg:
                dm=r
print(dm)


Measured memory_bytes: 49132
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int n;
    cin >> n;
    vector<int> nums(n);
    vector<int> cp(n);
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
        cp[i] = nums[i];
    }
    sort(nums.begin(), nums.end());
    int index = n / 2;
    for (int i = 0; i < n; i++) {
        if (cp[i] < nums[index]) {
            cout << nums[index];
        } else {
            cout << nums[index-1];
        }
        cout <<"\n";
    }
    return 0;
}


Measured memory_bytes: 3712
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    string s;
    cin>>s;
    
    int ans=0;
    
    for(int i=0;i<4;i++){
        if(s[i]=='+'){
            ans+=1;
        }else{
            ans-=1;
        }
    }
    
    cout<<ans<<endl;
    
    return 0;
}







Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] array = new int[10];
		for (int i = 0; i < 10; i++) {
			array[i] = Integer.parseInt(br.readLine());
		}
		Arrays.sort(array);
		for (int i = 9; 6 < i; i--) {
			System.out.println(array[i]);
		}
	}
}

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

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        y[i] = x[i];
    }
    sort(y.begin(), y.end());
    int midl = y[n / 2 - 1], midr = y[n / 2];
    for (int i = 0; i < n; i++) {
        if (x[i] <= midl)
            cout << midr << endl;
        else
            cout << midl << endl;
    }
    return 0;
}

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

using namespace std;

#define ge getchar()
#define Re read()

inline long long read() {
	long long x = 0, ch;
	while(!isdigit(ch = ge)) ;
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	return x;
}

const int MAXN = 100100;

struct Edge {
	int u, v;

	Edge() {}
	Edge(int u, int v):u(u), v(v) {}
}E[MAXN + 1];

int ct, N;
int fa[MAXN + 1];
int sz[MAXN + 1];

inline int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
inline void Merge(int u, int v) {
	int fu = find(u), fv = find(v);
	if(fu == fv) return ;
	fa[fu] = fv; ++N;
	sz[fv] += sz[fu];
}

int main() {
	int n = Re; long long m = Re; int q = Re;
	for(int i = 1; i <= n; i++) fa[i] = i;
	for(int i = 1; i <= q; i++) {
		int u = Re + 1, v = Re + 1, k = Re;
		if(k) {
			E[++ct] = Edge(u, v);
		} else {
			Merge(u, v);
		}
	}
	for(int i = 1; i <= ct; i++) {
		if(find(E[i].u) == find(E[i].v)) {
			puts("No");
			return 0;
		}
	} int SZ = 0;
	for(int i = 1; i <= n; i++) SZ += find(i) == i;
	if(SZ == 2) {
		puts("No");
		return 0;
	}
	m -= n - SZ;
	if(m > 1LL * SZ * (SZ - 1) / 2) {
		puts("No");
		return 0;
	} int tN = 0;
	for(int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1; N = 0;
	for(int i = 1; i <= ct; i++) Merge(E[i].u, E[i].v);
	for(int i = 1; i <= n; i++) tN += find(i) == i && sz[i] > 1 ? max(3, sz[i]) : 0;
	if(m < tN) {
		puts("No");
		return 0;
	} puts("Yes");
	return 0;
}


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

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define REPD(i,n) for(ll (i)=(ll)(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<=(b);(i)++)
#define FORD(i,a,b) for(ll (i)=(a);(i)>=(b);(i)--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define PB push_back
#define MP make_pair
#define F first
#define S second


//定数
constexpr ll INF = 1'010'000'000'000'000'017LL;

constexpr ll MOD = 1'000'000'007LL;

constexpr ll EPS = 1e-12;

constexpr ll PI = 3.14159265358979323846;

struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

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

void solve(){
    char s[3];
    cin >> s[0] >> s[1] >> s[2];
    if(s[0] == s[1] && s[1] == s[2]){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

signed main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main(){
    LL a;
    LL b;
    LL c;
    LL k;
    cin >> a >> b >> c;
    cin >> k;
    while(k>0 && b<=a){
        b*=2;
        k--;
    }
    while(k>0 && c<=b){
        c*=2;
        k--;
    }

    //cout << a << " " << b << " " << c << endl;

    if(b>a && c>b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Text;

class Program
{
    public void Proc()
    {
        string[] inpt = Console.ReadLine().Split(" "[0]);
        List<int> stack = new List<int>();
        foreach (string moji in inpt)
        {
            int num = 0;
            if(int.TryParse(moji, out num))
            {
                stack.Add(num);
            } else
            {
                switch(moji)
                {
                    case "+":
                        num = stack[stack.Count - 2] + stack[stack.Count - 1];
                        break;
                    case "-":
                        num = stack[stack.Count - 2] - stack[stack.Count - 1];
                        break;
                    case "*":
                        num = stack[stack.Count - 2] * stack[stack.Count - 1];
                        break;
                }
                stack.RemoveAt(stack.Count - 1);
                stack[stack.Count - 1] = num;

            }
        }
        Console.WriteLine(stack[0]);
    }

    static void Main(string[] args)

    {

        Program prg = new Program();
        prg.Proc();

    }
}

Measured memory_bytes: 9108
#include<iostream>
#include<vector>
#include<iomanip>
#include<float.h>
using namespace std;
using uint = unsigned int;

int main() {
	uint N, M;
	cin >> N >> M; 
	
	vector<vector<uint>> nodes(N);
	uint s, t;
	
	for(uint m=0; m<M; m++) {
		cin >> s >> t;
		nodes[s-1].push_back(t-1);
	}
	
	double ans = DBL_MAX;
	
	for(uint j=0; j<N; j++) {
		vector<double> e_dists(N);
		for(int i=N-2; i>=0; i--) {
			double max_dist = 0;
			double n_dist = 0;
			
			for(uint k=0; k<nodes[i].size(); k++) {
				n_dist += e_dists[nodes[i][k]];
				max_dist = max(max_dist, e_dists[nodes[i][k]]);
			}
			
			if ((nodes[i].size() > 1) && (i == j)) {
				e_dists[i] = 1 + (n_dist - max_dist) / (nodes[i].size() - 1);
			} else {
				e_dists[i] = 1 + n_dist / nodes[i].size();
			}
		}
		ans = min(ans, e_dists[0]);
	}
	
	cout << std::setprecision(7) << ans;
	
	return 0;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

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

    int counter = 0;

    while (input.ready())
    {
      String[] inputStr = input.readLine().split(" ");

      if (inputStr[0].equals("0") && inputStr[1].equals("0"))
      {
        break;
      }

      if (counter > 0)
      {
        System.out.println();
      }
      counter++;

      ArrayList<Integer> ansList = leapYearCount(Integer.parseInt(inputStr[0]),
          Integer.parseInt(inputStr[1]));

      if (ansList.size() == 0)
      {
        System.out.println("NA");
        continue;
      }

      for (Integer each : ansList)
      {
        System.out.println(each);
      }
    }

  }

  private static ArrayList<Integer> leapYearCount(int fromYear, int toYear)
  {
    ArrayList<Integer> yearList = new ArrayList<>();
    for (int i = fromYear; i <= toYear; i++)
    {
      if (isLeapYear(i))
      {
        yearList.add(i);
      }
    }
    return yearList;
  }

  private static boolean isLeapYear(int year)
  {
    if (year % 4 != 0)
    {
      return false;
    }

    if (year % 100 == 0)
    {
      if (year % 400 == 0)
      {
        return true;
      }
      return false;
    }
    return true;
  }
}

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

int main() {
	int n;
	scanf("%d", &n);
	vector<double> f(n+1, 0);
	f[0]=1;
	for (int i=1; i<=n; i++) {
		double p;
		scanf("%lf", &p);
		vector<double> nf(n+1, 0);
		for (int j=0; j<=i; j++) nf[j]=(j>=1?f[j-1]*p:0)+f[j]*(1-p); 
		f=nf;
	}	
	double ans=0;
	for (int i=n/2+1; i<=n; i++) ans+=f[i];
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
count=0
for i in range(n):
  if b[i]-a[i]>0:
    count+=a[i]
    if a[i+1]>(b[i]-a[i]):
      a[i+1]-=(b[i]-a[i])
      count+=(b[i]-a[i])
    elif a[i+1]<=b[i]-a[i]:
      count+=a[i+1]
      a[i+1]=0
  elif b[i]<=a[i]:
    count+=b[i]   
print(count)

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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>

void solve2()
{
	int k, n;
	cin >> k >> n;
	vi a(n);
	int ans = k;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		int prev = (i == 0) ? a[n - 1] : a[i - 1];
		int dist = abs(a[i] - prev);
		ans = min(ans, max(dist, k - dist));
	}
	cout << ans << "\n";
}
void solve()
{
	int k, n;
	cin >> k >> n;
	vi a(n);
	int ans = 0;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++)
		ans = max(ans, abs(a[i] - a[i - 1]));
	ans = max(ans, k - a[n - 1] + a[0]);
	cout << k - ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	solve();
	// int k, n, ma = 0;
	// cin >> k >> n;
	// vi A(n);
	// for (int i = 0; i < n; i++)
	// {
	// 	cin >> A[i];
	// }
	// for (int i = 1; i < n; i++)
	// {
	// 	ma = max(abs(A[i] - A[i - 1]), ma);
	// }
	// ma = max(ma, k - A[n - 1] + A[0]);
	// cout << k - ma;
}

Measured memory_bytes: 3972
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<ctime>
#include<map>
#include<queue>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<stack>

using namespace std;

	long long dp[1<<21][22];
	int nr[1<<21];
	int comp[22][22];
	
	vector < int > visit[22];
	#define MOD 1000000007

int main(){
	
	int n; cin >> n;
	for(int i = 0 ; i< n; i++){
		for(int j = 0; j < n; j++){
			cin >> comp[i][j];
		}
	}
	
	for(int i = 0; i < n; i++){
		if(comp[0][i] == 1){
			dp[1<<i][0] = 1;
		}
	}
	
	for(int i = 0; i < (1<<21); i++){
		for(int j = 0; j < 22; j++){
			if(i&(1<<j)) nr[i]++;
		}
		visit[nr[i]].push_back(i);	
	}
		
	
	
	
	for(int i = 0; i < n; i++){
		
		for(int j = 0; j < visit[i+1].size(); j++){
			
	//		cout << visit[i+1][j] << " ";
			if(dp[visit[i+1][j]][i] == 0) continue;
	
			//cout <<visit[i+1][j]<< endl;
	
			for(int k = 0; k < n; k++){
				
				
				if((visit[i+1][j] & (1<<k)) == 0 && comp[i+1][k]){
					
				//	cout << "kurac";
					
					dp[visit[i+1][j]|(1<<k)][i+1] += dp[visit[i+1][j]][i];
					dp[visit[i+1][j]|(1<<k)][i+1]%=MOD;
					
				}
				
			}
			
		}
	//	system("pause");
		
	}
	
	cout << dp[(1<<n)-1][n-1];


return 0;
}

Measured memory_bytes: 378300
#include <iostream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <limits>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;
using ll = long long;

void print(vector<ll> v) {
    for (int i = 0; i < v.size(); i++) {
        if (v[i] != 0) {
            cout << i << ": " << v[i] << endl;
        }
    }
}

int main() {

    string S;
    cin >> S;
    auto len = S.length();
    ll pairs = 0;

    int currMod = 0;
    vector<ll> modCounts(2019, 0);
    cout << endl;

    for (auto c : S) {
        int digit = c - '1' + 1;
        currMod = (currMod * 10 + digit) % 2019;
        vector<ll> nextCounts(2019, 0);

        for (int m = 0; m < 2019; m++) {
            if (modCounts[m] > 0) {
                int newMod = ((m * 10) + digit) % 2019;
                if (newMod == 0)
                    pairs += modCounts[m];
                nextCounts[newMod] += modCounts[m];
            }
        }
        nextCounts[digit]++;
        modCounts = nextCounts;
    }

    cout << pairs << endl;
    return 0;
}


Measured memory_bytes: 3704
#include<cstdio>
using namespace std;
const int maxn=200005;
char a[maxn],b[maxn];int len;
int main(){
	scanf("%s",a);
	for (int i=0;a[i];i++)
	if(a[i]=='S') b[++len]='S';else if(a[i]=='T')
	if(b[len]=='S'&&len) len--;else b[++len]='T';
	printf("%d\n",len);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
#define MOD 1000000007
typedef long long ll;
//------------------------------------------------------------------------

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

  int n,m; cin >> n >> m;
  vector<double> a(n);
  double sum = 0;
  rep(i,n){
    cin >> a[i];
    sum+= a[i];
  }

  int cnt = 0;
  double tmp = sum / (4*m);
  rep(i,n){
    if(a[i]>=tmp) cnt++;
  }

  if(cnt>=m) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

int main()
{
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B), cost(M);
    rep(i, 0, A)
    {
        cin >> a.at(i);
    }
    rep(i, 0, B)
    {
        cin >> b.at(i);
    }
    int x, y, c;
    rep(i, 0, M)
    {
        cin >> x >> y >> c;
        cost.at(i) = a.at(x - 1) + b.at(y - 1) - c;
    }
    sort(all(cost));
    sort(all(a));
    sort(all(b));
    if (cost.at(0) < a.at(0) + b.at(0))
    {
        cout << cost.at(0) << endl;
    }
    else
    {
        cout << a.at(0) + b.at(0) << endl;
    }
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int A = min(a,b);
  int B = max(a,b);
  for(int i=A;i<=B;i++){
    if(i == c){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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


int N;
string S,T;
int main(){
    ios_base::sync_with_stdio();
    scanf("%d", &N);
    cin >> S >> T;
    for(int i = 0; i < S.size(); ++i){
        cout << S[i];
        cout << T[i];
    }
}

Measured memory_bytes: 256
let cs, a_s = Array.(make 100001 0, init (read_int ()) @@ fun _ -> Scanf.scanf " %d" (+) 0)
let _ = Array.(iter (fun a -> cs.(a) <- cs.(a) + 1) a_s; List.(length @@ sort_uniq (-) @@ to_list a_s) - if (fold_left (fun s c -> if c > 0 && c mod 2 = 0 then s + 1 else s) 0 cs) mod 2 = 1 then 1 else 0) |> Printf.printf "%d\n"

Measured memory_bytes: 11648
from bisect import bisect_left, bisect_right

S = input()

ret = [0] * len(S)
L = []
R = []
for i, s in enumerate(S) :
    if s == 'L' :
        L.append(i)
    else :
        R.append(-i)

R = R[::-1]
for i, s in enumerate(S) :
    if s == 'L' :
        t = -R[bisect_right(R, -i)]
        if (i - t) % 2 == 0 :
            ret[t] += 1
        else :
            ret[t+1] += 1
    else :
        t = L[bisect_left(L, i)]
        if (t - i) % 2 == 0 :
            ret[t] += 1
        else :
            ret[t-1] += 1
            
print(' '.join(map(str, ret)))
    

Measured memory_bytes: 57964
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

int main() {
    int N;
    cin >> N;
    auto F = make_vec_nd(false, N, 5, 2);
    auto P = make_vec_nd((int)0, N, 11);
    for (int shop = 0; shop < N; shop++) {
        for (int day = 0; day < 5; day++) {
            for (int ap = 0; ap < 2; ap++) {
                int open;
                cin >> open;
                F[shop][day][ap] = (bool)open;
            }
        }
    }
    for (int shop = 0; shop < N; shop++) {
        for (int cnt = 0; cnt <= 10; cnt++) {
            int value;
            cin >> value;
            P[shop][cnt] = value;
        }
    }
    int max_value = numeric_limits<int>::min();
    for (int flag = 1; flag < (1 << 10); flag++) {
        int value = 0;
        for (int shop = 0; shop < N; shop++) {
            int open_cnt = 0;
            for (int day = 0; day < 5; day++) {
                for (int ap = 0; ap < 2; ap++) {
                    if ((flag & (1 << (2 * (4 - day) + (1 - ap)))) && F[shop][day][ap]) {
                        open_cnt++;
                    }
                }
            }
            value += P[shop][open_cnt];
        }
        max_value = max(max_value, value);
    }
    cout << max_value << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  //inter
  int h,w;
  cin>>h>>w;
  vector<string> a(h);
  for(int i=0;i<h;i++)
  {
    cin>>a[i];
  }

  //judgement of #
  vector<bool> row(h,false);
  vector<bool> col(w,false);
  for(int i=0;i<h;i++)
  {
    for(int j=0;j<w;j++)
    {
      if(a[i][j]=='#')
      {
        row[i]=true;
        col[j]=true;
      }
    }
  }

  //output
  for(int i=0;i<h;i++)
  {
    if(row[i]) {
                for(int j=0;j<w;j++)
                  {
                    if(col[j]) cout<<a[i][j];
                  }
                  cout<<endl;
                }

  }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

int main(void) {
    int r; cin >> r;
    cout << pow(r, 2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>

#define ll long long

using namespace std;

inline int read() {
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)) {if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*f;
}

int main() {
	int n=read(),r=read();
	if (n>=10) cout<<r<<endl;
	else cout<<r+100*(10-n)<<endl;
	return 0;
}

Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n,m = readline() |> split |> parseMap
	x = readline() |> split |> parseMap
	if n == 1
		println(maximum(x)-minimum(x))
	elseif n >= m
		println(0)
	else
		x = sort(x)
		a = Array{Int}(2,m-1)
		for i in 2:m
			a[1,i-1] = i-1
			a[2,i-1] = x[i]-x[i-1]
		end
		a = sortcols(a,by=t->t[2],rev=true)
		k = Int[]
		for i in 1:n-1
			push!(k,a[1,i])
		end
		k = sort(k)
		total = 0
		now = 1
		for i in 1:n-1
			total += x[k[i]]-x[now]
			now = k[i]+1
		end
		if now < m
			total += x[m]-x[now]
		end
		println(total)
	end
end
 
main()

Measured memory_bytes: 144844
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cstdlib>
using namespace std;
 
int main () {
	int n,m,i,j,t=0;
	int a,b,c,d,f,g,a11,b1,c1,d1,f1,g1;
	string s="EEEESEEEESEEEESEEEESESEEEESSEEE";
	n=s.size();
	int a1[n+1],a2[n+1],a3[n+1],a4[n+1],a5[n+1],a6[n+1];
	cin >> m;
	cin >> a >> b >> c >> d >> f >> g ;
	for(j=0;j<m-1;j++){
		int a1[n+1],a2[n+1],a3[n+1],a4[n+1],a5[n+1],a6[n+1];
		cin >> a11 >> b1 >> c1 >> d1 >> f1 >> g1;
		a1[0]=a11; a2[0]=b1; a3[0]=c1; a4[0]=d1; a5[0]=f1; a6[0]=g1;
		for(i=0;i<n;i++){
			if(s[i]=='S'){
				a1[i+1]=a5[i]; a2[i+1]=a1[i]; a3[i+1]=a3[i]; a4[i+1]=a4[i]; a5[i+1]=a6[i]; a6[i+1]=a2[i];
			}	
			else if(s[i]=='N'){
				a1[i+1]=a2[i]; a2[i+1]=a6[i]; a3[i+1]=a3[i]; a4[i+1]=a4[i]; a5[i+1]=a1[i]; a6[i+1]=a5[i];
			}
			else if(s[i]=='W'){
				a1[i+1]=a3[i]; a2[i+1]=a2[i]; a3[i+1]=a6[i]; a4[i+1]=a1[i]; a5[i+1]=a5[i]; a6[i+1]=a4[i];
			}
			else if(s[i]=='E'){
				a1[i+1]=a4[i]; a2[i+1]=a2[i]; a3[i+1]=a1[i]; a4[i+1]=a6[i]; a5[i+1]=a5[i]; a6[i+1]=a3[i];
			}
			if((a1[i+1]==a)&&(a2[i+1]==b)&&(a3[i+1]==c)&&(a4[i+1]==d)&&(a5[i+1]==f)&&(a6[i+1]==g)){
				t=1;  break;
			}
		}
	}
	if(t==1) cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 1196
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

int main(void){

char num_str[1002];

int num;

long sum = 0;

int i;

char tmp;

while(1){

fgets(num_str, sizeof(num_str), stdin);

if(num_str[0] == '0') break;

for(i=0;i<strlen(num_str)-1;i++){

tmp=num_str[i];

num=atoi(&tmp);

sum=sum+num;

}

printf("%ld\n",sum);

sum=0;

memset(num_str, 1002, 0);

}

return 0;

}

Measured memory_bytes: 532
# vim: fileencoding=utf-8


def main():
    s = list(input())
    c = 0
    p = "S"
    r = 0
    for e in s:
        if e == "R":
            c += 1
        if c > r:
            r = c
        if e == "S":
            c = 0
    print(r)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61832
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	int R;
	cin >> R;

	cout << R * 3.14159265358979 * 2;

	return 0;
}


Measured memory_bytes: 3800
'use strict';
function main(input) {
    var args = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));
    //let args = input.split(' ');
  	let cnt = 0
    let len = args.length
	while(args.filter(a => a % 2 === 0).length === len) {
      args = args.map(a => a / 2)
      cnt = cnt + 1
      //console.log(args, cnt)
    }
  	console.log(cnt)
  	
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
#include<stdio.h>
#include<stdlib.h>

int comp(const void *a, const void *b){
  return -1*(*(int*)a - *(int*)b);
}

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

  int A[N];
  int B[N];

  int C[N];
  long sumA = 0;
  long sumB = 0;
  int i;
  int M = 0;
  int m = 0;
  long sum = 0;
  long sum_m = 0;

  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
    sumA += A[i];
  }

  for(i = 0; i < N; i++){
    scanf("%d", &B[i]);
    sumB += B[i];
    C[i] = A[i] - B[i];
    if(C[i] < 0){
      m++;
      sum_m += C[i];
    }
  }
  sum_m *= -1;

  if(sumA < sumB){
    printf("-1\n");
    return 0;
  }
  if(m == 0){
    printf("0\n");
    return 0;
  }

  qsort(C, N, sizeof(int), comp);
  for(i = 0; i < N; i++){
    sum += C[i];
    if(sum >= sum_m) break;
  }

  M = m + i + 1;

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


Measured memory_bytes: 1660
# include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a!=0&&c!=0)
	{
		c=c-b;
		if(c<=0)
		{
		cout<<"Yes"<<endl;
		break;
		}
		a=a-d;
		if(a<=0)
		{
		cout<<"No"<<endl;
		break;
	}
	}
}

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

int main(){
	string S,A;
	cin >> S;
	for(int i=0; i<S.size(); i++){
		if(S[i]=='0'){
			A += "0";
		} else if(S[i]=='1'){
			A += "1";
		} else if(S[i]=='B'){
			if(A.size()>0){
				A.erase(A.end()-1);
			}
		}
	}
	cout << A << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		String s = scan.next();
		char[] c = s.toCharArray();

		int start = 0;
		for(int i = 0; i < s.length(); i++){
			if(c[i] == 'A'){
				start = i;
				break;
			}
		}

		int end = 0;
		for(int i = s.length()-1; i > start; i--){
			if(c[i] == 'Z'){
				end = i;
				break;
			}
		}
		System.out.println(end - start +1);
	}
}


Measured memory_bytes: 26552
# coding: utf-8
# Your code here!
import copy

N, K = map(int, input().split())
List = list(map(int, input().split()))
saki=[1]
ato=[]

i=0
j=1
while i<N:
    saki.append(List[j-1])
    j=List[j-1]
    i+=1

ato.append(List[j-1])

if K<=N:
    print(saki[K])
    quit()

start=saki.index(ato[0])

SA=(len(List)-start)+1

o=0
check=[]
while o<SA:
    check.append(List[j-1])
    j=List[j-1]
    o+=1
print(check[(K-start)%SA])

Measured memory_bytes: 33260
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
using namespace std;

int main()
{
  int N,K;
  cin >>N>>K;
  int ans=K;
  for(int i=0;i<N-1;i++)
  ans*=(K-1);

  cout <<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  100000LL
#define tmod            998244353
using namespace std;

int main()
{
//fast;
ll q=1;
//cin >> q;
while(q--)
{
    ll n,m,k,i,j,l,r,a,b,c=0,g,counter=0,u,v,d,e,x,w,y,flag1=0;
    //n=m=i=j=l=r=a=t=b=c=u=v=w=p=x=y=0;
    cin >> n >> k;
    vector<ll> V(n+2,-1),F,IS(n+2,0);
    CIN(V,0,n);
    ll ans=0;
    if(k==n) {cout << 1 << endl; return 0;}

    for(i=1;i<=n-k+1;i++)
    {
        if(IS[i-1]==1)
        {
            if(V[i+k-3] <= V[i+k-2]) IS[i] = 1;
            else    i = max(i,i+k-3);
        }
        else
        {
            ll flag = 1;
            for(j=i;j<i+k-1;j++)
            {
                if(V[j-1]>V[j+1-1]){flag = 0; break;}
            }
            if(flag)
            {
                IS[i] = 1;
                flag1=1;
            }
            else
            {
                i = max(i,j-1);
            }
        }
    }


    set<ll> X;
    for(i=1;i<k;i++)
    {
        X.insert(V[i]);
    }
    ans = 1;
    for(i=1;i<=(n-k);i++)
    {
        X.insert(V[i+k-1]);
        if(((V[i-1] <= *X.begin()) and V[i+k-1] == *X.rbegin())  or IS[i+1]==1)c = 0;
        else {ans++;}// cout << i << " ";}
        X.erase(X.lower_bound(V[i]));
    }
    if(IS[1]==0 and flag1==1) ans++;

    cout << ans;

}
    return 0;
}


Measured memory_bytes: 12672
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int N;
  while(cin >>N && N){
    int a = 0, b = 500;
    REP(i, N){
      int sum = 0;
      REP(j, 5){
        int tmp; cin >>tmp; sum += tmp;
      }
      a = max(a, sum);
      b = min(b, sum);
    }
    cout <<a <<" " <<b <<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
using namespace std;
#include <bits/stdc++.h>
#define FASTIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define debug(x) cout << #x << " = " << x << endl
void solve()
{
    int h, w, ch, cw, dh, dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;
    char s[1005][1005];
    rep(i, h) rep(j, w) cin >> s[i][j];
    int d[1005][1005];
    rep(i, h) rep(j, w) d[i][j] = 1e9;
    int di[4] = {1, 0, -1, 0};
    int dj[4] = {0, 1, 0, -1};
    deque<pair<int, int>> q;
    q.push_front({ch, cw});
    d[ch][cw] = 0;
    while (q.size())
    {
        pair<int, int> p;
        p = q.front();
        q.pop_front();
        int i, j;
        tie(i, j) = p;
        rep(k, 4)
        {
            int ni = i + di[k], nj = j + dj[k];
            if (ni < 0 || nj < 0 || ni >= h || nj >= w)
                continue;
            if (s[ni][nj] == '#' || d[ni][nj] <= d[i][j])
                continue;
            // we can also reach that vertex in the same amount of the cost
            // 0 1 bfs is a bfs in which we do bfs with dfs and first we go to the depth which
            // can be reached from that point using the same amount of cost and that can be implemented
            // by pushing the vertices at the front of the queueq instead the the back which is like the dfs and the
            // vertices which are present in the queue works as later vertices in the next for loop
            d[ni][nj] = d[i][j];
            q.push_front({ni, nj});
        }
        for (int ni = i - 2; ni <= i + 2; ni++)
        {
            for (int nj = j - 2; nj <= j + 2; nj++)
            {
                if (ni < 0 || nj < 0 || ni >= h || nj >= w)
                    continue;
                if (s[ni][nj] == '#' || d[ni][nj] <= d[i][j] + 1)
                    continue;
                // check all the conditons if the vertex is empty or not or having the less cost than the 
                // current vertex so that we do not change its current state and skip it
                // else make its cost as cost of previous plus one and then push it in the back direction like the 
                // one we do in the bfs call
                d[ni][nj] = d[i][j] + 1;
                q.push_back({ni, nj});
            }
        }
    }
    if (d[dh][dw] == 1e9)
        cout << -1 << endl;
    else
        cout << d[dh][dw] << endl;
}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
    FASTIO
    long long int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 8608
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 3e3 + 10, mod = 998244353;

ll ncr[2 * N][2 * N];

ll solve(int n, int x);
ll solve2(int n, int sum);
ll choose(int n, int k);

int main() {
	fast_cin();
	int n, x;
	cin >> n >> x;
	for (int i = 0; i < 2 * N; ++i) {
		ncr[i][0] = ncr[i][i] = 1;
		for (int j = 1; j < i; ++j) {
			ncr[i][j] = (ncr[i - 1][j] + ncr[i - 1][j - 1]) % mod;
		}
	}
	ll ans = 0;
	for (int k = 0; k <= n; ++k) {
		ll temp = solve(k, x);
		// cout << k << ' ' << temp << endl;
		temp *= choose(n, k);
		ans += temp;
		ans %= mod;
	}
	cout << ans << endl;
}

ll solve(int n, int x) {
	ll ans = 0;
	for (int i = 0; i <= n; ++i) {
		if (2 * i + (n - i) < x) {
			ans += choose(n, i);
		}
	}
	for (int i = 1; 2 * i <= min(n, x - 1); ++i) {
		ans += solve2(n - 2 * i, x - 1 - 2 * i);
	}
	if (x % 2 == 1 and n >= x) {
		++ans;
	}
	ans %= mod;
	return ans;
}

ll solve2(int n, int sum) {
	return choose(n, sum - n);
}

ll choose(int n, int k) {
	if (k < 0 or k > n) {
		return 0;
	} else {
		return ncr[n][k];
	}
}

Measured memory_bytes: 281600
#include <bits/stdc++.h>
#define NMAX 100005
using namespace std;
int n,m,x,y,grad[NMAX],i,sol,j,d[NMAX];
queue <int> coada;
vector <int> a[NMAX],v;
int main()
{
    cin>>n>>m;
    while(m--)
    {
        cin>>x>>y;
        a[x].push_back(y);
        grad[y]++;
    }
    for(i=1;i<=n;i++)
    {
        if(grad[i]==0)
            coada.push(i);
    }
    while(!coada.empty())
    {
        x=coada.front();
        coada.pop();
        v.push_back(x);
        for(i=0;i<(int)a[x].size();i++)
        {
            grad[a[x][i]]--;
            if(grad[a[x][i]]==0)
                coada.push(a[x][i]);
        }
    }
    for(i=0;i<(int)v.size();i++)
    {
        for(j=0;j<(int)a[v[i]].size();j++)
        {
            d[a[v[i]][j]]=max(d[a[v[i]][j]],d[v[i]]+1);
        }
    }
    for(i=1;i<=n;i++)
        sol=max(d[i],sol);
    cout<<sol;
    return 0;
}


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

using namespace std;
typedef long long ll;
const ll mod=998244353;
map<int,int> mii;
ll p[100050],q[100050],r[300050];
bool cmp(ll a,ll b)
{
    return a>b;
}
int main()
{
    ios::sync_with_stdio(false);
    int x,y,a,b,c;
    cin >> x>>y>> a >> b >> c;
    for(int i=0;i<a;i++)
        cin >> p[i];
    for(int i=0;i<b;i++)
        cin >> q[i];
    int len;
    for(len=0;len<c;len++)
        cin >> r[len];
    sort(p,p+a,cmp);
    sort(q,q+b,cmp);
    for(int i=0;i<x;i++)
        r[len++]=p[i];
    for(int i=0;i<y;i++)
        r[len++]=q[i];
    sort(r,r+len,cmp);
    ll ans=0;
    len=x+y;
    for(int i=0;i<len;i++)
        ans+=r[i];
    cout << ans;
    return 0;
}


Measured memory_bytes: 3968