akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <math.h>
#include <deque>
#include <queue>
#include <map>
#include <iterator>
#include <set>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }
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; }

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

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> u(m);
	for (int i = 0; i < m; i++) {
		cin >> u[i].second >> u[i].first;
	}

	sort(u.begin(), u.end());

	int mn = -1;
	int ans = 0;

	for (int i = 0; i < m; i++) {
		int a = u[i].second;
		int b = u[i].first;

		if (a < mn) continue;
		else {
			mn = b;
			ans++;
		}
	}

	cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    vector<int> R(n+1), W(n+1);
    for (int i = 0; i < n; ++i) {
        R[i+1] = R[i] + int(s[i] == 'R');
        W[i+1] = W[i] + int(s[i] == 'W');
    }
    int an = n+11;
    for (int i = 0; i <= n; ++i) {
        int a = W[i];
        int b = R[n] - R[i];
        an = min(an, max(a, b));
    }
    cout << an << '\n';
    return 0;
}


Measured memory_bytes: 5184
n, a, b = list(map(int, input().split()))
s = input()

# a: 国内の学生
# b: 海外の学生
# c: その他
# i番idxはi位


passes_num = 0  # 通過した人の数
foregin_rank = 1  # 海外の学生の中での順位
thredshould = a + b
for c in s:
    if c == "c":
        print("No")
    elif c == "a":
        if passes_num < thredshould:
            passes_num += 1
            print("Yes")
        else:
            print("No")
    else:
        if passes_num < thredshould and foregin_rank <= b:
            passes_num += 1
            foregin_rank += 1
            print("Yes")
        else:
            print("No")


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

/**
 * Maximum Sum
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int n, k, sum = 0, max = 0;
		int[] list;

		while (!(line = br.readLine()).equals("0 0")) {
			n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			k = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(br.readLine());
			}
			max = 0;
			for (int i = 0; i < k; i++) {
				max += list[i];
			}
			sum = max;
			for (int i = k; i < n; i++) {
				sum = sum - list[i - k] + list[i];
				if (sum > max)
					max = sum;
			}
			System.out.println(max);
		}
	}
}

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 1; i < s.size(); ++i) if (s[i-1] != s[i]) ++ans;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

const int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, x;
    cin >> n >> x;
    vi l(n), s(n+1, 0);
    rep(i, n) cin >> l[i];
    rep(i, n) s[i+1] = s[i] + l[i];
    int res = 0;
    rep(i, n+1) if (s[i] <= x) res++; else break;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
       Scanner sc = new Scanner(System.in);   
      //整数の取得
	  int x = sc.nextInt();
      int y = sc.nextInt();
      //グループ分け
      int[] G = {0,1,3,1,2,1,2,1,1,2,1,2,1};
      //同じグループ??
      if(G[x]==G[y]){
         System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }
}

Measured memory_bytes: 35844
#include<bits/stdc++.h>
using namespace std;
int dist(int a, int b, int c, int d) {
	return abs(a-c)+abs(b-d);
}
int main () {
	long long n;
	cin >> n;
	long long T = 0, px = 0, py = 0;
	for (int i=0; i<n; i++) {
		long long t, x, y;
		cin >> t >> x >> y;
		long long dt = t - T;
		long long dx = dist(x, y, px, py);
		if (dt%dx!=0) {cout << "No"; return 0;}
		T = t;
		px = x;
		py = y;
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 3632
use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        k: usize,
        a: [u64;n]
    }

    let mut one_pos = 0;
    println!("{}", ceil(n - 1, k - 1));
}

fn ceil(ue: usize, shita: usize) -> usize {
    return (ue + shita - 1) / shita;
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 8572
import java.util.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      long n = Integer.parseInt(sc.nextLine());
      System.out.println(factorial(n));
   }//main   
   
   public static long factorial(long n){
      if(n == 1){
         return 1;
      }else{
         return n * factorial(n - 1);
      }
   }
}//class

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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    string ch;
    cin>>ch;
    if (n%2==1)
        cout<<"No";
    else
    {
        string test;
        test="Yes";
        for(int i=0;i<n/2;i++)
        {
            if (ch[i]!=ch[i+n/2])
            {
            test="No";
            break;
            }
        }
        cout<<test;
    }

    return 0;
}



Measured memory_bytes: 256
/* ex 5_4
   yumizmiz */

