akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int H, W, N;
    cin >> H >> W >> N;
    map<P, int> mp;
    for(int i = 0; i < N; ++i){
        int x, y;
        cin >> x >> y;
        for(int j = max(1, x - 2); j <= x; ++j){
            if(j + 2 > H)   break;
            for(int k = max(1, y - 2); k <= y; ++k){
                if(k + 2 > W)   break;
                ++mp[P(j, k)];
            }
        }
    }
    vector<ll> ans(10, 0);
    for(auto it : mp)   ++ans[it.second];
    ans[0] = (ll)(H - 2) * (W - 2) - (int)mp.size();
    for(int i = 0; i < 10; ++i) cout << ans[i] << '\n';
}

Measured memory_bytes: 59840
N, A, B, C, D = map(int, input().split())
road = input()

def check_cont_rock(s, e):
  use_road = road[s:e]
  return "##" in use_road

def check_cont_road(s, e):
  use_road = road[s:e]
  return "..." in use_road

if D > C:
  if check_cont_rock(A-1, D-1):
    print("No")
  else:
    print("Yes")
else:
  if check_cont_rock(A-1, C-1):
    print("No")
  else:
    if check_cont_road(B-2, D+1):
      print("Yes")
    else:
      print("No")

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

int main() {
  int N,M;
  cin >> N >> M;
  int k=0;
  if(N==0||N==1)
    k=k;
  else
    k=k+N*(N-1)/2;
  if(M==0||M==1)
    k=k;
  else
    k=k+M*(M-1)/2;
  
  cout << k <<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a, bool g){
	if(g){
		if(a[index]<key){
			return true;
		}
	}
	else{
		if(a[index]>key){
			return true;
		}
	}
	return false;
}

ll bin_search(ll key, vector<ll> &a, bool g){
	
	ll l=-1;
	ll r=a.size();

	if(g){
		l=a.size();
		r=-1;
	}

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a, g)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

int main(){

	ll a,b;
	cin>>a>>b;

	if(b%a==0){
		cout<<a+b<<endl;
	}
	else{
		cout<<b-a<<endl;
	}
	
    return 0;
}


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

using namespace std;
const int maxn = 1e5+10;

int n, d, x;
int niz[maxn];
int main() {
    scanf("%d%d%d", &n, &d, &x);
    for (int i = 0; i < n; i++)
        scanf("%d", niz+i);

    for (int i = 0; i < n; i++)
        x += 1 + (d - 1) / niz[i];

    printf("%d", x);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;
int main() {
	string str;
	cin >> str;
	int n = str.length();
	string r_str;
	for(int i = 0; i < n; i++) {
		r_str += str.at(n - i - 1);
	}
	cout << r_str << endl;
	return 0;
}

Measured memory_bytes: 1176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ab = br.readLine().split(" ");
        int a = Integer.parseInt(ab[0]);
        int b = Integer.parseInt(ab[1]);
        System.out.println(problem144a(a, b));
    }

    private static int problem144a(int a, int b) {
        return (isValid(a) && isValid(b)) ? (a * b) : -1;
    }

    private static boolean isValid(int n) {
        return (1 <= n) && (n <= 9);
    }
}

Measured memory_bytes: 23124
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
a=sorted(h)
ans=a[k-1]-a[0]
for i in range(1,n-k+1):
    if a[k+i-1]-a[i]<ans:
        ans=a[k+i-1]-a[i]
print(ans)

