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

int main() {
  int n = 0;
  cin >> n;
  int sum = 0;
  int cnt = 0;
  std::vector<int> v;

  for(int i = 1; i <= n; i++){
    if(i % 2 == 0) continue;
    cnt = 0;
    for(int j = 1; j <= i; j++){
      if(i % j == 0) {
        cnt++;
      }
    }
    if(cnt == 8) {
      sum++;
      v.push_back(i);

    }
  }

  cout << sum << endl;
}



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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[1005][1005];
struct Vertex {
    vector<ll> node;
    ll cnt = 0;
};

Vertex V[1000005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        REP(j, N - 1) {
            cin >> A[i][j];
            A[i][j]--;
        }
    }

    vector<ll> v;
    REP(i, N) {
        REP(j, N - 2) {
            ll p = std::min(i, A[i][j]) * N + std::max(i, A[i][j]);
            ll nxt = std::min(i, A[i][j + 1]) * N + std::max(i, A[i][j + 1]);
            V[p].node.push_back(nxt);
            V[nxt].cnt++;
            v.push_back(p);
            v.push_back(nxt);
        }
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    ll ans = 0;
    queue<pll> q;
    REP(i, v.size()) {
        if (V[v[i]].cnt == 0)
            q.push(pll(v[i], 0));
    }

    while (!q.empty()) {
        pll t = q.front();
        q.pop();
        ans = std::max(ans, t.second);
        for (auto n:V[t.first].node) {
            if (--V[n].cnt == 0)
                q.push(pll(n, t.second + 1));
        }
    }

    REP(i, v.size()) {
        if (V[v[i]].cnt > 0) {
            cout << -1 << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 71140
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	p := nextInts(n)
	cnt := 0
	for i := 0; i < n; i++ {
		if p[i] != i+1 {
			cnt++
		}
	}
	if cnt == 0 || cnt == 2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 640
def f_a():
    s = list(input())
    k, a, b, c = 0, "", "", ""
    while True:
        if len(s) == 0:
            break
        a = s.pop()
        if b == a:
            b, c = "", a
        else:
            k += 1
            b, c = a+c, ""
    print(k)

if __name__ == "__main__":
    f_a()

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

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

int main() {

	int n, k, ans = 0;

	int m;
	scanf("%d", &m);
	For(i, 1, m) {
		scanf("%d%d", &n, &k); 
		while (n % k != 0) {
			int coe = (n - n / k * k) / (n / k + 1);
			if (!coe) coe = 1;
			n -= coe * (n / k + 1);
		}
		ans ^= n / k;
	}
	puts(ans ? "Takahashi" : "Aoki");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll A, V;
  ll B, W;
  ll T;
  cin >> A >> V >> B >> W >> T;
  if (A < B)
  {
    if (A + V * T >= B + W * T)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  else
  {
    if (A - V * T <= B - W * T)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}


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

int main()
{
    int n,ans;
    string s;

    cin >> n >> s;
    ans = 0;
    rep(i,n-2) {
        if (s.substr(i,3) == "ABC")
            ++ans;
    }

    cout << ans << endl;
}


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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

 	int n;
 	cin >> n;
 	int A[n];

 	FORN(i,1,n)
 		cin >> A[i];

 	int res=0,cc=A[1];
 	bool vis[n],flag=true;
 	memset(vis,false,sizeof(vis));
 	vis[cc]=true;
 	while(cc!=2){
 		cc=A[cc];
 		if(vis[cc]){
 			flag=false;
 			break;
 		}
 		vis[cc]=true;
 		res++;
 	}

 	if(!flag){
 		cout << -1 << endl;
 		return 0;
 	}
 	cout << res+1 << endl;
    
    return 0;
}


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

using namespace std;
using vi = vector<int>;

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

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

  string S;
  cin >> S;
  int N = S.length();

  vi pos;
  string palindrome;
  REP(i, N) {
    if (S[i] != 'x') {
      pos.push_back(i);
      palindrome += S[i];
    }
  }
  string palindrome_rev = palindrome;
  reverse(ALL(palindrome_rev));
  if (palindrome.length() == 0)
    OUT(0);
  else if (palindrome != palindrome_rev)
    OUT(-1);
  else {
    int mid1 = pos[(pos.size()-1) / 2];
    int mid2 = pos[pos.size() / 2];
    int i = 0, j = N-1;
    int ans = 0;
    while (true) {
      if (i >= mid1 && j <= mid2)
        break;

      if (i >= mid1) {
        ans += j - mid2;
        j = mid2;
      } else if (j <= mid2) {
        ans += mid1 - i;
        i = mid1;
      } else if (S[i] == S[j]) {
        ++i; --j;
      } else if (S[i] == 'x') {
        ++ans;
        ++i;
      } else if (S[j] == 'x') {
        ++ans;
        --j;
      }
    }
    OUT(ans);
  }

  return 0;
}


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

using namespace std;

const int N = 1e5 + 10;

int n, m, ans[N], ord[N];
long long qn, a[N], t[N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", a + i);
		ord[i] = ans[i] = i;
	}
	for (int i = n; i >= 1; --i) {
		a[i] -= a[i - 1];
	}
	scanf("%d%lld", &m, &qn);
	for (int i = 0; i < m; ++i) {
		int x;
		scanf("%d", &x);
		swap(ord[x], ord[x + 1]);
	}
	for (; qn; qn >>= 1) {
		if (qn & 1) {
			for (int i = 1; i <= n; ++i) {
				ans[i] = ord[ans[i]];
			}
		}
		for (int i = 1; i <= n; ++i) {
			t[i] = ord[ord[i]];
		}
		for (int i = 1; i <= n; ++i) {
			ord[i] = t[i];
		}
	}
	for (int i = 1; i <= n; ++i) {
		t[i] = a[ans[i]];
	}
	for (int i = 1; i <= n; ++i) {
		a[i] = t[i] + a[i - 1];
		printf("%lld.0\n", a[i]);
	}
}

Measured memory_bytes: 3840
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest
import copy
from collections import deque

def yn(b):
    print("Yes" if b==1 else "No")
    return

def sagasu(h,w,mp,sh,sw):
    d = deque()
    x=sw
    y=sh
    d.append([y,x,0])
    while len(d)>0:
        y,x,cnt=d.popleft()
        if mp[y][x]==-2 or mp[y][x] > cnt:
            mp[y][x]=cnt
            nxt=[[y-1,x],[y+1,x],[y,x-1],[y,x+1]]
            for nx in nxt:
                y2=nx[0]
                x2=nx[1]
                if y2 < 0:
                    continue
                if y2 >= h:
                    continue
                if x2 < 0:
                    continue
                if x2 >= w:
                    continue
                if mp[y2][x2] == -2 or mp[y2][x2] > cnt:
                    d.append([y2,x2,cnt+1])
    ret=-1
    for y in range(h):
        for x in range(w):
            ret=max(ret,mp[y][x])
    return ret
def resolve():
    readline=sys.stdin.readline

    h,w=map(int, readline().rstrip().split())

    mp=[[0 for i in range(w)] for j in range(h)]
    for y in range(h):
        ss=readline().rstrip()
        for x in range(w):
            if ss[x]=="#":
                mp[y][x]=-1 #kabe
            else:
                mp[y][x]=-2 #miti
    ans=0
    for y in range(h):
        for x in range(w):
            if mp[y][x]==-2:
                mp2=copy.deepcopy(mp)
                n=sagasu(h,w,mp2,y,x)
                ans=max(ans,n)
    print(ans)
    
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 16248
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


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

	vector<char> v(100005);
	v[1] = 'S'; v[2] = 'S';
	for (int i = 2;i < n+3;i++) {
		if (v[i] == 'S'&&s[(i - 1) % n] == 'o') v[i + 1] = v[i - 1];
		if (v[i] == 'W'&&s[(i - 1) % n] == 'x') v[i + 1] = v[i - 1];
		if (v[i] == 'S'&&s[(i - 1) % n] == 'x') if (v[i - 1] == 'S') v[i + 1] = 'W';else v[i + 1] = 'S';
		if (v[i] == 'W'&&s[(i - 1) % n] == 'o') if (v[i - 1] == 'S') v[i + 1] = 'W';else v[i + 1] = 'S';
	}
	if (v[n+1] ==v[1]) if (v[n +2] == v[2]) ans = true;
	if (ans == true) { for (int i = 1;i <= n;i++) cout << v[i];cout << endl; return 0; }
	
	v[1] = 'W'; v[2] = 'S';
	for (int i = 2;i < n + 3;i++) {
		if (v[i] == 'S'&&s[(i - 1)%n] == 'o') v[i + 1] = v[i - 1];
		if (v[i] == 'W'&&s[(i - 1)%n] == 'x') v[i + 1] = v[i - 1];
		if (v[i] == 'S'&&s[(i - 1)%n] == 'x') if (v[i - 1] == 'S') v[i + 1] = 'W';else v[i + 1] = 'S';
		if (v[i] == 'W'&&s[(i - 1)%n] == 'o') if (v[i - 1] == 'S') v[i + 1] = 'W';else v[i + 1] = 'S';
	}
	if (v[n + 1] == v[1]) if (v[n + 2] == v[2]) ans = true;
	if (ans == true) { for (int i = 1;i <= n;i++) cout << v[i];cout << endl; return 0; }

	v[1] = 'S'; v[2] = 'W';
	for (int i = 2;i < n + 3;i++) {
		if (v[i] == 'S'&&s[(i - 1) % n] == 'o') v[i + 1] = v[i - 1];
		if (v[i] == 'W'&&s[(i - 1) % n] == 'x') v[i + 1] = v[i - 1];
		if (v[i] == 'S'&&s[(i - 1) % n] == 'x') if (v[i - 1] == 'S') v[i + 1] = 'W';else v[i + 1] = 'S';
		if (v[i] == 'W'&&s[(i - 1) % n] == 'o') if (v[i - 1] == 'S') v[i + 1] = 'W';else v[i + 1] = 'S';
	}
	if (v[n + 1] == v[1]) if (v[n + 2] == v[2]) ans = true;
	if (ans == true) { for (int i = 1;i <= n;i++) cout << v[i];cout << endl; return 0; }

	v[1] = 'W'; v[2] = 'W';
	for (int i = 2;i < n + 3;i++) {
		if (v[i] == 'S'&&s[(i - 1) % n] == 'o') v[i + 1] = v[i - 1];
		if (v[i] == 'W'&&s[(i - 1) % n] == 'x') v[i + 1] = v[i - 1];
		if (v[i] == 'S'&&s[(i - 1) % n] == 'x') if (v[i - 1] == 'S') v[i + 1] = 'W';else v[i + 1] = 'S';
		if (v[i] == 'W'&&s[(i - 1) % n] == 'o') if (v[i - 1] == 'S') v[i + 1] = 'W';else v[i + 1] = 'S';
	}
	if (v[n + 1] == v[1]) if (v[n + 2] == v[2]) ans = true;
	if (ans == true) { for (int i = 1;i <= n;i++) cout << v[i];cout << endl; return 0; }

	cout << -1 << endl;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<long long> L(n+1);
  L.at(0) = 2;
  L.at(1) = 1;
  for (int i = 2; i <= n; i++) {
    L.at(i) = L.at(i-1) + L.at(i-2);
  }
  
  cout << L.at(n) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct List {
	struct List *next;
	int v;
} list;

int N, a[200001], ans[200001] = {}, dp[200001], flag[200001] = {};
list *adj[200001] = {}, e[400001];

void DFS(int u, int k)
{
	if (flag[u] == 1) return;
	else flag[u] = 1;
	
	int l = 0, r = k + 1, prev;
	while (l < r) {
		if (dp[(l+r)/2] < a[u]) l = (l + r) / 2 + 1;
		else r = (l + r) / 2;
	}
	prev = dp[l];
	dp[l] = a[u];
	if (l == k + 1) ans[u] = k + 1;
	else ans[u] = k;
	
	list *p;
	for (p = adj[u]; p != NULL; p = p->next) DFS(p->v, ans[u]);
	
	dp[l] = prev;
}

int main()
{
	int i, u, w;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	for (i = 0; i < N - 1; i++) {
		scanf("%d %d", &u, &w);
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}
	
	ans[1] = 1;
	dp[0] = 0;
	dp[1] = a[1];
	DFS(1, ans[1]);
	for (i = 1; i <= N; i++) printf("%d\n", ans[i]);
	fflush(stdout);
	return 0;
}

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

using namespace std;

int main(){

    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        arr[i] = -arr[i];
    }
    vector<int> val(n+1, 1e9+7);
    val[0] = arr[0];
    int mx = 1;
    for(int i = 1; i < n; i++){
        auto lb = upper_bound(val.begin(), val.begin()+mx, arr[i] );
        val[(lb - val.begin())] = arr[i];
        if( (lb - val.begin()) == mx )
            mx++;
    }

    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 1024
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy
#import heapq
#import math
#import string

setrecursionlimit(10**6)
input=stdin.readline

n=int(input().rstrip())
a=sorted([(int(j),int(i)) for i,j in enumerate(input().split(),1)])
ans=[]
for i in a:
    ans.append(i[1])
print(*ans)

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

int main() {
  uint64_t N;
  cin >> N;
  uint64_t M = 1;
  for (int i = 0; i < 9; i++) {
    M *= 10;
  }
  M += 7;
  uint64_t result = 1;
  for (uint64_t i = 1; i <= N; i++) {
    result = (result * i) % M;
  }
  cout << result << endl;
}

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

using namespace std;
typedef long long ll;

int main() {
    string s;
    ll k;
    cin >> s >> k;
    if (k > s.length()) {
        for (auto c : s) {
            if (c != '1') {
                cout << c << endl;
                break;
            }
        }
    } else {
        for (int i = 0; i < k; ++i) {
            if (s[i] != '1') {
                cout << s[i] << endl;
                return 0;
            }
        }
        cout << s[k - 1] << endl;
    }
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
        int b = sc.nextInt();
        int c[] = new int[a];
        int ans,count = 0;
      	for(int i = 0;i < a;i++){
          c[i] = sc.nextInt();
          b -= c[i];
          count += 1;
        }
        Arrays.sort(c);
        while(b >= c[0]){
          b -= c[0];
          count += 1;
          
        }
        
          System.out.println(count);

 
      	
 
    }
}

Measured memory_bytes: 35976
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[105],b[105],c[105];
int main()
{
    int i,n,j,x;
    a[0]=0;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&x);
        a[i]=a[i-1]+x;
    }

    j=a[n];
    for(i=1; i<=n-1; i++)
    {
        if(j-a[i]*2>=0)
        {
            b[i]=j-a[i]*2;
        }
        else
        {
            b[i]=(j-a[i]*2)*(-1);
        }
    }
    sort(b+1,b+n);
    printf("%d\n",b[1]);

    return 0;


}


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

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

    for (int i = 0; i <= Y / 10000; i++) {
        for (int j = 0; j <= Y / 5000; j++) {
            int k = (Y - 10000 * i - 5000 * j) / 1000;
            if (k >= 0 && i + j + k == N) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    
    double rad;
    double PI = acos(-1);
    rad = c*PI/180;
    
    double sinc = sin(rad);
    double cosc = cos(rad);
    double s = double(a*b*sinc)/2;
    double cl = a*a+b*b-2*a*b*cosc;
    cl = sqrt(cl);
    double l = double(a)+ double(b)+cl;
    double h = double(s/a*2);
    
    
    printf("%f\n %f\n %f\n" ,s , l , h );
    
    
}


Measured memory_bytes: 3580
fun main(args: Array<String>) {
    val S = readString().map { it - '0' }

    fun f(sum: Int, op: List<Char>, i: Int): Boolean {
        if (i == S.size) {
            if (sum != 7)
                return false

            println("${S[0]}${op[0]}${S[1]}${op[1]}${S[2]}${op[2]}${S[3]}=7")
            return true
        }
        return f(sum + S[i], op + '+', i + 1) || f(sum - S[i], op + '-', i + 1)
    }

    f(S[0], listOf(), 1)
}

fun readString() = readLine()!!

Measured memory_bytes: 33588
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

int main(void) {
    long long N, M;
    cin >> N >> M;
    vector<long long> b((int)2 * sqrt((double)M), 0);

    long long j = 0;

    if (N == 1 && M == 1) {
        cout << 1 << endl;
        return 0;
    }

    for (long long i = 1; i < sqrt((double)M); i++) {
        if (M % i == 0) {
            b[j] = i;
            b[j + 1] = M / i;
            j += 2;
        }
    }

    j = (j == 0) ? 1 : j;
    b.resize(j);

    sort(b.begin(), b.end(), greater<int>());

    for (long long i = 0; i < b.size(); i++) {
        if (b[i] <= M / N) {
            cout << b[i] << endl;
            break;
        }
    }

    return 0;
}


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

using namespace std;
int main()
{
	long long monsters, special_moves;
	cin>>monsters>>special_moves;
	vector <long long> grid;
	long long total = 0;
	for(long long i = 0; i < monsters; i++)
	{
		long long h;
		cin>>h;
		total += h;
		grid.push_back(h);
	}
	sort(grid.begin(), grid.end());

	if(special_moves == monsters)
	{
		cout<<0<<endl;
		return 0;
	}
	int i = monsters - 1;
	while(special_moves > 0 && i >= 0)
	{
		total -= grid[i];
		i--;
		special_moves--;
	}
	cout<<total<<endl;
}

Measured memory_bytes: 2420
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        h: isize,
        a: isize,
    }
    println!("{}", (h + a - 1) / a);
}


