akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define REV(i,a,n) for(int i=a;i>=n;i--)
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin >> num_tests;
    while(num_tests-->0){
        int n,m,x; cin >> n >> m >> x;
        vector<int> cost(n);
        int skills[n][m];
        FOR(i,0,n)
        {
            cin >> cost[i];
            FOR(j,0,m) cin >> skills[i][j];
        }
        int ans = 1e18;
        int bit = (1 << n);
        FOR(i,0,bit)
        {
            int val = 0;
            vector<int> learnt(m,0);
            FOR(j,0,n)
            {
                if(i & (1 << j))
                {
                    val += cost[j];
                    FOR(k,0,m)
                        learnt[k] += skills[j][k]; 
                }
            }
            bool ok = 1;
            FOR(j,0,m)
                if(learnt[j] < x)
                {
                    ok = 0; break;
                }
            if(ok)
                ans = min(ans,val);
        }
        if(ans == 1e18)
            cout << -1;
        else
            cout << ans ;
    }    
}

Measured memory_bytes: 3652
t_list=[int(input()) for i in range(5)]
k = int(input())

def hoge(t_list, k):
  for i in range(5):
    for j in range(5):
      if abs(t_list[i] - t_list[j]) > k :
        return(":(")
  return("Yay!")

print(hoge(t_list, k))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int a, b, k; cin >> a >> b >> k;
	if(k <= a){
		cout << a-k << " " << b << "\n";
	}else if(k <= a+b){
		cout << 0 << " " << b-(k-a) << "\n";
	}else{
		cout << 0 << " " << 0 << "\n";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
  if ( c == 'a' || c== 'i' ||c == 'u' ||c == 'e' ||c == 'o' ) {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;
//emplace_back next_permutation tie get

typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define OUT(a) cout<<(a)<<endl;

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

    int n,a,b,x=0,y=0;
    cin >> n >> a >> b;
    string s;
    cin>> s;
    REP(i,n){
        if(s[i]=='a'){
            if(x+y<a+b){
                cout << "Yes" <<endl;
                x++;
            }
            else cout << "No" <<endl;
        }
        else if(s[i]=='b'){
            if(x+y<a+b and y<b){
                cout << "Yes" <<endl;
                y++;
            }
            else cout << "No" <<endl;
        }
        else{
            cout <<"No" <<endl;
        }

    }
    return 0;
}


Measured memory_bytes: 976
#include<iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest;
  l = 2*i;
  r = 2*i+1;

  if(l<=H && A[l] > A[i]) largest = l;
  else largest = i;
  if(r<=H && A[r] > A[largest]) largest = r;
  
  if(largest != i){
    swap(A[i],A[largest]);
    maxHeapify(largest);
  }
}
int main(){
  cin >> H;

  for(int i=1;i<=H;i++) cin >> A[i];
  for(int i=H/2; i>=1; i--) maxHeapify(i);

  for(int i=1;i<=H;i++){
    cout << " " << A[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 5064
#include <bits/stdc++.h>
using namespace std;
 
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
 
typedef long long Int;
typedef vector<int> VI;
typedef pair<int, int> PII;
 
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000;
const Int LINF = INF * (Int) INF;
const int MAX = 3007;
const int MOD = 998244353;

mt19937 rng;

int gcd(int a, int b) {
    if (!b) return a;
    return gcd(b, a % b);
}

Int dp[MAX][MAX][2];

int main(int argc, char* argv[])
{
	//ios::sync_with_stdio(false); cin.tie(0);
    rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    dp[a][b][0] = 1;

    FOR(i, a, c + 1)
        FOR(j, b, d + 1) 
            FOR(t,0,2) {  
            if (i == c) {
                dp[i][j + 1][t] += dp[i][j][t] * i % MOD;
                dp[i][j + 1][t] %= MOD;
                continue;
            }
            int coef = j;
            if (t == 1) coef = 1;
            dp[i + 1][j][0] += dp[i][j][t] * coef % MOD;
            dp[i + 1][j][0] %= MOD;

            dp[i][j + 1][1] += dp[i][j][t] * i % MOD;
            dp[i][j + 1][1] %= MOD;
        }

    cout << dp[c][d][0] << endl;
    
    
    cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;
	return 0;
}



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

int gcd(int x, int y);
int fac(ll n, vector<int> num);

const int INF = 1001001001;

//mint�p�̕ϐ� (10��9��)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }

//��߂����Ƃɂ���āA�Z�k����鋗����ۑ����Ă���(�����2
//�̋��������̏�ŋ��߂�΂悳����

//���鋗�� = (i-1)��i�̋���+(i+1)��i�̋���������
//�����鋗�� = (i-1)��(i+1)�̋���
int main() {
    ll n;
    cin >> n;
    vector<ll> ch('Z' + 1);
    ll flag = 0;
    rep(i, n) {
        string s;
        cin >> s;
        ch[s[0]]++;
    }

    ll ans = 0;
    ans += ch['M'] * ch['A'] * ch['R'];
    ans += ch['M'] * ch['A'] * ch['C'];
    ans += ch['M'] * ch['A'] * ch['H'];
    ans += ch['M'] * ch['R'] * ch['C'];
    ans += ch['M'] * ch['R'] * ch['H'];
    ans += ch['M'] * ch['C'] * ch['H'];
    ans += ch['A'] * ch['R'] * ch['C'];
    ans += ch['A'] * ch['R'] * ch['H'];
    ans += ch['A'] * ch['C'] * ch['H'];
    ans += ch['R'] * ch['C'] * ch['H'];

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

/*�f��������*/
//���색�C�u����
int fac(ll n, vector<int> num) {
    ll kazu = n;
    for (int i = 2; i <= sqrt(n); i++) {
        while (1) {
            if (kazu % i != 0) break;

            kazu /= i;
            num[i]++;
        }
    }
    if (kazu == n && n != 1) return 1;
    int ans = 0;
    if (kazu != 1) ans++;
    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = 1; j <= num[i]; j++) {
            num[i] -= j;
            ans++;
        }
    }
    return ans;
}

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

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

typedef struct {
	list **adj;
} graph;

int main()
{
	int i, u, w, N;
	scanf("%d", &N);
	list **adj = (list**)malloc(sizeof(list*) * (N + 1)), *d = (list*)malloc(sizeof(list) * N * 2);
	for (i = 0; i < N - 1; i++) {
		scanf("%d %d", &u, &w);
		d[i*2].v = w;
		d[i*2+1].v = u;
		d[i*2].next = adj[u];
		d[i*2+1].next = adj[w];
		adj[u] = &(d[i*2]);
		adj[w] = &(d[i*2+1]);
	}
	
	list *p;
	int flag[100001] = {}, q[100001], head, tail;
	flag[1] = 1;
	flag[N] = -1;
	q[0] = 1;
	q[1] = N;
	for (head = 0, tail = 2; head < tail; head++) {
		for (p = adj[q[head]]; p != NULL; p = p->next) {
			if (flag[p->v] == 0) {
				flag[p->v] = flag[q[head]];
				q[tail++] = p->v;
			}
		}
	}
	
	int count = 0;
	for (i = 1; i <= N; i++) count += flag[i];
	if (count > 0) printf("Fennec\n");
	else printf("Snuke\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 4864
import java.util.*;

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 x = 0;
    int y = 0;

    while(A > 0) {
      A = A - D;
      x++;
    }
    while(C > 0) {
      C = C - B;
      y++;
    }
    if (x >= y) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

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

int saitan(int x,int y ,int xx,int yy);
int check(int d, int tt);

int main(void){
	int n = 0, i = 0;
	int *x, *y, *t;
	x = calloc(100000, sizeof(int ));
	y = calloc(100000, sizeof(int ));
	t = calloc(100000, sizeof(int ));
	if(x == NULL||y == NULL||t == NULL)exit(0);
	
	scanf("%d",&n);
	
	t[0] = 0; x[0] = 0; y[0] = 0;
	for(i=1;i<=n;i++){
		scanf("%d %d %d",&t[i], &x[i], &y[i]);
	}
	
	int d = 0, tt = 0, a = 0;
	
	for(i=0;i<n;i++){
		d = saitan(x[i], y[i], x[i+1], y[i+1]);
		tt = t[i+1] - t[i];
		
		a = check(d, tt);
		if(a == 0){
			printf("No");
			free(x);free(y);free(t);
			return 0;
			}
	}
	printf("Yes");
	free(x);free(y);free(t);
	return 0;
}

int saitan(int x,int y ,int xx,int yy){
	int d = 0;
	d += abs(xx - x);
	d += abs(yy - y);
	
	return d;
}

int check(int d, int tt){
	if(tt >= d){
		if(tt % 2 == d % 2) return 1;
		}
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

const ll mod=1e9+7;

ll com(ll N, ll K, ll L) {
  ll d = 1, e = (L*K)%mod, m_ = mod-2;
  while(m_ != 0) {
    if (m_&1) d = (d*e)%mod;
    e = e*e%mod;
    m_ = m_ >> 1;
  }
  return (N*d)%mod;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,k,val=1,ans=0;cin>>n>>k;
  lvector v(n,0),a(n,0);rep(i,n) cin>>v[i];
  sort(v.begin(),v.end());
  a[0]=1;
  for(ll i=1;i<=n-1;++i) a[i]=(a[i-1]*i)%mod;
  for(ll i=0;i<=n-k;++i) ans-=(v[i]*com(a[n-1-i],a[k-1],a[n-i-k]))%mod;
  for(ll i=k-1;i<n;++i) ans+=(v[i]*com(a[i],a[k-1],a[i-k+1]))%mod;
  ans%=mod;
  print(ans);
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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 revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N, M; cin >> N >> M;
    vector<int> counter(M, 0);
    rep (i, 0, N) {
        int K; cin >> K;
        rep (j, 0, K) {
            int in; cin >> in; --in;
            ++counter[in];
        }
    }
    int ans = 0;
    rep (i, 0, counter.size()) if (counter[i] == N) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
 
#define N 101
 
int G[N][N], X[N], Y[N], n;
 
void find(int x, int y){
  int i;
  X[x] = y;
  for(i = 1; i <= Y[x]; i++)
    if(y + 1 < X[G[x][i]]) find(G[x][i], y + 1);
}
 
int main(){
  int i, j, m;
 
  scanf("%d", &n);
 
  for(i = 1; i <= n; i++){
    X[i] = 100000000;
    scanf("%d", &m);
    scanf("%d", &Y[m]);
 
    for(j = 1; j <= Y[m]; j++) scanf("%d", &G[m][j]);
  }
 
  find(1, 0);
 
  for(i = 1; i <= n; i++)
    if(X[i] == 100000000) X[i] = -1;
 
  for(i = 1; i <= n; i++) printf("%d %d\n", i, X[i]);
 
  return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
set<int> s;

int main()
{
	int n;
	cin>>n;
	int num;
	for(int i=0;i<n;i++)
	{
		cin>>num;
		set<int>::iterator it=s.find(num);
		if(it!=s.end())s.erase(it);
		else s.insert(num);

	}
	cout<<s.size();

	//system("pause");
}



Measured memory_bytes: 4864
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

// reference: http://ir5.hatenablog.com/entry/20171209/1512821837

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

use std::mem;
use std::cmp;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let S: String = sc.read();
    // let mut ans = 0;
    // for i in 0..N {
    //     let a: u32 = sc.read();
    //     ans += a;
    // }    
    // ans /= N;
    // if S.len() >= 3 {
        println!("{}", &S[0..3]);
    // }
}

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

// macros
#define int long long 
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef long double ld;

// template functions
template < typename A, typename B >
ostream &operator << ( ostream& os, const pair< A, B > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "[";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "{";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename A, typename B >
ostream &operator << ( ostream & os, const map< A, B > &v ) {
    os << "[";
    typename map< A, B >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " -> " << it -> second ;
    }
    return os << "]";
}
template<typename T>
T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; }
template<typename T>
T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; }

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 1e15;
const int modn = 1e9+7;
const int maxn = 300+3;

ld dp[maxn][maxn][maxn];

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
    cout << fixed << setprecision(15);
    int n;
    cin>>n;
    vi a(n);
    vi cnt(4);
    for(int i=0; i<n; i++) {
        int x;
        cin>>x;
        cnt[x]++;
    }
    memset(dp, (ld)-1, sizeof(dp));
    function<ld(int,  int, int) > solve = [&](int c0, int c1, int c2)
    {
        if(c1 < 0 or c2 < 0) return (ld)0;
        if(c0==n) {
            return (ld)0;
        }
        int c3 = n - (c0 + c1 + c2);
        ld &ans = dp[c0][c1][c2];
        if(abs(ans + 1) > eps) return ans;

        ans = (ld)n/(n-c0) * (1 + (c1 > 0 ? (ld)c1/n*solve(c0+1, c1-1, c2) : 0) + (c2 > 0 ? (ld)c2/n*solve(c0, c1+1, c2-1) : 0) + (c3 > 0 ? (ld)c3/n*solve(c0, c1, c2+1) : 0) ) ;
        return ans;
    };
    cout << solve(cnt[0], cnt[1], cnt[2]) << "\n";
    // watch(dp[1][1][0]);
    return 0;
}



Measured memory_bytes: 435072
# from line_profiler import LineProfiler
from collections import deque
from sys import stdin

def main():
    while(True):
        W, H = map(int, stdin.readline().split())
        if not W: break
        tx,ty = map(int, stdin.readline().split())
        kx,ky = map(int, stdin.readline().split())
        ma = [[False]*(W+2) for _ in range(H+2)]
        for i in range(1,H+1):
            for j,a in enumerate(stdin.readline().split()):
                ma[i][j+1] = bool(1-int(a))
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if not(tx-kx or ty-ky):
                ans = c
                break
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy = [ dx, dy] if ma[ty+dy][tx+dx] else [0,0]
                kdx, kdy = [-dx,-dy] if ma[ky-dy][kx-dx] else [0,0]
                if (tx+tdx,ty+tdy,kx+kdx,ky+kdy) in pas: continue
                if c+1 > 100: continue
                que.append([tx+tdx,ty+tdy,kx+kdx,ky+kdy,c+1])
                pas.add((tx+tdx,ty+tdy,kx+kdx,ky+kdy))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()


Measured memory_bytes: 35196
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Node;
const ll INF=2e18;
const ll MOD=1e9+7;
ll N,M,L,Q;
struct Edge{
    ll to,cost;
};
vector<Edge> edges[310];
ll d[305][305];
ll e[305][305];
int main(){
    cin>>N>>M>>L;
    for(ll i=0;i<N;i++){
        for(ll j=0;j<N;j++){
            if(i==j){
                d[i][j]=0;
                e[i][j]=0;
            }
            else{
                d[i][j]=INF;
                e[i][j]=INF;
            }
        }
    }
    for(ll i=0;i<M;i++){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        if(c<=L){
            d[a][b]=c;
            d[b][a]=c;
        }
    }
    
    for(ll k=0;k<N;k++){
        for(ll i=0;i<N;i++){
            for(ll j=0;j<N;j++){
                if(d[i][j]>d[i][k]+d[k][j]){
                    d[i][j]=d[i][k]+d[k][j];
                }
            }
        }
    }

    for(ll i=0;i<N;i++){
        for(ll j=0;j<N;j++){
            if(d[i][j]<=L){
                e[i][j]=1;
            }
        }
    }

    for(ll k=0;k<N;k++){
        for(ll i=0;i<N;i++){
            for(ll j=0;j<N;j++){
                if(e[i][j]>e[i][k]+e[k][j]){
                    e[i][j]=e[i][k]+e[k][j];
                }
            }
        }
    }

    cin>>Q;
    for(ll i=0;i<Q;i++){
        ll s,t;
        cin>>s>>t;
        s--;t--;
        if(d[s][t]==INF){
            cout<<-1<<endl;
            continue;
        }
        cout<<e[s][t]-1<<endl;
    }

    
    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long Q,H,S,D,N;
	cin >> Q >> H >> S >> D >> N;
	Q*=4; H*=2;
	S = min({Q,H,S});
	D = min({2*S,D});
	cout << (N/2)*D + (N%2)*S << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

  int A[4][3][10] = {}, n, b, f, r, v, i, j, k;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d %d %d %d", &b, &f, &r, &v);
    A[b-1][f-1][r-1] += v;
  }

  for(i = 0; i < 4; i++) {
    for(j = 0; j < 3; j++) {
      for(k = 0; k < 10; k++) {
        if(A[i][j][k] < 0) A[i][j][k] = 0; 
        if(A[i][j][k] > 9) A[i][j][k] = 9;
        printf(" %d", A[i][j][k]);
      }
      printf("\n");
    }
    if(i != 3) printf("####################\n");
  }

  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  vector<ll> D;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      D.emplace_back(i);
      D.emplace_back(N / i);
    }
  }
  ll res = 0;
  for (ll d : D) {
    ll k = d - 1;
    if (k == 0) continue;
    if (N / k == N % k) res += k;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


  

long long power(long long a, long long b,long long mod) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %mod;
        a = a * a %mod;
        b >>= 1;
    }
    return res;
}