Measured memory_bytes: 51268
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 , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { let mut $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { let $ var = $ iter . next ( ) . unwrap ( ) . parse ::< usize > ( ) . unwrap ( ) ; 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 > ( ) . unwrap ( ) } ; }
use std::cmp::min;
fn main() {
    input! { n, cap, wv: [(usize, usize); n] };
    const V: usize = 1_000_00;
    let mut dp = vec![std::usize::MAX; V + 1];
    dp[0] = 0;
    for &(w, v) in &wv {
        for vi in (0..(V + 1)).rev() {
            if dp[vi] == std::usize::MAX {
                continue;
            }
            if vi + v <= V {
                dp[vi + v] = min(dp[vi + v], dp[vi] + w);
            }
        }
    }
    println!(
        "{}",
        dp.iter()
            .enumerate()
            .filter_map(|(v, &w)| if w <= cap { Some(v) } else { None })
            .max()
            .unwrap()
    );
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int X;
    cin >> X;
    if (X == 7 || X == 5 || X == 3) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import numpy as np
import sys

input = sys.stdin.readline

n, k = [int(x) for x in input().split()]
A = np.array([int(a) for a in input().split()], dtype="int64")

A = np.sort(A)

A_pos = A[A > 0]
A_neg = A[A < 0]
A_zero = A[A == 0]

# 積がc以下となる組み合わせの数を求める
def n_comb_lt(c):
    n_comb = 0
    # A[i] > 0であるA[i]について
    target = c // A_pos  # target以下の値がA[i]の相方
    n_comb += np.searchsorted(A, target, side="right").sum()

    # A[i] == 0であるA[i]について
    n_comb += n * len(A_zero) if c >= 0 else 0

    # A[i] < 0であるA[i]について
    target = -(-c // A_neg)
    n_comb += (n - np.searchsorted(A, target, side="left")).sum()

    # 組み合わせのうち、A[i]*A[i]となっているものを引いて、2で割る
    n_comb -= A[A * A <= c].size
    n_comb //= 2

    return n_comb

ok = -10 ** 18 - 1
ng = 10 ** 18 + 1

# k番目の積は、積がm未満となる組み合わせがk個未満となる最大のm
# ←→積が(m-1)以下となる組み合わせがk個未満となる最大のm
while ng - ok > 1:
    mid = (ng + ok) // 2
    if n_comb_lt(mid - 1) < k:
        ok = mid
    else:
        ng = mid

print(ok)

Measured memory_bytes: 32304
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h,m,s,a;
    cin >> a ;
    
    h = a / 3600;
    m = (a % 3600) / 60;
    s = ((a % 3600) % 60);
    
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define PI 3.141592653589
using namespace std;
using ll = long long;

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int r, d, x;
  cin >> r >> d >> x;

  ll x_ans;
  for(int i=0; i<10; ++i){
    if(i==0){
      x_ans = r * x - d;
      cout << x_ans << endl;
    }
    else{
      x_ans = r * x_ans - d;
      cout << x_ans << endl;
    }
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  string s, key = "keyence";
  cin >> s;

  int n = s.size(), i = 0, now = 0;

  while (s[i] == key[now]) {
    if (now == 6) {
      cout << "YES" << endl;
      return 0;
    } else {
      i++;
      now++;
    }
  }

  if (s.substr(n - 7 + i) == key.substr(now))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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 = sc.nextInt();
		int d = sc.nextInt();
		int k = sc.nextInt();
		int time = (c - a) * 60 + (d - b);
		if(time < k)
			System.out.println(0);
		else
			System.out.println(time - k);
	}
}

Measured memory_bytes: 35776
n,a = map(int,raw_input().split())

arr = map(int,raw_input().split())
arry = []

for i in range(n):
	arry.append(arr[i]-a)


dp = [[0 for i in range((n)*50*2)] for j in range(n+1)]
dp[0][n*50] = 1

for i in range(n):
	for j in range(n*50*2):
		if 0 <= j-arry[i] and j-arry[i] < n*50*2 :
			dp[i+1][j] = dp[i][j]+dp[i][j-arry[i]]
		else :
			dp[i+1][j] = dp[i][j]

print dp[n][n*50]-1

Measured memory_bytes: 5380
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
    string str;
    while(cin >> str){
        if(str[0] == 'a' || str[0] == 'e' ||str[0] == 'i' ||str[0] == 'o'||str[0] == 'u'){
            cout << "vowel" << endl;
        }else cout << "consonant" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define ls rt<<1
#define rs rt<<1|1
#define pb push_back
#define inf 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false)
typedef long long ll;
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 1e5+5;
const ll MOD = 1e9+7;
const int N = 1e5;

int main()
{
    ll fib[45] = {1, 1};
    int n;
    cin >> n;
    rep(i, 2, n){
        fib[i] = fib[i-1] + fib[i-2];
    }
    cout << fib[n] << endl;

    return 0;
}



Measured memory_bytes: 3084
X = input()
c = 0
d = -1
for i in range(len(X)):
  if X[i] == 'S':
    c += 1
    if c == 1:
      d = 0
  if d >= 0 and X[i] == 'T':
    c -= 1
    if c == 0:
      d = -1
print(c * 2)

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

int main() {
    int n;
    cin >> n;
    char before_last;
    bool ok = true;
    set<string> used;

    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        if (i != 0 && (before_last != s[0]) || used.count(s)) {
            ok = false;
            break;
        }
        before_last = *(s.end() - 1);
        used.insert(s);
    }
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
a.append(0)
d = 0
for j in range(N+1):
    d += abs(a[j+1] - a[j])
# print(d)

for i in range(1,N+1):
    d_pre = a[i] - a[i-1]
    d_nxt = a[i+1] - a[i]
    # print(d_pre,d_nxt)

    if d_pre * d_nxt>=0:
        out = d
    else:
        out = d - 2 * min(abs(d_nxt), abs(d_pre))
    print(out)

Measured memory_bytes: 14048
using System;

namespace management
{
    class Program
    {
        static void Main(string[] args)
        {
            var workers = int.Parse(Console.ReadLine());

            var member = new int[workers - 1];

            var bossInput = Console.ReadLine().Split(' ');
            for (int b = 1; b < workers; b++)
            {
                var boss = int.Parse(bossInput[b - 1]);
                member[boss - 1]++;
            }

            for (int m = 0; m < workers - 1; m++) Console.WriteLine(member[m]);
            Console.WriteLine(0);
        }
    }
}


Measured memory_bytes: 42156
n = gets.chomp.to_i
#a,b = gets.chomp.split().map(&:to_i)
c,s,f = (n-1).times.map{gets.split.map(&:to_i)}.transpose

(n-1).times do |i|
  current = 0
  i.upto(n-2).each do |j|
    if current < s[j]
      current = s[j] + c[j]
    else
      now = (current - s[j]) % f[j]
      if now == 0
        current += c[j]
      else
        current += c[j] + f[j] - now
      end
    end
  end
  puts current
end

puts 0

Measured memory_bytes: 1788
#include <stdio.h>
#include <math.h>
int main( void ){
	int t = 90, d, r;
	double x, y, a;
	x = y = 0.0;
	a = asin(1.) / 90.;
	for(; scanf("%d,%d",&r,&d),r|d;){
		x += r * cos( t * a );
		y += r * sin( t * a );
		t -= d;
	}
	return!printf("%d\n%d\n",t=x,d=y);
}

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

//int _; 

int x;

int main()
{
	//for(scanf("%d",&_);_;_--)
	cin >> x;
	for(int i=0;i<1000;i++)
		for(int j=0;j<1000;j++)
		{
			for(int k=0;k<3;k++)
			{
				if(k == 1)
					i=-i;
				if(k == 2)
					j=-j;
				if(i*i*i*i*i-j*j*j*j*j == x)
				{
					cout << i << ' ' << j << endl;
					return 0;
				}
				i=abs(i);
				j=abs(j);
			}
		} 	
	return 0;
}

Measured memory_bytes: 3640
import numpy as np
import sys

input = sys.stdin.readline


x = []
for _ in range(5):
    x.append(int(input()))


min_x = 9
flag = False
cnt = 0

y = []

see = False
for a in x:
    if a%10 != 0:
        y.append((a//10)*10+10)
        min_x = min(a%10,min_x)
        see = True
    else:
        y.append(a)

if see:print(sum(y)-(10-min_x))
else:print(sum(y))

Measured memory_bytes: 17900
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;
#define debug2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define debuga(g,h,w) rep(i,0,h) { rep(j,0,w) cout << g[i][j] << " "; cout << endl;}
#define debugv(v) for(auto&& x : v){cout << x << " ";} cout << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
typedef pair<ll, ll> Pll; 

int g[101010];

int calc(int h, int m, int s) 
{
	return h*60*60 + m*60 + s;
}

int main()
{
	int n;
	while (cin >> n && n != 0) {
		memset(g,0,sizeof(g));
		rep(i,0,n) {
			Vi a(3);
			char b, c;
			rep(j,0,3) {
				cin >> b >> c;
				b=='0' ? a[j] = (int)(c-'0') : a[j] = (int)(b-'0')*10 + (int)(c-'0');
				if (j != 2) cin >> b;
			}
			g[calc(a[0], a[1], a[2])]++;
			rep(j,0,3) {
				cin >> b >> c;
				b=='0' ? a[j] = (int)(c-'0') : a[j] = (int)(b-'0')*10 + (int)(c-'0');
				if (j != 2) cin >> b;
			}
			g[calc(a[0], a[1], a[2])]--;
		}
		int ans = 0;
		rep(i,1,101010) {
			g[i] = g[i] + g[i-1];
			ans = max(ans, g[i]);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3476
#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>
#include <boost/any.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 output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<"\n";}while(0)
#define output2(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);}
template<typename T=lint>T in(){
    T x;
    cin>>x;
    return x;
}
template<typename T=lint>initializer_list<T> in(lint n){
    vector<T> x(n);
    rep(i,n)cin>>x[i];
    return x;
}
int main(){
    string s;
    cin>>s;
    mat dp (s.size(),vec(2,0));
    if(s.size()==1){
        cout<<1;
        return 0;
    }
    dp[0][0]=1;
    dp[0][1]=0;
    if(s[0]==s[1])dp[1][0]=0;
    else dp[1][0]=2;
    dp[1][1]=1;
    repi(i,2,s.size()){
        if(s[i]==s[i-1])dp[i][0]=dp[i-1][1]+1;
        else dp[i][0]=max(dp[i-1][0],dp[i-1][1])+1;
        dp[i][1]=dp[i-2][0]+1;
        if(i>2&&(s[i-3]!=s[i-1]||s[i-2]!=s[i]))dp[i][1]=max(dp[i][1],dp[i-2][1]+1);
    }
    cout<<max(dp[s.size()-1][0],dp[s.size()-1][1]);
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i=0; i<n; i++) {
    cin >> p[i];
  }
  
  vector<int> sub(3);
  int ans = 0;  
  for (int i=1; i<n-1; i++) {
    if (min(p[i-1], p[i+1]) < p[i] && p[i] < max(p[i-1], p[i+1])) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    A = [list(map(int, input().split())) for i in range(2)]

    cntmax = 0
    for i in range(n):
        cnt = 0
        for a in range(i+1):
            cnt += A[0][a]
        for b in range(i, n):
            cnt += A[1][b]
        if cntmax < cnt:
            cntmax = cnt

    print(cntmax)


resolve()

Measured memory_bytes: 38640
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REP1(i,n) for(int i=1; i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
typedef long long ll;
using namespace std;

int main() {
  int N; cin>>N;
  if(N<105) cout<<0<<endl;
  else if(N<135) cout<<1<<endl;
  else if(N<165) cout<<2<<endl;
  else if(N<189) cout<<3<<endl;
  else if(N<195) cout<<4<<endl;
  else cout<<5<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int dp[3114][3514], ct[3100];
signed main(){
	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	vector< pair<int,int> > p;
	int cur = -1;
	for(int i=0;i<m;i++){
		int xx,yy;
		cin>>xx>>yy;
		if( i > 0 && p.back().first == xx ){
			if( p.back().second < yy ){
				p.pop_back();
			}
		}
		if( cur < yy ){
			p.pb(mp(xx,yy));
			cur = yy;
		}
	}
	vector<int> lefs;
	for(int i=0;i<p.size();i++){ lefs.pb(p[i].first); }
	for(int i=1;i<=n;i++){
		if( s[i-1] == '1') ct[i] = ct[i-1]+1;
		else ct[i] = ct[i-1];
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		int idx = upper_bound(lefs.begin(),lefs.end(),i)-lefs.begin();
		if( idx == 0 || p[idx-1].second < i){
			dp[i][ct[i]] += dp[i-1][ct[i-1]];
			dp[i][ct[i]] %= inf;
		}
		else{
			int rig = p[idx-1].second;
			for(int j=0;j<=n;j++){
				if( ct[rig] >= j+1 ){
					dp[i][j+1] += dp[i-1][j];
					dp[i][j+1] %= inf;
				}
				if( rig - ct[rig] >= i-j ){
					dp[i][j] += dp[i-1][j];
					dp[i][j] %= inf;
				}
			}
		}
	}
	cout<<dp[n][ct[n]]<<endl;
	return 0;
}

Measured memory_bytes: 84224
N, K = gets.split.map(&:to_i)
P = gets.split.map(&:to_i)

def Next _N, _P, _O1, _I, o
	(_N-1).downto(0){|i|
		j = [_I[i]+1, _N].min
		j = _O1[j] while j < _N and _P[j] <= _P[i]
		o[i] = j
	}
end

def Gen _N, _P
	io = (0..._N).to_a # 0
	Next(_N, _P, io, io, io)
	o1 = io.dup # 1
	return Enumerator.new{|y|
		y << o1.dup # 1
		loop {
			Next(_N, _P, o1, io, io)
			y << io.dup # 2, 3, 4,...
		}
	}
end

RL = Gen(N, P.map{|_| -_ }).next
LU = Gen(N, P.reverse).next.map!{|i| N-1-i }.reverse!

UP = [1] * N
(N-2).downto(0){|i|
	UP[i] = P[i] < P[i+1] ? UP[i+1]+1 : 1
}
IsPM = lambda{|i|
	return K <= UP[i]
}

pm, n = IsPM[0] ? [1, 0] : [0, 1]
(N-K).times{|i|
#p({:i=>i, :IsPM=>IsPM[i+1], :RU=>RU[i], :LU=>LU[i+K]})
	if IsPM[i+1]
		pm += 1
	elsif RL[i] < i+K or i < LU[i+K]
		n += 1
	end
}

p n+[pm,1].min


Measured memory_bytes: 30132
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

x=list(map(int,input().split()))
for i in range(5):
    if x[i]==0:
        print(i+1)

Measured memory_bytes: 68112
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
    int a,b;cin>>a>>b;
    if(abs(a)<abs(b)){
        cout<<abs(b)-abs(a)+(a<0?1:0)+(b<0?1:0)<<endl;
    }else if(abs(a)==abs(b)){
        cout<<1<<endl;
    }else{
        cout<<abs(a)-abs(b)+(a>0?1:0)+(b>0?1:0)<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;

void chmin(T)(ref T a, T b) {
	if (b < a) {
		a = b;
	}
}

void main() {
	enum Inf = long.max / 2;

	long n, capacity;
	readf(" %s %s", &n, &capacity);

	auto weights = new long[n];
	auto values = new long[n];
	long sumValue = 0;

	foreach (i;0..n) {
		readf(" %s %s", &weights[i], &values[i]);
		sumValue += values[i];
	}

	auto dp = new long[sumValue + 1];
	dp[1..$] = Inf;

	foreach (i;0..n) {
		foreach_reverse (v;0..sumValue + 1) {
			if (dp[v] == Inf) {
				continue;
			}

			if (v + values[i] < dp.length) {
				chmin(dp[v + values[i]], dp[v] + weights[i]);
			}
		}
	}

	foreach_reverse (size_t i, e;dp) {
		if (e <= capacity) {
			writeln(i);
			break;
		}
	}
}


Measured memory_bytes: 2812
#include<iostream>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)
#define ll long long

int n;
ll a[100000];
ll c[2];
ll csum;

int main(){
    cin >> n;
    REP(i, n){
        cin >> a[i];
    }

    c[0] = 0; c[1] = 0;
    REP(l, 2){
        csum = 0;
        ll sign;
        if(l==0){sign = 1;} else {sign = -1;}

        csum += a[0];
        if(csum == 0){
            c[l] += 1;
            csum += sign;
        } else if(csum * sign < 0){
            c[l] = sign * (-csum+sign);
            csum += -csum + sign;
        }

        for(int i=1; i<n; i++){
            ll bsum = csum;
            bsum += a[i];

            if (csum*bsum>=0){
                if(csum>0){
                    c[l] += (bsum+1);
                    bsum -= (bsum+1);
                } else {
                    c[l] += (-bsum+1);
                    bsum += (-bsum+1);
                }
            }
            csum = bsum;
        }
    }
    cout << min(c[0], c[1]) << endl;
}


Measured memory_bytes: 1024
from math import ceil
n, h = map(int, raw_input().split())
s = []
for x in xrange(n):
    ta, tb = map(int, raw_input().split())
    s.extend([(ta, 1), (tb, 0)])
s.sort(key = lambda _: _[0], reverse = True)
att = 0
for i, _ in enumerate(s):
    if att >= h or _[1]:
        cnt = i
        break
    att += _[0]
print cnt + int(ceil(float(h - att) / max([_[0] for _ in s if _[1]]))) if att < h else cnt


Measured memory_bytes: 30392
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());

        // 主処理
        long rt = (long) Math.sqrt(n);
        while (n % rt != 0) {
            rt--;
        }
        long result = rt + n / rt - 2;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23764
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = sc.next()
    println(problem145b(n, s))
}

fun problem145b(n: Int, s: String): String {
    if (s.length % 2 != 0) return "No"
    return if (s.take(n / 2) == s.takeLast(n / 2)) "Yes" else "No"
}

Measured memory_bytes: 29600
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

signed main(){
	int k;
	string s;
	cin>>k>>s;
	if(s.size()<=k)cout<<s<<endl;
	else{
		rep(i,k)cout<<s[i];
		cout<<"..."<<endl;
	}
	

}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int r = sc.nextInt();
		int n = sc.nextInt();
		/*int hako[]=new int[n];
		for(int i=0;i<n;i++) {
			hako[i]=sc.nextInt();
		}*/
		int ans=0;
		for(int i=l;i<=r;i++) {
			if(i%n==0) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35464
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll n, k;
vector<pair<ll,ll>> vec;
int main(void){
    cin >> n >> k;
    vec.resize(n);
    rep(i, n) cin >> vec[i].first >> vec[i].second;
    ll ans = 0;
    for(ll i = 0; i < 32; i++){
        ll bit = 0;
        for(ll j = 0; j < 32; j++){
            if(j < i){
                bit |= (1LL << j);
            } else if(j > i){
                bit |= ((1LL << j) & k);
            }
        }
        if(bit > k) continue;
        ll tmp = 0;
        rep(j, n){
            if((vec[j].first | bit) == bit){
                tmp += vec[j].second;
            }
        }
        ans = max(ans, tmp);
    }

    cout << ans << endl;

}


Measured memory_bytes: 4796
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  string S; cin >> S;
  int cnt1 = 0, cnt2 = 0;
  int d1 = 0, d2 = 1;
  for (int i = 0; i < S.size(); ++i) {
    int v = S[i] - '0';
    if (d1 != v) ++cnt1;
    if (d2 != v) ++cnt2;
    swap(d1, d2);
  }
  cout << min(cnt1, cnt2) << endl;
}


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

#include <string>
#include <vector>
int main(){
    int n,m; cin >> n >> m;
    vector<int> h(n);
    vector<vector<int>> tenbou(n,vector<int>());
    for(int i=0; i<n; i++) cin >> h[i];
    int ina,inb;
    for(int i=0; i<m; i++){
        cin >> ina >> inb;
        tenbou[ina-1].push_back(inb-1);
        tenbou[inb-1].push_back(ina-1);
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        int flag = 1;
        for(int j=0; j<tenbou[i].size(); j++){
            if(h[tenbou[i][j]]>=h[i]){
                flag=0;
                break;
            }
        }
        if(flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8728
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

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

    int a = l, b = l + n-1;
    int sum = n * (a+b) / 2;

    int d;
    if (a < 0 && b > 0) d = 0;
    else {
        if (abs(a) < abs(b)) d = a;
        else d = b;
    }

    sum -= d;

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
import heapq as hq
from collections import deque
from copy import deepcopy
N, K = map(int, input().split())
Sushi = [None for _ in range(N)]
TotalType = set()
for _ in range(N):
    t, d = map(int, input().split())
    Sushi[_] = [d, t]
Sushi.sort(reverse = True)

ChosenType = set()
Double = []
hq.heapify(Double)
BasePoint = 0
for goodsushi in Sushi[:K]:
    BasePoint += goodsushi[0]
    if goodsushi[1] in ChosenType:
        hq.heappush(Double, goodsushi)
    else: ChosenType |= {goodsushi[1]}

NotChosen = deque(deepcopy(Sushi[K:]))
MaxHappiness = BasePoint + len(ChosenType)**2
while Double and NotChosen:
    TrushPoint, TrushType = hq.heappop(Double)
    BasePoint -= TrushPoint
    while NotChosen:
        addPoint, addType = NotChosen.popleft()
        if addType not in ChosenType:
            BasePoint += addPoint
            ChosenType |= {addType}
            break
    MaxHappiness = max(MaxHappiness, BasePoint + len(ChosenType)**2)
print(MaxHappiness)

Measured memory_bytes: 44564
import sys

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

# 仮の高さを計算する
for x, y, h in XYH:
    if h != 0:
        px, py, ph = x, y, h
        break

for cx in range(0, 101):
    for cy in range(0, 101):
        # 仮の高さ
        H = ph + abs(cx - px) + abs(cy - py)

        for x, y, h in XYH:
            if max(H - abs(x - cx) - abs(y - cy), 0) != h:
                break
        else:
            print(cx, cy, H)
            sys.exit()


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

int main(){
  int N,K;
  cin>>N>>K;
  int L[N];
  for (int i=0;i<N;i++){
    cin>>L[i];
  }
  
  sort(L,L+N);
  int sum=0;
  for (int i=0;i<K;i++){
    sum=sum+L[N-1-i];
  }
  cout<<sum<<endl;
  return 0;
}

      

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  int i,n;
  cin >> s;
  if(s=="Sunny") s="Cloudy";
  else if(s=="Cloudy") s="Rainy";
  else s="Sunny";
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3628
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque as d

N, M = map(int, readline().split())
m = map(int, read().split())
AB = zip(m, m)
graph = [[] for _ in range(N + 1)]

for a, b in AB:
  graph[a].append(b)
  graph[b].append(a)

que = d([1])
ans = [0]*(N+1)
while que:
  x = d.popleft(que)
  for i in graph[x]:
    if i == 1 or ans[i] != 0:
        continue
    ans[i] = x
    que.append(i)

if 0 in ans[2:]:
    print('No')
    exit()
print('Yes')
print('\n'.join(map(str, ans[2:])))


Measured memory_bytes: 55792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define int ll
#define FOR(i,n,k) for(int i=n;i<k;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N = 1e5 + 5;
int dp[N];

int32_t main()
{
    IOS;
    memset(dp,9999,sizeof(dp));
    int n,k;
    cin>>n>>k;
    int a[n+1];
    FOR(i,1,n+1) cin>>a[i];
    dp[1] = 0;
    FOR(i,2,n+1)
    {
        FOR(j,1,k+1)
        {
            if(i-j > 0)
            {
                dp[i] = min(dp[i-j] + abs(a[i] - a[i-j]),dp[i]);
            }
        }
    }
    cout<<dp[n]<<"\n";
    return 0;
}

Measured memory_bytes: 1792
n,q=map(int,input().split())
s=input()

b=[0]*n
for i in range(1,n):
 if s[i-1]+s[i]=='AC':
  b[i]=b[i-1]+1
 else:
  b[i]=b[i-1]

for i in range(q):
 l,r=map(int,input().split())
 print(b[r-1]-b[l-1])

Measured memory_bytes: 6188
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+7;

#define ll long long
ll a[N];
multiset<ll>st;
int cnt(multiset<ll> &st,int p){
    int ans=0;
    for(auto x:st){
        if(x&(1ll<<p))ans++;
    }
    return ans;
}
multiset<ll> f(multiset<ll>st,int p){
    multiset<ll>ans;
    for(auto x:st){
        if(x&(1ll<<p)){
            ans.insert(x);
            //cout<<x<<' ';
        }
    }
    //cout<<endl;
    return ans;
}
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(int i=0;i<n;i++){
        ll cnt=0;
        for(int j=i;j<n;j++){
            cnt+=a[j];
            st.insert(cnt);
        }
    }
    /*
    for(auto x:st)
        cout<<x<<endl;*/

    ll ans=0;
    for(int i=45;i>=0;i--){
        //cout<<cnt(st,i)<<endl;
        if(cnt(st,i)>=k){
            ans+=(1ll<<i);
            st=f(st,i);
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 52860
N, A, B = gets.chomp.split(' ').map(&:to_i)

if N <= A + B
  if N >= A
    puts A
  else
    puts N
  end
  exit
end

m = (N / (A + B).to_f).floor
o = N - m * (A + B)

puts m * A + [A, o].min


Measured memory_bytes: 3836
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            BigInteger a = new BigInteger(sc.next());
            BigInteger b = new BigInteger(sc.next());
            BigInteger k = new BigInteger(sc.next());

            if (a.compareTo(k) > 0) {
                a = a.subtract(k);
            } else {
                b = b.subtract(k.subtract(a));
                a = new BigInteger("0");
                if (b.compareTo(new BigInteger("0")) < 0) {
                    b = a;
                }
            }
            System.out.println(a + " " + b);
        }
    }

}


Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

ll gcd(ll a, ll b) {
    while (b) {
        ll c = a % b;
        a = b;
        b = c;
    }
    return a;
}

ll po(ll a, ll b) {
    ll c = 1;
    while (b) {
        if (b % 2) c = c * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return c;
}

ll f[2000006], g[2000006];

void comb() {
    f[0] = 1;
    for (int i = 1; i <= 2000000; i++) f[i] = f[i - 1] * i % mod;
    g[2000000] = 407182070;
    for (int i = 1999999; i >= 0; i--) g[i] = g[i + 1] * (i + 1) % mod;
}

int p[200005];

int root(int x) {return p[x] < 0 ? x : p[x] = root(p[x]);}

void mer(int x, int y) {
    if ((x = root(x)) == (y = root(y))) return;
    if (p[x] > p[y]) swap(x, y);
    p[x] += p[y];
    p[y] = x;
}

int main() {
    ios::sync_with_stdio(false);
    int n, a = mod + mod, b = -mod - mod, c = mod + mod, d = -mod - mod, x, y;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        a = min(a, x + y);
        b = max(b, x + y);
        c = min(c, x - y);
        d = max(d, x - y);
    }
    cout << max(b - a, d - c);
}


Measured memory_bytes: 3644
n = int(input())
a = list(map(int,input().split()))
set_a = set(a)
a.sort()
k = 0
p = 0
ans = 0
for a_ in set_a:
    s = a[k]
    while True:
        if k<len(a) and a[k]==s:
            k+=1
            p+=1
        else:
            if p>=s:
                ans+=p-s
            else:
                ans+=p
            p=0
            break
print(ans)


Measured memory_bytes: 14268
n = int(input())

ans, tailA, headB, overlap = 0, 0, 0, 0
for _ in range(n):
    s = input()
    ans += s.count('AB')
    tailA += 1 * (s[-1] == 'A')
    headB += 1 * (s[0] == 'B')
    overlap += 1 * (s[-1] == 'A' and s[0] == 'B')

if overlap > 0:
    tailA -= overlap
    headB -= overlap
    ans += overlap - 1
    if tailA > 0:
        ans += 1
        tailA -= 1
    if headB > 0:
        ans += 1
        headB -= 1

ans += min(tailA, headB)
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;

int main(){

  string str;

  while(getline(cin, str)){
    if(str[0]=='.') break;

    stack<char> s;
    bool f=true;

    for(int i=0;i<str.size();i++){
      if(str[i]=='('||str[i]=='[') s.push(str[i]);
      if(str[i]==')'){
        if(s.empty()){
          f=false;
          break;
        }
        if(s.top()=='(') s.pop();
        else{
          f=false;
          break;
        }
      }else if(str[i]==']'){
        if(s.empty()){
          f=false;
          break;
        }
        if(s.top()=='[') s.pop();
        else{
          f=false;
          break;
        }
      }
    }
    if(f&&s.empty()) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }

  return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, N;
  cin >> H >> N;
  int Asum=0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    Asum += A.at(i);
  }
  if (Asum >= H) {
    cout << "Yes" << endl;
  }
  else {
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 640
import math
x=int(input())
ok=0
ans=0
if x==2:
    print(x)
else:
    if x%2==0: #偶数なら一個上の奇数から
        x+=1
    while ok==0:
        now=x
        sosu=0 #素数だったら、０のまま
        for i in range(2,int(math.sqrt(now))+1):
            if i%2==0:
                continue
            else:
                if now%i==0: #素数じゃない
                    sosu=1
                    break
        x+=2
        if sosu==0:
            ok=1
            ans=now
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
// #define DEBUG

using namespace std;

const int N = 1<<12;
const int M = 1e3+7;

int n, m, res = -1;
int a[M], b[M], c[M];
int dp[M][N];

int main()
{
    cin >> n >> m;
    memset(dp, -1, sizeof dp);
    dp[0][0] = 0;
    for (int i = 1; i <= m; ++i) {
        cin >> a[i] >> b[i];
        for (int j = 0, tmp; j < b[i]; ++j) {
            cin >> tmp;
            --tmp;
            c[i] += (1<<tmp);
        }
#ifdef DEBUG
        cout << i << " " << c[i] << endl;
#endif
        for (int j = 0; j < (1<<n); ++j) dp[i][j] = dp[i-1][j];
        for (int j = 0; j < (1<<n); ++j) {
            if (dp[i-1][j] == -1) continue;
            if (dp[i][j|c[i]] == -1) dp[i][j|c[i]] = dp[i-1][j]+a[i];
            else dp[i][j|c[i]] = min(dp[i][j|c[i]], dp[i-1][j]+a[i]);
        }
#ifdef DEBUG
        for (int j = 0; j < (1<<n); ++j) cout << j << " " << dp[i][j] << endl;
#endif
        if (dp[i][(1<<n)-1] == -1) continue;
        if (res == -1) res = dp[i][(1<<n)-1];
        else res = min(res, dp[i][(1<<n)-1]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5, mod = 1e9 + 7;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int a, b;
    cin >> a >> b;
    int sum = 3 * a + b;
    cout << sum / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int cnt = 0;
	for (int i = A; i <= B; i++) {
		string s = to_string(i);
		if ((s.at(0) == s.at(4)) && (s.at(1) == s.at(3))) cnt++;
	}

	cout << cnt << endl;
}

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

int main(){
  string n; cin >> n;
  string s=n.substr(0,1);
  bool a = true;
  for(int64_t i=1;i<n.size();i++){
    a = a&&n[i]=='9';
  }
  if((int)n.size()==1){
    cout << n << endl;
    return 0;
  }

  if(a){
    cout << 9*(n.size()-1)+stoi(s) << endl;
  }else{
    if(s=="1") cout << 9*(n.size()-1) << endl;
    else cout << 9*(n.size()-1)+stoi(s)-1;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<ll, bool> pt;

#define fi first
#define se second
#define lson ((p<<1))
#define rson ((p<<1)+1)
#define mid ((L+R)>>1)
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

li n, k, res, x;

int main() {
    fastIO;
    cin >> n >> k;
    for(li i = 0; i < n; i ++) {
        cin >> x;
        if(x >= k) res++;
    }
    cout << res;

}


Measured memory_bytes: 256
#include <stdio.h>

int S[100001];
int n, q;

int search(int key){
    int right = n;
    int left = 0;
    int mid;

    while(left + 1 < right){
        mid = (right + left) / 2;
        if(key < S[mid]) right = mid;
        else left = mid;

    }

    if(key == S[left]) return 1;
    else return 0;

}

int main() {
    int i;
    int t;
    int cnt = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &S[i]);
    }

    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &t);
        if(search(t)) cnt++;
    }

    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 988
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

using namespace std;

int main() {
 
   long long int K;
   long long int X;

   cin >> K >> X;
   if(K*500>=X){
      cout << "Yes" << endl;
   }else{
      cout << "No" << endl;
   }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    int n;
    cin>>n;
    int a[n],cnt=0;
    map<int,int>m;
    for(int i=0;i<n;i++){
        cin>>a[i],m[a[i]]++;
    }
    for(int i=0;i<n;i++){
        int flag=1;
        if(a[i]==1 && m[1]==1) {cnt++;continue;}
        for(int j=1;j<=sqrt(a[i]);j++){
            if(a[i]%j==0){
                if(m[j]) {flag=0;break;}
                if(a[i]/j!=a[i]&&m[a[i]/j]) {flag=0;break;}
                if(a[i]/j==a[i]&&m[a[i]/j]>1) {flag=0;break;}
            }
        }
        if(flag) cnt++;
    }
    cout<<cnt;
}


Measured memory_bytes: 33160
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
#include<vector>
using namespace std;
double s;
int a[1000005];
inline bool cmd(int a,int b)
{
	return a>b;
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i],s+=a[i];
	s=s/(m*4);
	sort(a+1,a+n+1,cmd);
	for(int i=1;i<=m;i++)
	{
		if(a[i]<s)
		{
			cout<<"No";return 0;
		}
	}
	cout<<"Yes";
}


Measured memory_bytes: 256
a,b,c = gets.chomp.split(" ").map(&:to_i) 

def digit_sum (n)
    sum = 0
    while n > 0 do
        sum += n % 10
        n /= 10
    end
    sum
end
total =0
(0..a).each do |n|
    if digit_sum(n) >=b && digit_sum(n) <=c
        total += n
    end
end
p total

Measured memory_bytes: 1788