Measured memory_bytes: 4352
# ALDS_1_6_B Partition
import sys


def partition(A, p, r):
    x = A[r]
    i = p
    for j in range(p, r, 1):
        if A[j] <= x:
            A[i], A[j] = A[j], A[i]
            i += 1

    A[i], A[r] = A[r], A[i]
    return i


n = int(input())
A = [int(i) for i in sys.stdin.readline().strip().split()]

q = partition(A, 0, n - 1)
print(' '.join(map(str, A[0: q])), end='')
print(' [{}] '.format(str(A[q])), end='')
print(' '.join(map(str, A[q + 1: n])))


Measured memory_bytes: 16372
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int N = (int) 1e5 + 100;
char str[N];
int d[N], dd[N];
int len;
int gt[N];

vector <int> g[N];

void addSeg(int l, int r)
{
    l = max(l, 0);
    r = min(r, len - 1);
    if (l > r) return;
    r++;
    g[l].push_back(r);
    g[r].push_back(l);
}

bool used[N];
int sum;

void dfs(int v)
{
    used[v] = true;
    sum += dd[v];
    for (int to : g[v] )
        if (!used[to] )
            dfs(to);
}

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    scanf("%s", str);
    int n = strlen(str);
    len = n / 2;
    for (int i = 0; i < len; i++)
        d[i] = (26 + str[i] - str[n - 1 - i] ) % 26;
    
    int prv = 0;
    for (int i = 0; i <= len; i++)
    {
        dd[i] = d[i] - prv;
        prv = d[i];
    }
    int q;

    for (int i = 0; i < len; i++)
        eprintf("%d ", d[i] );
    eprintf("\n");
    for (int i = 0; i <= len; i++)
        eprintf("%d ", dd[i] );
    eprintf("\n");

    scanf("%d", &q);
    for (int i = 0; i < q; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        l--;
        r--;
        if (l < n / 2 && r >= n / 2)
        {
            r = n - 1 - r;
            if (l == r) continue;
            if (l < r)
                addSeg(l, r - 1);
            else
                addSeg(r, l - 1);
        }
        else if (r < n / 2)
            addSeg(l, r);
        else
            addSeg(n - 1 - r, n - 1 - l);
    }

    for (int i = 0; i <= len; i++)
    {
        if (used[i] ) continue;
        sum = 0;
        dfs(i);
        if (sum % 26 != 0)
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");


	return 0;
}



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

