akhauriyash/Code-Regression huggingface dataset:
import sys
import math


def main():
    """
    2 <= K <= N <= 10^5
    1 <= ai <= N
    1 <= i <= N
    """
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    #ans = f_K(N, K, A)
    ans = editorial(N, K, A)
    print(ans)


def test_examples():
    nka_ans = [
        (4, 3, [2, 3, 1, 4], 2),
        (3, 3, [1, 2, 3], 1),
        (8, 3, [7, 3, 1, 8, 4, 6, 2, 5], 4),
    ]

    for N, K, A, ans in nka_ans:
        assert editorial(N, K, A) == ans
        assert f_K(N, K, A) == ans


def test_ans():
    nka_ans = [
        (5, 2, [1, 2, 3, 4, 5], 4),
        (5, 3, [1, 2, 3, 4, 5], 2),
        (5, 2, [5, 4, 3, 2, 1], 4),
        (5, 3, [5, 4, 3, 2, 1], 2),
    ]

    for N, K, A, ans in nka_ans:
        assert editorial(N, K, A) == ans
        assert f_K(N, K, A) == ans


def f_K(N, K, A):
    """
    最初に置く範囲は、 1_idx - K + 1 から 1_idx
    """
    idx = [i for i, a in enumerate(A) if a == 1][0]
    left_idx = max(0, idx - K)
    ans = float("inf")
    for i in range(left_idx, idx + 1):
        left = i
        right = max(0, N - left - K)
        tmp = (left + (K - 1) - 1) // (K - 1)
        tmp += 1
        tmp += (right + (K - 1) - 1) // (K - 1)
        ans = min(ans, tmp)

    return ans


def editorial(N, K, A):
    """
    端から端までカバーしていく
        K + (K - 1) * N (N >= 0)
        これは仮に１番左に1があったとき
    結果的には順番は気にしなくて良い
    上記でカバーしていくと、いつかは最初の1をカバーする
        カバーした順番を1をカバーしたことを最初に行えば変わらない

    TODO: editorial pdfの意味
        1 + g(K − 1) ≤ p ≤ 1 + (g + 1)(K − 1) なる整数 g
    """
    return ((N-1) + (K-1) - 1) // (K-1)



if __name__ == '__main__':
    main()


Measured memory_bytes: 13940
#include <math.h>
int kan(int n){
  int sum=1,i=2;
  double s=sqrt(n);
  if(n<6)return -1;
  for(;i<s;i++){
    if(n%i==0)sum += i+n/i;
  }
  if(floor(s)==s&&n%(int)s==0)sum+=s;
  return sum-n;
}

int main(){
  int n,r;
  while(1){
    scanf("%d",&n);
    if(n==0)return 0;
    r=kan(n);
    if(r<0)printf("deficient number\n");
    if(r==0)printf("perfect number\n");
    if(r>0)printf("abundant number\n");
  }
}

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

int main(){
    int a, b, c;
    int k;
    int n;
    
    scanf("%d%d%d", &a, &b, &c);
    n = 0;
    for (k = a; k <= b; k++){
        if(c % k == 0)n++;
    }
    printf("%d\n", n);
    return 0;
}