const int mod=998244353;
int seg[800005];
int pp[200005];
int pre[200005];
int lz[800005];

void build(int ver,int tl,int tr)
{
    if(tl>tr)
            return ;
    else if(tl==tr)
    {
        seg[ver]=pp[tl];
    }
    else
    {
        int tm=(tl+tr)/2;
        build(2*ver,tl,tm);
        build(2*ver+1,tm+1,tr);
        seg[ver]=(seg[2*ver]+seg[2*ver+1])%mod;
    }
}

void push(int ver,int tl,int tm,int tr)
{
    lz[2*ver]=lz[ver];
    lz[2*ver+1]=lz[ver];
    seg[2*ver]=(pre[tl]-pre[tm+1]+mod)*lz[ver]%mod;
    seg[2*ver+1]=(pre[tm+1]-pre[tr+1]+mod)*lz[ver]%mod;
    lz[ver]=0;
}

void upd(int ver,int tl,int tr,int l,int r,int val)
{
    if(tl>tr||l>r||tr<l||r<tl)
            return ;
    else if(tl==l&&tr==r)
    {
        lz[ver]=val;
        seg[ver]=(pre[tl]-pre[tr+1]+mod)*val%mod;
    }
    else
    {
        int tm=(tl+tr)/2;
        if(lz[ver])
            push(ver,tl,tm,tr);
        upd(2*ver,tl,tm,l,min(tm,r),val);
        upd(2*ver+1,tm+1,tr,max(tm+1,l),r,val);
        seg[ver]=(seg[2*ver]+seg[2*ver+1])%mod;
    }
}


