akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define watch(x) cout << (#x) << " is " << (x) << endl
#define watchArray(v) for(auto i : v) cout << i << " "; cout << endl;
#define all(v) (v).begin(), (v).end()

#define endl '\n'
#define MAX 100000
#define MOD 100000007
#define INF numeric_limits<int>::max()
#define INFLL numeric_limits<long long int>::max()

typedef long long int lli;
typedef long double ld;

vector<vector<int>> v, memo;
int n, ans;

int main(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n;
  v.resize(n);
  memo.assign(n, {0, 0, 0});
  for(int i = 0; i < n; i++) {
    v[i].resize(3);
    for(int j = 0; j < 3; j++) cin >> v[i][j];
  }
  memo[0] = v[0];

  for(int i = 1; i < n; i++) {
    for(int j = 0; j < 3; j++) {
      memo[i][j] = memo[i-1][j];
      for(int k = 0; k < 3; k++) {
        if(k != j) memo[i][j] = max(memo[i][j], memo[i-1][k] + v[i][j]);
      }
    }
  }

  ans = *max_element(all(memo[n-1]));

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11264
//#include <bits/stdc++.h>
#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>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

ll nl, nm;

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

  int n;
  ll tkhs=1LL, aoki=1LL;
  cin >> n;  
  REP(i, n){
    int t, a;
    cin >> t >> a;
    ll val = max(((tkhs+t-1)/t), ((aoki+a-1)/a));
    aoki = val * a;
    tkhs = val * t;
  }
  
  cout << aoki + tkhs << endl;
  
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x%y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;


int main() {

	int H, W;
	while (true) {
		cin >> H >> W;

		if (W == 0 && H == 0)break;

		for (int i = 0; i < H; i++)
		{
			for (int i = 0; i < W; i++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;

	}

}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t q;
    cin >> q;
    vi l(q), r(q);
    rep(i,q) cin >> l.at(i) >> r.at(i);
    // 最大10^5の幅か
    // まずは全部の2017に似た数をだせば良いのでは…？
    // 1. 素数を出す
    // 2. 条件を満たすのを探す
    // 3. クエリを返す
    vi prime(100001,1);
    prime.at(0) = 0;
    prime.at(1) = 0;
    for(int64_t i=2; i<1001; i++){
        int64_t j=2;
        while(i*j<=100000){
            prime.at(i*j) = 0;
            j++;
        }
    }
    vi like2017(100001,0);
    for(int64_t i=1; i<100001; i=i+2){
        if(prime.at(i) && prime.at((i+1)/2)){
            like2017.at(i) = 1;
        }
    }
    // ここでTLEか → 累積和しておく
    int64_t sum = 0;
    vi sumv(100001,0);
    for(int64_t i=1; i<100001; i=i+2){
        sum += like2017.at(i);
        sumv.at(i) = sum;
    }
    int64_t x=0;
    rep(i,q){
        cout << sumv.at(r.at(i)) - sumv.at(l.at(i)) + like2017.at(l.at(i)) << endl;
    }
}

Measured memory_bytes: 4608
def solve():
    N,M,K = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    ans = 0
    time = 0

    for i in range(N):
        ans += 1
        time += A[i]
        if time > K:
            ans -= 1
            time -= A[i]
            break
    a_bottom = ans - 1
    
    cnt = ans
    b_bottom = 0
    while b_bottom < M:
        if time + B[b_bottom] <= K:
            time += B[b_bottom]
            cnt += 1
            ans = max(cnt, ans)
            b_bottom += 1
        else:
            if a_bottom == -1:
                break
            time -= A[a_bottom]
            a_bottom -= 1
            cnt -= 1
    
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 111044
object Main {
	def main(args: Array[String]) {
		val N = io.StdIn.readLine().toInt
		val a = io.StdIn.readLine().split(" ").map(_.toInt)

		val result = a.zipWithIndex.count( t => a(t._1 - 1) == (t._2 + 1)) / 2

		println(result)
	}
}

Measured memory_bytes: 36184
import java.text.ParseException;
import java.util.Scanner;

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

		String s = sc.next();

		char[] array = s.toCharArray();
		int count = 0;
		int max = 0;

		for (char c : array) {
			switch (c) {
			case 'A':
				count++;
				break;
			case 'T':
				count++;
				break;
			case 'G':
				count++;
				break;
			case 'C':
				count++;
				break;
			default:
				if (count > max) {
					max = count;
				}
				count = 0;
			}

		}
		if (count > max) {
			max = count;
		}
		System.out.println(max);

	}

}


Measured memory_bytes: 21844
import sys

input = lambda: sys.stdin.readline().rstrip()


class SegTree:

    def __init__(self, init_val, segfunc, ide_ele):

        n = len(init_val)
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.num = 2**(n - 1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num

        for i in range(n):
            self.seg[i + self.num - 1] = init_val[i]

        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])

    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k - 1) // 2
            self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])

    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res