Measured memory_bytes: 2104
import java.util.Scanner;

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

        int ans = 0;

        int n = scan.nextInt();
        int[] d = new int[n];
        for(int i = 0; i < n; i++){
            d[i] = scan.nextInt();
        }

        for(int i = 0; i < n - 1; i++){
            for(int j = i + 1; j < n; j++){
                ans += d[i] * d[j];
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(ll i=0,i##_len=(n);i<i##_len;i++)
#define rep2(i,a,b) for(ll i=(a),i##_len=(b);i<=i##_len;i++)
#define rrep(i,n) ll i=(n);ll now=-1;while(i--&&(now++||1))
#define Yes(n) cout<<((n)?Yes:No)
#define vll vector<ll>
#define pb push_back
using namespace std;
using ll = long long;

static inline void ignore_ret(int x) {x++;}
template<class T> inline bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
template<class T> inline T gcd_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=gcd(r,v.at(i));return r;}
template<class T> inline T lcm_vec(vector<T>v){T r=v.at(0);for(T i=1;i<v.size();i++)r=lcm(r,v.at(i));return r;}
template<class T> inline T factorial(T n){if(n==0)return 1;T r=1;for(T i=2;i<=n;i++)r*=i;return r;}
template<class T> inline T nCr(T n,T k){if(n<k||n<0||k<0)return 0;T r=1;k=min(k,n-k);for(T i=n-k+1;i<=n;i++)r*=i;return r/factorial(k);}
template<class T> inline T dot_product(vector<T>u,vector<T>v){T r=0;for(T i=0;i<u.size();i++)r+=u.at(i)*v.at(i);return r;}
template<class T> inline T sum(vector<T>v){return reduce(all(v),0LL);}

// Template ends here

void solve(ll R){
    cout << 2 * 3.14159265359 * R << "\n";
}

int main() {
    ll R;
    ignore_ret(scanf("%lld",&R));
    solve(R);
    return 0;
}


Measured memory_bytes: 3872
MOD = 10**9 + 7
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

def differenceOfMaximumSumAndMinimumSum(cumulative_sum, i):
    return (cumulative_sum[-1] - cumulative_sum[-i-1]) - cumulative_sum[i - 1]

def solve(N, K):
    ret = ModInt(1)
    cumulative_sum = [0] * (N + 1)
    tmp_sum = 0
    for i in range(1, N + 1):
        tmp_sum += i
        cumulative_sum[i] = tmp_sum

    for i in range(K, N + 1):
        ret += differenceOfMaximumSumAndMinimumSum(cumulative_sum, i) + 1
    return ret


if __name__ == '__main__':
    N, K = map(int, input().split())
    print(solve(N, K))

Measured memory_bytes: 67772
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;
constexpr ll INF = 1e18;

struct item {
    ll a, b, c;
    item() {}
    item(ll a, ll b, ll c) : a(a), b(b), c(c) {}
};

ll dp[41][401][401];

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<item> items(N);
    for (auto&& i : items) {
        ll a, b, c;
        cin >> a >> b >> c;
        i = item(a, b, c);
    }

    for (ll n = 0; n <= N; n++) {
        for (ll a = 0; a <= N * 10; a++) {
            for (ll b = 0; b <= N * 10; b++) {
                dp[n][a][b] = INF;
            }
        }
    }

    dp[0][0][0] = 0;
    for (ll n = 1; n <= N; n++) {
        dp[n][0][0] = 0;
        auto i = items[n - 1];
        for (ll a = 1; a <= N * 10; a++) {
            for (ll b = 1; b <= N * 10; b++) {
                if (a >= i.a && b >= i.b) {
                    dp[n][a][b] = min(dp[n - 1][a][b], dp[n - 1][a - i.a][b - i.b] + i.c);
                } else {
                    dp[n][a][b] = dp[n - 1][a][b];
                }
            }
        }
    }

    ll ans = INF;

    for (ll a = 1; a <= N * 10; a++) {
        for (ll b = 1; b <= N * 10; b++) {
            if (a % Ma == 0 && b % Mb == 0 && a / Ma == b / Mb) {
                ans = min(ans, dp[N][a][b]);
            }
        }
    }

    cout << (ans == INF ? -1 : ans) << endl;

    return 0;
}



Measured memory_bytes: 51712
H,W,N = map(int,input().split())

A = {}
for i in range(N):
  a,b = map(int,input().split())
  a-=1;b-=1
  for t in range(3):
    for s in range(3):
      if 0<=a-t<H-2 and 0<=b-s<W-2:
        if (a-t,b-s) not in A:
          A[(a-t,b-s)]  = 1
        else:
          A[(a-t,b-s)]  += 1
#print(A)
ans = [-1]
temp = list(A.values())
total = 0
for i in range(1,10):
  c = temp.count(i)
  total += c
  ans.append(c)
ans[0] = (H-2)*(W-2)-total
print(*ans, sep="\n")

  

Measured memory_bytes: 174180
N, Ma, Mb = map(int, input().split())
Drug = [list(map(int, input().split())) for i in range(N)]


dp = [[[float('inf')] * 401 for j in range(401)] for i in range(N + 1)]
dp[0][0][0] = 0
for i, (a, b, c) in enumerate(Drug):
    for ma in range(401):
        for mb in range(401):
            if (ma + a < 401) and (mb + b < 401):
                dp[i + 1][ma + a][mb + b] = min(dp[i + 1][ma + a][mb + b], dp[i][ma][mb] + c)
            dp[i + 1][ma][mb] = min(dp[i + 1][ma][mb], dp[i][ma][mb])

ans = float('inf')
for i in range(1, 401):
    if (Ma * i) < 401 and (Mb * i) < 401:
        ans = min(ans, dp[-1][Ma * i][Mb * i])
    else:
        break

print(ans if ans != float('inf') else -1)


Measured memory_bytes: 133212
function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");
	
	var L = parseInt(tmp[0], 10);
	var R = parseInt(tmp[1], 10);
	var d = parseInt(tmp[2], 10);
	
	var result = Math.floor(R / d) - Math.floor(L / d);
	
	if  (Math.floor(L % d) == 0) {
	result = result + 1;
	} else {
	}
	
	var a = Math.floor(L / d);
	var b = Math.floor(R / d);
	
	console.log(result);
	}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {

	int n, m;	cin >> n >> m;

	priority_queue<long long > p_que;
	for (int i = 0; i < n; i++) {
		long long tmp; cin >> tmp;
		p_que.push(tmp);
	}

	for (int i = 0; i < m; i++) {
		long long tmpMax = p_que.top();
		p_que.pop();
		tmpMax /= 2;
		p_que.push(tmpMax);
	}
	
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += p_que.top();
		p_que.pop();
	}

	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 1400
