akhauriyash/Code-Regression huggingface dataset:
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
bool check(int* counts) {
	int kind = 0;
	int two = 0;
	for (int k = 0; k < 26; k++) if (counts[k] > 0) {
		kind++;
		if (counts[k] == 2) two++;
	}
	return kind == 2 and two == 2;
}
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");
	
	char s[5];
	scanf("%s", s);
	int counts[26] = { 0 };
	for (char ch : s) counts[ch - 'A']++;
	puts(check(counts) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
// uncompleted
// https://atcoder.jp/contests/abc143/tasks/abc143_e
#include <bits/stdc++.h>
#define MAX_V 350
using namespace std;
// const int INF = 2100100100;
const long long INF = 1e17;
long long d[MAX_V][MAX_V];
int next_v[MAX_V][MAX_V]; // next_v[i][j] := i から j への最短経路における i の1つ後の点

void warshall_floyd(int v) {
    // v is the number of vertex
    for (int k = 0; k < v; k++) {
        for (int i = 0; i < v; i++) {
            for (int j = 0; j < v; j++) {
                if (d[i][k] + d[k][j] < d[i][j]) {
                    d[i][j] = d[i][k] + d[k][j];
                    next_v[i][j] = next_v[i][k];
                }
            }
        }
    }
}

void init_WF(int v) {
    for (int i = 0; i < v; i++) {
        for (int j = 0; j < v; j++) {
            if (i == j) {
                d[i][j] = 0;
            } else {
                d[i][j] = INF;
            }
            next_v[i][j] = j;
        }
    }
}

vector<int> get_path(int s, int t) {
    vector<int> path;
    for (int cur = s; cur != t; cur = next_v[cur][t]) {
        path.push_back(cur);
        // printf(" %d", cur);
    }
    path.push_back(t);
    // printf(" %d\n", t);
    return path;
}

int N, M, L;
long long d2[MAX_V][MAX_V];
void warshall_floyd2(int v) {
    // v is the number of vertex
    for (int k = 0; k < v; k++) {
        for (int i = 0; i < v; i++) {
            for (int j = 0; j < v; j++) {
                if (d2[i][k] + d2[k][j] < d2[i][j]) {
                    d2[i][j] = d2[i][k] + d2[k][j];
                }
            }
        }
    }
}

void init_WF2(int v) {
    for (int i = 0; i < v; i++) {
        for (int j = 0; j < v; j++) {
            if (i == j) {
                d2[i][j] = 0;
            } else if (d[i][j] <= L) {
                d2[i][j] = 1;
            } else {
                d2[i][j] = INF;
            }
        }
    }
}

int main() {

    scanf("%d %d %d", &N, &M, &L);
    init_WF(N);

    using P = pair<int, long long>;
    for (int i = 0; i < M; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        a--;
        b--;
        d[a][b] = c;
        d[b][a] = c;
    }

    int Q;
    vector<int> ss, ts;
    scanf("%d", &Q);
    for (int i = 0; i < Q; i++) {
        int s, t;
        scanf("%d %d", &s, &t);
        s--;
        t--;
        ss.push_back(s);
        ts.push_back(t);
    }

    warshall_floyd(N);
    init_WF2(N);
    warshall_floyd2(N);
    for (int q = 0; q < Q; q++) {
        if (d2[ss[q]][ts[q]] == INF) {
            printf("%d\n", -1);
        } else {
            printf("%d\n", d2[ss[q]][ts[q]] - 1);
        }
    }

    return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
	string S;
	cin >> S;
	bool if_in_S[4];
	for(int i = 0; i < 4; i++){
		if_in_S[i] = false;
	}
	for(int i = 0; i < S.size(); i++){
		if(S[i] == 'N'){
			if_in_S[0] = true;
		}else if(S[i] == 'S'){
			if_in_S[1] = true;
		}else if(S[i] == 'E'){
			if_in_S[2] = true;
		}else{
			if_in_S[3] = true;
		}
	}
	if(if_in_S[0]^if_in_S[1] || if_in_S[2]^if_in_S[3]){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
}

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

int main() {
  ll N = 0;
  cin >> N;
  map<ll,ll> mp;
  rep(i,N-1){
    ll a = 0;
    cin >> a;
    mp[a]++;
  }
  for(ll k = 1; k <= N; k++){
    cout << mp[k] << endl;
  }
}

Measured memory_bytes: 16052
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include<cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include<bitset>

typedef long long ll;

#define REP(i,b,n) for(ll i=b;i<(ll)n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define FOR(it,o)  for(__typeof((o).begin()) it=(o).begin(); it!=(o).end(); ++it)
#define dbg(x) cout << __LINE__ << ' ' << #x << " = " << (x) << endl



using namespace std;

ll solve(vector<ll> &v){
    ll cnt = 0;
    bool last = false;
    rep(i, v.size()){
        ll tmp = v[i] + last;
        cnt += tmp/2;
        if(v[i] == 0){
            last = false;
            continue;
        }
        last = tmp%2;
    }
    return cnt;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n){
        cin >> v[i];
    }
    cout << solve(v) <<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n; cin >> n;
	vector<int> p(n), t(n);
	for (auto& e : p) cin >> e;
	t[0] = p[0];
	for (int i = 1; i < n; ++i)
		t[i] = min(t[i - 1], p[i]);
	int ans = 0;
	for (int i = n - 1; i >= 0; --i)
		if (t[i] >= p[i]) ++ans;
	cout << ans << endl;

	return 0;
}

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

#define MAX 100005
#define NINF INT_MIN
using namespace std;

bitset<MAX> inicios, visitado;

vector<int> grafo[MAX];
stack<int> pilha;
int dist[MAX];

void toposort(int nodo){
    visitado[nodo] = 1;
    
    for(int u: grafo[nodo]){
        if (visitado[u] == 0)
            toposort(u);
    
    }
    
    pilha.push(nodo);
}


int longestPath(int n){

    for(int v=1; v<=n; v++){
        if(visitado[v] == 0)
            toposort(v);
            
        if(inicios[v] == 1)
            dist[v] = 0;
    }
    
    while(!pilha.empty()){
        int u = pilha.top();
        pilha.pop();
        
        for(int v: grafo[u]){
            dist[v] = max(dist[u] + 1, dist[v]);
            
        }
    }
    
    int m = 0;
    for(int a: dist){
        m = max(m, a);
    }
    return m;
}


int main(){
    
    int n,m;
    
    inicios.set();
    visitado.reset();
    
    cin >> n >> m;
    
    for(int i=0; i<n; i++)
        dist[i] = NINF;
    
    for (int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        grafo[a].push_back(b);
        inicios[b] = 0;
    }
    
    cout << longestPath(n) << endl;

}

Measured memory_bytes: 8576
package main

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

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	ans := 0
	for i := 0; i < n; i++ {
		sc.Scan()
		h, _ := strconv.Atoi(sc.Text())
		if h >= k {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 896
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;



int main() {
    int n, m;
    cin >> n >> m;
    if(n == m) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a >= b&& a >= c) {
		cout << 10 * a + b + c << endl;
	}
	else if (b >= a&& b >= c) {
		cout << 10 * b + a + c << endl;
	}
	else cout << c * 10 + a + b << endl;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const ll N = 1e6+5;
string s;
vector<ll> v[N];
ll n,a,b;

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> a >> b;
  cout << (a*n < b ? a*n : b) << endl;
}


Measured memory_bytes: 23680
#include <cstdio>
typedef unsigned long long ULL;

int n;
ULL f[100];

int main(){
	scanf("%d",&n);
	f[0]=2LLU,f[1]=1LLU;
	for (int i=2;i<=n;i++) f[i]=f[i-1]+f[i-2];
	return printf("%llu\n",f[n])&0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int a[200005],p[200005],cov[200005],n,m;
int main (){
	int i,x,y,j,ans=0;
	scanf ("%d%d",&n,&m);
	for (i=1;i<=n;i++)
	{scanf ("%d",&a[i]);
	p[a[i]]++;
	}
	for (i=1;i<=n;i++)
	{for (j=i;j>=i-p[i]+1&&j>=1;j--)
	{cov[j]++;}
	}
	for (i=1;i<=n;i++)
	{if (cov[i]==0) {ans++;}
	}
	while (m--)
	{scanf ("%d%d",&x,&y);
	int pre=a[x];a[x]=y;
	p[pre]--;
	if (pre-p[pre]>=1)
	{cov[pre-p[pre]]--;
	if (cov[pre-p[pre]]==0) {ans++;}
	}
	p[y]++;
	if (y-p[y]+1>=1)
	{cov[y-p[y]+1]++;
	if (cov[y-p[y]+1]==1) {ans--;}
	}
	printf ("%d\n",ans);
	}
	return 0;
}
	
	

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

int main()
{
    int c = 0;
    char a[3];
    for (int i = 0; i < 3;i++)
    {
        scanf("%s", &a[i]);
    }
    for (int i = 0; i < 3; i++)
    {

        if (a[i]=='R')
        {
          
                if(a[i]==a[i+1] && a[i+1]==a[i+2])
                {
                    c = 3;
                    break;
                                }
                if (a[i + 1] == 'R' && i < 3)
             {
                     c = 2;
                    break;
                                }
                else {
                    c = 1;
                                
            }
        }
    }
    printf("%d", c);
}
            

Measured memory_bytes: 1728
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

int main() {
  //
  ll n;
  cin >> n;
  double p = (double)(n - n / 2) / n;
  cout << setprecision(10) << fixed << p << endl;
  return 0;
}


Measured memory_bytes: 888
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;


int main(){
    vector<ll> dp(20000,E);
    dp[0]=0;
    ll n,W;
    cin>>n>>W;
    for(int i=0;i<n;i++){
        ll v,w;
        cin>>v>>w;
        for(ll t=15000-v;t>=0;t--){
            dp[t+v]=min(dp[t+v],dp[t]+w);
        }
    }
    ll mx=0;
    for(ll h=15000;h>=0;h--){
        if(dp[h]<=W){mx=h; break;}
    }
    cout<<mx<<endl;
    
    return 0;
}



Measured memory_bytes: 3116
import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

const NF = "NF";

class Node {
    string name;
    Node parent;
    Node[string] children;
    this(string name, Node parent) {
        this.name = name;
        this.parent = parent;
        this.children["."] = this;
        this.children[".."] = parent;
    }
    void add(string[] path) {
        //writeln("(add) ", name, ": ", path);
        assert(path.front == name);
        path.popFront;
        if (path.empty) return;
        if (path.front !in children) {
            children[path.front] = new Node(path.front, this);
        }
        children[path.front].add(path);
    }
    Node query(string[] path) {
        //writeln("(query) ", name, ": ", path);
        assert(path.front == name || path.front == "." || path.front == "..");
        path.popFront;
        if (path.empty) {
            return this;
        }
        if (path.front in children && children[path.front] !is null && isDir) {
            return children[path.front].query(path);
        }
        return null;
    }
    bool isDir() {
        return children.length > 2;
    }
    bool isFile() {
        return !isDir;
    }
}

void main() {
    int N, M;
    bool solve() {
        scanf("%d %d\n", &N, &M);
        if (N == 0 && M == 0) return false;
        Node root = new Node("", null);
        foreach (i; 0 .. N) {
            root.add(readln.chomp.chomp("/").split("/"));
        }
        foreach (i; 0 .. M) {
            auto a = readln.chomp,
                 b = readln.chomp;
            bool filea, fileb;
            if (a.back == '/') {
                a ~= "index.html";
                filea = true;
            }
            if (b.back == '/') {
                b ~= "index.html";
                fileb = true;
            }
            auto qa = a.split("/"),
                 qb = b.split("/");
            auto x = root.query(qa),
                 y = root.query(qb);
            if (x is null || y is null) {
                writeln("not found"); continue;
            }
            if (filea && x.isDir) x = null;
            if (fileb && y.isDir) y = null;
            if (!filea && x.isDir) {
                x = root.query( (a ~ "/index.html").split("/") );
                if (x !is null && x.isDir) x = null;
            }
            if (!fileb && y.isDir) {
                y = root.query( (b ~ "/index.html").split("/") );
                if (y !is null && y.isDir) y = null;

            }
            if (x is null || y is null) {
                writeln("not found"); continue;
            }
            writeln(x == y ? "yes" : "no");
        }
        return true;
    }
    while (solve) {}
}

Measured memory_bytes: 1148
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if(a + b >= k){
        cout << min(a, k) << endl;
    }
    else{
        cout << a - (k - (a + b)) << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int num[110000];

int main(){
  P A[110000];
  int N,a,b;
  ll K;
  cin>>N>>K;

  for(int i=0;i<N;i++){
    cin>>a>>b;
    A[i]=P(a,b);
    //cout<<A[i].first<<endl;
  }

  sort(A,A+N);
  int i=0;
  ll now=0;
  while(now<K){
    now+=A[i].second;
    i++;
    //cout<<i<<endl;
  }
  cout<<A[i-1].first<<endl;
}


Measured memory_bytes: 1152
<?php

while($s = fgets(STDIN)){
	$len = strlen($s);
	for($n = 0; $n < 26; $n++){
		for($i = 0; $i < $len; $i++){
			$c = $s[$i];
			if('a' <= $c && $c <= 'z'){
				$c = chr(ord($c) + 1);
				if($c > 'z'){
					$c = 'a';
				}
				$s[$i] = $c;
			}
		}
		if(preg_match('/( |^)(the|this|that)( |\.|\n)/', $s)){
			echo $s;
			$n = 256;
			break;
		}
	}
}

Measured memory_bytes: 15444
<?php
list($n,$x)=explode(" ",trim(fgets(STDIN)));
if($n==1){
  $a=trim(fgets(STDIN));
  echo abs($a-$x);
}else{
  $a=explode(" ",trim(fgets(STDIN)));
  $min=1000000000;
  foreach($a as $v){
    $d=abs($v-$x);
    $b[]=$d;
    $min=min($min,$d);
  }
  $i=0;
  while($i<$n){
    if($b[$i]%$min!=0){
      $mod=$b[$i]%$min;
      $min=gcd($min,$mod);
    }
    ++$i;
  }
  echo $min;
}

function gcd($a,$b) {
    return ($a % $b) ? gcd($b,$a % $b) : $b;
}

Measured memory_bytes: 18932
#include <vector>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <list>
#include <map>
#include <istream>
#include <bitset>
#include <sstream>
#include <unordered_map>
#include <stack>
#include <set>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <queue>
#include <string>

#define int long long
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rr return 0
#define xx first
#define yy second
#define pii pair<int,int>

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1000000007;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    for(int i = 0;i < m;i++){
        int x;
        cin >> x;
        mp[x]++;
    }
    int dp[n + 1];
    dp[0] = 1;
    if(mp[1] == 1){
        dp[1] = 0;
    }else{
        dp[1] = 1;
    }
    for(int i = 2;i <= n;i++){
        if(mp[i] == 1){
            dp[i] = 0;
        }else{
            dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
        }
    }
    cout << dp[n];
    rr;
}


Measured memory_bytes: 7296
import sys

stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


class SegmentTreeRMQ(object):  # 1-indexed [l,r)
    def __init__(self, size, value):
        self.len = 1 << size.bit_length()
        # print(self.len)
        self.array = [value] * (2 * self.len)

    def update(self, i, x):
        i += self.len
        while i > 0:
            self.array[i] = max(self.array[i], x)
            i >>= 1
        # print(self.array)

    def get(self, i):
        return self.array[i + self.len]

    def get_maximum(self, l, r):
        L = l+self.len
        R = r+self.len
        ANS = -1 << 30

        while L < R:
            if L & 1:
                ANS = max(ANS, self.array[L])
                L += 1

            if R & 1:
                R -= 1
                ANS = max(ANS, self.array[R])
            L >>= 1
            R >>= 1

        return ANS


N = ni()
h_array = na()
a_array = na()

ans = SegmentTreeRMQ(N+1, 0)



for h, a in zip(h_array, a_array):
    tmp = ans.get_maximum(0, h) + a
    if ans.get(h) < tmp:
        ans.update(h, tmp)

print(ans.get_maximum(0, N+1))


Measured memory_bytes: 118060
from fractions import gcd
N,K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
g = A[0]
for i in range(1, N):
    g = gcd(g, A[i])
print('POSSIBLE' if (K <= A[-1] and K % g == 0) else 'IMPOSSIBLE')


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

int main(){
  int n;
  int maxx,maxy;
  int minx,miny;
  int x[300];
  int y[300];
  int dy[4]={0,-1,0,1};
  int dx[4]={-1,0,1,0};
  while(cin>>n,n){
    x[0]=0;
    y[0]=0;
    maxx=maxy=minx=miny=0;
    for(int i=1;i<n;i++){
      int a,b;
      cin>>a>>b;
      x[i]=x[a]+dx[b];
      y[i]=y[a]+dy[b];
      maxx=max(maxx,x[i]);
      maxy=max(maxy,y[i]);
      minx=min(minx,x[i]);
      miny=min(miny,y[i]);
    }
    cout << maxx - minx + 1  << " " << maxy - miny + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
s = input()
s_len = len(s)

to_l = [0] * s_len
to_r = [0] * s_len
ans = [0] * s_len
cnt = 0
for i, c in enumerate(s):
    if c == 'R':
        cnt = 0
    else:
        cnt += 1
    to_r[i] = cnt

cnt = 0
for i,c in enumerate(reversed(s)):
    if c == 'L':
        cnt = 0
    else:
        cnt += 1
    to_l[s_len-i-1] = cnt

for i in range(s_len):
    c = s[i]
    if c == 'R':
        d = to_l[i]
    else:
        d = to_r[i]

    if d % 2 == 0:
        to_d = d
    else:
        to_d = d - 1

    if c == 'R':
        to_i = i + to_d
    else:
        to_i = i - to_d
    
    if to_i < 0 or s_len <= to_i:
        pass
    else:
        ans[to_i] += 1

#ans_s = str(ans[0])
#for cnt in ans[1:]:
#    ans_s += (" " + str(cnt))
#print(ans_s)
for i in ans:
    print(i)

Measured memory_bytes: 52316
def find_root(x):
    if parent[x] == x:
        return x
    else:
        return find_root(parent[x])


def unite(x, y):
    x = find_root(x)
    y = find_root(y)

    if x != y:
        if rank[x] < rank[y]:
            parent[x] = y
            size[y] += size[x]
        else:
            parent[y] = x
            size[x] += size[y]
            if rank[x] == rank[y]:
                rank[x] += 1


def roots():
    roots = []
    for i in range(N):
        roots.append(find_root(i))
    return roots


def group_count():
    return len(set(roots()))


N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

parent = [i for i in range(N)]  # 根
rank = [1] * N  # 深さ
size = [1] * N  # iを根とするグループのサイズ

edge = [[ab[M - 1 - i][0] - 1, ab[M - 1 - i][1] - 1] for i in range(M)]

for i in range(M):
    unite(edge[i][0], edge[i][1])
count = group_count()

ans = 0
for j in range(M):
    # 再構築するため、初期化し直す
    parent = [i for i in range(N)]
    rank = [1] * N
    size = [1] * N
    for i in range(M):
        if j == i:
            continue
        unite(edge[i][0], edge[i][1])
    if group_count() > count:
        ans += 1
print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;
 
class Main {
  public static void main(String[] args){
 
    Scanner sc = new Scanner(System.in);
 
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
//Math.adsで絶対値(+-)を取得
      if (Math.abs(x - a) < Math.abs(x - b)){
      System.out.println("A") ;
      }
      else {
      System.out.println("B") ;
      }
  }
}

Measured memory_bytes: 21716
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int vol;
    while(cin>>vol){
        int ans=2000000000;
        if(!vol)break;
        vol/=100;
        for(int i=0;i<=50;i++){
            for(int j=0;j<=50;j++){
                for(int k=0;k<=50;k++){
                    if((i+j+k)!=vol)continue;
                    if((i%2)||(j%3)||(k%5))continue;
                    int An=i/2,Bn=j/3,Cn=k/5;
                    //printf("[%d][%d][%d] [%d][%d][%d]\n",i,j,k,An,Bn,Cn);
                    ans=min(ans,An/5*1520+(An%5)*380+Bn/4*1870+(Bn%4)*550+Cn/3*2244+(Cn%3)*850);
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

int main() {
    long int n,d;
    cin>>n>>d;
    long int a[n][d+1];
    for(long int i=0;i<n;i++)
    {
        for(long int j=0;j<d;j++)
        {
            cin>>a[i][j];
        }
    }
    long int count=0;
    for(long int i=0;i<n;i++)
    {
        
        for(long int j=i+1;j<n;j++)
        {
            long int ans=0;
            for(long int k=0;k<d;k++)
            {
                long  int temp= abs(a[i][k]-a[j][k]);
                temp*=temp;
                ans+=temp;
            }
            double d = sqrt(ans);
            long int d1= sqrt(ans);
          //  cout<<d<<" "<<d1<<endl;
            if((d)== d1)
            {
                count++;         
            }
            
        }
        
    }
    cout<<count<<endl;
	return 0;
}

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

using namespace std;

int main(void) {
    int n, s[110], sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sum += s[i];
    }
    sort(s, s + n);

    if (!(sum % 10)) {
        for (int i = 0; i < n; i++) {
            if (s[i] % 10) {
                sum -= s[i];
                break;
            }
        }
        if (!(sum % 10)) sum = 0;
    }
    cout << sum << endl;
    
    return 0;
}

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

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    int n, t;
    cin >> n >> t;
    
    int ans = -1, cost = 1003;
    
    while(n--)
    {
        int c, d;
        cin >> c >> d;
        
        if(d <= t)
            cost = min(cost, c);
    }
    
    if(cost == 1003)
        cout << "TLE\n";
    else
        cout << cost << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
bool isp(ll n) {
    bool res = true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}

int main() {
  ll N;
  cin >> N;
  ll big = 0;
  ll wa = 0;
  ll n = 0;
  rep(i,N){
    cin >> n;
    wa += n;
    big = max(big,n);
  }
  cout << wa - big / 2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
     
typedef struct dice{
  int up;
  int front;
  int right;
  int left;
  int back;
  int down;
} dice;
  
dice *rotate(dice *d,char c){
  int temp;
 
  if(c=='N'){
    temp=d->front;
    d->front=d->down;
    d->down=d->back;
    d->back=d->up;
    d->up=temp;
  } else if(c=='S') {
    temp=d->back;
    d->back=d->down;
    d->down=d->front;
    d->front=d->up;
    d->up=temp;
  } else if(c=='E') {
    temp=d->left;
    d->left=d->down;
    d->down=d->right;
    d->right=d->up;
    d->up=temp;
  } else if(c=='W') {
    temp=d->right;
    d->right=d->down;
    d->down=d->left;
    d->left=d->up;
    d->up=temp;
  }
  
  return d;
}
  
int main(void){
  dice d1;
  dice *root;
  char c;
  int temp,i,num,utemp,ftemp;
      
  root=&d1;
  scanf("%d%d%d%d%d%d",&d1.up,&d1.front,&d1.right,&d1.left,&d1.back,&d1.down);
  scanf("%d",&num);
  for(i=0;i<num;i++){ 
    scanf("%d%d",&utemp,&ftemp);
    if(utemp==d1.up) ;
    else if(utemp==d1.front)  root=rotate(root,'N');
    else if(utemp==d1.right)  root=rotate(root,'W');
    else if(utemp==d1.left)  root=rotate(root,'E');
    else if(utemp==d1.back)  root=rotate(root,'S');
    else if(utemp==d1.down){
      root=rotate(root,'N');  root=rotate(root,'N');
    }
  
    if(ftemp==d1.front)  printf("%d\n",d1.right);
    else if(ftemp==d1.right)  printf("%d\n",d1.back);
    else if(ftemp==d1.left)  printf("%d\n",d1.front);
    else if(ftemp==d1.back)  printf("%d\n",d1.left);
  }
  
  return 0;
}

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9
#define MAX 1000

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

int main(){
    ll N;
    cin >> N;
    ll v[N];
    ll ans = 0;
    Rep(i,N){
        cin >> v[i];
        ans += v[i];
    }
    ll x = (N*(N+1)/2);
    ans -= x;
    cout << ans << endl;
    //cin >> N;
}


Measured memory_bytes: 3884
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
#define int long long int

void solve() {
  // int x;
  // cout << endl;
}

std::string to_binString(unsigned int val) {
  if (!val)
    return std::string("0");
  std::string str;
  while (val != 0) {
    if ((val & 1) == 0)             // val は偶数か？
      str.insert(str.begin(), '0'); //  偶数の場合
    else
      str.insert(str.begin(), '1'); //  奇数の場合
    val >>= 1;
  }
  return str;
}

signed main() {
  int n;
  cin >> n;

  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }

  int i;
  if (n > 0) {
    i = 1;
    while (i < n) {
      i = (i << 2) | 0b01;
    }
  } else {
    n *= -1;
    i = 0b10;
    while (i < n) {
      i = (i << 2) | 0b10;
    }
  }
  int p = i - n;

  cout << to_binString(i ^ p) << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProconTemplate
{
    class Doing
    {
        public static void Main(string[] args)
        {
            var lineCount = int.Parse(Console.ReadLine());
            //Console.ReadLine();
            var lengthSet = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderBy(x => x);
            var maxValue = lengthSet.Max();
            var anotherValueSum = lengthSet.Take(lineCount - 1).Sum();
            if (maxValue < anotherValueSum) {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

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

  if(N==25) cout << "Christmas" << endl;
  if(N==24) cout << "Christmas Eve" << endl;
  if(N==23) cout << "Christmas Eve Eve" << endl;
  if(N==22) cout << "Christmas Eve Eve Eve" << endl;
  
}


Measured memory_bytes: 3568
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,a[100011]={};
LL c=0;
	cin>>n;
	FOR(i,0,n){
		cin>>a[i];
	}
	sort(a,a+n);
	int idx=0;
	while(idx<n){
		int t=a[idx];
		int m=upper_bound(a,a+n,t)-lower_bound(a,a+n,t);
		if(t<=m){
			c+=m-t;
		}else{
			c+=m;
		}
		idx=upper_bound(a,a+n,t)-a;
	}
	cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 640
// +build ignore
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	N := sc.nextInt()
	M := sc.nextInt()
	A := make([]int, N)
	total := 0
	for i := 0; i < N; i++ {
		A[i] = sc.nextInt()
		total += A[i]
	}
	border := float64(total) / float64(4*M)
	sum := 0
	for i := 0; i < N; i++ {
		if float64(A[i]) >= border {
			sum++
		}
	}

	if sum >= M {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

pbds pos,neg;
int timer;
ll len[100011];
ll shiftpos,shiftneg;

void addpos(ll x)
{
	pos.insert(mp(x-shiftpos,timer++));
}

void addneg(ll x)
{
	neg.insert(mp(x-shiftneg,timer++));
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	ll m=0; ll c=0;
	for(int i=0;i<n;i++)
	{
		ll l,r; cin>>l>>r;
		len[i]=r-l;
		//last m elements increase by len[i-1];
		if(i>0)
		{
			shiftpos+=len[i-1];
			c-=len[i-1]*m;
		}
		//the rest decrease by len[i]
		shiftneg-=len[i];
		addpos(l); addpos(l);
		auto it=pos.begin();
		ll res=it->fi+shiftpos;
		pos.erase(pos.begin()); addneg(res);
		int neglas=prev(neg.end())->fi+shiftneg;
		int posles=pos.begin()->fi+shiftpos;
		if(!neg.empty()&&neglas>posles)
		{
			neg.erase(prev(neg.end())); pos.erase(pos.begin());
			addpos(neglas); addneg(posles);
		}
		m++; c-=l;
	}
	while(m>0)
	{
		c+=(*prev(pos.end())).fi+shiftpos;
		m--;
		pos.erase(prev(pos.end()));
	}
	cout<<c<<'\n';
}


Measured memory_bytes: 13568
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n,m;
    cin>>n;vector<pii>v(1001+1);
    rep(i,n)cin>>v[i].first>>v[i].second;
    cin>>m;rep(i,m)cin>>v[i+n].first>>v[i+n].second;
    sort(v.begin(),v.begin()+n+m);
    vb check(n+m,true);
    int l=0;
    rep(i,n+m)rep(j,n+m)if(i!=j&&check[i]&&v[i]==v[j]){check[j]=false;}
    rep(i,n+m)if(check[i]){if(l)cout<<" ";l++;printf("%d:%02d",v[i].first,v[i].second);}
    cout<<endl;
}



Measured memory_bytes: 3232
import sys

def main(inp):
    N=list(map(int,next(inp).split()))
    L=list(map(int,next(inp).split()))
    
    maxindex = [i for i , x in enumerate(L) if x==max(L)]
    
    maxi=L.pop(maxindex[0])
    
    if sum(L)>maxi:
        print("""Yes
""")
    else: print("""No
""")
      
main(sys.stdin)

Measured memory_bytes: 3064
D = int(input())
C = list(map(int, input().split()))
S = [[] for _ in range(D)]
for i in range(D):
    S[i] = list(map(int, input().split()))

def based_b():
    last = [0 for _ in range(26)]
    for i in range(D):
        d = i + 1
        max_score = (-1) * float('inf')
        t = 0
        for contest in range(26):
            last_tmp = last[:]
            score = S[i][contest]
            last_tmp[contest] = d
            for x in range(26):
                score -= C[x] * (d - last_tmp[x])
            if max_score < score:
                t = contest
                max_score = score
        last[t] = d
        print(t+1)

based_b()

Measured memory_bytes: 74648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

const int MOD = 1000000007;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for (int i = 0; i < H; ++i) {
        cin >> a[i];
    }

    vector<vector<int>> dp(H, vector<int>(W, 0));
    dp[0][0] = 1;

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            dp[i][j] %= MOD;
            if (j + 1 < W && a[i][j + 1] == '.') {
                dp[i][j + 1] += dp[i][j];
            }
            if (i + 1 < H && a[i + 1][j] == '.') {
                dp[i + 1][j] += dp[i][j];
            }
        }
    }

    cout << dp[H - 1][W - 1] << endl;
    return 0;
}


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

using namespace std;

const int N = 300005;
const int inf = 1000000000;

int mx[N * 4];

void update(int l, int r, int x, int p, int v) {
	if(l == r) {
		mx[x] = v;
		return;
	}
	int mid = l + r >> 1;
	if(p <= mid) {
		update(l, mid, x << 1, p, v);
	} else {
		update(mid + 1, r, x << 1 | 1, p, v);
	}
	mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
}

int query(int l, int r, int x, int a, int b) {
	if(l > b || r < a) {
		return -inf;
	}
	if(l >= a && r <= b) {
		return mx[x];
	}
	int mid = l + r >> 1;
	return max(query(l, mid, x << 1, a, b), query(mid + 1, r, x << 1 | 1, a, b));
}

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

	int n, k;
	cin >> n >> k;

	memset(mx, -0x3f3f, sizeof(mx));

	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	for(int i = 0; i < n; ++i) {
		int x = query(0, N - 1, 1, max(a[i] - k, 0), min(a[i] + k, N - 1));
		x = max(x, 0) + 1;
		update(0, N - 1, 1, a[i], x);
	}

	cout << mx[1] << '\n';

	return 0;
}

Measured memory_bytes: 9012
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        String s = sc.next();
        
        int l = 0;
        int r = 0;
        for(int i = 0; i < k; i++){
            r = s.indexOf("0", r);
            r = s.indexOf("10", r);
            if(r == -1){
                r = n-1;
                break;
            }
        }
        
        int max = 0;
        while(true){
            if(r-l+1 > max){
                max = r-l+1;
            }
            if(r == n-1) break;
            
            r = s.indexOf("0", r);
            r = s.indexOf("10", r);
            if(r == -1){
                r = n-1;
            }
            l = s.indexOf("01", l) +1;
        }
        
        System.out.println(max);
    }
}

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

#define endl "\n"
#define int long long

const int MOD = 1e9 + 7;
const int INF = 2e15;

void debug(vector <int> &dp, int l, int r) {
	for (int i = 1; i <= r; i++) {
		if (dp[i] == INF) cout << "inf ";
		else cout << dp[i] << " ";
	}
	cout << endl;
}

void max_self(int &a, int b) {
	a = max(a, b);
}

void min_self(int &a, int b) {
	a = min(a, b);
}

signed main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

	int n, k;
	cin >> n >> k;

	vector <int> heights(n + 1, 0);
	for (int i = 1; i <= n; i++) cin >> heights[i];

	vector <int> dp(n + 1, INF);
	dp[1] = 0;

	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= i + k and j <= n; j++) {
			min_self(dp[j], dp[i] + abs(heights[j] - heights[i]));
		}
	}

	//debug(dp, 0, n);
	cout << dp[n] << endl;
}

Measured memory_bytes: 4724
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    n = int(input().strip())
    A = [None] + [int(i) for i in input().strip().split()]
    ans = 0
    for i in range(1, n + 1):
        if i == A[A[i]]:
            ans += 1

    print(ans // 2)

    return


if __name__ == "__main__":
    main()

Measured memory_bytes: 85484
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll h,a;cin>>h>>a;
  cout<<(h+a-1)/a<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

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

int main(){
  string s,adf="",adb="";
  ll q,qty;

  std::cin >> s>>q;

  ll rvcnt=0;
  rep(i,q){
    std::cin >> qty;
    if(qty==1){
      rvcnt++;
    }else{
      int f;char c;
      std::cin >> f >>c;
      if(f==1){
        if(rvcnt%2==0)adf=c+adf;
        else adb+=c;
      }else{
        if(rvcnt%2==0)adb+=c;
        else adf=c+adf;
      }
    }
  }

  if(adb.size()!=0 || adf.size()!=0)s=adf+s+adb;
  if(rvcnt%2!=0 && rvcnt!=0)reverse(s.begin(),s.end());


  std::cout << s << '\n';
  return 0;
}


Measured memory_bytes: 1360
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCoder
{
    class ABC176
    {
        static void Main(string[] args)
        {
            string n = Console.ReadLine();
            int count = 0;
            for(int i = 0; i < n.Length; i++)
            {
                string ni = n[i].ToString();
                count += int.Parse(ni);
            }
            if(count%9 == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 32652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1300005,INF=1<<29;

vector<int> prime;//i番目の素数
bool is_prime[MAX+1];

void sieve(int n){
    for(int i=0;i<=n;i++){
        is_prime[i]=true;
    }
    
    is_prime[0]=is_prime[1]=false;
    
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i;j<=n;j+=i){
                is_prime[j] = false;
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    sieve(1300002);
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        if(is_prime[N]){
            cout<<0<<endl;
            continue;
        }
        
        auto it=lower_bound(all(prime),N),it2=it;
        it2--;
        cout<<*it-*it2<<endl;
    }
}




Measured memory_bytes: 4676