#include <stdio.h>

//大きい方を返す関数
int max(int x,int y){
    if(x>y)
        return x;
    else
        return y;
}

int main(void){
    //10文字以下なので最大の要素数は\0を含めて11
    //ptr: sequenceの各要素へのポインタ
    char sequence[11], *ptr;

    scanf("%s", sequence);

    //ptrにsequenceの最初のポインタを渡す
    ptr = sequence;

    //最大のACGT文字列長
    int max_length = 0;
    //現在のACGT文字列長
    int length = 0;
    while(*ptr){

        //ACGTならカウントする，異なればリセット
        if(*ptr=='A'||*ptr=='C'||*ptr=='G'||*ptr=='T')
            ++length;
        else
            length = 0;
        
        //最大値を更新
        max_length = max(length, max_length);
        ++ptr;
    }

    printf("%d\n", max_length);
    return 0;
}

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

int main() {
    int N, D;
    cin >> N >> D;
    vector <vector<int>> A(N, vector <int> (D));
    for (int i=0; i<N; i++){
        for (int j=0; j<D; j++){
            cin >> A.at(i).at(j);
        }
    }
    int count=0;
    for (int i=0; i<N; i++){
        for (int j=i+1; j<N; j++){
            int normal=0;
            for (int k=0; k<D; k++){
                int diff=abs(A[i][k]-A[j][k]);
                normal+=diff*diff;
            }
            bool integer=false;
            for (int k=0; k<=normal; k++){
                if (k*k==normal){
                    integer=true;
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll k; cin >> k;
    ll n; cin >> n;
    vector <ll> as;
    REP(i, n){
        ll a; cin >> a;
        as.push_back(a);
    }
    ll maximum = k - as[n-1] + as[0];
    REP(i, n-1){
        maximum = max(maximum, as[i+1] - as[i]);
    }
    cout << k - maximum << endl;
    return 0;
}

Measured memory_bytes: 2420
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int[] arr= new int[n];
		for(int i=0;i<n;i++){
			arr[i]=Integer.valueOf(sc.next());
		}
		sc.close();
		for(int i=1;i<n;i++){
			print(arr);
			int t=arr[i];
			int j=i-1;
			while(j>=0&&t<arr[j]){
				arr[j+1]=arr[j];
				j--;
			}
			arr[j+1]=t;
		}
		print(arr);
	}
	public static void print(int[] arr){
		System.out.print(arr[0]);
		for(int i= 1;i<arr.length;i++)
			System.out.print(" "+arr[i]);

		System.out.println();
	}
}

Measured memory_bytes: 32664
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "c.cpp"

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

  for (ll i = 0; i+k < n; i++) {
    cout << (a[i] < a[i+k] ? "Yes" : "No") << el;
  }
}


Measured memory_bytes: 4752
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
using namespace std;


int main(){
    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;

    int cnt = 0;
    int cntL = 0;
    int cntR = 0;
    for(int i = 0; i < N; i++){
        if(s[i] == 'L' && i != 0 && s[i-1] == 'L')
            cnt++;
        if(s[i] == 'R' && i != N-1 && s[i+1] == 'R')
            cnt++;
    }

    for(int i = 0; i < N; i++){
        if(i == 0){
            if(s[i] == 'L')
                cntL++;
            else
                cntR++;
        } else {
            if(s[i] != s[i-1]){
                if(s[i] == 'L')
                    cntL++;
                else
                    cntR++;
            }
        }
    }

    while(K > 0){
        if(cntL == 0 || cntR == 0) break;
        else{
            if((cntL==1&&cntR==2)||(cntL==2&&cntR==1)){
                cnt = N-1;
                break;
            }
            cntL--;
            cntR--;
            if(cntL == 0 || cntR == 0) cnt++;
            else cnt += 2;
        }
        K--;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 512
N = int(input())
X_list = list(map(int,input().split()))

X_sort = X_list.copy()
X_sort.sort()

mae_idx = N//2 - 1
ato_idx = N//2

mae_num = X_sort[mae_idx]
ato_num = X_sort[ato_idx]

for x in X_list:
    if x <= mae_num:
        print(ato_num)
    else:
        print(mae_num)

Measured memory_bytes: 25624
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void){
    int n;
    ll ans = 0,tmp;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
        b[i] = (a[i] - (i+1));
    }
    sort(b.begin(),b.end());
    if(n % 2 == 1){
        tmp = b[n/2];
        for(int i = 0;i < n;i++)ans += abs(b[i]-tmp);
        cout << ans << endl;
    }else{
        tmp = b[n/2];
        for(int i = 0;i < n;i++)ans += abs(b[i]-tmp);
        tmp = b[n/2-1];
        cout << ans << endl;
    }
    return 0;
}

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

const int64_t MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n,q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> posCount(n+1,0);
  int searchPos = -1;
  while(true){
  	int nextPos = s.find("AC",searchPos+1);
    if(nextPos!=string::npos){
      for(int i=searchPos+1;i<nextPos;i++){
        posCount[i+1] = posCount[i];
      }
      posCount[nextPos+1] = posCount[nextPos]+1;
      searchPos = nextPos;
    }
    else{
      for(int i=searchPos+1;i<n;i++){
        posCount[i+1] = posCount[i];
      }
      break;
    }
  }
  /*
  for(auto c:posCount){
    cout << c << " ";
  }
  cout << endl;
  */

  int l,r;
  for(int i=0;i<q;i++){
    cin >> l >> r;
    cout << posCount[r-1]-posCount[l-1] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3860
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5+3;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int n;
	cin>>n;
	rep(i, n/4+2){
		rep(j, n/7 + 2){
			if(i*4+j*7 == n){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define MOD 998244353
#define MAX 1000005
#define loop(i,a,b) for(long long int i=a;i<b;i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
typedef long long int ll;

using namespace std;
//using namespace boost::multiprecision;

ll prime[MAX];
void sieve()
{
	prime[1] = 1;
	for(ll i=2;i<MAX;i++)
	if(prime[i]==0)
	for(ll j=i;j<MAX;j+=i)
	prime[j]=i;
}

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

//sieve();


ll t=1;
//cin>>t;

loop(k,0,t)
{
	ll x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<"\n";
}



return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	vl a(n),b(n),c(n);
	rep(i,0,n)cin>>a[i];
	rep(i,0,n)cin>>b[i];
	rep(i,0,n)cin>>c[i];
	sort(all(a)); sort(all(b)); sort(all(c));
	ll ans=0;
	vl s(n),t(n);
	rep(i,0,n){
		ll k=b[i];
		ll p=lower_bound(all(a),k)-a.begin();
		ll q=c.end()-upper_bound(all(c),k);
		ans+=q*p;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 7204
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

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

int main() {
  vector<int> ans;
  int A, B, K; cin>>A>>B>>K;
  for(int i = 1; i <= max(A, B); i++) {
    if(A % i == 0 && B % i == 0) {
      ans.push_back(i);
    }
  }
  cout << ans[ans.size()-K] << endl;
  return 0;
}


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

using namespace std;


int main(void)
{
	long int a,b,k;
	cin>>a>>b>>k;
	if(a >= k){
		//cout<<a-k<<" "<<b<<endl;
		printf("%ld %ld\n",a-k,b);
	}
	else if(a < k && a+b > k){
		//cout<<"0 "<<a+b-k<<endl;
		printf("0 %ld\n",a+b-k);
	}
	else{
		printf("0 0\n");
		//cout<<"0 0"<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
using namespace std;
int main() {
	int n, ans1 = 0, ans2 = 0;
	vector<int> a, b, ans;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a1;
		cin >> a1;
		a.emplace_back(a1);
	}
	for (int j = 0; j < n; j++) {
		int b1;
		cin >> b1;
		b.emplace_back(b1);
		ans.emplace_back(n - j);
	}
	for (int k = 0; k < 100000; k++) {
		if (equal(ans.begin(), ans.end(), a.begin())) {
			ans1 = k;
			break;
		}
		else {
			next_permutation(a.begin(),a.end());
		}
	}
	for (int l = 0; l < 100000; l++) {
		if (equal(ans.begin(), ans.end(), b.begin())) {
			ans2 = l;
			break;
		}
		else {
			next_permutation(b.begin(), b.end());
		}
	}
	if (ans1 >= ans2) {
		cout << ans1 - ans2 << endl;
		return 0;
	}
	else {
		cout << ans2 - ans1 << endl;
		return 0;
	}
}

Measured memory_bytes: 256
n=int(input())
P=[int(i) for i in input().split()]
n_max=10**5
nn=n_max.bit_length()+1
BIT=[0]*(2**nn)
BIT.insert(0,0)
def bitsum(BIT,i):
  s=0
  while i>0:
    s+=BIT[i]
    i-=i&(-i)
  return s
def bitadd(BIT,i,x):
  while i<=2**nn:
    BIT[i]+=x
    i+=i&(-i)
  return BIT
def bitlb(BIT,s):
  if s<=0:
    return 0
  else:
    ret=0
    k=2**nn
    while k>0:
      if k+ret<=2**nn and BIT[k+ret]<s:
        s-=BIT[k+ret]
        ret+=k
      k//=2
    return ret+1
D=dict()
for i in range(n):
  D[P[i]]=i+1
PP=sorted(P,reverse=True)
bitadd(BIT,D[PP[0]],1)
ans=0
for i in range(1,n):
  cur=D[PP[i]]
  bitadd(BIT,cur,1)
  tot=bitsum(BIT,cur)
  l2,l1,r1,r2=bitlb(BIT,tot-2),bitlb(BIT,tot-1),min(n+1,bitlb(BIT,tot+1)),min(n+1,bitlb(BIT,tot+2))
  add=PP[i]*((-l1+cur)*(r2-r1)+(l1-l2)*(r1-cur))
  ans+=add
print(ans)

Measured memory_bytes: 66540
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

int N;
LL Z,W;
LL a[2000];

LL labs(LL x){
    if(x<0)
        return -x;
    else
        return x;
}

LL cache[2000][2];

LL rec(int n,int p){
    LL &r=cache[n][p];
    int op=(p==0)?1:0;
    if(r!=-1){
        ;
    }else if(p){
        LL Y=(n==0)?W:a[n-1];
        r=labs(Y-a[N-1]);
        for(int i=n;i<N-1;i++)
            r=max(r,rec(i+1,op));
    }else{
        LL X=a[n-1];
        r=labs(X-a[N-1]);
        for(int i=n;i<N-1;i++)
            r=min(r,rec(i+1,op));
    }
    return r;
}

int main(void){
    scanf("%d%lld%lld",&N,&Z,&W);
    REP(i,N)
        scanf("%lld",a+i);
    memset(cache,-1,sizeof(cache));
    printf("%lld\n",rec(0,1));
     return 0;
}

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

int n; 
long long a, b;

bool isOK(long long count, const vector<int> &v) {
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        if (v.at(i) - b * sum <= 0) return true;
        
        long long c = ceil(((double)(v.at(i) - b * sum) - b * count) / (a - b));
        if (c > count) return false;
        else {
            count -= c;
            sum += c;
        }
    }

    return true;
}

// 二分探索
long long binary_search(const vector<int> &v) {
    long long ng = -1;
    long long ok = 1'000'000'000ll;

    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;

        if (isOK(mid, v)) ok = mid;
        
        else ng = mid;
        
    }
    return ok;
}

int main() {
    cin >> n >> a >> b;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());
    
    cout << binary_search(h) << endl;
}   

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class EDivisibleSubstring {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, P;
        cin >> N >> P;
        string s;
        cin >> s;
        reverse(s.begin(), s.end());

        if (P == 2 || P == 5) {
            int res = 0;
            REP(i, N) {
                int n = s[i] - '0';
                if (n % P == 0) {
                    res += N - i;
                }
            }
            cout << res << endl;
            return;
        }

        vector<int> v(N), sum(N + 1);
        REP(i, N) {
            int n = s[i] - '0';
            v[i] = n % P;
        }

        int cur = 1;
        REP(i, N) {
            sum[i + 1] = (sum[i] + v[i] * cur) % P;
            cur *= 10;
            cur %= P;
        }

        map<int, int> cnt;
        int res = 0;
        REP(i, N + 1) {
            res += cnt[sum[i]];
            cnt[sum[i]]++;
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    EDivisibleSubstring solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 4244
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

#define ll long long
#define MOD 1000000007

int main(){
    ll N, K, ans = 0;
    cin >> N >> K;
    for(ll i = K; i < N + 2; i++){
        ans += (i * N - i * (i - 1) / 2) - i * (i - 1) / 2 + 1;
    }
    cout << ans%MOD << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  bool ans = false;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      if (N == i * j) {
        ans = true;
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int mod){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%mod;Rac[n-1]=modInv(Fac[n-1],mod);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 1e5;
string s;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  FOR(i, 0, sz(s)) cout << 'x'; cout << endl;
}

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

def main():
    N = int(input())
    s = []
    for i in range(N):
        s.append("".join(sorted(list(input().strip()))))
    s = sorted(s)
    # print(s)
    tmp = []
    pre = s[0]
    count = 1
    for i in range(1, N):
        if s[i] == pre:
            count += 1
        else:
            if count > 1:
                tmp.append(count)
            count = 1
        if i == N-1:
            if count > 1:
                tmp.append(count)
        pre = s[i]
    ans = 0
    for n in tmp:
        ans += (n * (n-1))//2
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 11380
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b);i++)
#define repv(vec,v) for(v=(vec).begin(); v!=(vec).end();v++)
#define sz(vec) (int)(vec).size()
#define PB push_back
#define F first
#define S second

ll comb2(ll n){ // n! / ((n-2)! * 2!)
	return n*(n-1)/2;
}


int main(){
	ll n,m;
	cin >> n >> m;
	
	cout << comb2(n) + comb2(m);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        System.out.println(max(a + b, a - b, a * b));
        inp.close();
    }
    public static int max(int... args) {
        int r = args[0];
        int s = 0;
        for (int i = 1; i < args.length; i++) {
            s = Math.max(args[i - 1], args[i]);
            if (s >= r) r = s;
        }
        return r;
    }
}


Measured memory_bytes: 23252
#include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(void)
{
	int x, y, s;
	while(cin >> x >> y >> s, x > 0){
		int ans = 0;
		for(int i=1; i<=s-1; i++){
			int j = s-i;
			int x1, x2, y1, y2;
			x1 = (i*100+100+x-1)/(100+x);
			x2 = (j*100+100+x-1)/(100+x);
			if (x1*(100+x)/100!=i || x2*(100+x)/100!=j){
				continue;
			}
			y1 = x1*(100+y)/100;
			y2 = x2*(100+y)/100;
			ans = max(ans, y1+y2);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>

int main() {
    int n, b, f, r, v, s;
    int xs[4*3*10];
    s = sizeof(xs)/sizeof(*xs);
    for(int i=0; i<s; i++) {xs[i]=0;}
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        xs[(b-1)*30+(f-1)*10+(r-1)] += v;
    }
    for(int i=0; i<s; i++) {
        if(i%30 == 0 && i != 0) printf("####################\n");
        printf(" %d", xs[i]);
        if((i+1)%10 == 0) printf("\n");
    }
}


Measured memory_bytes: 2692
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
     
template<typename T>
T gcd(T a, T b){
	return b != 0 ? gcd(b, a % b) : a;
}    

int main() {
  ll x=0,y=0,z=0,k,n,m,h,w,ans=0,sum=0,Max=-1,Min=1e9+1;
  bool ok = true;
  string s,t,r;
  cin >> n >> k;
  for(ll i=k; i<=n+1; i++){
    ll l = i*(i-1)/2;
    ll r = n*i - l;
    ans += r-l+1;
  }
  cout << ans%mod << endl;
  return 0;
}

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

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

    int n;
    cin >> n;

    for(int i = 1; i <= 9; i++){
        for(int j =1; j <=9; j++){
            if(i * j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a;
	cin >> a;
	if(a>='a' && a<='z'){
  		cout << "a" << endl;
    }
  	if(a>='A' && a<='Z'){
      	cout << "A" << endl;
    }
} 

Measured memory_bytes: 3540
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int sm(int x) {
    int s = 0;
    while (x > 0) {
        s += x % 10;
        x /= 10;
    }
    return s;
}

int main() {
    int k;
    scanf("%d", &k);
    vector<bool> used(k);
    vector<int> dst(k);
    set<pair<int, int>> st;
    for (int i = 1; i <= k; i++) {
        dst[i % k] = sm(i);
        st.insert({dst[i % k], i % k});
    }

    while (!st.empty()) {
        auto p = *st.begin();
        st.erase(st.begin());
        int m = p.second;
        int d = p.first;
        if (m == 0) {
            cout << d << endl;
            return 0;
        }
        for (int x = 0; x < 10; x++) {
            int m1 = (m * 10 + x) % k;
            int d1 = d + x;
            if (d1 < dst[m1]) {
                st.erase({dst[m1], m1});
                dst[m1] = d1;
                st.insert({dst[m1], m1});
            }
        }
    }

    return 0;
}

Measured memory_bytes: 5376
def main():
    n = int(input())
    v = list(map(int, input().split()))
    
    if len(v) == 1:
        return
    
    v = sorted(v, reverse=True)
    ans = (v.pop() + v.pop()) / 2
    
    while v != []:
        v = sorted(v, reverse=True)
        ans = (ans + v.pop()) / 2
        
    print(ans)
    
if __name__ == '__main__':
    main()

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

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

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

    cout << LCM(n,m) << endl;



}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    ll i, o, t, j, l, s, z;
    cin >> i >> o >> t >> j >> l >> s >> z;

    ll ans = o;

    ll c = min({i, j, l});
    ans += 3 * c;
    i -= c; j -= c; l -= c;

    ans += i / 2 * 2; i %= 2;
    ans += j / 2 * 2; j %= 2;
    ans += l / 2 * 2; l %= 2;

    if (i + j + l == 2 && c > 0) ans++;

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int l;
int q;
int x[maxn];
int ne[maxn][21];

int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
    //freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
    gbtb;
    cin>>n;

    repd(i,0,n-1)
    {
        cin>>x[i];
    }
    cin>>l;
    repd(i,0,n-1)
    {
        ne[i][0]=lower_bound(x+i,x+n,x[i]+l+1)-x-1;
    }
    repd(i,0,19)
    {
        rep(j,0,n)
        {
            ne[j][i+1]=ne[ne[j][i]][i];
        }
    }
     cin>>q;
     int xx,yy;
     while(q--)
     {
        cin>>xx>>yy;
        xx--;
        yy--;
        if(xx>yy)
        {
            swap(xx,yy);
        }
        int day=0;
        for(int i=19;i>=0;i--)
        {
            if(ne[xx][i]<yy)
            {
                xx=ne[xx][i];
                day+=1<<i;
            }
        }
        cout<<day+1<<endl;
     }
    
    
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



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

using namespace std;

long long INF = 1e18;

long long solve() {
    int n;
    cin >> n;
    vector<long long> a(n+1);
    vector<long long> mxLvl(n+1, 1);
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
        if (i > 0) {
            mxLvl[i] = min(INF, 2*mxLvl[i-1]);
        }
    }

    long long prevL = 0;
    long long prevR = 0;
    vector<pair<long long, long long>> b(n+1);
    for (int i = n; i >= 0; i--) {
        long long curL = a[i] + prevL/2 + (prevL%2 == 0 ? 0 : 1);
        long long curR = min(a[i] + prevR, mxLvl[i]);
        if (curL > curR) {
            return -1;
        }
        b[i] = {curL, curR};
        prevL = curL;
        prevR = curR;
    }
    long long mxCur = 1;
    long long ans = 0;
    for (int i = 0; i <= n; i++) {
        long long cur = min(mxCur, b[i].second) - a[i];
        mxCur = min(2*cur, INF);
        ans += a[i] + cur;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << solve() << endl;
}



Measured memory_bytes: 6340
n = int(input())
l = list(map(int, input().split()))

ss = []
s = 0
for i in range(1, n):
  if l[i-1] >= l[i]:
    s += 1
  else:
    ss.append(s)
    s = 0
else:
  ss.append(s)
print(max(ss))
    
  

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

int main () {
  int N;
  cin >> N;
  int A,B,C,D;
  D = N%10;
  N /= 10;
  C = N%10;
  N /= 10;
  B = N%10;
  N /= 10;
  A = N;
  string op1,op2,op3;
  vector<string> ops(3);
  ops = {op1,op2,op3};
  vector<int> vec(3);
  vec = {B,C,D};

  // すべての選び方を試して、総和がKになるものがあるかを調べる
  for (int tmp = 0; tmp < (1 << 3); tmp++) {
    bitset<3> s(tmp);  // 最大20個なので20ビットのビット列として扱う

    // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    int sum = A;
    for (int i = 0; i < 3; i++) {
      if (s.test(i)) {
        sum += vec.at(i);
        ops[i] = "+";
      }
      else
      {
        sum -= vec[i];
        ops[i] = "-";
      }
      
    }
    if (sum == 7) {
      break;
    }
  }
  cout << A << ops[0] << B << ops[1] << C << ops[2] << D << "=" << 7 << endl;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,m,x;
  cin >> n >> m >> x;
  ll cl=0,cr=0;
  REP(i,m){
    ll a;
    cin >> a;
    if(a<x) cl++;
    else cr++;
  }
  cout << min(cl,cr) << endl;
  return 0;
}


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




// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
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;}


// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(10005);


//nPk
 mint f(int n, int k) {
    if (n < 0) return 0;
    // nPk = nCk * k!
    mint res = comb(n,k);
    res *= comb.fact[k];
    return res;
}




//組み合わせの数nCrを計算
   int calcNumOfCombination(int n, int r){
       int num = 1;
       for(int i = 1; i <= r; i++){
           num = num * (n - i + 1) / i;
       }
       return num;
   }

mint dp[13][100005];
int main() {
rep(i,13)rep(j,100005)dp[i][j]=0;
dp[0][0]=1;
string s;
cin>>s;
ll t=1;
rep(i,s.size()){
  char C=s[s.size()-1-i];
  if (C!='?'){
    ll c=s[s.size()-1-i]-'0';
    ll temp=c*t;
    temp%=mod;
  //  temp%=13;
    rep(j,13){
      dp[(temp+j)%13][i+1]+=dp[j][i];
    }
  }
  else{
    rep(k,10){
      ll temp=k*t;
      temp%=mod;
      rep(j,13){
        dp[(temp+j)%13][i+1]+=dp[j][i];
      }
    }
  }
  t*=10;
  t%=13;
}
cout<<dp[5][s.size()];

}


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

#define vi vector<int>

int main() {

    int N;
    cin >> N;

    vi C, S, F;
    int c, s, f;

    for (int i = 0; i < N-1; i++) {
        cin >> c >> s >> f;
        C.push_back(c);
        S.push_back(s);
        F.push_back(f);
    }

    int time;
    for (int i = 0; i < N-1; i++) {
        time = S[i] + C[i];
        for (int j = i+1; j < N-1; j++) {
            if (time <= S[j]) {
                time = S[j] + C[j];
            }
            else {
                time = S[j] + ((time - S[j] - 1) / F[j] + 1) * F[j] + C[j];
            }
        }
        cout << time << endl;
    }
    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256