#ABC145D

MOD = 10 ** 9 + 7
import math
x,y = map(int,input().split())
a,b = -1,-1

for i in range(x+1):
    m = 0
    if (x-i) % 2 == 0:
        m = (x-i) // 2
        if 2*i + m == y:
            if i >= 0 and m >= 0:
                a = i
                b = m
                break
    else:
        continue
        
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%MOD)

fact_inv[-1] = pow(fact[-1],MOD-2,MOD)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%MOD

def com(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod  
        
        
if a == -1 and b == -1:
    print(0)
else:
    print(com(a+b,a,MOD))

Measured memory_bytes: 101996
""" スニペット """
def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split()))
""" スニペット """
import math
# 2つ選ぶ通り数を算出 nC2
def choose2(n):
    return math.floor(n*(n-1)/2)

# インプット
N = get_int()
An = get_ints()
""" 全ての要素から2つのボールを選ぶ通り数を求める """
uni = [0] * (N+1)
# ユニーク数の配列を求める
for i in range(N):
    uni[An[i]] += 1
sumWay = 0
# 各数値の2通りの選択通り数を足していく ここのindex=0がいらない
for i in range(N+1):
    sumWay += choose2(uni[i])
""" 全ての要素数 - 削除する要素の通り数 + 削除する要素を引いた際の通り数 を求める """
for i in range(N):
    print(sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]]-1)) 

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

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

	for (int i = 0; i < str.size(); i++){
		if  (str[i] == ','){
			cout << " ";
		} else {
			cout << str[i];
		}
	}
	puts("");
}


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

int main()
{
    char a[20], b[20], c[20];
    scanf("%s %s %s", &a, &b, &c);
    int al, bl;

    al = strlen(a)-1, bl = strlen(b)-1;

    if(a[al]==b[0] && b[bl]==c[0])
    printf("YES");

    else printf("NO");
}

Measured memory_bytes: 1720
import java.util.HashSet;
import java.util.Scanner;

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

		int[] groups = new int[n];
		int[] counts = new int[n];
		int groupCount = 0;
		HashSet<Integer>[] sets = new HashSet[n];
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int ga = groups[a - 1];
			int gb = groups[b - 1];
			if (ga == 0 && gb == 0) {
				groupCount++;
				groups[a - 1] = groupCount;
				groups[b - 1] = groupCount;
				sets[groupCount - 1] = new HashSet<Integer>();
				sets[groupCount - 1].add(a);
				sets[groupCount - 1].add(b);
			} else if (groups[a - 1] == 0) {
				groups[a - 1] = gb;
				sets[groups[b - 1] - 1].add(a);
			} else if (groups[b - 1] == 0) {
				groups[b - 1] = ga;
				sets[groups[a - 1] - 1].add(b);
			} else if (ga != gb) {
				int g1 = ga;
				int g2 = gb;
				if (sets[groups[a - 1] - 1].size() < sets[groups[b - 1] - 1].size()) {
					g1 = gb;
					g2 = ga;
				}
				for (Object x : sets[g2 - 1]) {
					groups[(int)x - 1] = g1;
				}
				sets[g1 - 1].addAll(sets[g2 - 1]);
			}
			counts[a - 1]++;
			counts[b - 1]++;
		}

		for (int i = 0; i < k; i++) {
			int c = sc.nextInt();
			int d = sc.nextInt();
			if (groups[c - 1] == groups[d - 1]) {
				counts[c - 1]++;
				counts[d - 1]++;
			}
		}
		sc.close();

		int[] gc = new int[groupCount];
		for (int i = 0; i < n; i++) {
			if (groups[i] != 0) {
				gc[groups[i] - 1]++;
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			int result = 0;
			if (groups[i] != 0) {
				result += (gc[groups[i] - 1] - 1 - counts[i]);
			}
			sb.append(i == 0 ? "" : " ");
			sb.append(result);
		}
		System.out.print(sb.toString());
	}
}


Measured memory_bytes: 127860
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100005;

int dp[1<<16],V[MAXN],cnt[16];

int DP(int s)
{
	if(s==0)
		return 0;
	if(dp[s]!=-1)
		return dp[s];
	dp[s]=0x3FFFFFFF;
	for(int i=1;i<16;i++)
		if(s&(1<<i))
			for(int j=1;j<16;j++)
				if(s&(1<<j))
				{
					int ns=s^(1<<i)^(1<<j)^(1<<(i^j));
					if(__builtin_popcount(ns)<__builtin_popcount(s))
						dp[s]=min(dp[s],DP(ns)+1+(((1<<(i^j))&s)==(1<<(i^j))));
				}
	return dp[s];
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1,x,y,a;i<n;i++)
	{
		scanf("%d%d%d",&x,&y,&a);
		V[x]^=a;
		V[y]^=a;
	}
	for(int i=0;i<n;i++)
		if(V[i])
			cnt[V[i]]++;
	int ans=0,st=0;
	for(int i=0;i<16;i++)
	{
		ans+=cnt[i]/2;
		st^=(cnt[i]&1)<<i;
	}
	memset(dp,-1,sizeof dp);
	ans+=DP(st);
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 896
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
  