using namespace std;

#define var auto
#define ll long long


signed main(){
  while (true){
    ll n;
    cin >> n;
    if (n == 0) break;
    ll a = 1;
    string bs;
    cin >> bs;
    for (int i = 0; i < 52; i++){
      a <<= 1;
      a += (bs[i] - '0');
    }
    //cout << "a" << endl;
    const ll MAX = 1L << 53;
    //cout << a << endl;
    //cout << MAX << endl;
    int se = 0;
    ll sm = a;
    while (0 < n && a != 0){
      ll gap = MAX - sm;
      ll next = (gap + a - 1)/ a;
      ll step = min(next, n);
      n -= step;
      sm += a * step;
      //cout << gap << " " << step << " " << n << endl;
      if (sm >= MAX){
        se++;
        sm >>= 1;
        a >>= 1;
      }
    }

    string ses = "";
    string sms = "";
    for (int i = 11; i >= 0; i--){
      ses += '0' + ((se >> i) & 1);
    }
    for (int i = 51; i >= 0; i--){
      sms += '0' + ((sm >> i) & 1);
    }

    cout << ses + sms << endl;
  }
  return 0;
}



Measured memory_bytes: 3096
N,M = map(int,input().split())
A,B,Ans = [[] for _ in range(N)],[],0
def s(v,a,b):
    visited[v] = True
    for n in A[v]:
        if not visited[n] and set([v,n]) != set([a,b]):
            s(n,a,b)