// int get(int ver,int tl,int tr,int l,int r)
// {
//     if(tl>tr||l>r||tr<l||r<tl)
//             return 0;
//     else if(tl==l&&tr==r)
//             return seg[ver];
//     else
//     {
//         int tm=(tl+tr)/2;
//         return max(get(2*ver,tl,tm,l,min(tm,r)),get(2*ver+1,tm+1,tr,max(tm+1,l),r));
//     }
// }


signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      


    int n,q;
    cin>>n>>q;

    pp[n]=1;
    pre[n]=1;
    for(int i=n-1;i>=1;i--)
    {
        pp[i]=(pp[i+1]*10)%mod;
        pre[i]=(pre[i+1]+pp[i])%mod;
    }
    build(1,1,n);
    int x,y,z;
    while(q--)
    {
        cin>>x>>y>>z;
        upd(1,1,n,x,y,z);
        cout<<seg[1]<<'\n';
    }
}

Measured memory_bytes: 14984
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int       lint;
typedef vector<int>         vi;
typedef vector<lint>        vl;
typedef pair<int, int>      pii;
typedef vector<pii>         vii;
typedef set<int>            si;
typedef map<string, int>    msi;
 
#define pb(n)           push_back(n)
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define M               10000000
#define MOD             10000007
#define INF             1e9+7
#define REP(i,a,b)      for(int i = int(a); i <= int(b); i++)
#define REPL(i,a,b)     for(lint i = lint(a); i <= lint(b); i++)
#define fastIO()        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    lint a, b, c;
    cin>>a>>b>>c;

    /*
        sqrt(a) + sqrt(b) < sqrt(c)
        sqrt( sqrt(a) + sqrt(b) ) < c
        2sqrt(a*b) < c - a - b
        4ab < sqrt(c - a- b)
    */
    lint dif = c - a - b;

    puts(dif > 0 && (4*a*b) < (dif * dif) ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 256
str1=input()

str2="abcdefghijklmnopqrstuvwxyz"


aaa=[]

for i in str2:
    #print(i)
    if (i in str1) == False:
        aaa.append(i)

aaa.sort()

if len(aaa)==0:
    print(None)
else:
    print(aaa[0])
    

Measured memory_bytes: 9192
#include <algorithm>
#include <iostream>
#include <string>
//#include "stdafx.h"
using namespace std;

int main()
{
	int a,b,c,d;

	cin >> a >> b >> c >>d; //スペースで区切られたものを別々に入力

	if ((a + b) > (c + d)) {
		cout << "Left" << endl;
	}else if ((a + b) < (c + d)) {
		cout << "Right" << endl;
	}
	else {
		cout << "Balanced" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Two Switches
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int x = min(b, d) - max(a, c);
  printf("%d\n", (x > 0) ? x : 0);
  return 0;
}


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

long long f(long long H) {
    if (H == 1) return 1;
    return 2 * f(H / 2) + 1;
}

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

    cout << f(H) << endl;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

class union_find {
private:
    vector<int> parent, rank, gs;
    int size;

public:
    int count_group;
    union_find() = default;
    union_find(int n) { init(n); }

    void init(int n) {
        size = n;
        count_group = n;
        parent.resize(size);
        rank.assign(size, 0);
        gs.assign(size, 1);
        for (int i = 0; i < size; ++i) parent[i] = i;
    }

    int find(int x) {
        if (parent[x] == x)
            return x;
        else
            return parent[x] = find(parent[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            parent[x] = y;
            gs[y] += gs[x];
        } else {
            parent[y] = x;
            gs[x] += gs[y];
            if (rank[x] == rank[y]) ++rank[x];
        }
        --count_group;
    }

    bool is_same_group(int x, int y) {
        return find(x) == find(y);
    }

    int group_size(int x) {
        return gs[find(x)];
    };
};

void solve(){
    i64 H,W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i,0,H) cin >> S[i];

    union_find uf(H*W);

    vector<i64> dy={0,-1,0,1},dx={1,0,-1,0};
    rep(i,0,H){
        rep(j,0,W){
            rep(k,0,4){
                i64 ni=i+dy[k],nj=j+dx[k];
                if(ni<0 or H<=ni or nj<0 or W<=nj) continue;
                if(S[i][j]!=S[ni][nj]) uf.unite(i*W+j,ni*W+nj);
            }
        }
    }

    map<i64,i64> black,white;
    rep(i,0,H){
        rep(j,0,W){
            if(S[i][j]=='#') ++black[uf.find(i*W+j)];
            else ++white[uf.find(i*W+j)];
        }
    }

    i64 ans=0;
    rep(i,0,H){
        rep(j,0,W){
            if(S[i][j]!='#') continue;
            ans+=white[uf.find(i*W+j)];
        }
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 19584
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;

int main(){
	ll K;
	cin>>K;
	cout<<50<<endl;
	REP(i,50){
		ll ans;
		if (i<K%50){
			ans=100-(K%50)+K/50;
		}else{
			ans=49-(K%50)+K/50;
		}
		if (i){
			cout<<" ";
		}
		cout<<ans;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
h = [int(x) for x in input().split()]
DP = [10000] * N
DP[0] = 0
DP[1] = max(h[0]-h[1],h[1]-h[0])
for i in range(2,N):
  DP[i] = min(DP[i-2] + max(h[i]-h[i-2],h[i-2]-h[i]),DP[i-1] + max(h[i]-h[i-1],h[i-1]-h[i]))
print(DP[N-1])

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

int main(){
	int N, P, m = 10000000, i, ans = 0;
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		scanf("%d", &P);
		if(m >= P){
			ans++;
			m = P;
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
  
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  
  if(U == S) cout << A-1 << " " << B << endl;
  else cout << A << " " << B-1 << endl;

}

Measured memory_bytes: 3624
N = int(input())
F = [list(map(str, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]

plist = []
for i in range(1,1024):
    plist.append(format(i,'010b'))

score = {}
for i in range(len(plist)):
    m = 0
    choice = plist[i]
    for j in range(N):
        count = 0
        for k in range(10):
            if choice[k] == F[j][k] == "1":
                count += 1
        m += P[j][count]
    score[i] = m

print(max(score.values()))


Measured memory_bytes: 3316
#include <cstdio>
#include <utility>
#include <vector>
#include <complex>
#include <cmath>

using namespace std;

static const double EPS=1e-12;
static const double INF=1e24;

using Point=complex<double>;
using Plane=vector<Point>;

bool operator<(const Point &a, const Point &b) {
    return real(a)!=real(b)? real(a)<real(b) : imag(a)<imag(b);
}

double cross_prod(const Point &a, const Point &b) {
    return imag(conj(a)*b);
}

double dot_prod(const Point &a, const Point &b) {
    return real(conj(a)*b);
}

struct Line: public vector<Point> {
    Line() {}
    Line(const Point &a, const Point &b) {
        push_back(a);
        push_back(b);
    }
};

struct Circle {
    Point p;
    double r;
    Circle() {}
    Circle(const Point &p, const double r): p(p), r(r) {}
};

int main() {
    double x, y;
    scanf("%lf %lf", &x, &y);
    Point p1(x, y);

    scanf("%lf %lf", &x, &y);
    Point p2(x, y);

    Point e(real(p2)-real(p1), imag(p2)-imag(p1));
    e /= abs(e);

    size_t q;
    scanf("%zu", &q);
    for (size_t i=0; i<q; ++i) {
        double x, y;
        scanf("%lf %lf", &x, &y);
        Point p(x, y);

        double r=dot_prod(p-p1, e);
        Point z=p1+r*e;
        printf("%.12f %.12f\n", real(z), imag(z));
    }

    return 0;
}

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

class Union_find
{
public :
    vector<int> par;
    vector<int> rank;
    
    Union_find (int n) {
        par.resize(n);

        for (int i = 0; i < n; i++) {
            par[i] = i;
        }
    }

    int find (int);
    void unite (int, int);
    bool same (int, int);
};

int Union_find::find (int x) {
    if (par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void Union_find::unite (int x, int y) {
    x = find(x);
    y = find(y);

    if (par[x] < par[y]) {
        par[x] = y;
    } else {
        par[y] = x;
    }
}

bool Union_find::same (int x, int y) {
    return find(x) == find(y);
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    for (auto &i : p) cin >> i;
    vector<int> x(m), y(m);
    for (int i = 0; i < m; i++) {
	cin >> x[i] >> y[i];
	x[i]--, y[i]--;
    }

    Union_find uf(n);
    for (int i = 0; i < m; i++) {
	uf.unite(x[i], y[i]);
    }

    vector<vector<int>> v(n);
    vector<set<int>> w(n);
    for (int i = 0; i < n; i++) {
	v[uf.find(i)].push_back(p[i] - 1);
	w[uf.find(i)].insert(i);
    }

    int sum = 0;
    for (int i = 0; i < n; i++) {
	for (auto j : v[i]) {
	    if (w[i].find(j) != w[i].end()) {
		sum += 1;
	    }
	}
    }

    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
string s,t;
cin>>s;
cin>>t;
vector<ll>v[27];
ll i,j,c=0,k=s.size(),a=0,b;
for(i=0;i<s.size();i++)
{
    v[s[i]-'a'].pb(i+1);
}
for(i=0;i<t.size();i++)
{
    if(v[t[i]-'a'].size()==0)
    {
        cout<<-1<<endl;
        return 0;
    }
    b=t[i]-'a';
    auto it=upper_bound(v[t[i]-'a'].begin(),v[t[i]-'a'].end(),a);
    if(it==v[b].end())
    {
        c=c+(k-a+*v[b].begin());
        a=*v[b].begin();
    }
    else
    {
        c=c+(*it-a);
        a=*it;
    }
}
cout<<c<<endl;
}


















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Measured memory_bytes: 1724
#二つの文字列を渡すと、文字列rotationにより一致する文字列になるかどうかを調べ、
#'Yes'または'No'を返す関数、match_rotation()を定義
def match_rotation(s,t):
    for i in s:
        s = s[1::] + s[0]
        if s == t:
            return 'Yes'
    else:
        return 'No'

#入力値読み込み
S = str(input())
T = str(input())

#関数呼び出し
print(match_rotation(S, T))

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


using namespace std;
using ll = long long;


int main() {
    string a, b;
    cin >> a >> b;
    int res = 0;
    for(int i = 0; i < (int) a.length(); i++) {
        if(a[i] != b[i]) {
            res++;
        }
    }
    cout << res << "\n";



    return 0;
}



Measured memory_bytes: 3932
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a;
    cin>>a;
    char r[n];
    cin>>r;

    for (int i=0;i<n;i++)
    {if (a==(i+1))
      {
          r[i]= r[i]+32;
      }
           cout<< r[i];


    }

    return 0;
}


Measured memory_bytes: 256
x=int(input())
n=x
count_a=0
while(count_a==0):
  div=2
  count=0
  while(div<n):
    if(n%div==0):
      count+=1
    else:
      pass
    div+=1
  if(count==0):
    count_a+=1
  else:
    n+=1
print(n)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<int> A(N),B(N),C(N);
  for(int &i:A)
    cin>>i;
  for(int &i:B)
    cin>>i;
  for(int &i:C)
    cin>>i;
  sort(A.begin(),A.end());
  sort(C.begin(),C.end());
  int ans=0;
  for(int i:B){
    ans+=(lower_bound(A.begin(),A.end(),i)-A.begin())*(N-(upper_bound(C.begin(),C.end(),i)-C.begin()));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5652
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  tas <- replicateM n $ (\[x,y] -> (x,y)) . map read . words <$> getLine
  let (x,y) = foldl1 solve tas
  print $ x + y

solve :: (Integer,Integer) -> (Integer,Integer) -> (Integer,Integer)
solve (x,y) (t,a) = let x' = fromInteger x
                        y' = fromInteger y
                        t' = fromInteger t
                        a' = fromInteger a
                        f = max ((x' + t' - 1) `div` t') ((y' + a' - 1) `div` a')
                    in (f * t, f * a)


Measured memory_bytes: 1916
#include <cstdio>
#include <utility>
using namespace std;

using i64 = long long;

#define REP(i, stop) for (int i = 0, i##_len = stop; i < i##_len; ++i)

i64 D[13];
i64 E[13];
char s[100001];
const i64 M = 1000000007;
signed main() {
	D[0] = 1;
	scanf("%s", s);
	i64 i = 0;
	while(true) {
		char c = s[i];
		if (c == 0) {
			break;
		} else if (c == '?') {
			REP(r, 13) {
				i64 s = 0;
				REP(j, 10) {
					s += D[(j - r + 13) * 9 % 13];
				}
				E[r] = s % M;
			}
		} else {
			i64 d = c - '0';
			/*
			REP(r, 13) {
				E[r] = D[(d - r + 13) * 9 % 13];
			}
			*/
			E[d] = D[0];
			E[(d + 10) % 13] = D[1];
			E[(d + 7) % 13] = D[2];
			E[(d + 4) % 13] = D[3];
			E[(d + 1) % 13] = D[4];
			E[(d + 11) % 13] = D[5];
			E[(d + 8) % 13] = D[6];
			E[(d + 5) % 13] = D[7];
			E[(d + 2) % 13] = D[8];
			E[(d + 12) % 13] = D[9];
			E[(d + 9) % 13] = D[10];
			E[(d + 6) % 13] = D[11];
			E[(d + 3) % 13] = D[12];
		}
		swap(D, E);
		++i;
	}
	printf("%d", D[5]);
}


Measured memory_bytes: 256
let rec solve (cost1, cost2) (h1, h2) hs =
    match hs with
    | h :: hs' ->
            let m = min (cost1 + abs (h - h1)) (cost2 + abs (h - h2)) in
            solve (cost2, m) (h2, h) hs'
    | [] -> cost2

let () =
    let _ = read_line () in
    let h =
        read_line ()
        |> Str.split (Str.regexp " ")
        |> List.map int_of_string
    in
    match h with
    | h1 :: h2 :: hs ->
            print_int (solve (0, abs (h2 - h1)) (h1, h2) hs);
            print_newline ()
    | _ -> ()


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

using pii = pair <int, int>;

#define N 300000

int n, m;
int dp[N], val[N], w[N];

int D, Q;

vector <pii> can[N];

void query(int &ans, int v, int L, int cur) {
	if (v <= m) {
		ans = max(ans, cur + (--lower_bound(can[v].begin(), can[v].end(), pii(L + 1, 0))) -> second);
		return;
	}
	query(ans, v >> 1, L, cur);
	if (L >= w[v]) query(ans, v >> 1, L - w[v], cur + val[v]);
	return;
}

int main() {
	D = 11;
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) scanf("%d %d", &val[i], &w[i]);
	dp[1] = 0;
	for (int i = 2; i <= n; i ++) dp[i] = dp[i>>1] + 1;
	m = min(n, (1<<D) - 1);
	can[0] = {{0, 0}};
	for (int i = 1; i <= m; i ++) {
		auto &res = can[i];
		auto &from = can[i>>1];
		vector <pii> tmp;
		tmp = from;
		for (auto x : from) {
			tmp.emplace_back(x.first + w[i], x.second + val[i]);
		}
		sort(tmp.begin(), tmp.end());
		for (auto x : tmp) {
			if (!res.empty() && res.back().second >= x.second) continue;
			res.push_back(x);
		}
	}
	scanf("%d", &Q);
	while (Q --) {
		int v, L, ans = 0;
		scanf("%d %d", &v, &L);
		query(ans, v, L, 0);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 35564
n = gets.to_i
a = [gets.split.map{|i|i.to_i}, gets.split.map{|i|i.to_i}]
candyNums = []
num = 0

0.upto(n-1) do |i|
  0.upto(n-1) do |j|
    if i == j
      num += a[0][j]
      num += a[1][j]
    elsif i > j
      num += a[0][j]
    else
      num += a[1][j]
    end
  end
  candyNums.push num
  num = 0
end

puts candyNums.max

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

using namespace std;

typedef long long LL;

constexpr int N = 10001, MOD = 1e9+7;

int n, r;
char s[N];

struct Vec {
  LL a[4];
  Vec() { memset(a, 0, sizeof(a)); }
  LL& operator [] (const int &i) { return a[i]; }
  const LL& operator [] (const int &i) const { return a[i]; }
  void print() {
    for(int i = 0; i < 4; ++i)
      fprintf(stderr, "%lld%c", a[i], "\t\n"[i==3]);
  }
};
struct Mat {
  Vec a[4];
  Vec& operator [] (const int &i) { return a[i]; }
  const Vec& operator [] (const int &i) const { return a[i]; }
  Mat operator * (const Mat &b) {
    Mat rtn;
    for(int i = 0; i < 4; ++i)
      for(int j = 0; j < 4; ++j)
        for(int k = 0; k < 4; ++k)
          rtn[i][j] = (MOD + rtn[i][j] + a[i][k] * b[k][j]) % MOD;
    return rtn;
  }
  Vec operator * (const Vec &v) {
    Vec rtn;
    for(int i = 0; i < 4; ++i)
      for(int j = 0; j < 4; ++j)
        rtn[i] = (MOD + rtn[i] + a[i][j] * v[j]) % MOD;
    return rtn;
  }
  void print() {
    cerr << string(30, '-') << endl;
    for(int i = 0; i < 4; ++i)
      a[i].print();
  }
};

int main() {
  Mat eye, mul, pos, neg, dig;
  for(int i = 0; i < 4; ++i)
    eye[i][i] = 1;
  mul[0][0] = mul[1][2] = mul[3][3] = 1;
  pos[0][0] = pos[0][2] = pos[1][3] = pos[3][3] = 1;
  neg[0][0] = neg[0][2] = neg[3][3] = 1;
  neg[1][3] = -1;
  dig[0][0] = dig[1][1] = dig[3][3] = 1;
  dig[2][2] = 10;
  Vec v;
  v[1] = v[3] = 1;
  scanf("%d", &n);
  for(int i = 0; i < n; ++i) {
    scanf("%d %s", &r, s);
    Mat t = eye;
    for(int j = 0; s[j]; ++j) {
      if(s[j] == '*')
        t = mul * t;
      else if(s[j] == '+')
        t = pos * t;
      else if(s[j] == '-')
        t = neg * t;
      else {
        dig[2][1] = (s[j] - '0');
        t = dig * t;
      }
    }
    Mat cur = eye;
    while(r) {
      if(r & 1)
        cur = t * cur;
      r >>= 1;
      t = t * t;
    }
    v = cur * v;
  }
  printf("%lld\n", (MOD + v[0] + v[2]) % MOD);
}

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

using namespace std;
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    while(n){
        int a[n];
        int mini = INT_MAX, maxi = INT_MIN;
        int mincnt=0, maxcnt=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            mini = min(mini, a[i]);
            maxi = max(maxi, a[i]);
        }
        for(int i=0;i<n;i++){
            if(a[i]==mini)  mincnt++;
            else if(a[i]==maxi) maxcnt++;
        }
        //cout<<mini<<" "<<mincnt<<" "<<maxi<<" "<<maxcnt<<endl;
        int sum=0;
        int cnt=0;
        for(int i=0;i<n;i++){
            if(a[i]==mini && mincnt>1){
                sum +=a[i];
                cnt++;
                mincnt--;
            }
            else if(a[i]==maxi && maxcnt>1){
                sum +=a[i];
                cnt++;
                maxcnt--;
            }
            else if((a[i]!=mini) && (a[i]!=maxi)){
                sum +=a[i];
                cnt ++;
            }
        }
        cout<<sum/cnt<<endl;
        cin>>n;
    }
    return 0;
}




Measured memory_bytes: 3008
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int sum=n;
  rep(i,n-1){
    if(s[i]==s[i+1])sum--;
  }
  cout << sum;
}



Measured memory_bytes: 512
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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 Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

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

void Main(){
    string A, B;
    cin >> A >> B;
    string S;
    cin >> S;
    regex re("\\d{"+A+"}-\\d{"+B+"}");
    smatch match;
    if(regex_match(S, match, re)){
        cout << "Yes" << el;
    }else{
        cout << "No" << el;
    }
}



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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int c = 0;
	for (int i = 0; i < n; i++)
	{
		int l, r;
		cin >> l >> r;
		c += r-l+1;
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
	long long N,P=2,a,cnt;
	cin>>N>>a;
	cnt=a-1;
	while(--N){
		cin>>a;
		if(P==a)P++;
		else cnt+=(a-1)/P;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

N, C = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]
stc.sort(key=itemgetter(2, 0))

cs = [0] * (10 ** 5 * 2 + 1)
pc = -1
for s, t, c in stc:
    if pc != c:
        pt = -1
        pc = c
    if pt == s:
        cs[s * 2] += 1
    else:
        cs[s * 2 - 1] += 1
    cs[t * 2] -= 1
    pt = t

for i in range(1, 10 ** 5 * 2 + 1):
    cs[i] += cs[i - 1]

print(max(cs))


Measured memory_bytes: 35464
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
signed main(){
	string s;
	cin>>s;
	if(stoi(s.substr(0,4))>2019) puts("TBD");
	else if(stoi(s.substr(0,4))<2019) puts("Heisei");
	else{
		if(stoi(s.substr(5,2))<5) puts("Heisei");
		else puts("TBD");
	}
	return 0;
}


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

#define ll long long
#define mod 1000000007
#define debug1(x) cerr<<#x<<" : "<<x<<"\n";
#define debug2(x,y) cerr<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    freopen("input.txt", "rt" , stdin);
//    freopen("output.out", "wt",stdout);


int main() {
    IOS;
    ll x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y;
    return 0 ;
}


Measured memory_bytes: 3608