N = int(input())

ans = 0
for i in range(1, N+1, 2):
    if len(make_divisors(i))==8:
        ans += 1
        
print(ans)

Measured memory_bytes: 9132
def comb(arr, k):
    n = len(arr)
    def dfs(curr,cnt,tmp):
        ret = []
        if cnt==0:
            return [tmp]
        for i in range(curr,n-cnt+1):
            ret += dfs(i+1,cnt-1,tmp+[arr[i]])
        return ret
    return dfs(0,k,[])

from math import *
N=int(input())
k1 = int(sqrt(2*N))
k2 = k1+1
if k1*k2 == 2*N:
    print("Yes")
    print(k2)
    ans = [[] for _ in range(k2)]
    for i, (i1, i2) in enumerate(comb(list(range(k2)), 2)):
        ans[i1].append(i+1)
        ans[i2].append(i+1)
    
    for arr in ans:
        print(" ".join([str(v) for v in [k1]+arr]))
else:
    print("No")


Measured memory_bytes: 57436
#include<bits/stdc++.h>
using namespace std;
#define mx 100000
#define md 1000000007ll

int ar[102];
int dp[102][102][102];
int DP(int i,int k, int baki){
    if(i>k)return 0;
    if(baki==0)return 0;

    int &ret=dp[i][k][baki];

    if(ret!=-1)return ret;

    ret=0;

    if(baki>=2){ret=max(ret,DP(i+1,k,baki-2));
    ret=max(ret,DP(i,k-1,baki-2));
    }

    ret=max(ret,ar[i]+DP(i+1,k,baki-1));
    ret=max(ret,ar[k]+DP(i,k-1,baki-1));


    return ret;
}

int main(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>ar[i];

    memset(dp, -1,sizeof dp);

    cout<<DP(1,n,k)<<endl;
  
    return 0;
}

Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
using namespace std;
const long long Mod=1e9+7;
int n;
long long ans=1,tot;
char s[200020];
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	scanf("%s",s);
	for(int i=0;i<n*2;i++){
		if((s[i]=='B')^(i&1)) tot++;
		else{
			if(!tot){
				printf("0\n");
				return 0;
			}
			ans*=tot;
			ans%=Mod;
			tot--;
		}
	}
	if(tot){
		printf("0\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
		ans=ans*i%Mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include<iostream>
using namespace std;
typedef long long ll;
int check(ll n, ll div){
     if(n % div==0)
        return check(n/div, div);
    else  return (n % div == 1) ;
}

int main(){
	ll n;
	int res = 0;

	scanf("%lld", &n);
	for(ll i=2; i*i <= n; i++) {
		if(check(n, i)) {
			res++;
			if(i != n / i && check(n, n/i))
				res++;
		}
	}
	if(n==2)     printf("%d",res+1);
	else      printf("%d",  res+2);

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// using namespace std;

using ll = long long;

void Main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);

  ll x2 = 0;

  for (int i = 0; i < n; ++i) {
    std::cin >> a[i];
    if (i % 2 == 0) {
      x2 += a[i];
    } else {
      x2 -= a[i];
    }
  }
  std::vector<int> ans(n);
  ans[0] = x2 / 2;
  for (int i = 0; i < n - 1; ++i) {
    ans[i + 1] = a[i] - ans[i];
  }
  for (int i = 0; i < n; ++i) {
    ans[i] *= 2;
    std::cout << ans[i] << (i == n - 1 ? "\n" : " ");
  }
}

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


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

int main() {
    long n, m, ans;
    scanf("%ld%ld", &n, &m);
    if (n < m/2) ans = n + ((m/2 - n)*2) / 4;
    else ans = m / 2;
    printf("%ld\n", ans);
}

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


int main(){
  int n, m, q; cin >> n >> m >> q;
  vector<pair<int, int>> lr(m);
  rep(i, m){
    int l, r; cin >> l >> r;
    lr[i].first = l;
    lr[i].second = r;
  }
  sort(lr.begin(), lr.end());

  vector<vector<int>> dp(501, vector<int>(501, 0));

  for(int i = 0; i < m; i++){
    dp[1][lr[i].second]++;
  }
  for(int r = 1; r <= 500; r++){
    dp[1][r] += dp[1][r - 1];
  }

  int cnt = 0;
  for(int l = 2; l <= n; l++){
    for(int r = l; r <= n; r++){
      dp[l][r] = dp[l - 1][r];
    }
    while(l - 1 == lr[cnt].first){
      for(int r = lr[cnt].second; r <= n; r++){
        dp[l][r]--;
      }
      cnt++;
    }

    /*cout << endl;
    for(int l = 1; l <= n; l++){
      for(int r = 1; r <= n; r++){
        cout << dp[l][r] << " ";
      }
      cout << endl;
    }*/

  }

  vector<pair<int, int>> qe(q);
  rep(i, q){
    int l, r; cin >> l >> r;
    qe[i].first = l;
    qe[i].second = r;
  }

  rep(i, q){
    cout << dp[qe[i].first][qe[i].second] << endl;
  }

  return 0;
}


Measured memory_bytes: 6592
while True:
    h, w = map(int,input().split())
    if(h == w == 0):
        break
    for i in range(1,h+1):
        if i % 2 == 0:
            print((".#"*w)[:w])
        else:
            print(("#."*w)[:w])
    print()
        



Measured memory_bytes: 5612
/*
      بسم اللہ الرحمن الرحیم
    Bismillahir Rahmanir Raheem.
    In the name of Allah, Most Gracious, Most Merciful.
*/
/*
    Masum
    RUET
    CSE-19
    #1903086
    NDC
    #11901058
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define endl '\n'
int recur_depth = 0;
#ifndef ONLINE_JUDGE
#define dbg(x)                                                   \
    {                                                            \
        ++recur_depth;                                           \
        auto x_ = x;                                             \
        --recur_depth;                                           \
        cout << string(recur_depth, '\t') << __func__ << ":"     \
             << __LINE__ << "\t" << #x << " = " << x_ << "\n\n"; \
    }
#else
#define dbg(x)
#endif
template <typename Ostream, typename Cont>
typename enable_if<is_same<Ostream, ostream>::value, Ostream&>::type
operator<<(Ostream& os, const Cont& v) {
    os << "[";
    for (auto& x : v) {
        os << x << ", ";
    }
    return os << "]";
}
template <typename Ostream, typename... Ts>
Ostream& operator<<(Ostream& os, const pair<Ts...>& p) {
    return os << "{" << p.first << "," << p.second << "}";
}
/*________________________________________________________________*/

void sol();
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    /* Test cases */
    bool isT = 0;
    if (isT) {
        int t;
        cin >> t;
        while (t--)
            sol();
    } else
        sol();
    return 0;
}
void sol() {
    /* Remember about test cases --> exits or not */

    string s, s_;
    cin >> s >> s_;
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != s_[i]) cnt++;
    }
    cout << cnt;
}
/*
        Self_Motivation:
    First think, then code.
    Do not jump between problems
*/