for i in range(M):
    a,b = map(int,input().split())
    A[a-1].append(b-1)
    A[b-1].append(a-1)
    B.append((a-1,b-1))
for i in range(M):
    visited = [True]+[False]*(N-1)
    a,b = B[i]
    s(0,a,b)
    if visited != [True]*N:
        Ans += 1
print(Ans)

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

int main(){

 int a,b;
  cin>>a>>b;
  
  int _min=min(a,b);
  int _max=max(a,b);
  
  for(int i=1;i<=_max;i++) printf("%d",_min);
  printf("\n");


return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {	
	Main main = new Main();
    	main.solveC();
    }
    
    private void solveA() {
	Scanner sc = new Scanner(System.in);
    	String s = sc.next();
	int ans = 0;

	for (int i=0;i < 4;i++){
	    if (s.charAt(i) == '+'){
		ans++;
	    }
	    else{
		ans--;
	    }
	}
    	System.out.println(ans);
    }

    private void solveB() {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int m = n;
	int s = 0;

	while(n != 0){
	    s += n%10;
	    n /= 10;
	}

	if (m%s == 0){
	    System.out.println("Yes");
	}
	else{
	    System.out.println("No");
	}
    }
    private void solveC() {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int k = sc.nextInt();
	int[] a = new int[n];
	
	for(int i=0; i < n; i++){
	    a[i] = sc.nextInt();
	}

	n--;
	k--;
	int cnt = 0;
	while(n>0){
	    n -=k;
	    cnt++;
	}

	System.out.println(cnt);
    }
}

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

