akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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 (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



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

        rep(i, 0, K) {
                if (odd(A)) {
                        --A;
                }
                B += A/2;
                A /= 2;

                ++i;
                if (i >= K) break;

                if (odd(B)) {
                        --B;
                }
                A += B/2;
                B /= 2;
        }

        cout << A << ' ' << B << endl;
}


Measured memory_bytes: 3644
#include<stdio.h>
typedef long long ll;
int main()
{
	ll n,a,b;
	scanf("%lld %lld %lld",&n,&a,&b);
	ll ans=0;
	if(a>b)  ans=0;
	else if(n==1&&a!=b)  ans=0;
	else if(n==1&&a==b)  ans=1;
	else ans=(n-2)*(b-a)+1;
	printf("%lld\n",ans);
	return 0;
 } 

Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
	int n, m;
	cin>>n>>m;
	int sum = 0;
	int arr[m];
	for(int i = 0; i<m; i++)
		cin>>arr[i];
	for(int i = 0; i<m; i++)
	{
		sum+= arr[i];
	}
	int hang = (n-sum);
	if(sum > n)
	{
		cout<<"-1"<<endl;
	}
	else
	{
		cout<<hang<<endl;
	}

}

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

int main() {
	int n,m;
	cin>>n>>m;
	vector<P> p(m);//vectorのvector
	
	rep(i,m)cin>>p[i].first>>p[i].second;
	rep(x,1000){
		int keta=1;
		int nx=x/10;
		vector<int> d(1,x%10);//?
		
		while(nx){//nxが0にならない限り
			keta++;
			d.push_back(nx%10);
			nx/=10;
		}
		if(keta!=n)continue;
		bool ok=true;
		reverse(d.begin(),d.end());
		rep(i,m){
			if(d[p[i].first-1]!=p[i].second)ok=false;
		}
		if(ok){
			cout<<x<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

//vectorでCE




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


int main(){
  int N;
  cin >> N;
  
  vector <int> A(N);  
  rep(i,N) cin >> A.at(i);
  
  int even_number = 0;
  int odd_number = 0;
  bool able_or_not = true;
  
  rep(i,N){
    if(A.at(i)%2 == 0) even_number++;
  }
  odd_number = N - even_number;
  
  if(odd_number % 2 == 1){
    able_or_not = false;
  }else{
    able_or_not = true;
  }
  
  if(able_or_not == true){
    cout << "YES";
  }else{
    cout << "NO";
  }
  
  
}

Measured memory_bytes: 1148
#include<stdio.h>
int main(void){
  long long int N;
  scanf("%lld",&N);
  long long int sum=0;
  for(int i=1;i<N;i++){
    sum = sum + N/i;
    if(N % i == 0)
      sum--;
  }
  printf("%lld",sum);
  return 0;
}

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

int main(){
  char a, b, c;
  int rainy = 0;
  int streak = 0;
  
  cin >> a >> b >> c;
  if (a == 'R'){rainy++;}
 
  if (b == 'R'){rainy++;}
  else if (b == 'S') {
    if (rainy > streak){streak = rainy;}
    rainy = 0; 
  }
  
  if (c == 'R'){rainy++;}
  else if (c == 'S') {
    if (rainy > streak){streak = rainy;}
    rainy = 0;
  }
  
  if (rainy > streak){streak = rainy;}
  cout << streak;
 
  return 0;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <queue>
#include <stack>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
#include <set>
using namespace std;

char makeChr(char c, int p){
  const int len  = ('Z' - 'A' + 1);
  return 'A' + (int)(c - 'A' + p + len * 100) % len;
}

int main(){
  string s;
  while(cin >> s, s != "."){
    vector<char> ans;
    int p = 0;
    stack<int> st;
    REP(i,s.size()){
      if(s[i] == '+') p++;
      else if(s[i] == '-') p--;
      else if(s[i] == '[') st.push(ans.size());
      else if(s[i] == ']'){
        reverse(ans.begin() + st.top(), ans.end());
        st.pop();
      }else{
        if(s[i] == '?') ans.push_back('A');
        else ans.push_back(makeChr(s[i], p));
        p = 0;
      }
    }
    cout << string(ans.begin(), ans.end()) << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#define mod 1000000007
typedef long long lint;
int k,n=-1,cnt=13;
char c[15];
lint fact[2000010],inv[2000010];
int main(){
	while(true){
		*c=getchar_unlocked();
		if(*c=='\n')break;
		k*=10;
		k+=*c-'0';
	}
	while(getchar_unlocked()!=-1)n++;
	fact[0]=1;
	for(int i=1;i<=n+k;i++)fact[i]=fact[i-1]*i%mod;
	inv[n+k]=1;
	lint now=fact[n+k];
	int b=mod-2;
	while(b){
		if(b&1){
			inv[n+k]*=now;
			inv[n+k]%=mod;
		}
		b>>=1;
		now*=now;
		now%=mod;
	}
	for(int i=n+k-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
	lint ans=1;now=1;
	for(int i=1;i<=k;i++){
		now*=25;
		now%=mod;
		ans+=fact[n+k]*inv[n+k-i]%mod*inv[i]%mod*now;
		ans%=mod;
	}
	*(c+14)='\n';
	while(ans){
		*(c+cnt)=ans%10+'0';
		ans/=10;
		cnt--;
	}
	fwrite(c+cnt+1,1,14-cnt,stdout);
	return 0;
}

Measured memory_bytes: 32712
#include<bits/stdc++.h>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int n,k;
	cin >> n >> k;
	int a[n];
	for(int i=0;i<n;i++)	cin >> a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0;i<k;i++){
		ans+=a[i];
	}
	cout<<ans;


	return 0;
}

Measured memory_bytes: 3552
# https://atcoder.jp/contests/abc164/tasks/abc164_d

import sys
input = sys.stdin.readline


S = input().rstrip()

res = 0

T = [0]
x = 0
p = 1
L = len(S)
MOD = 2019
for i, s in zip(range(L),reversed(S)):
    """ 累積和 """
    x = (int(s)*p + x)%MOD
    p = p*10%MOD
    T.append(x)

reminder = [0]*2019
for i in range(L+1):
    reminder[T[i]%MOD] += 1

for c in reminder:
    res += c*(c-1)//2

print(res)

Measured memory_bytes: 82820
h, w = map(int, input().split())
s = [['.' for _ in range(w + 2)]]

for _ in range(h):
    s.append(['.'] + list(input()) + ['.'])

s.append(['.' for _ in range(w + 2)])

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == '.':
            count = 0
            for k in range(i - 1, i + 2):
                count += s[k][j - 1:j + 2].count('#')
                s[i][j] = count


for i in range(1, h + 1):
    print(''.join(map(str, s[i][1:w + 1])))

Measured memory_bytes: 3064
m, k = map(int, input().split())
if pow(2, m) <= k:
    print(-1)
elif not m == 1:
    ans = [k] * pow(2, m + 1)
    i = 0
    for j in range(pow(2, m) - 1):
        if i == k:
            i += 1
        ans[j] = i
        ans[pow(2, m + 1) - 2 - j] = i
        i += 1
    print(*ans)
else:
    if k == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)

Measured memory_bytes: 15184
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 2 * 105000;

int n, k;
int h[MAXN];
long long ans;

int main() { 

  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    scanf("%d", &h[i]);
  }
  sort(h, h + n);
  reverse(h, h + n);

  for (int i = 0; i < n; i++) {
    if (i + 1 <= k) {
      continue;
    } else {
      ans += h[i];
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
const double pi = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll sx, sy, tx, ty, N;
	cin >> sx >> sy >> tx >> ty >> N;
	if (sx > tx) {
		swap(sx, tx);
		swap(sy, ty);
	}
	vector<pii> v;
	REP(i, N) {
		int x, y;
		cin >> x >> y;
		if (x >= sx&&x <= tx&&y >= min(sy, ty) && y <= max(sy, ty))v.push_back({ x,y });
	}
	sort(ALL(v));

	int n = v.size();
	vi dp(n + 1, INF);
	if (sy < ty) {

		REP(i, n) {
			int c = lower_bound(ALL(dp), v[i].second) - dp.begin();
			dp[c] = v[i].second;
		}
	}
	else {
		REP(i, n) {
			int c = lower_bound(ALL(dp), -v[i].second) - dp.begin();
			dp[c] = -v[i].second;
		}
	}
	int k = lower_bound(ALL(dp), INF) - dp.begin();
	double ans;
	if (k == int(min(abs(ty - sy), abs(tx - sx))) + 1) {
		ans = 100 * (abs(tx - sx) + abs(sy - ty)) + 5 * (k + 1)*pi - k * 20;
	}
	else ans = 100 * (abs(tx - sx) + abs(sy - ty)) - k*(20 - 5 * pi);
	cout << fixed << setprecision(18) << ans << endl;
}


Measured memory_bytes: 2672
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<int> E(N + 2);
    E.push_back(0);
    rep(i, N) E[i + 1] = A[i];
    E.push_back(0);

    vector<int> diff(N + 1);
    rep (i, N) {
        int x = abs(E[i + 1] - E[i]) + abs(E[i + 2] - E[i + 1]);
        int y = abs(E[i + 2] - E[i]);
        diff[i + 1] =  y - x;
    }

    int base = 0;
    rep (i, N + 1) {
        base += abs(E[i + 1] - E[i]);
    }

    rep (i, N) {
        put(base + diff[i + 1]);
    }

    return 0;
}

Measured memory_bytes: 4568
n,x=map(int,input().split())

def f(n,x):
  if n==0:
    if x>0:return 1
    else:return 0
  if x<=(2**(n+2)-3-1)//2:
    return f(n-1,x-1)
  else:
    tmp=x-((2**(n+2)-3-1)//2+1)
    return 2**n-1+1+f(n-1,tmp)
  
print(f(n,x))


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner stdIn=new Scanner(System.in);
		String s=stdIn.next();
		long k=stdIn.nextLong();
		int S=0;
		int z=0;
		while(z<s.length()){
			S=Integer.valueOf(s.substring(z,z+1));
			if(S!=1)
				break;
			else
				if(z+1==k)
					break;
			z++;
		}
		System.out.println(S);
	}
}

Measured memory_bytes: 23764
N, M = map(int,input().split())
d = {}
for i in range(N):
    l = list(map(int, input().split()))
    for ak in l[1:]:
        if ak in d:
            d[ak] += 1
        else:
            d[ak] = 1

cnt = 0
for k in d.keys():
    if d[k] == N:
        cnt+=1

print(cnt)


Measured memory_bytes: 3060
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i,  r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define X real()
#define Y imag()
#define maxN 100005
#define oo 2000000007

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, cnt[maxN];
ll ans;

int main () {
    scanf("%d", &n);
    fto(i, 1, n) scanf("%d", &cnt[i]);

    fdto(i, n, 2) {
        if (cnt[i]%2 == 1 && cnt[i-1] > 0) {
            ++ans;
            --cnt[i];
            --cnt[i-1];
        }
    }

    fto(i, 1, n) ans += cnt[i]/2;

    cout << ans;

    return 0;
}


Measured memory_bytes: 640
program walk_on_multiplication_table
  implicit none
  integer(8) :: n, r
  read(*,*) n
  r = int(floor(sqrt(real(n,8)+0.5d0)),8)
  do while (mod(n,r) /= 0_8)
    r = r-1_8
  end do
  write(*,'(i0)') r+n/r-2_8
end program walk_on_multiplication_table

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
bool flag;
int n,lenls,ans;
int nmap[305][305];
int cass[305][305];
char map[305][305];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%s",&map[i]);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            for(int k=1;k<n;k++){
                if(map[((i-k+n)%n)][j]==map[i][((j-k+n)%n)])
                    ++cass[i][j];
                else break;
            }
    for(int a=0;a<n;a++)
        for(int b=0;b<n;b++){
            flag=true;
            for(int i=0;i<n;i++) if(cass[(a-b+i+n)%n][i]<i) flag=false;
            if(flag) ans++;
        }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
template<class T,class U>constexpr bool bit(const T n,const U k){return (n>>k)&1;}

//デバッグ
template<class T>
void Vout(vector<T> &V){
    cout<<"start"<<endl;
    const int sz=V.size();
    for(int i=0;i<sz;i++){
        cout<<i<<" "<<V[i]<<'\n';
    }
    cout<<"end"<<endl;
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


constexpr int MAX=1<<30;
constexpr ll INF=1LL<<62;
constexpr int MOD=1e9+7;

//__builtin_popcount(S);
//#define int ll
//vector<vector<int>> data(3, vector<int>(4));
//vector.resize(a,vector<int>(b,-1));
//vector<vector<vector<要素の型>>> 変数名(要素数1, vector<vector<要素の型>>(要素数2, vector<要素の型>(要素数3, 初期値)));



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

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

    int N,Ma,Mb;
    cin>>N>>Ma>>Mb;
    vector<vector<vector<int>>> dp(N+1, vector<vector<int>>(401, vector<int>(401, MAX)));
    
    dp[0][0][0]=0;
    vector<int> a(N,0),b(N,0),c(N);
    for(int i=0;i<N;i++) cin>>a[i]>>b[i]>>c[i];
    for(int i=0;i<N;i++){
        for(int j=0;j<400;j++){
            for(int k=0;k<400;k++){
                if(dp[i][j][k]==MAX) continue;
                chmin(dp[i+1][j][k],dp[i][j][k]);
                chmin(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
            }
        }
    }
    int ans=MAX;
    for(int i=1;Ma*i<=400 && Mb*i<=400;i++){
        chmin(ans,dp[N][Ma*i][Mb*i]);
    }
    if(ans==MAX) cout<<-1<<endl;
    else cout<<ans<<endl;
}

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


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

    int n, y;
    cin >> n >> y;
    y /= 1000;

    for (int i = 0; i <= n; ++i) {
        for (int j = 0, k; j <= n; ++j) {
            k = n - i - j;
            if (y == 10*i + 5*j + k && k >= 0) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1"<< endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, k;
    cin >> n >> k;

    if(2*k-1 > n) {
        cout << -1 << endl;
        return 0;
    }

    vector<ll> a, b, c;
    if(n%2) {
        ll l = (n+1)/2;
        for(ll i=k; i<=k+2*l-2; i+=2) a.push_back(i);
        for(ll i=k+3*l-2; i>=k+2*l-1; --i) b.push_back(i);
        for(ll i=k+1; i<=k+2*l-3; i+=2) a.push_back(i);
        for(ll i=k+4*l-3; i>=k+3*l-1; --i) b.push_back(i);
        FOR(i, k+2*n, k+3*n) c.push_back(i);
    } else {
        ll l = n/2;
        for(ll i=k; i<=k+2*(l-1); i+=2) a.push_back(i);
        for(ll i=k+3*l-1; i>=k+2*l; --i) b.push_back(i);
        for(ll i=k+1; i<=k+2*(l-1)+1; i+=2) a.push_back(i);
        for(ll i=k+4*l-1; i>=k+3*l; --i) b.push_back(i);
        FOR(i, k+2*n, k+3*n) c.push_back(i);
    }

    REP(i, n) cout << a[i] << " " << b[i] << " " << c[i] << endl;

    return 0;
}

Measured memory_bytes: 4720
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  double r;
  cin>>r;
  double ans = 2 * PI * r;
  cout<<fixed<<setprecision(5)<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

using pll = pair<ll, ll>;

ll solve(ll N, vector<ll> A, vector<ll> B) {
	vector<pll> v;
	REP(i, 3) if (A[i] < B[i]) v.emplace_back(A[i], B[i] - A[i]);
	
	vector<ll> dp(N + 1);
	REP(i, N) {
		chmax(dp[i + 1], dp[i]);
		REP(j, v.size()) {
			if (i + v[j].fi > N) continue;
			chmax(dp[i + v[j].fi], dp[i] + v[j].se);
		}
	}
	return N + dp[N];
}

int main() {
	ll N;
	vector<ll> A(3), B(3);
	cin >> N;
	REP(i, 3) cin >> A[i];
	REP(i, 3) cin >> B[i];
	
	ll ans = solve(N, A, B);
	ans = solve(ans, B, A);
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

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

	int N;
	cin >> N;
	vector<double> v(N);
	for(auto &i : v) cin >> i;

	vector<vector<double>> dp(N+1, vector<double>(N+1, 0));
	dp[0][0] = 1;

	for(int i=1; i<=N; i++){
		dp[i][0] = dp[i-1][0]*(1-v[i-1]);
		for(int j=1; j<=i; j++){
			dp[i][j] = v[i-1]*dp[i-1][j-1] + (1-v[i-1])*dp[i-1][j];
		}
	}
/*
	for(int i=1; i<=N; i++){
		for(int j=1; j<=N; j++)
			cout << dp[i][j] << " ";
		cout << "\n";
	}
*/
	double ans = 0;
	for(int i=N/2+1; i<=N; i++)
		ans += dp[N][i];
	cout << setprecision(12)  << ans;
}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int n;
int main() {
	cin >> n;
	int a[n];
	rep(i,1,n+1){
		cin >> a[i];
	}
	int c = 1,t,ans = 0;
	rep(i,1,n+1){
		t = a[c];
		c = t;
		ans += 1;
		if(t == 2){
			pout(ans);
			return 0;
		}
		else if(i == n){
			pout(-1);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
struct P
{
    int x,y,X,Y;
    P(){}
    P(int a,int b,int c,int d)
    {
        x=a;y=b;
        X=c;Y=d;
    }
}sc[505*505];
struct T
{
    int x,y;
    T(){}
    T(int a,int b)
    {
        x=a;y=b;
    }
};
struct
{
    vector<T>v;
}p[505];
vector<T>sz;
int main()
{
    int n,m,ans=0,tnt=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            int x;
            scanf("%d",&x);
            if(x%2==1)
            {
                p[i].v.push_back(T(i,j));
            }
        }
        int len=p[i].v.size();
        for(int j=0;j<len;j+=2)
        {
            if(j+1==len) {sz.push_back(p[i].v[j]);break;}
            for(int k=p[i].v[j].y;k<p[i].v[j+1].y;k++)
            {
                sc[ans++]=P(i,k,i,k+1);
            }

        }
    }
    int len=sz.size();
    if(len>=2)
    {
        for(int i=0;i<len;i+=2)
        {
            if(i+1==len) break;
            for(int j=sz[i].y;j<m;j++)
            {
                sc[ans++]=P(sz[i].x,j,sz[i].x,j+1);
            }
            for(int j=sz[i+1].y;j<m;j++)
            {
                sc[ans++]=P(sz[i+1].x,j,sz[i+1].x,j+1);
            }
            for(int j=sz[i].x;j<sz[i+1].x;j++)
            {
                sc[ans++]=P(j,m,j+1,m);
            }
        }
    }
    printf("%d\n",ans);
    for(int i=0;i<ans;i++)
        printf("%d %d %d %d\n",sc[i].x,sc[i].y,sc[i].X,sc[i].Y);

    return 0;
}


Measured memory_bytes: 6016
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    
    if(s.contains("A")&&s.contains("B")){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

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

int main() {
  string S; cin >>S;
  S[3]='8';
  cout <<S <<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
x = [0]* n
y = [0]* n
for i in range(n):
    x[i], y[i] = map(int, input().split())

xi = [(i,x[i]) for i in range(n)]
yi = [(i,y[i]) for i in range(n)]

xi.sort(key=lambda x:x[1])
yi.sort(key=lambda x:x[1])

INF = float('inf')

# xycost = [[INF]*n for i in range(n)]
# for i in range(n-1):
#     xycost[xi[i][0]][xi[i+1][0]] = min(xycost[xi[i][0]][xi[i+1][0]], xi[i+1][1] -xi[i][1])
#     xycost[xi[i+1][0]][xi[i][0]] = min(xycost[xi[i+1][0]][xi[i][0]], xi[i+1][1] -xi[i][1])
#     xycost[yi[i][0]][yi[i+1][0]] = min(xycost[yi[i][0]][yi[i+1][0]], yi[i+1][1] -yi[i][1])
#     xycost[yi[i+1][0]][yi[i][0]] = min(xycost[yi[i+1][0]][yi[i][0]], yi[i+1][1] -yi[i][1])

xycost = []

for i in range(n-1):
    tmp = (xi[i][0], xi[i+1][0], xi[i+1][1] -xi[i][1])
    xycost.append(tmp)
    tmp = (yi[i][0], yi[i+1][0], yi[i+1][1] -yi[i][1])
    xycost.append(tmp)

xycost.sort(key=lambda x:x[2])

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def root(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.root(x)]

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def members(self, x):  # 計算量n
        root = self.root(x)
        return [i for i in range(self.n) if self.root(i) == root]

    def all_roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.all_roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.all_roots()}

    def __str__(self):
        return ''.join('{}: {}'.format(r, self.members(r)) for r in self.all_roots())

uf = UnionFind(n)
ans = 0
for i,j, cost in xycost:
    if not uf.is_same(i,j):
        uf.union(i,j)
        ans += cost
    if uf.size == n: break

print(ans)


Measured memory_bytes: 58652
/*input
4 5 3
*/
macro_rules! read_line_vec {
    () => {
        read_line!()
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };
    ($delimiter:expr) => {
        read_line!()
            .split($delimiter)
            .map(|x| x.parse().unwrap())
            .collect()
    };
}

macro_rules! read_line {
    () => {{
        let mut return_ = format!("");
        std::io::stdin().read_line(&mut return_).ok();
        return_.pop();
        return_
    }};
}

fn main() {
    let v: Vec<i64> = read_line_vec!();
    println!(
        "{} {}",
        v.iter()
            .fold(std::i64::MAX, |x, y| if x < *y { x } else { *y }),
        v.iter()
            .fold(std::i64::MIN, |x, y| if x > *y { x } else { *y })
    );
}



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

n = int(input())
A = list(map(int, input().split()))
x = 0
for a in A:
  x ^= a
now = 0
for i in range(59, -1, -1):
  if x>>i & 1:
    continue
  for j in range(now, n):
    if A[j]>>i & 1:
      A[now], A[j] = A[j], A[now]
      for k in range(n):
        if k != now and A[k]>>i & 1:
          A[k] ^= A[now]
      now += 1
      break
b = 0
for a in A:
  b ^= a
ans = b + (x^b)
print(ans)

Measured memory_bytes: 21932
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll roundd(ll x,ll n){
  if(x>n){return x%n;}
  else if(x<0){return x%n+n;}
  else return x;
}
bool isprime(ll n){
    if(n==1)return false;
    for (ll i = 2; i * i <= n; i++) {
        if(n%i==0)return false;
    }
    return true;
}

ll modpow(ll x, ll n){
	ll r=1;
	while(n){
		if(n&1) r=r*x%MOD;
		x=x*x%MOD;
		n>>=1;
	}
	return r;
}
int main(){
  ll n;cin>>n;
  vll a(n),b(0);
  ll now=1000,kabu;
  rep(i,0,n){cin>>a[i];}
  b.push_back(a[0]);
  rep(i,0,n-1){
    if(a[i]!=a[i+1]){b.push_back(a[i+1]);}
  }
  ll m=b.size();
  vll dp(m,1000);
  rep(i,1,m){
    ll tmp=dp[i-1];
    rep(j,0,i){
      ll mi=201;
      rep(k,j,i){
        mi=min(mi,b[k]);
      }
      tmp=max(tmp,(dp[j]/mi)*b[i]+(dp[j]%mi));
      
    }
    dp[i]=tmp;
    
  }
  cout<<dp[m-1]<<endl;
}



Measured memory_bytes: 3644
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int H = Integer.parseInt(st.nextToken());       
        int W = Integer.parseInt(st.nextToken());       

        String[] orig = new String[H];

        for(int i=0; i<H; i++){
            String cur = br.readLine();
            orig[i]=cur;
        }

        for(int i=0; i<H; i++){
            System.out.println(orig[i]);
            System.out.println(orig[i]);
        }



        
    }
}


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


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

  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= m; ++j) {
      int t = j * (n - i) + i * (m - j);
      if (t == k) {
	puts("Yes");
	return 0;
      }
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
D = set([i for i in map(str,input().split())])

for i in range(N,10**6):
  ng = 0
  str_i = str(i)
  for s in str_i:
    if s in D:
      ng = 1
      break
  if ng == 0:
    print(i)
    break

Measured memory_bytes: 3060
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
a1=A[0]
a2=0
ans=B[a1-1]
for i in range(1,N):
  a2=A[i]
  ans+=B[a2-1]
  if a2==a1+1:
    ans+=C[a1-1]
    a1=a2
  else:
    a1=a2
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;
long long a[100100];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	int cache=-1; 
	long long aa=0,b=0,c=0;
	for(int i=n;i>=2;i--) if(c<2&&a[i]==a[i-1]&&cache-i!=1) if(aa==0) aa=a[i],c++,cache=i; else b=a[i],c++;
	printf("%lld",aa*b);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
string s;
map<pair<int,int>,int> mp;
int prv1,prv2;
long long res=0LL;
int res1[200100],res2[200100];
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	res1[s.size()-1]=1;
	res2[s.size()-1]=1;
	for(int i=s.size()-2;i>=0;i--){
		res1[i]=(res1[i+1]*10)%3;
		res2[i]=(res2[i+1]*10)%673;
	}
	mp[make_pair(0,0)]++;
	for(int i=0;i<s.size();i++){
		prv1=(prv1*10+s[i]-'0')%3;
		prv2=(prv2*10+s[i]-'0')%673;
		res1[i]=(res1[i]*prv1)%3;
		res2[i]=(res2[i]*prv2)%673;
		res+=(long long)(mp[make_pair(res1[i],res2[i])]);
		mp[make_pair(res1[i],res2[i])]++;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 5232
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>
#include<numeric>
//by Skeef79

typedef long long ll;
typedef long double ld;

typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SZ(a) int(a.size())

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];

}

const ll mod = 1e9 + 7;
ll pw(ll x, ll n)
{
	ll ans = 1;
	for (int i = 0; i < n; i++)
		ans = (ans%mod)*(x%mod) % mod;
	return ans % mod;
}
void solve()
{
	ll n;
	cin >> n;
	ll ans = (pw(10, n) % mod - 2*pw(9, n)%mod + pw(8,n) % mod + mod * mod) % mod;
	//ans = (ans%mod - 2 * pw(9, n) % mod + mod * mod) % mod;
	cout << ans;
}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);

	int tst = 1;
	//cin >> tst;

	while (tst--)
		solve();
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001001001001ll;

struct segtree{
    static const int SEG=1<<17;
    vint dat,put;
    segtree():dat(SEG*2),put(SEG*2){}
    inline void push(int k){
        dat[k]+=put[k];
        if(k<SEG-1){
            put[k*2+1]+=put[k];
            put[k*2+2]+=put[k];
        }
        put[k]=0;
    }
    void add(int a,int b,int x,int k=0,int l=0,int r=SEG){
        push(k);
        if(r<=a||b<=l)return;
        if(a<=l&&r<=b){
            put[k]=x;
            push(k);
            return;
        }
        add(a,b,x,k*2+1,l,(l+r)/2);
        add(a,b,x,k*2+2,(l+r)/2,r);
        dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
    int query(int a,int b,int k=0,int l=0,int r=SEG){
        push(k);
        if(r<=a||b<=l)return INF;
        if(a<=l&&r<=b)return dat[k];
        return min(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
};

int N;
int A[111111],B[111111];
int C[111111];
int Q;
int D[111111],E[111111];

int ei[111111];
int to[111111];
signed main(){
    cin>>N;
    rep(i,N)cin>>A[i]>>B[i];
    rep(i,N+1)cin>>C[i];
    cin>>Q;
    rep(i,Q)cin>>D[i]>>E[i];

    sort(C,C+N+1);
    rep(i,N){
        chmin(B[i],A[i]);
        A[i]=lower_bound(C,C+N+1,A[i])-C;
        B[i]=lower_bound(C,C+N+1,B[i])-C;
    }

    segtree seg;
    for(int i=0;i<=N;i++)seg.add(i,i+1,N+1-i);
    vpint latte;
    rep(i,N){
        seg.add(0,B[i]+1,-1);
        latte.pb({B[i],A[i]});
    }

    if(seg.query(0,N+2)<0){
        rep(i,Q)puts("-1");
        return 0;
    }
    sort(all(latte));reverse(all(latte));

    int base=0;
    rep(i,latte.size()){
        int a,b;
        tie(b,a)=latte[i];
        if(seg.query(b+1,a+1)==0)continue;
        seg.add(b+1,a+1,-1);
        chmax(ei[b],a);
        base++;
    }

    int r=-1;
    int pos=0;
    for(int i=0;i<=N;i++){
        while(pos<=N&&seg.query(pos,pos+1)>0){
            chmax(r,ei[pos]);
            pos++;
        }
        to[i]=pos;
        seg.add(0,r+1,1);
    }

    rep(i,Q){
        D[i]=lower_bound(C,C+N+1,D[i])-C;
        E[i]=lower_bound(C,C+N+1,E[i])-C;
        int ans=-1;

        int k=upper_bound(to,to+N+1,D[i])-to;
        if(k!=N+1)chmax(ans,base-k+1);
        k=upper_bound(to,to+N+1,E[i])-to;
        if(k!=N+1)chmax(ans,base-k);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 12400
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
int n,i;

cin>>n>>i;
cout<<n+1-i<<endl;


  return 0;
}

Measured memory_bytes: 256
import bisect
import sys
input = sys.stdin.readline
N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
A = A[::-1]
INF = int(1e+9 + 10)
lis = [INF] * N
for n in range(N):
    i = bisect.bisect(lis, A[n])    
    lis[i] = A[n]
print (bisect.bisect_left(lis, INF))

Measured memory_bytes: 7840
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	ll n;
	cin >> n;
	int ans = sqrt(n);
	cout << ans * ans;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
n,m,c=gets.chomp.split(" ").map{|a| a.to_i}
b=gets.chomp.split(" ").map{|a| a.to_i}
puts n.times.select{gets.chomp.split(" ").map(&:to_i).zip(b).map{|x,y| x*y}.inject(:+)+c>0}.size

Measured memory_bytes: 3836
import java.io.*;

class Main
{
    public static void main(String[] args) throws IOException
    {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	String str = br.readLine();

	int X = Integer.parseInt(str);

	find_max(2, 2, X, 1);
    }

    public static void find_max(int e, int x, int X, int max)
    {
	if(X == 1 || X == 2 || X == 3){
	    System.out.println(1);
	}else{
	    if(Math.pow((double) e, (double) x) <= (double) X){
		if(Math.pow((double) e, (double) x) > (double) max){
		    find_max(e, x+1, X, (int) Math.pow((double) e, (double) x));
		}else{
		    find_max(e, x+1, X, max);
		}
	    }else{
		if(Math.pow((double) (e+1), (double) 2) <= (double) X){
		    find_max(e+1, 2, X, max);
		}else{
		    System.out.println(max);
		}
	    }
	}
    }
}

Measured memory_bytes: 21332
#include<stdio.h>
#include<string.h>
int n,m;
char ch1[2][4],ch2[2][4];
int main(){
	int i,j;
	memset(ch1,0,sizeof(ch1));
	memset(ch2,0,sizeof(ch2));
	for(i=1;i<=2;i++)
		scanf("%s",ch1[i]+1);
	ch2[2][3]=ch1[1][1];ch2[1][1]=ch1[2][3];
	ch2[2][2]=ch1[1][2];ch2[1][2]=ch1[2][2];
	ch2[2][1]=ch1[1][3];ch2[1][3]=ch1[2][1];
	for(i=1;i<=2;i++){
		for(j=1;j<=3;j++){
			if(ch1[i][j]!=ch2[i][j]){
				printf("NO\n");
				return 0;
			}
		}
	}
	printf("YES\n");
	return 0;
} 

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

using namespace std;

long poww(long a, long b) {
    long r = 1;
    while(b) {
        if(b&1) r *= a;
        a *= a;
        b >>= 1;
    }
    return r;
}

int main(void) {
    long n, a, b, c;
    cin >> n >> a >> b >> c;

    vector<long> l(n);
    for(auto &x: l) cin >> x;

    auto f = [&](long s, vector<long> &ls) -> long {
        long r = 1e10;
        for(int i=1; i<1<<ls.size(); i++) {
            long t = 0;
            for(int j=0; j<ls.size(); j++)
                if(i & (1<<j)) t += ls[j];
            r = min(r, abs(t - s) + (__builtin_popcount(i)-1)*10);
        }
        return r;
    };

    long r = 1e10;
    for(int i=0; i<poww(3, n); i++) {
        long ii = i;
        vector<long> lss[3];
        for(int j=0; j<n; j++)
            lss[ii%3].push_back(l[j]), ii/=3;
        r = min(r, f(a, lss[0]) + f(b, lss[1]) + f(c, lss[2]));
    }
    cout << r << endl;
}


Measured memory_bytes: 256
n, m = gets.split(" ").map{|v|v.to_i}
cakes = Array.new(8) {|i| Array.new }
n.times{|i|
  x, y, z = gets.split(" ").map{|v|v.to_i}
  cakes[0] << (x + y + z)
  cakes[1] << (-x + y + z)
  cakes[2] << (x - y + z)
  cakes[3] << (-x - y + z)
  cakes[4] << (x + y - z)
  cakes[5] << (-x + y - z)
  cakes[6] << (x - y - z)
  cakes[7] << (-x - y - z)
}

if m == 0
  puts 0
  exit
end

max = 0
cakes.each{|c|
  c.sort!{|a, b|
    v = 0 if a == b
    v = 1 if a < b
    v = -1 if a > b
    v
  }
  max = [max, c[0, m].inject(:+)].max
}
puts max


Measured memory_bytes: 1916
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
       Map<String,Integer> S = new HashMap<>();
        for(int i=0;i<n;i++){
            String s = sc.next();
            String t = sc.next();
            if(s.charAt(0)=='i') S.put(t,1);
            else if(S.get(t)==null) System.out.println("no");
            else System.out.println("yes");
        }
    }
}


Measured memory_bytes: 209584
#include <cstdio>
#include <algorithm>
using namespace std;
int N, A[200002], L[200002], R[200002];
int main() {
  scanf("%d", &N);
  for(int i = 1; i <= N; ++i) scanf("%d", &A[i]);
  for(int i = 1; i <= N; ++i) {
    L[i] = max(L[i-1], A[i]);
    R[N-i+1] = max(R[N-i+2], A[N-i+1]);
  }
  for(int i = 1; i <= N; ++i) {
    printf("%d\n", max(L[i-1], R[i+1]));
  }
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int depth(vector<int>& parent ,int x){
    if(parent[x]==-1)return 0;
    else return 1+depth(parent,parent[x]);
}

int main(){
    int n;
    in(n);
    vector<int> parent(n,-1);
    vector<vector<int>> children(n);
    int x,y,k;
    rep(i,n){
        in(x,k);
        rep(j,k){
            in(y);
            children[x].push_back(y);
            parent[y]=x;
        }
    }
    rep(i,n){
        printf("node %d: parent = %d, depth = %d, ",i,parent[i],depth(parent,i));
        if(parent[i]==-1)printf("root, ");
        else if(children[i].size()>=1)printf("internal node, ");
        else printf("leaf, ");
        printf("[");
        rep(j,children[i].size()){
            if(j==0)printf("%d",children[i][j]);
            else printf(", %d",children[i][j]);
        }
        printf("]\n");
    }
}


Measured memory_bytes: 6260
N=int(input())
s=[input() for i in range(N)]
count=0
if(len(s)!=len(set(s))):
  count=1
else:
  for i in range(N-1):
    len_s=len(s[i])
    if(s[i][len_s-1]!=s[i+1][0]):
      count=1
      break
    else:continue
if(count==0):
	print('Yes')
else:print('No')

Measured memory_bytes: 3064