Measured memory_bytes: 3772
n,m,t=map(int,input().split())
d=0
a=[int(i) for i in input().split()]
b=a[0]-m
c=a[0]+m
for i in range(1,n):
    if a[i]>c+m:
        d+=c-b
        b=a[i]-m
    c=a[i]+m
if c<t:d+=c-b
else:d+=t-b
print(t-d)

Measured memory_bytes: 7748
#include <stdio.h>
  
void insertionSort(int [], int, int);
void shellSort(int [], int);
  
int cnt = 0;
int a[1000000];
  
void insertionSort(int a[], int n, int g){
  int i, j, key;
  
  for(i = g;i < n;i++){
    key = a[i];
    j = i - g;
    while(j >= 0 && a[j] > key){
      a[j+g] = a[j];
      j = j - g;
      cnt++;
    }
    a[j+g] = key;
  }
}
  
void shellSort(int a[], int n){
  int m = 13; 
  int g[13] = {1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 165720, 797161};
  int i;
  
  cnt = 0;
  while(g[m-1] > n){
    m--;
  }
  printf("%d\n", m);
  for(i = m-1;i >= 1;i--){
    printf("%d ", g[i]);
  }
  printf("%d\n", g[0]);
  for(i = m-1;i >= 0;i--){
    insertionSort(a, n, g[i]);
  }
}
 
main(){
  int n, i;
  
  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%d", &a[i]);
  }
  shellSort(a, n);
  printf("%d\n", cnt);
  for(i = 0;i < n;i++){
    printf("%d\n", a[i]);
  }
  return 0 ;
}


Measured memory_bytes: 5648
A = [int(input()) for i in range(5)]
A.sort()
dec = 10
dsum = 0
f = 0
for i in A:
    if i % 10 >= 1:
        dec = min(dec,i % 10)
        f = 1
    if not i % 10 == 0:
        dsum = dsum + (i - (i % 10) + 10)
    else:
        dsum = dsum + i
print(dsum+dec-10 if f == 1 else dsum)