int n,cnt ;
char table[260][260] ;
int dx[] = {-1,-1,0,1,1,1,0,-1} ;
int dy[] = {0,-1,-1,-1,0,1,1,1} ;

int f( int y , int x ){
	int cnt = 0 , c[4] = {} ;
	for( int k=0 ; k<8 ; k++ ){
		int nx = x+dx[k] , ny = y+dy[k] ;
		while( table[ny][nx] == '1' ){
			c[k%4]++ ;
			nx += dx[k] ;
			ny += dy[k] ;
		}
	}
	for( int k=0 ; k<4 ; k++ ) cnt = max( cnt , c[k]+1 ) ;
	return cnt ;
}

main(){
	while( cin >> n , n ){
		for( int i=0 ; i<=n+1 ; i++ ){
			for( int j=0 ; j<=n+1 ; j++ ){
				if( !i || !j || i==n+1 || j==n+1 ) table[i][j] = '0' ;
				else cin >> table[i][j] ;
			}
		}
		
		int ans = 0 ;
		for( int i=1 ; i<=n ; i++ ){
			for( int j=1 ; j<=n ; j++ ){
				if( table[i][j] == '1' ){
					f(i,j) ;
					ans = max( ans , f(i,j) ) ;
				}
			}
		}
		
		cout << ans << endl ;
	}
}

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

void solve(long long N, long long M, vector<long long> a, vector<long long> b){
	vector<int> nodes;
  int paths[9][9] = {0};
  for (int i = 0; i < N; i++) {
    nodes.push_back(i + 1);
  }
  for (int i = 0; i < M; i++) {
    paths[a[i]][b[i]] = 1;
    paths[b[i]][a[i]] = 1;
  }
  int ans = 0;
  do {
    if (nodes[0] != 1) continue;
    bool valid = true;
    for (int i = 1; i < N; i++) {
      if (paths[nodes[i-1]][nodes[i]] == 0) {
        valid = false;
        break;
      }
    }
    if (valid) ans++;
  } while (next_permutation(nodes.begin(), nodes.end()));
  cout << ans << endl;
}

int main(){	
	long long M;
	long long N;
	scanf("%lld",&N);
	scanf("%lld",&M);
	vector<long long> b(M-1+1);
	vector<long long> a(M-1+1);
	for(int i = 0 ; i <= M-1 ; i++){
		scanf("%lld",&a[i]);
		scanf("%lld",&b[i]);
	}
	solve(N, M, a, b);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sz size
#define re return
#define gl getline
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rept(i,a,b) for(int i=a;i<=b;i++)
#define all(a) (a).begin(),(a).end()
#define inf 1<<30
string s;
int main(){
	int ans=0;
	cin>>s;
	rep(i,0,s.size())ans+=s[i]-'0';
	if(ans%9!=0)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 3684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		for (int index = 0; index < S.length(); index++) {
			String ch = S.substring(index, index + 1);
			String r = "R";
			String l = "L";
			if ((index + 1) % 2 == 0) {
				//偶数文字目の処理
				if (ch.equals(r)) {
					System.out.println("No");
					return;
				} else {
				}
			} else if ((index + 1) % 2 != 0) {
				//奇数文字目の処理
				if (ch.equals(l)) {
					System.out.println("No");
					return;
				} else {
				}
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 21844
#include<cstdio>
#include<algorithm>
int main(){
	int n;
	int ans=0;
	scanf("%d",&n);
	int a[n/2]={};
	int b[n/2]={};
	int va[100001]={};
	int vb[100001]={};
	int vva[100001]={};
	int vvb[100001]={};
	
	int p, q;
	for(int i=0;i<n/2;i++){
		scanf("%d%d",&p,&q);
		a[i]=p;
		b[i]=q;
		va[p]++;
		vva[p]++;
		vb[q]++;
		vvb[q]++;
	}
	std::sort(vva,vva+100001);
	std::sort(vvb,vvb+100001);
	
	int c;
	int d;
	int e;
	int f;
	for(int i=0;i<100001;i++){
		if(va[i]==vva[100000]){
			c=i;
			break;
		}
	}
	for(int i=0;i<100001;i++){
		if(va[i]==vva[99999]&&i!=c){
			d=i;
			break;
		}
	}
	for(int i=0;i<100001;i++){
		if(vb[i]==vvb[100000]){
			e=i;
			break;
		}
	}
	for(int i=0;i<100001;i++){
		if(vb[i]==vvb[99999]&&i!=e){
			f=i;
			break;
		}
	}
	if(c!=e){
		ans=n-va[c]-vb[e];
	}else{
		ans=std::min(n-va[c]-vb[f], n-va[d]-vb[e]);
	}
	
	printf("%d\n",ans);
	return 0;
}
	

Measured memory_bytes: 2176
from itertools import product


def makelist(BIT):
    LIST, tmp = [], s[0]
    for i, bi in enumerate(BIT, 1):
        if bi == 1:
            LIST.append(tmp)
            tmp = s[i]
        elif bi == 0:
            tmp = [p + q for p, q in zip(tmp, s[i])]
    else:
        LIST.append(tmp)
    return LIST


def solve(LIST):
    CNT, tmp = 0, [l[0] for l in LIST]
    if any(num > k for num in tmp):
        return h * w
    for i in range(1, w):
        cal = [tmp[j] + LIST[j][i] for j in range(len(LIST))]
        if any(num > k for num in cal):
            CNT += 1
            tmp = [l[i] for l in LIST]
        else:
            tmp = cal
    return CNT


h, w, k = map(int, input().split())
s = [[int(sij) for sij in input()] for _ in range(h)]

ans = h * w
for bit in product([0, 1], repeat=(h - 1)):
    numlist = makelist(bit)
    ans = min(ans, solve(numlist) + sum(bit))
print(ans)


Measured memory_bytes: 77136
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var NW = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, W) = (NW[0], NW[1]);
        var wv = new (int w, int v)[N];
        for (int i = 0; i < N; i++)
        {
            var _wv = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            wv[i] = (_wv[0], _wv[1]);
        }

        void ChMin<T>(ref T min, T value) where T : IComparable { if (value.CompareTo(min) < 0) min = value; }
        void ChMax<T>(ref T max, T value) where T : IComparable { if (value.CompareTo(max) > 0) max = value; }

        var dp = new long[N + 1, W + 1];

        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j <= W; j++)
            {
                ChMax(ref dp[i + 1, j], dp[i, j]);
                if (j >= wv[i].w)
                    ChMax(ref dp[i + 1, j], dp[i, j - wv[i].w] + wv[i].v);
            }
        }

        var ans = dp[N, W];

        WriteLine(ans);
    }
}