def solve():

    N = int(input())
    S = list(input())
    Q = int(input())
    seg = [1 << (ord(s) - ord('a')) for s in S]

    segtree = []
    segfunc = lambda a, b: a | b

    segtree = SegTree(seg, segfunc, 0)

    ans = []
    for i in range(Q):
        a, b, c = input().split()
        a = int(a)

        if a == 1:
            b = int(b) - 1
            al = ord(c) - ord('a')
            segtree.update(b, 1 << al)
        elif a == 2:
            b, c = int(b) - 1, int(c)
            res = segtree.query(b, c)
            res = sum(list(map(int, bin(res)[2:])))
            ans.append(res)

    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 52244
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int n, k;
  string s;
  cin >> n >> k >> s;
  s[k-1] = tolower(s[k-1]);
  cout << s << endl;
  return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	vector<vector<pii>> r(n);
	rep(i, n-1){
		int u, v, w;
		cin >>u >>v >>w;
		r[u-1].emplace_back(v-1, w%2);
		r[v-1].emplace_back(u-1, w%2);
	}
	VI dst(n, MD); 
	
	auto dfs =[&](auto dfs, int c, int p=-1)->void{
		for(auto& x: r[c]) if(x.first != p){
			dst[x.first] = dst[c] + x.second;
			dfs(dfs, x.first, c);
		}
	};
	dst[0] = 0;
	dfs(dfs, 0);
	rep(i, n) cout << dst[i]%2 <<"\n";
	return 0;
}


Measured memory_bytes: 7552
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;

int main()
{
    list<int> l;
    for (int i = 0; i < 3; i++)
    {
        int x;
        cin >> x;
        l.push_back(x);
    }
    l.sort();
    cout << l.front() << " " << l.back() << endl;
}


Measured memory_bytes: 3104
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class Main {
	static final long MOD=1000000007;//998244353;
	static int[] par;
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		InputReader sc=new InputReader(System.in);
		long A=sc.nextLong();
		long B=sc.nextLong();
		System.out.println(f(A-1)^f(B));
   	}
	static long f(long A) {
		if (A<0) {
			return 0;
		}
		long c=(A+1)/2;
		long a=0;
		if ((A+1)%2!=0) {
			a=A;
		}
		if (c%2==0) {
			return a;
		}else {
			return a^1;
		}
	}
		static class InputReader { 
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;
		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}
 
		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}
 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
 
		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}
 
		public boolean hasNext() {
			skip();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public double nextDouble() {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
 
		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
	}

Measured memory_bytes: 32588
N = gets.to_i
A = gets.split.map &:to_i
h = A.group_by{|x| x}.map{|k, v| [k, v.size] }.sort_by{|k, v| v}
puts case h.size
when 1
  h[0][0] == 0
when 2
  h[0][1] * 2 == h[1][1] && h[0][0] == 0
when 3
  h[0][1] == h[1][1] && h[1][1] == h[2][1] && h[0][0] ^ h[1][0] ^ h[2][0] == 0
else
  false
end ? :Yes : :No

Measured memory_bytes: 24064
#include <stdio.h>
int main()
{
int n,a,t,i,j,k;
while(1)
    {
scanf("%d%d",&n,&a);
if (n != 0 || a != 0){
t=0;
for(i = 0; i < n; i++){
for(j = 0; j < i; j++){
for(k = 0; k < j; k++){
if (i+j+k+3 == a){
t++;
}
}
}
}
printf("%d\n",t);
}
else
    {
      break;
}

  }

  return 0;

}



Measured memory_bytes: 2104
# ABC151 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
from collections import deque
def bfs(sy,sx):
    q = deque([[sy,sx]])
    visited[sy][sx]=0
    while q:
        y,x = q.popleft()
        for j,k in ([1,0],[-1,0],[0,1],[0,-1]):
            ny,nx = y+j,x+k
            if ny<0 or ny>h-1 or nx<0 or nx>w-1 or path[ny][nx]=="#":
                continue
            if path[ny][nx]=="." and visited[ny][nx]==-1:
                visited[ny][nx]=visited[y][x]+1
                q.append([ny,nx])
    ret=-1
    for i in range(h):
        for j in range(w):
            ret=max(visited[i][j],ret)
    return ret
h,w=nm()
path=[input() for i in range(h)]
visited = [[-1]*w for i in range(h)]
sy,sx=0,0
gy,gx=0,0
ans=0
for i in range(h):
    for j in range(w):
        if path[i][j]=='#':
            continue
        sy,sx=i,j
        visited = [[-1]*w for i in range(h)]
        t=bfs(sy,sx)
        ans=max(t,ans)
print(ans)


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

int n,A[20],q,p,m[2000]={};

void judge(int i=0,int sum=0){
  if(i==n){
    m[sum]=1;
    return;
  }
  judge(i+1,sum+A[i]),judge(i+1,sum);
}


int main(){
  cin >> n;
  for(int i=0;i<n;i++) cin >> A[i];
  cin>>q,judge();
  for(int i=0;i<q;i++){
    cin >> p;
    cout << (m[p]?"yes":"no");
    cout << endl;
  }
}



Measured memory_bytes: 3112
#include <stdio.h>

#define N 100

int M[N][N];

int main(){
  int n, i, j, x, v;

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      M[i][j] = 0;
    }
  }

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d %d", &x, &v);

    for(j = 0; j < v; j++){
      scanf("%d", &x);
      M[i][x-1] = 1;
    }

  }

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(j == n-1)
	printf("%d", M[i][j]);
      else
        printf("%d ", M[i][j]);
    }
    printf("\n");
  }

  return 0;
}

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