Measured memory_bytes: 3060
/*
    Solution solved by Maksat Sakenuly
*/
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define sqr(x) ((x)*(x))
#define sz(x) int(x.size())
#define tos(str) string(#str)
#define gcd(x, y) __gcd(x, y)
#define all(x) x.begin(), x.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define count1 __builtin_popcountl
#define tie cin.tie(0);cout.tie(0)
#define ios ios_base::sync_with_stdio(false)
#define debug(x) cout << (#x) << " is " << (x) << endl
#define m ((l + r)/ 2)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector <ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vector<int> > vvi;

const int oo = 0x3f3f3f3f;
const ll N = 2e5 + 123;
const ll MOD = 1e9 + 7;
const ll INF = 2e9 + 7;
const double pi = acos(-1);

int a[N], l[N], r[N];

int main() {
    ios; tie;

    int n;
    cin >> n;

    stack <int> s1, s2;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        while(!s1.empty() && a[s1.top()] >= a[i]) s1.pop();
        if(s1.empty()) l[i] = 0;
        else l[i] = s1.top();
        s1.push(i);
    }
    for(int i = n; i >= 1; i--) {
        while(!s2.empty() && a[s2.top()] >= a[i]) s2.pop();
        if(s2.empty()) r[i] = n + 1;
        else r[i] = s2.top();
        s2.push(i);
    }

    ll ans = 0;
    for(int i = 1; i <= n; i++)
        ans += 1ll*(r[i]-i)*(i-l[i])*a[i];

    cout << ans;
    return 0;
}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

        int n, k, s;
        cin >> n >> k >> s;
        for (int i = 1; i <= k; i++)
                cout << s << " ";
        if (s > n)
                for (int i = 1; i <= n - k; i++)
                        cout << 1 << " ";
        else
                for (int i = 1; i <= n - k; i++)
                        cout << (int) 1e9 << " ";
        cout << "\n";
}


Measured memory_bytes: 1280
# https://atcoder.jp/contests/abc127/tasks/abc127_c
N, M = list(map(int, input().split()))
L = 0
R = N
for _ in range(M):
    l, r = list(map(int, input().split()))
    L = max(L, l)
    R = min(R, r)

print(max(R - L + 1, 0))


Measured memory_bytes: 44120
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ff first
#define ss second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define loopf(i,a,b) for(int i = a;i < b;i++)
#define loopb(i,a,b) for(int i = a;i >= b;i--)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;



int32_t main()
{
    fast

   int test=1;
   // cin>>test;
  
  while(test--)
  {
    int s;
    cin>>s;
    int x=s%10;
    if(x==3)
    {
        cout<<"bon";
    }
    else if(x==1||x==0||x==6||x==8)
        cout<<"pon";
    else cout<<"hon";



    // while loop ending
   }
  

return 0;
}

Measured memory_bytes: 3616
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	m := make([]int, n+1)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		m[a]++
	}
	sort.Ints(m)

	ans := 0
	for _, v := range m[:len(m)-k] {
		ans += v
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7040
from fractions import gcd

t = int(input())
for _ in range(t):
    a, b, c, d = list(map(int, input().split()))
    if b > a:
        print("No")
    elif b > d:
        print("No")
    elif c >= b:
        print("Yes")
    else:
        g = gcd(b, d)
        if b - g + (a % g) > c:
            print("No")
        else:
            print("Yes")


Measured memory_bytes: 5432
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,long double> Pi;
typedef pair <long double,int> Pd;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
ll pl=12000;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<int> p(n),r(n);
vector<ll> a(n),b(n);
for(int i=0;i<n;i++){cin>>p[i];r[p[i]-1]=i+1;}
for(int i=0;i<n;i++){
    a[i]=30000*(i+1);
    b[i]=30000*(n-i)+r[i];
}
for(int i=0;i<n;i++)cout<<a[i]<<" ";
cout<<endl;
for(int i=0;i<n;i++)cout<<b[i]<<" ";
cout<<endl;
}



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