Measured memory_bytes: 124528
<?php
// Your code here!
$N = fgets(STDIN);
$countAC = 0;
$countWA = 0;
$countTLE = 0;
$countRE = 0;

for ($i = 1; $i <= $N; $i++) {
    $S = trim(fgets(STDIN));
    
    if ($S == 'AC') {
        $countAC++;
    } elseif ($S === 'WA') {
        $countWA++;
    } elseif ($S === 'TLE') {
        $countTLE++;
    } else {
        $countRE++;
    }
}
echo 'AC x ' . $countAC . "\n" . 'WA x ' . $countWA . "\n" . 'TLE x ' . $countTLE . "\n" . 'RE x ' . $countRE; 
?>


Measured memory_bytes: 16120
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
typedef long long ll;
using namespace std;

int main()
{
    int N; cin >> N;
    vector<int> L(N * 2);
    for (int i = 0; i < N * 2; i++) {
        int a; cin >> a;
        L[i] = a;
    }
    sort(L.begin(), L.end());

    int sum = 0;
    for (int i = 0; i < (int)L.size(); i += 2) {
        sum += min(L[i], L[i + 1]);
    }
    cout << sum << endl;
}

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

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
pair< T, int > dfs(const WeightedGraph< T > &g, int idx, int par) {
  pair< T, int > ret(0, idx);
  for(auto &e : g[idx]) {
    if(e.to == par) continue;
    auto cost = dfs(g, e.to, idx);
    cost.first += e.cost;
    ret = max(ret, cost);
  }
  return ret;
}

template< typename T >
pair< int, int > tree_diameter(const WeightedGraph< T > &g) {
  auto p = dfs(g, 0, -1);
  auto q = dfs(g, p.second, -1);
  return {p.second, q.second};
}

vector< int > vv;
int ptr;

void dfs2(WeightedGraph< int > &g, int s, int t, int par = -1) {
  int space = 0, link = -1;
  for(auto &to : g[s]) {
    if(to == par) continue;
    if(g[to].size() == 1 && to != t) ++space;
    else link = to;
  }
  for(int i = 0; i < space; i++) {
    vv[ptr + i] = ptr + i + 1;
  }
  ptr += space;
  vv[ptr] = ptr - space;
  ++ptr;
  if(~link) dfs2(g, link, t, s);
}

int main() {
  int N;
  cin >> N;
  WeightedGraph< int > g(N);
  for(int i = 1; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].emplace_back(y, 1);
    g[y].emplace_back(x, 1);
  }
  auto pp = tree_diameter(g);
  vv.resize(N);
  ptr = 0;
  dfs2(g, pp.first, pp.second);
  if(ptr < N) {
    cout << -1 << endl;
    return 0;
  }
  auto latte = vv;
  ptr = 0;
  dfs2(g, pp.second, pp.first);
  auto malta = vv;
  if(latte > malta) swap(latte, malta);
  for(auto &p : latte) cout << p + 1 << " ";
  cout << endl;
}



Measured memory_bytes: 15232
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
using namespace std;
char H[105];
int main()
{
	int l;
	cin >> l;
	double p =( double(l)) / 3;
	cout << std::fixed << p * p * p << endl;
}

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