using namespace std;

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

typedef long long i64;
typedef pair<i64, i64> pii;

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d, n;
  cin >> d >> n;

  int s = 1;
  rep(i, d) s *= 100;

  if (n < 100) {
    cout << s * n << "\n";
  }

  else cout << s * 101 << "\n";

  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 10000
#define INF 10001000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rep2(i, a, n) for(int i = a; i <= n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define rrep2(i, a, n) for(int i = a; i >= n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;


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

    return 0;
}


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

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if(t & 1 == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

string s;
mint dp[100000][2];

int main(){
    cin >> s;
    dp[0][0] = mint(2);
    dp[0][1] = mint(1);
    for(int i=1;i<s.size();i++){
        if(s[i] == '0'){
            dp[i][0] = dp[i-1][0];
            dp[i][1] = mint(3) * dp[i-1][1];
        }else{
            dp[i][0] = dp[i-1][0] * mint(2);
            dp[i][1] = dp[i-1][0] + dp[i-1][1] * mint(3); 
        }
    }
    cout << dp[s.size()-1][0] + dp[s.size()-1][1] << endl;
    return 0;
}

Measured memory_bytes: 2048
N = int(input())
A = list(int(i) for i in input().split())
if N == 1:
    print("Yes")
else:
    for i in range(N-1):
        if A[i+1] -A[i] > 0:
            A[i+1] -= 1
        elif  A[i+1] -A[i] < 0 :
            print("No")
            break
        if i == N-2 :
            print("Yes")


Measured memory_bytes: 63984
#include<cstdio>
#include<algorithm>
#include<cstring>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=500000+10;
char s[maxn];
int a[maxn];
int i,j,k,l,t,n,m,num;
int main(){
    scanf("%s",s);
    n=strlen(s);
    reverse(s,s+n);
    fo(i,0,n-1) a[i]=s[i]-'0';
    t=i=0;
    while (i<n){
        t+=a[i]*9;
        a[i]=t%10;
        t/=10;
        if (t&&i==n-1) n++;
        i++;
    }
    fo(i,0,n-1) num+=a[i];
    fo(k,1,n*20){
        a[0]+=9;
        num+=9;
        //if (a[0]<10) continue;
        t=i=0;
        while (i<n){
            t+=a[i];
            num-=a[i];
            a[i]=t%10;
            num+=a[i];
            t/=10;
            if (!t) break;
            if (i==n-1) n++;
            i++;
        }
        /*l=(k-1)/9+1;
        if (!a[0]&&num>=k&&num<=l*9) break;*/
        if (num<=9*k) break;
    }
    printf("%d\n",k);
}

Measured memory_bytes: 2560
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var p = new int[n].Select(_ => int.Parse(Console.ReadLine())).OrderBy(x => x).ToArray();
		Console.WriteLine(p.Sum() - p.Last() / 2);
	}
}


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