int main() {
    int N, ans = 1;
    string S;
    cin >> N >> S;
    rep(i, N - 1) {
        if (S[i] != S[i + 1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
N = int(input())
B6 = [6**i for i in range(1,7)]
B9 = [9**i for i in range(1,6)]
L = B6 + B9
L = sorted(list(set(L)))
dp = [int(i) for i in range(N+1)]

for i in L:
    for j in range(1, N+1):
        if j - i >= 0:
            dp[j] = min(dp[j], dp[j-i] + 1)
print(dp[N])

Measured memory_bytes: 7064
n = int(input())
a = [int(input()) for i in range(n)]

ans = a[0] // 2
for i in range(1,n):
  tmp = a[i-1] % 2 + a[i]
  ans += tmp // 2
  if tmp // 2:
    a[i] = tmp % 2
print(ans)

Measured memory_bytes: 7072
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <climits>
#include <vector>
#include <cmath>
#include <cstring>
#include <set>

using namespace std;

int main(void)
{

    int N, M;
    cin >> N >> M;

    int s[M], c[M];
    for (int i = 0; i < M; i++)
    {
        cin >> s[i] >> c[i];
    }

    for (int i = 0; i < 1000; i++)
    {
        if (int(log10(i)) == N - 1 || (N == 1 && i == 0))
        {
            for (int m = 0; m < M; m++)
            {
                // 右からsrightけた目。0始まり
                int sright = N - s[m];
                int keta = (i / int(pow(10, sright))) % 10;
                if (keta != c[m])
                {
                    goto endloop;
                }
            }
            cout << i << endl;
            return 0;
        }

    endloop:
        continue;
    }

    puts("-1");
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;
	int a[n];
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	int ans = inf;
	rep(i, n - k + 1) { ans = min(ans, a[i + k - 1] - a[i]); }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

struct Item
{
	string name;
	int w;
	int s;
};

class ShieldDesc
{
public:
	bool operator()( const Item& a, const Item& b ) const
	{
		if( a.s > b.s ) return true;
		return false;
	}
};

double calcG( vector< Item >& v, vector< int > p )
{
	double num = 0.0, den = 0.0;
	for( int i = 0; i < (int)p.size(); ++i ){
		num += ( v[ p[ i ] ].w * ( i + 1 ) );
		den += v[ p[ i ] ].w;
	}
	return num / den;
}

vector< int > rec( vector< Item >& v, int used, vector< int > p, vector< int > r, vector< int >& a )
{
	int rest = v.size() - p.size();
	if( rest == 0 ){
		if( a.empty() || calcG( v, p ) < calcG( v, a ) ){
			a = p;
		}
		return a;
	}

	int shift = 0;
	for( int i = 0; i < rest; ++i ){
		int bit = 1;
		while( used & bit << shift ){
			++shift;
		}
		vector< int > pp = p;
		vector< int > rr = r;
		int w = v[ shift ].w;
		bool failed = false;
		for( int j = p.size() - 1; j >= 0; --j ){
			rr[ j ] -= w;
			if( rr[ j ] < 0 ){
				failed = true;
				break;
			}
		}
		if( failed ){
			++shift;
			continue;
		}

		pp.push_back( shift );
		rr.push_back( v[ shift ].s );
		rec( v, used | ( 1 << shift ), pp, rr, a );
		++shift;
	}
	return a;
}

vector< int > stack( vector< Item >& v )
{
	vector< int > p, r, a;
	return rec( v, 0, p, r, a );
}

int main()
{
	int n;

	while( cin >> n && n ){
		vector< Item > v;
		for( int i = 0; i < n; ++i ){
			Item item;
			cin >> item.name >> item.w >> item.s;
			v.push_back( item );
		}
		sort( v.begin(), v.end(), ShieldDesc() );

		vector< int > ans = stack( v );
		for( int i = 0; i < n; ++i ){
			cout << v[ ans[ i ] ].name << endl;
		}
	}

	return 0;
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  string n;
  cin >> n;
  cout << (n[0] == '9' || n[1] == '9' ? "Yes" : "No") << endl;
}



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

int main()
{
  int a,b,k;

  cin >> k >> a >> b;

  for (int i=a; i<=b; i++){
    if(i%k==0){
      cout << "OK\n" << endl;
      return 0;
    }
  }

  cout << "NG\n";

  return 0;
}

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

int main () {

  int H, W;
  cin >> H >> W;

  int a[500][500];
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cin >> a[i][j];
    }
  }

  int N = 0;
  int ans[250000][4];
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      if (a[i][j]%2==1) {
	if (j+1 < W) {
	  a[i][j]--;
	  a[i][j+1]++;
	  ans[N][0] = i + 1;
	  ans[N][1] = j + 1;
	  ans[N][2] = i + 1;
	  ans[N][3] = j+1 + 1;
	  N++;
	} else if (i+1 < H){
	  a[i][j]--;
	  a[i+1][j]++;
	  ans[N][0] = i + 1;
	  ans[N][1] = j + 1;
	  ans[N][2] = i+1 + 1;
	  ans[N][3] = j + 1;
	  N++;
	}
      }
    }
  }
  
  cout << N << endl;
  for (int k=0; k<N; k++){
    cout << ans[k][0] << " " << ans[k][1] << " " << ans[k][2] << " " << ans[k][3] << endl; 
  }

  return 0;
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///


void _case()
{
    ll n,i;
    cin>>n;
    cout<<(n*(n-1))/2 el;
}

main()
{
    fastio();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!



Measured memory_bytes: 3628
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int R,G;
int main() {
	cin>>R>>G;

	cout<<R+(G-R)*2<<endl;
	return 0;
}


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

int main(){
  ll n,d,x,y;cin>>n>>d;
  ll sum=0;
  d*=d;
  rep(i,n){
    cin>>x>>y;
    x*=x;
    y*=y;
    if(d>=x+y)sum++;
  }
  cout<<sum;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        string str;
        cin >> str;
        vector<long> v;
        long ans = 0;
        v.assign(str.length() , 0);
        long t = 0;
        for(int i = str.length() - 1 ; i >= 0; i--  ){
            if(str[i] == 'W'){
                t += 1;
            }
            v[i] = t;
        }
        for(int i = 0 ; i < str.length() ; i++){
            if(str[i] == 'B'){
                ans += v[i];
            }
        }
        
        cout << ans << endl;
        
        return 0;
    }

Measured memory_bytes: 2180
N = int(input())
a = [-1]
for i in range(N):
    k = int(input())
    a.append(k)

k = 1
ans = 0
while ans < N+1:
    k = a[k]
    ans += 1
    if k == 2:
        break
if ans > N:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 49864
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;

void g(pair<int, bool> arr[3][3], int b) {
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            if (arr[i][j].first == b) {
                arr[i][j].second = true;
            }
        }
    }
}

bool f(pair<int, bool> arr[3][3]) {

    for (int i = 0; i < 3; ++i) {
        bool horizontal = true;
        for (int j = 0; j < 3; ++j) {
            if (!arr[i][j].second) {
                horizontal = false;
                break;
            }
        }
        if (horizontal) {
            return true;
        }
    }

    for (int i = 0; i < 3; ++i) {
        bool horizontal = true;
        for (int j = 0; j < 3; ++j) {
            if (!arr[j][i].second) {
                horizontal = false;
                break;
            }
        }
        if (horizontal) {
            return true;
        }
    }

    return (arr[0][0].second and arr[1][1].second and arr[2][2].second) or
            (arr[0][2].second and arr[1][1].second and arr[2][0].second);
}

int main() {

    pair<int, bool> arr[3][3];

    int A;

    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> A;
            arr[i][j] = make_pair(A, false);
        }
    }

    int N;
    cin >> N;

    int b;
    for (int i = 0; i < N; ++i) {
        cin >> b;
        g(arr, b);
    }

    if (f(arr)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

int main()
{
    canhazfast();

    int n, k, ans = 0;

    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        int h;
        cin >> h;
        if (h >= k) ++ans;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
int N, H;

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

  cin >> N >> H;
  int a_max = 0;
  int a=0;
  int b=0;
  vector<int> V(N);
  rep(i, N){
    cin >> a >> b;
    a_max = max(a_max, a);
    V[i] = b;
  }
  sort(ALL(V), greater<int>());
  int cnt=0;
  rep(i, N){
    int c = V[i];
    if (a_max>=c) break;
    H-=c;
    cnt++;
    if (H<=0){
      cout << cnt << "\n";
      return 0;
    }
  }

  cnt += (H+a_max-1)/a_max;
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define cout (cout<<fixed<<setprecision(15))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define out(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<"\n";}while(0)
#define out2(v) for(auto i:v)output(i);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define sum(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
lint binary_search(function<bool(lint)> func) {
    lint left = -1;
    lint right =LINF-1;
    while (right - left > 1) {
        lint mid = left + (right - left) / 2;
        if (func(mid)) right = mid;
        else left = mid;
    }
    return right;
}
int main(){
    lint n,m;
    cin>>n>>m;
    vec a(m),b(m);
    mat v(n,vec{});
    rep(i,m)cin>>a[i]>>b[i];
    rep(i,m){
        v[a[i]-1].push_back(b[i]-1);
        v[b[i]-1].push_back(a[i]-1);
    }
    stack<pair<lint,lint>> s;
    s.push({0,1});
    lint cnt=0;
    while(!s.empty()){
        auto d=s.top();
        s.pop();
        if(d.second==(1<<n)-1){
            cnt++;
        }
        else for(lint to:v[d.first]){
            if(!(d.second&(1<<to))){
                s.push({to,d.second+(1<<to)});
            }
        }
    }
    cout<<cnt;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
long long n;
const int N=20;
long long a[N];
int main()
{
	scanf("%lld",&n);
	int num=0;
	while(n){
		num++;
		a[num]=n%10;
		n/=10;
	}
	long long sum=0;
    for(int i=num;i>=1;i--){
		if(i==1)
			sum+=a[i];
		else if(a[i-1]==9){
			sum+=a[i];
		}
		else if(i!=1){
			sum+=a[i]-1;
            sum+=9*(i-1);
            break;
		}
    }
    printf("%lld\n",sum);
}


Measured memory_bytes: 128
//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		String S = sc.next();
		char s[] = new char[S.length()];
		
		for(int i=0;i<S.length();i++) {
			s = S.toCharArray();
			//System.out.println(s[i]);
		}
		
		
		if(S.length()<=K) {
			System.out.println(S);
		}
		if(S.length()>K){
			for(int j=0;j<K;j++) {
				{
					System.out.print(s[j]);
					//System.out.print("...");
				}
			}System.out.print("...");
		}
		
	}
	
}

Measured memory_bytes: 35840