int main(){
   int N,t0 = 0,x0 = 0,y0 = 0,t,x,y;
   cin >> N;
   for (int i=0; i<N; ++i){
      cin >> t >> x >> y;
      int d=abs(x-x0)+abs(y-y0);
      if ((t-t0 < d) or ((t-t0-d)%2 == 1)){
         cout << "No" << endl;
         return 0;
      }
      x0 = x;
      y0 = y;
      t0 = t;
   }
   cout << "Yes" << endl;
   return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = [input() for _ in range(N)]
    # B***
    # ***A
    # B**A
    c_a, c_b, c_ba = 0, 0, 0
    ans = 0
    for s in S:
        if s[0] == 'B' and s[-1] == 'A':
            c_ba += 1
        elif s[-1] == 'A':
            c_a += 1
        elif s[0] == 'B':
            c_b += 1
        ans += len(s.split('AB')) - 1
    ans += max(0, c_ba - 1)
    if c_ba > 0:
        if c_a > 0:
            c_a -= 1
            ans += 1
        if c_b > 0:
            c_b -= 1
            ans += 1
    ans += min(c_a, c_b)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9640
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int i,n,a[100010],x[100010],y[100010],max=0,k,l,ans=0;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%d ",&a[i]);
  }
  for(i=0;i<=100000;i++){
    x[i]=0,y[i]=0;
  }
  for(i=0;i<n;i=i+2){
    x[a[i]]++;
  }
  for(i=1;i<n;i=i+2){
    y[a[i]]++;
  }
  for(i=0;i<=100000;i++){
    if(max<x[i]){
      max=x[i];
      k=i;
    }
  }
  max=0;
  for(i=0;i<=100000;i++){
    if(max<y[i]){
      max=y[i];
      l=i;
    }
  }
  sort(x,x+100001,greater<int>());
  sort(y,y+100001,greater<int>());
  if(k==l){
    if(x[0]+y[1]<x[1]+y[0]){
      ans=x[1]+y[0];
    }
    else{
      ans=x[0]+y[1];
    }
  }
  else{
    ans=x[0]+y[0];
  }
  printf("%d\n",n-ans);
  return 0;
}

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

int main() {
    int n, x, tmp = 0, cnt = 0;
    int l[120];
    cin >> n >> x;
    rep(i, n) {
        cin >> l[i];
        tmp += l[i];
        if (tmp <= x) {
            cnt++;
        }
    }
    cout << cnt + 1 << endl;
    return 0;
}