int main() {
  int n, d;
  cin >> n >> d;

  int q = n%(2*d+1);
  int pre = n/(2*d+1);
  if(q == 0) cout << pre << endl;
  else cout << pre + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    string ans = "second\n";
    rep(i, N) {
        int a;
        cin >> a;
        if (a % 2) ans = "first\n";
    }
    cout << ans;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        long k=sc.nextLong();
        long a=sc.nextLong();
        long b=sc.nextLong();
        long t=Math.max(0,k-a);
        if(t<=0){
            out.println(1);
        }else{
            if(a<=b){
                out.println(-1);
            }else{
                t=(t+a-b-1)/(a-b);
                out.println(2*t+1);
            }
        }
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] nextIntArray(int n){
            int[]r=new int[n];
            for(int i=0;i<n;++i)r[i]=nextInt();
            return r;
        }
    }
}


Measured memory_bytes: 23252
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
l = []
for i  in range(N):
    l.append(abs(N-2*i-1))
l.sort()
A.sort()
if l != A:
    ans = 0
else:
    ans = pow(2,N//2,mod)
print(ans)

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

using namespace std;

void Main() {
    int n;
    cin >> n;
    list<int> ans;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (n % 2 == 0) {
            if (i % 2 == 0) {
                ans.push_back(a);
            }
            else {
                ans.push_front(a);
            }
        }
        else {
            if (i % 2 == 0) {
                ans.push_front(a);
            }
            else {
                ans.push_back(a);
            }
        }
    }
    bool first = true;
    for (auto e : ans) {
        if (first) {
            cout << e;
            first = false;
        }
        else {
            cout << " " << e;
        }
    }
    cout << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 9848
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<cmath>
#include<algorithm>
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rrep(i, a, b) for(int i=b-1; i>=a; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define rREP(i, n) for(int i=n-1; i>=0; i--)
#define MAX 200
typedef long long ll;
using namespace std;

int main(void){
  int n;
  int a[MAX];
  int pow2 = 2, ans = 0;
  cin >> n;
  REP(i, n) cin >> a[i];
  while(true){
    REP(i, n) if(a[i]%pow2!=0){
      cout << ans << endl;
      return 0;
    }
    pow2*=2;
    ans++;
  }
}


Measured memory_bytes: 256
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    T = list(input())
    
    for i in range(len(T)):
        if T[i] == '?':
            T[i] = 'D'


    print(''.join(T)) 


    
main()

Measured memory_bytes: 71948
#include  <cmath>
#include  <fstream>
#include  <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
using namespace std;


int main(void)
{
    string Str = "";
    cin >> Str;
    
    if(Str.find("7") != std::string::npos)
    {
        cout << "Yes" << flush;
    }
    else
    {
        cout << "No" << flush;
    }



    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
 void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
 int main()
{
    fast();
    int n, m, a[10005],sum=0;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    if (sum <= n)
        cout << n - sum;
    else
        cout << "-1";
    return 0;
    }
   


Measured memory_bytes: 3568
a = {"name": "A", "cards": list(input())}
b = {"name": "B", "cards": list(input())}
c = {"name": "C", "cards": list(input())}

players = [a, b, c]
current_player = a

while True:
    if not current_player["cards"]:
        print(current_player["name"])
        break

    next = current_player["cards"].pop(0)
    for player in players:
        if next.upper() == player["name"]:
            current_player = player
            break



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    int k, a, b;
    cin >> k >> a >> b;

    int flag = 0;
    for(int i = a;i <= b;++i){
        if(i%k == 0){
            flag = 1;
        }
    }

    if(flag){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	//cout<<"ASDAsd";
	string s;cin>>s;
  	int ans = 0 ;
  	if( ( (s[0] == s[1] && s[1] == s[2])  && s[1]=='R')  )
         ans = 3 ;
          else if((s[0] == s[1] || s[1] == s[2])  && s[1]=='R')
  			ans = 2;
             else if( s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
                  ans = 1;
              cout<<ans<<endl; 

}

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

function main()
	ta,tb = readline() |> split |> parseMap
	aa,ab = readline() |> split |> parseMap
	ba,bb = readline() |> split |> parseMap
	if aa*ta+ab*tb==ba*ta+bb*tb
		println("infinity")
	elseif (aa<ba&&aa*ta+ab*tb<ba*ta+bb*tb)||(aa>ba&&aa*ta+ab*tb>ba*ta+bb*tb)
		println(0)
	elseif aa<ba
		v = div(ta*(ba-aa),ta*(aa-ba)+tb*(ab-bb))
		if v*(ta*aa+tb*ab)+ta*aa == v*(ta*ba+tb*bb)+ta*ba
			println(2*div(ta*(ba-aa),ta*(aa-ba)+tb*(ab-bb)))
		else
			println(1+2*div(ta*(ba-aa),ta*(aa-ba)+tb*(ab-bb)))
		end
	elseif ba<aa
		v = div(ta*(ba-aa),ta*(aa-ba)+tb*(ab-bb))
		if v*(ta*aa+tb*ab)+ta*aa == v*(ta*ba+tb*bb)+ta*ba
			println(2*div(ta*(ba-aa),ta*(aa-ba)+tb*(ab-bb)))
		else
			println(1+2*div(ta*(aa-ba),ta*(ba-aa)+tb*(bb-ab)))
		end
	end
end

main()

Measured memory_bytes: 125036
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
ll a[100000];
ll dom[100001];

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

int main(){
  int a,b;
  cin>>a>>b;
  if(a>=10||b>=10)cout<<"-1";
  else cout<<a*b;
  return 0;
}

Measured memory_bytes: 256
#d=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
#import numpy as np
#n=int(input())
#li=input().split()
#import fractions
#n=int(input())
#S=input()
import math

lis=list(map(int,input().split()))
ans=0
for i in range(1,lis[0]+1):
    s=0
    while True:
        if i*(2**s)>=lis[1]:
            ans+=1/(lis[0]*(2**s))
            break
        else:
            s+=1







print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

struct GinkoNumber
{
	int m;
	int n;

	GinkoNumber(int m, int n) : m(m), n(n){}

	GinkoNumber operator *(const GinkoNumber& data) const {
		return GinkoNumber(m*data.m - n * data.n, m*data.n + n * data.m);
	}

	GinkoNumber operator +(const GinkoNumber& data) const {
		return GinkoNumber(m*data.m + n * data.n, m*data.n - n * data.m);
	}
};

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

	for (long long int i = 0; i < n; i++) {
		GinkoNumber a = GinkoNumber(0, 0);
		cin >> a.m >> a.n;

		bool h = true;

		for (int j = 2; j < a.m*a.m + a.n*a.n; j++) {
			if ((a.m*a.m + a.n*a.n) % j == 0) {
				/*if (j == 13) {
					cout << 'b' << endl;
				}*/
				for (int k = -sqrt(j); k*k <= j; k++) {
					//cout << k << endl;
					int k2 = sqrt(j - k * k);
					if (k*k + k2 * k2 == j) {
						GinkoNumber b = GinkoNumber(k, k2);
						GinkoNumber c = GinkoNumber(k, -k2);

						/*if ((b.m==2&&b.n==2) || (b.m==3&&b.n==3)) {
							cout << 'a' << endl;
						}*/

						GinkoNumber ab = a + b;

						if (ab.m%j == 0 && ab.n%j == 0) {
							h = false;
							break;
						}

						GinkoNumber ac = a + c;
						if (ac.m%j == 0 && ac.n%j == 0) {
							h = false;
							break;
						}

					}
				}
			}
		}
		if (h) {
			cout << "P" << endl;
		}
		else {
			cout << "C" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
int main() {
 string s,t,u;
 cin >> s >> t >> u;
 cout << s[0] << t[0] << u[0];
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;


int a[50][50]={};
int w,h;

void island(int x,int y)
{
	a[x][y]=0;
	for(int i=-1;i<2;i++)
	{
		for(int j=-1;j<2;j++)
		{
			if( y+j<0||y+j>h-1||x+i>w-1||x+i<0)
			{
				continue;
			}
			if(a[x+i][y+j]==1)
			{
				island(x+i,y+j);
			}
		}
	}
}

int main() 
{
	while(cin>>w>>h,!(w==0&&h==0))
	{
		REP(i,h){REP(j,w){cin>>a[j][i];}}
		int ans(0);
		REP(i,h){REP(j,w){if(a[j][i]==1){island(j,i);ans++;}}}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1348
package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()
	var N, x int
	fmt.Fscanf(bufin, "%d %d\n", &N, &x)
	if x == 1 || x == 2*N-1 {
		fmt.Fprintf(bufout, "No\n")
		return
	}
	fmt.Fprintf(bufout, "Yes\n")
	if x >= N {
		for i := N; i <= 2*N-1; i++ {
			if i == x {
				continue
			}
			fmt.Fprintf(bufout, "%d\n", i)
		}
		fmt.Fprintf(bufout, "%d\n", x)
		for i := N - 1; i >= 1; i-- {
			fmt.Fprintf(bufout, "%d\n", i)
		}
	} else {
		for i := N + 1; i <= 2*N-1; i++ {
			fmt.Fprintf(bufout, "%d\n", i)
		}
		fmt.Fprintf(bufout, "%d\n", x)
		for i := 1; i <= N; i++ {
			if i == x {
				continue
			}
			fmt.Fprintf(bufout, "%d\n", i)
		}
	}

}


Measured memory_bytes: 3456
#include <stdio.h>
#include <math.h>
int main()
{
    int N,M,i,j,k,l;
    scanf("%d %d",&N,&M);
    long long int a[N][2],b[M][2],c[N],n,d;

    for(i=0;i<N;i++)
    {
        scanf("%lld",&a[i][0]);
        scanf("%lld",&a[i][1]);
    }

    for(j=0;j<M;j++)
    {
        scanf("%lld",&b[j][0]);
        scanf("%lld",&b[j][1]);
    }
    for(k=0;k<N;k++)
    {
        n=pow(10,17);
        for(l=0;l<M;l++)
        {
            d=fabs(a[k][0]-b[l][0])+fabs(a[k][1]-b[l][1]);
            if(d<n)
            {
              c[k]=l+1;
              n=d;
            }
        }
        printf("%lld\n",c[k]);
    }
    return 0;
}


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

typedef long long int64;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;

#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SZ(c) ((int)(c).size())

const int MAXN = 1 << 17;

int N, M;
vector<pii> G[MAXN];
int ans[MAXN];

void dfs(int u, int color, int parent) {
  ans[u] = color;
  for (auto& e : G[u]) {
    int v = e.first;
    int z = e.second;
    if (v == parent) continue ;
    if (!ans[v]) {
      dfs(v, z ? (3 - color) : color, parent);
    }
  }
}

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

  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    int u, v, z; cin >> u >> v >> z;
    --u;
    --v;
    G[u].push_back({v, z});
    G[v].push_back({u, z});
  }

  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    if (!ans[i]) {
      dfs(i, 1, -1);
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 11520
N = int(input())
S = [input() for _ in range(N)]

Total = 0
for i in range(N):
    Synmmetry = True
    for a in range(N):
        for b in range(a, N):
            if S[a][(b + i) % N] != S[b][(a + i) % N]:
                Synmmetry = False
                break
        if not Synmmetry: break
    else: Total += 1
print(Total * N)

Measured memory_bytes: 41708
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
using namespace std;
string s;
int k;
vector <string> v;
int main(){
  cin>>s>>k;
  for (int i=0;i<s.size();i++){
  	string cur;
  	for (int j=i;j<s.size()&&j<i+k;j++){
  	  cur += s[j];
  	  v.push_back(cur);
    }
  }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  cout<<v[k-1];
  return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main () {
    string a,b;   
    cin >> a >> b;
    for(int i =0;i<a.size();i++) {
        if (a[i] != b[i]) {
            no
            return 0;
        }
    }
    yes
}

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

int main() {
	
int a,b,c,d,n,k;
while(cin>> n) {
k=0;
for(a=0;a<10;a++){
	for(b=0;b<10;b++){
		for(c=0;c<10;c++){
			for(d=0;d<10;d++){
				if(a+b+c+d==n){
					k=k+1;
				}
			}
		}
	}
}
cout<<k<<endl;
}
	return 0;
}

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

int main(){
  int a;
  cin >> a;
  cout << 3*a*a << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;
typedef long long ll;

ll A, B;

/*
F(A) = 0xor1xor2xor3xor...xorA だとすると、XORの単位元の定義と交換法則により
f(A, B) = F(A - 1) xor F(B)
*/

//効率が悪いO(log B)でとくやつ
ll F(ll a) {
	
	int max_expo = 0;
	while (a >= pow(2, max_expo))max_expo++;
	max_expo--;

	ll ans = 0;

	for (; max_expo >= 0; max_expo--) {
		if (max_expo == 0) {
			if (a % 4 == 1 || a % 4 == 2)ans += 1;
		}
		else {
			ll tmp = a % static_cast<ll>(pow(2, max_expo + 1));
			if (tmp >= static_cast<ll>(pow(2, max_expo))) {
				if ((tmp - static_cast<ll>(pow(2, max_expo))) % 2 == 0) {
					ans += static_cast<ll>(pow(2, max_expo));
				}
			}
		}
	}

	return ans;

}

int main() {
	cin >> A >> B;

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

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

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

	cout << (F(A - 1) ^ F(B)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;
unsigned long long int a[100000]={};
unsigned long long int fib(long long int n){
  if(a[n]!=0)return a[n];
  if(n==0)return 1;
  if(n==1)return 1;
  return a[n]=fib(n-1)+fib(n-2);
}


int main(){
  int a;
  cin>>a;
  cout<<fib(a)<<endl;
  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int p = 0;
    for (int i = 0; i < 5; i++) {
        int t;
        cin >> t;
        if (t < 40) t = 40;
        p += t;
    }
    cout << p / 5 << "\n";
    return 0;
}


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

int main(){
	int a,b;

	while( cin >> a >> b , a|b ){
		int x = b - a;
		int ans[3] = {};
		while( x ){
			if( x >= 1000 )
				++ans[2],x -= 1000;
			else if( x >= 500 )
				++ans[1], x -= 500;
			else 
				++ans[0], x -= 100;
		}
		cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
	}
}

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

const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

/*
#include <atcoder/segtree>
using namespace atcoder;
*/

template<class T>
class Segtree{
	int n;
	vector<T>dat;
	T INIT;
	T E;
	function<T(T,T)>F;
public:
	Segtree(int n_,T INIT,T E,function<T(T,T)>F):INIT(INIT),E(E),F(F){
		n=1;while(n<n_)n<<=1;
		dat=vector<T>(2*n,INIT);
	}
	void set(int k,T x){
		k+=n;
		dat[k]=x;
		while(k>1){
			k>>=1;
			dat[k]=F(dat[k<<1],dat[(k<<1)+1]);
		}
	}
	void update(int k,T x){
		k+=n;
		dat[k]=F(dat[k],x);
		while(k>1){
			k>>=1;
			dat[k]=F(dat[k<<1],dat[(k<<1)+1]);
		}
	}
	T query(int l,int r){
		T resl=E,resr=E;
		for(l+=n,r+=n;l<r;l>>=1,r>>=1){
			if(l&1)resl=F(resl,dat[l++]);
			if(r&1)resr=F(dat[--r],resr);
		}
		return F(resl,resr);
	}
};

int main(){
	int n,K;cin>>n>>K;
	Segtree<int>seg(400000,0,0,[](int a,int b){return max(a,b);});
	rep(i,n){
		int a;scanf("%d",&a);
		int l=max(0,a-K);
		int r=min(400000,a+K+1);
		seg.update(a,seg.query(l,r)+1);
	}
	cout<<seg.query(0,400000)<<endl;
}

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


using namespace std;

const int maxi=3e5;


int gr[maxi];
int cnt[maxi];
int tip[maxi];
int len;
int n;
int dp[maxi][100];
int dp1[maxi][100];
int sled[maxi];
string s;

int main()
{
    cin>>s;

   int n=s.size();

   for (int i=0;i<26;i++)
    {
        dp[0][i]=-1;
        dp1[n+1][i]=n+1;
    }

    for (int i=1;i<=n;i++)
        for (int j='a';j<='z';j++)
        if (j==s[i-1]) dp[i][j-'a']=i; else dp[i][j-'a']=dp[i-1][j-'a'];

      for (int i=n;i>0;i--)
        for (int j='a';j<='z';j++)
        if (j==s[i-1]) dp1[i][j-'a']=i; else dp1[i][j-'a']=dp1[i+1][j-'a'];

    int tot=0;
     for (int i=1;i<=n;i++)
     {
         cnt[s[i-1]]++;
         if (cnt[s[i-1]]==1) tot++;
         if (tot==26)
         {
             len++;
             gr[len]=i;
             tot=0;
             for (int j=gr[len-1]+1;j<=gr[len];j++)
                tip[j]=len;

             for (int j='a';j<='z';j++)
                cnt[j]=0;
         }
     }

     for (int i=1;i<=n;i++)
        sled[i]=-1;

     if (len==0)
     {
         for (int i='a';i<='z';i++)
            if (!cnt[i])
         {
             printf("%c\n",i);
             return 0;
         }
     }

    int granica=n;

    for (int i=len;i>0;i--)
    {
        if (i==len){
        for (int j=gr[len];j>gr[len-1];j--)
            for (int k='a';k<='z';k++)
                {
                    int poz=dp[granica][k-'a'];
                    if (poz<=j && sled[j]==-1) sled[j]=k;
                }
        }
        else
        {
            granica=gr[i];

            for (int j=gr[i];j>gr[i-1];j--)
                for (int k='a';k<='z';k++)
                  {
                      int poz=dp1[granica+1][k-'a'];
                      int poz1=dp[granica][k-'a'];
                      if (poz1<=j && sled[poz]!=-1 && sled[j]==-1) sled[j]=poz;
                  }
        }
    }

        granica=gr[0];
        int poz=0;

        for (int j='a';j<='z';j++)
        {
             poz=dp1[granica+1][j-'a'];
            if (sled[poz]!=-1)
            {
                printf("%c",j);
                break;
            }
      }

      poz=sled[poz];
       //cout<<poz<<"\n";
      for (int i=2;i<=len;i++){
        printf("%c",s[poz-1]);
        poz=sled[poz];
      }

      printf("%c",poz);
    return 0;
}


Measured memory_bytes: 162052
const int isDebugMode = 1;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long gcd(T1 a, T2 b){return a % b ? gcd(b , a % b) : b;}
template<class T1, class T2> void reduce(T1 &a, T2 &b){ll g = gcd(a, b); a /= g; b /= g; return;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

int main(){
    ll N, M;  cin >> N >> M;
    vector<string> a(N), b(M);
    rep(i, N) cin >> a[i];
    rep(i, M) cin >> b[i];
    rep(i, N - M + 1) rep(j, N - M + 1){
        bool flag = true;
        rep(h, M) rep(w, M){
            if(a[i + h][j + w] != b[h][w]) flag = false;
        }
        if(flag){
            pt("Yes");
            return 0;
        }
    }
    pt("No");
    return 0;
}

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

#include <atcoder/maxflow>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace atcoder;
using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, m;
    cin >> n >> m;

    vector b(n, vector<bool>(m));
    vector<string> t(n);
    for (auto i : irange(0L, n)) {
        string s;
        cin >> s;
        for (auto j : irange(0L, m)) {
            b[i][j] = (s[j] == '.');
        }
        t[i] = s;
    }

    mf_graph<int64_t> g(n * m + 2);
    int64_t src = n * m, dst = n * m + 1;

    for (auto i : irange(0L, n)) {
        for (auto j : irange(0L, m)) {
            if (!b[i][j]) {
                continue;
            }

            bool is_even = (i + j) % 2;
            int64_t idx = i * m + j;

            if (is_even) {
                g.add_edge(src, idx, 1);
            } else {
                g.add_edge(idx, dst, 1);
            }

            int64_t dxs[] = {-1, 1, 0, 0};
            int64_t dys[] = {0, 0, -1, 1};
            for (auto k : irange(0L, 4L)) {
                auto dx = dxs[k];
                auto dy = dys[k];

                if (0 <= i + dx && i + dx < n && 0 <= j + dy && j + dy < m) {
                    if (!b[i + dx][j + dy]) {
                        continue;
                    }

                    int64_t idx2 = (i + dx) * m + j + dy;
                    if (is_even) {
                        g.add_edge(idx, idx2, 1);
                    } else {
                        g.add_edge(idx2, idx, 1);
                    }
                }
            }
        }
    }

    auto f = g.flow(src, dst);

    for (const auto& edge : g.edges()) {
        if (edge.from == src || edge.to == dst) {
            continue;
        }

        if (edge.flow == 0) {
            continue;
        }

        int64_t i0 = edge.from / m, j0 = edge.from % m;
        int64_t i1 = edge.to / m, j1 = edge.to % m;

        if (i0 == i1) {
            if (j0 > j1) {
                swap(j0, j1);
            }
            t[i0][j0] = '>';
            t[i0][j1] = '<';
        } else {
            if (i0 > i1) {
                swap(i0, i1);
            }
            t[i0][j0] = 'v';
            t[i1][j0] = '^';
        }
    }

    cout << f << endl;
    for (const auto& tt : t) {
        cout << tt << endl;
    }
}

Measured memory_bytes: 8640