Measured memory_bytes: 3580
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int k,x;
  cin >> k >> x;
  for(int i=max(x-k+1,-1000000); i<=min(x+k-1,1000000); i++) {
    cout << i << " ";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int ans = 0, n, i, j, k, h, w, x, y;
	cin >> n >> h >> w;
	while (n--) {
		cin >> x >> y;
		if ((x >= h) && (y >= w)) ans++;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
#define REP(i,first,last) for(int i=first;i<=last;++i)
#define DOW(i,first,last) for(int i=first;i>=last;--i)
using namespace std;
const int MAXN=2e5+5;
int n,m;
int T;
void YES()
{
	printf("YES\n");
}
void NO()
{
	printf("NO\n");
}
void read(int &a)
{
	scanf("%d",&a);
}
void work()
{

}
int main()
{
	scanf("%d%d",&n,&m);
	int a;
	REP(i,1,m)
	{
		scanf("%d",&a);
		n-=a;
	}
	if(n<0)
	{
		printf("-1\n");
	}
	else
	{
		printf("%d\n",n);
	}
	return 0;
}

Measured memory_bytes: 3828
import sys
input = sys.stdin.readline

class SegmentTree:
    def __init__(self, size, op, I):
        n = 1
        while n < size:
            n <<= 1
        self.size = n
        self.op = op
        self.I = I
        self.node = [I] * (2 * n)

    def __getitem__(self, k):
        return self.node[k + self.size]

    def build(self, v):
        for k in range(len(v)):
            self.node[k + self.size] = v[k]
        for k in range(self.size - 1, 0, -1):
            self.node[k] = self.op(self.node[2 * k], self.node[2 * k + 1])

    def update(self, k, x):
        k += self.size
        self.node[k] = x
        while k > 1:
            k >>= 1
            self.node[k] = self.op(self.node[2 * k], self.node[2 * k + 1])

    def query(self, l, r):
        vl = vr = self.I
        l += self.size
        r += self.size
        while l < r:
            if l & 1:
                vl = self.op(vl, self.node[l])
                l += 1
            if r & 1:
                r -= 1
                vr = self.op(self.node[r], vr)
            l >>= 1
            r >>= 1
        return self.op(vl, vr)

N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
M = 300000
st = SegmentTree(M + 1, max, 0)
for i in range(N):
    a = A[i]
    x = st.query(max(0, a - K), min(a + K, M) + 1)
    st.update(a, x + 1)
print(st.query(0, M + 1))

Measured memory_bytes: 116972
#include <cstdio>

int main() {
    long long int n, tmp;
    scanf("%lld", &n);
    long long int two = 0, four = 0, odd = 0;
    for (long long int i = 0; i < n; i++) {
        scanf("%lld", &tmp);
        if (tmp % 4 == 0) four++;
        else if (tmp % 2 == 0) two++;
        else odd++;
    }

    printf((four >= odd - (n % 2))?"Yes\n":"No\n");

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cassert>
#include <numeric>
#include <queue>
#include <unordered_set>

using namespace std;

struct P {
    int64_t x;
    int64_t y;
};

struct D {
    int idx;
    int next;
    int64_t d;

    bool operator>(const D& rhs) const {
        return d > rhs.d;
    }
};


using pq = priority_queue<D, vector<D>, greater<D>>;

void calc_d(const vector<int>& ss, const vector<int>& pos, const vector<int64_t>& c, int idx, pq* que) {
    auto pp = pos[idx];

    if (pp > 0) {
        que->push(D{idx, ss[pp - 1], abs(c[ss[pp - 1]] - c[idx])});
    }
    if (pp + 1 < ss.size()) {
        que->push(D{idx, ss[pp + 1], abs(c[ss[pp + 1]] - c[idx])});
    }
}

int64_t solve(const vector<int64_t>& x, const vector<int64_t>& y) {
    vector<int> xs(x.size());
    vector<int> ys(y.size());

    iota(xs.begin(), xs.end(), 0);
    sort(xs.begin(), xs.end(), [&x](int lhs, int rhs) {
        return x[lhs] < x[rhs];
    });

    iota(ys.begin(), ys.end(), 0);
    sort(ys.begin(), ys.end(), [&y](int lhs, int rhs) {
        return y[lhs] < y[rhs];
    });

    vector<int> xpos(x.size()), ypos(y.size());
    for (int i = 0; i < x.size(); ++i) {
        xpos[xs[i]] = i;
        ypos[ys[i]] = i;
    }

    priority_queue<D, vector<D>, greater<D>> q;

    calc_d(xs, xpos, x, 0, &q);
    calc_d(ys, ypos, y, 0, &q);

    unordered_set<int> selected;
    selected.insert(0);

    int64_t ans = 0;

    while(true) {
        D md;

        while (!q.empty()) {
            md = q.top();
            if (selected.count(md.next) > 0) {
                q.pop();
                continue;
            }
            break;
        }

        if (q.empty()) {
            break;
        }

        int next;
        q.pop();
        ans += md.d;
        next = md.next;
        selected.insert(next);
        calc_d(xs, xpos, x, next, &q);
        calc_d(ys, ypos, y, next, &q);
    }

    return ans;
}

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

    vector<int64_t> x(n), y(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }

    cout << solve(x, y) << endl;

    return 0;
}

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

int main() {
  int a;
  int b;
  cin >> a;
  cin >> b;
  
  if ((a * b) % 2 == 1) {
    cout << "Odd" << endl;
  }
  
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
from collections import deque

s=input().split()
q=deque()
op=["+","-","*"]
for i in s:
    if i in op:
        a=q.pop()
        b=q.pop()
        q.append(eval("b"+i+"a"))
    else:
        q.append(int(i))
print(q[0])


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  int mx=0;
  int sm=0;
  for(int i=0;i<n;i++){
    int l;cin>>l;
    mx=max(l,mx);
    sm+=l;
  }
  sm-=mx;
  cout<<((sm>mx)?"Yes":"No")<<endl;

  return 0;
}


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

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

#define MOD 1000000007

int main(void) {
    ll N, D;
    ll count = 0;
    vector<vector<double>> X;
    cin >> N >> D;
    X.resize(N, vector<double>(D));
    for(ll i = 0;i < N;i++) {
        for(ll j = 0;j < D;j++) cin >> X[i][j];
    }
    for(ll i = 0;i < N - 1;i++) {
        for(ll j = i + 1;j < N;j++) {
            double t;
            double distance = 0;
            for(ll d = 0;d < D;d++) {
                ll temp = X[j][d] - X[i][d];
                distance += temp * temp;
            }
            distance = sqrt(distance);
            if(modf(distance, &t) == 0) count++;
        }
    }
    cout << count << endl;
    return 0;
}


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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n,k,cnt=0,a,b;
    vector<pii> x;
    cin>>n>>k;

    rep(i,0,n){
        cin>>a>>b;
        x.emplace_back(a,b);
    }

    sort(all(x));

    rep(i,0,n){
        cnt += x[i].second;
        if(cnt >= k){ 
            cout<<x[i].first<<'\n';
            return 0;
        }
    }
}

Measured memory_bytes: 2420
function main(input){
  input = input.split('\n');
  const X = BigInt(input[0]);

  let sum = 100n;
  let years = 0;
  while(sum < X){
    let rishi = sum/100n;
    sum += BigInt(String(rishi).split('.')[0]);
    years++;
  }

  console.log(years)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());


Measured memory_bytes: 30648
import java.util.*;
import java.util.stream.IntStream;

public class Main {
    static int n;
    static int[][] a = new int[2000][2000];


    static Scanner sc;

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

        if(n==1) {
            System.out.println("Yes");
            System.out.println("2");
            System.out.println("1 1");
            System.out.println("1 1");
            return;
        }

        if(n<3) {
            System.out.println("No");
            return;
        }
        int tmp = 4;
        a[0][0] = 1;
        a[0][1] = 2;
        a[1][0] = 2;
        a[1][1] = 3;
        a[2][0] = 3;
        a[2][1] = 1;
        if(n == 3) {
             out();
             return;
        }
        for (int i = 0; i < 1000; i++) {
            int j = 0;
            int l = 0;
            for (int k = 0; k < a[j].length; k++) {
                if (a[j][k] == 0) {

                    l = k;
                    break;
                }
            }
            while(a[j][0] != 0) {
                a[j][l] = tmp;
                tmp++;
                j++;
            }
            for (int k = 0; k <= l; k++) {
                a[j][k] = a[k][l];
            }
            if(tmp == n+1) {
                break;
            }
            if(tmp > n+1) {
                System.out.println("No");
                return;
            }
        }

        out();
    }

    static void out() {
        int l = 0;
        System.out.println("Yes");
        for (int i = 0; i < a[0].length; i++) {
            if(a[0][i] == 0 ){
                l = i;
                break;
            }
        }
        int ttt =0 ;
        for (int i = 0; i < a.length; i++) {
            if(a[i][0] == 0) {
                ttt = i;
                break;
            }
        }
        System.out.println(ttt);
        for (int i = 0; i < a.length; i++) {
            if(a[i][0] == 0) {
                return;
            }
            System.out.print(l + " ");
            for (int j = 0; j < l; j++) {
                System.out.print(a[i][j] + " ");
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 60948