akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using static Assistant.Input;
using static Assistant.Debug;
using System.Linq;
using Assistant;

namespace ABC112A
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = ReadInt;
            if (A == 1)
            {
                Console.WriteLine("Hello World");
            }
            else
            {
                var a = ReadInt;
                var b = ReadInt;
                Console.WriteLine(a + b);
            }




        }


    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] ReadLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        static public void Draw2D(int[,] map, int mode = 1)
        {
#if DEBUG
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
#endif
        }

        public static void Draw1D(int[] array, int mode = 0)
        {
#if DEBUG
            Console.WriteLine(string.Join(" ", array));
#endif
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<vector>
#include<set>
#include<unordered_map>
using namespace std;

int gcd(int a,int b){


	if(a==0||b==0){
		return a+b;
	}
	return gcd(b%a,a);
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	long long int a,b;
	cin>>a>>b;
	int k = gcd(a,b);

	cout<<(a*b*1ll)/k;



}



Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
vector<int> w,v;

long int dpv[100001][101];
long int dp(int W,int N)
{
	if(dpv[W][N])
		return dpv[W][N];
	if(W==0 || N==0)
		return 0;
	if(w[N]<=W)
		dpv[W][N]=max(dp(W-w[N],N-1)+v[N],dp(W,N-1));
	else
		dpv[W][N]=dp(W,N-1);
	return dpv[W][N];
}
int main()
{
  	w.pb(0);v.pb(0);
	int N,W,i,w1,v1;
	cin>>N>>W;
	for(i=1;i<=N;i++)
	{
		cin>>w1>>v1;
		w.pb(w1);
		v.pb(v1);	
	}
	cout<<dp(W,N);
}

Measured memory_bytes: 78848
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll L,R,ans=2019;
  cin>>L>>R;
  if(R-L>=2018){cout<<0<<endl;return 0;}
  else{
    for(ll i=L;i<=R-1;i++){
      for(ll j=i+1;j<=R;j++){ans=min(ans,i*j%2019);}
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

vec on(0);
struct edge{
    int id, to;
    edge(){}
    edge(int a, int b){
        to = a;
        id = b;
    }
};
vector<vector<edge> > G(int(1e+5) + 1, vector<edge>(0));
vector<bool> ans(int(2e+5) + 10, false), used(int(1e+5) + 1, false);
int dfs(int v, int p){
    used[v] = true;
    int res = on[v];
    for(edge e : G[v]){
        if(!used[e.to]){
            res += dfs(e.to, e.id);
        }
    }
    if(p != -1){
        if(res&1) ans[p] = true;
        return res;
    }else{
        if(res&1) return 0;
         return 1;
    }
}

int main() {
    cin>>N>>M;
    vec tl(M), tr(M);
    vector<P> pa(N);
    rep(i, N) {
        cin>>pa[i].fi>>pa[i].se;
    }
    pa.insert(pa.begin(), make_pair(-1, 0));
    pa.emplace_back(int(1e+9) + 10, 0);
    N += 2;
    sort(ALL(pa));
    rep(i,N) on.push_back(pa[i].se == 1);
    rep(i,N - 1) on[i] = (on[i+1] != on[i]);
    on[N - 1] = false;
    rep(i,M) cin>>tl[i]>>tr[i];
    vec a(N), l(M), r(M);
    rep(i,N) a[i] = pa[i].fi;
    rep(i,M){
        l[i] = lower_bound(ALL(a), tl[i]) - a.begin();
        r[i] = upper_bound(ALL(a), tr[i]) - a.begin();
        --l[i];
        --r[i];
        G[l[i]].emplace_back(r[i], i);
        G[r[i]].emplace_back(l[i], i);
    }
    rep(i,N) {
        if(!used[i]) {
            if(!dfs(i, -1)) {
                cout<<-1<<endl;
                return 0;
            }
        }
    }
    int num = 0;
    rep(i,M) num += ans[i];
    cout<<num<<endl;
    rep(i,M) {
        if(ans[i]){
            --num;
            cout<<i + 1;
            num != 0 ? cout<<' ' : cout<<endl;
        }
    }
    if(num == 0) cout<<endl;
}

Measured memory_bytes: 23268
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>

#define rep(i,n) for(long long int (i)=0;(i)<n;(i)++)
#define repa(i,n) for(long long int (i)=0;i<=n;i++)
#define co(a) cout<<(a)<<endl;
typedef long long ll;
using namespace std;

int main(){
  int n,j=0,d,e,f=0;
  cin >> n;
  int a[n],c[n];
  rep(i,n) {cin >> a[i];
  	c[i]=0;}
  for(int i=0;i<n-1;i++){
  	while(a[i+1]==a[i]){
  		c[j]++;
  		i++;
  		}
  	j++;
  }
  for(int i=0;i<n;i++){
  	d=c[i]%2;
  	if(d==0){
  		e=c[i]/2;
  	}
  	else{
  		e=(c[i]+1)/2;
  	}
  	f+=e;
  }
cout << f << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,m;cin>>n>>m;
    ll ans=0;
    ll kai[10000];
    kai[0]=1;
    rep(i,1,10000)kai[i]=kai[i-1]*i%m;
    rep(i,0,3*n+1){
        rep(j,0,3*n+1){
            ll a=3*n-3*i-2*j;
            ll b=j;
            ll c=i;
            if(a<b)break;
            //cout<<a<<" "<<b<<" "<<c<<endl;
            ll sum=kai[3*n];
            (sum*=gyaku(kai[a],m))%=m;
            (sum*=gyaku(kai[b],m))%=m;
            (sum*=gyaku(kai[c],m))%=m;
            ll y=beki(kai[3],c,m);
            (y*=beki(kai[2],b,m))%=m;
            (sum*=gyaku(y,m))%=m;
            (sum*=beki(2,c,m))%=m;
            (ans+=sum)%=m;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
	for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
	for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
	os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")";
	return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 2e3 + 100;
ll dis[N];

int main(){
	fio; cout<<fixed<<setprecision(25);	
	int n , x , y;
	cin >> n >> x >> y;

	// for(int i = 1;i < x ; ++i){
	// 	int dis = 0;
	// 	int tmp = -1;
	// 	for(int j = i+1;j <= n ; ++j){
	// 		if(j <= x){
	// 			++dis;
	// 			tmp = dis;
	// 		}
	// 		else if(j > x && j < y){
	// 			dis = min(tmp + j-x , tmp+1 - (y-j));
	// 		}
	// 		else if(j == y){
	// 			dis = tmp+1;
	// 		}
	// 		else{
	// 			++dis;
	// 		}
	// 		++ans[dis];
	// 	}
	// }
	for(int i = 1;i <= n ; ++i){
		
		for(int j = i+1 ;j <= n ; ++j){
			int ans = n;
			ans = min(ans , abs(j-i));
			ans = min(ans , abs(i-x) + abs(y-j)+1);
			ans = min(ans , abs(i-y) + abs(x-j)+1);
			dis[ans]++;
		}

	}

	for(int i = 1;i < n;  ++i){
		cout << dis[i] << endl;
	}





	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <string.h>

int main() {

    int eachalphabetnum[26];

    for (int i = 0;i<26;i++) {
            eachalphabetnum[i] = 0;
        }

    char s[1200];

    while (scanf("%s", s) != EOF) {

        

        for(int i = 0; s[i] != '\0'; i++) {

            char c = s[i];

            if (c >= 65 && c <= 90) {
                eachalphabetnum[c-65]++;
            } else if (c >= 97 && c <= 122) {
                eachalphabetnum[c-97]++;
            }

        }
    }   


    for (int i = 0; i<26;i++) {
        char d = i + 97;
        std::printf("%c : %d\n",d,eachalphabetnum[i]);
    }


}


Measured memory_bytes: 2716
//
//  main.cpp
//  ABC161D
//
//  Created by KJC of Kindai University on 2020/04/09.
//  Copyright © 2020 KJC of Kindai University. All rights reserved.
//

#include <iostream>
#include <queue>
using namespace std;
int main(int argc, const char * argv[]) {
    int K;
    cin>>K;
    queue<unsigned long>Q;
    for (unsigned long i=1; i<10; i++) {
        Q.push(i);
    }
    unsigned long x;
    for (int i=1; i<K; i++) {
        x=Q.front();  // 先頭を取り出して
        Q.pop();     // 先頭を削除
        if (x%10!=0) {
            Q.push(10*x+(x%10)-1);
        }
            Q.push(10*x+(x%10));
        if (x%10!=9) {
            Q.push(10*x+(x%10)+1);
        }
    }
    cout<<Q.front()<<endl;

    return 0;
}


Measured memory_bytes: 1792
use std::io::stdin;
use std::io::BufRead;
use std::io::BufReader;

fn main() {

    let mut st = String::new();
 
    std::io::stdin().read_line(&mut st)
        .expect("Failed to read line");
 
    let st: i32 = st.trim().parse()
        .expect("Please type a number");

    let mt: i32 = st/60;

    let h: i32 = mt/60;
    
    let m: i32 = mt-(h*60);
    
    let s: i32 = st-((h*3600)+(m*60));
    
    println!("{}:{}:{}", h, m, s);
}


Measured memory_bytes: 5036
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;

ll my_gcd(ll a, ll b){
	return (b==0) ? a : my_gcd(b, a%b);
}

ll my_lcm(ll a, ll b){
	return a*b / my_gcd(a,b);
}

ll factorial(ll a){
	ll ans = 1;
	for(ll i=a; i>0; i--){
		ans *= i;
	}
	return ans;
}

ll pow(ll a, ll b) {
	ll a_powered = 1;
	for (int i=0; i<b; i++) { a_powered *= a;
	}
	return a_powered;
}


int main(int argc, char *argv[]){
	int N; cin >> N;
	vector<int> v(N);
	for(int i=0; i<N; i++){
		cin >> v[i];
	}

	sort(v.begin(), v.end());
	double ans = v[0];
	for(int i=1; i<N; i++){
		ans = (double)((ans + v[i])/2);
	}

	cout << scientific;
	cout << ans << endl;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i = 0; i < N; i++)
    cin >> h.at(i);
  int count = 0;
  for(int i = 0; i < N; i++){
    if(h.at(i) >= K)
      count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 640
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val Array(n, m, s, g) = readLine.trim.split(' ').map(_.toInt)
  val edges = Array.tabulate(n){_ ⇒ Nil: List[(Int, Edge)]}
  for (_ ← 0 until m){
    val Array(u, v, a, b) = readLine.trim.split(' ').map(_.toLong)
    val edge = Edge(a, b)
    edges(u.toInt - 1) ::= (v.toInt - 1, edge)
    edges(v.toInt - 1) ::= (u.toInt - 1, edge)
  }
  val minTime = Array.tabulate(n){ _ ⇒ Long.MaxValue}.also{ arr ⇒ arr(s - 1) = 0l}
  val queue = mutable.PriorityQueue()(Ordering.by[(Int, Long), Long](_._2).reverse).also{que ⇒ que.enqueue((s - 1, 0l))}
  while (queue.nonEmpty){
    val (top, current) = queue.dequeue()
    if (minTime(top) == current){
      for ((next, edge) ← edges(top)){
        if (edge.minTime >= current){
          val near = List(edge.minTime.ceil.toLong, edge.minTime.floor.toLong).map{t ⇒ t + edge.costAt(t)}.min
          if (minTime(next) > near) {
            minTime(next) = near
            queue.enqueue((next, near))
          }
        }else if (minTime(next) > edge.costAt(current) + current){
          minTime(next) = edge.costAt(current) + current
          queue.enqueue((next, minTime(next)))
        }
      }
    }
  }
  println(if (minTime(g - 1) == Long.MaxValue) -1 else minTime(g - 1))
  case class Edge(private val a: Long, private val b: Long) {
    def costAt(time: Double): Long = math.ceil(b / (time + a)).toLong
    def minTime: Double = {
      val time = math.sqrt(b) - a
      if (time >= 0) time
      else 0d
    }
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, m;
PII a[N];
HEAP heap;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i ++ ) scanf("%d%d", &a[i].F, &a[i].S);
	sort(a, a + n);
	
	int res = 0, j = 0;
	for (int i = 1; i <= m; i ++ )
	{
		int k = j;
		while (k < n && a[j].F == i)
		{
			heap.push(a[j].S);
			j ++ ;
		}
		
		if (heap.size())
		{
			res += heap.top();
			heap.pop();
		}
	}
	
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 1660
fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }
    val sum = a.sum()
    var subsum = 0L
    a.take(n-1).map {
        subsum += it
        Math.abs(sum - 2 * subsum)
    }.min().let(::println)
}

Measured memory_bytes: 83156
N,K = map(int,input().split())
D = list(map(int,input().split()))
l = [i for i in range(10)]
for i in range(K):
  l.remove(D[i])

ansl = []
def dfs(s):
  if len(s) < len(str(N))+1:
    for i in l:
      new = s+str(i)
      ansl.append(int(new))
      dfs(new)
dfs("")
ansl.sort()
for i in ansl:
  if i >= N:
    print(i)
    break

Measured memory_bytes: 5720
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
struct tur{
	int x,y;
}q[100001];
int c[501],n,m,ans;
inline bool check(int x,int y){
	memset(c,0,sizeof(c));
	c[x]=c[y]=1;
	for (int i=m; i>=1; i--){
		if (c[q[i].x]&&c[q[i].y]) return false;
		if (c[q[i].x]) c[q[i].y]=1;
		else if (c[q[i].y]) c[q[i].x]=1;
	}
	return true;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1; i<=m; i++)
		scanf("%d%d",&q[i].x,&q[i].y);
	for (int i=1; i<=n; i++)
		for (int j=1+i; j<=n; j++){
			if (check(i,j)) ans++;
		}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;


int main()
{
    int N;
	cin >> N;
	char c[200001];
	int rcnt = 0;
	int wcnt = 0;
	
	for(int i= 0; i< N; i++) {
		cin >> c[i];
		if(c[i] == 'W') wcnt++;
		if(c[i] == 'R') rcnt++;
	}
	
	int cnt = 0;
	for(int i = 0; i < rcnt; i++) {
		if(c[i] == 'W') cnt++;
	}
	
	
	printf("%d\n", cnt);
	
    return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;




void ABC143E()
{
	int N, M, L;
	cin >> N >> M >> L;
	vvi dist(N, vi(N, 1000000009));
	vvi cost = dist;
	for (int i = 0; i < M; ++i)
	{
		int A, B, C;
		cin >> A >> B >> C;
		--A; --B;
		dist[A][B] = C;
		dist[B][A] = C;
	}

	for (int k = 0; k < N; ++k)
	{
		for (int i = 0; i < N; ++i)
		{
			for (int j = 0; j < N; ++j)
			{
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[j][k]);
			}
		}
	}

	vvi graph(N, vi(N, 1000000009));
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < i; ++j)
		{
			if (dist[i][j] <= L)
			{
				graph[i][j] = 1;
				graph[j][i] = 1;
			}
		}
	}

	for (int k = 0; k < N; ++k)
	{
		for (int i = 0; i < N; ++i)
		{
			for (int j = 0; j < N; ++j)
			{
				graph[i][j] = min(graph[i][j], graph[i][k] + graph[j][k]);
			}
		}
	}

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; ++i)
	{
		int s, t;
		cin >> s >> t;
		--s; --t;
		if (graph[s][t] == 1000000009)
		{
			cout << -1 << endl;
		}
		else
		{
			cout << graph[s][t] - 1 << endl;
		}
	}

}

int main()
{
	ABC143E();
	return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
char cc[10][10],b[10][10];
int r[10],c[10],n,m,k,ans;
void dfs(int x,int y){
	int i,j;
	if(x>n&&y>m){
		for(i=1;i<=n;i++)
			for(j=1;j<=m;j++)b[i][j]=cc[i][j];
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				if(c[i]==1)b[i][j]='.';
				if(r[j]==1)b[i][j]='.';
			}
		}
		int cnt=0;
		for(i=1;i<=n;i++){
			for(j=1;j<=m;j++){
				if(b[i][j]=='#')cnt++;
			}
		}
		if(cnt==k)ans++;
		return ;
	}
	if(x<=n){
		c[x]=1;dfs(x+1,y+1),c[x]=0;
	}
	if(y<=m){
		r[y]=1,dfs(x+1,y+1);r[y]=0;
	}
	if(x<=n&&y<=m){
		c[x]=r[y]=1;dfs(x+1,y+1);c[x]=r[y]=0;
	}
	dfs(x+1,y+1);
}
int main(){
	int i,j;
	cin>>n>>m>>k;
	for(i=1;i<=n;i++)cin>>cc[i]+1;
	dfs(1,1);
	cout<<ans;
} 

Measured memory_bytes: 3624
#include<stdio.h>
    
   int S[1000000],N,x;
int solve(int i,int m){
if(m==0){
return 1;
}
if(i>=N){
return 0;
}
 x =solve(i+1,m)||solve(i+1,m-S[i]);
return x;
}


int main(){
   
int i,k,q; 

    
    scanf("%d", &N);
     for ( i = 0; i < N; i++ ){ 
scanf("%d", &S[i]);
}
     
 scanf("%d", &q);
     for ( i = 0; i < q; i++ ){ 
scanf("%d", &k);
 
if(solve(0,k)){
printf("yes\n");
}
else printf("no\n");
}    
return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<assert.h>

#define max(a,b) ((a)>(b))?(a):(b)
#define min(a,b) ((a)>(b))?(b):(a)

typedef long long ll;
typedef unsigned long long ull;

int main(void)
{
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    printf("%d %d %d\n", z, x, y);
}


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

int main()
{
    string s;
    cin >> s;
    string t;
    cin >> t;

    t.pop_back();

    if (t == s) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const int N = 14;
string s; int n,pw[N];vector<char> w; vector<vector<char> > f,g; vector<int> h,p;
inline int get(int x,int l){ return x % pw[l]; }
inline void add(vector<char> &s,char c) {
	if (c == 'R') s.push_back(c);
	else if (s.size() && s[s.size()-1] == 'S') s.pop_back();
	else s.push_back(c);
}
int main(){
	int i;
	cin >> n >> s;
	for (pw[0] = i = 1; i <= 12 ; ++i) pw[i] = pw[i-1]*3;
	for (i = 0; i < s.size(); ++i) w.push_back(s[i]);
	f.push_back(w),h.push_back(0);
    for (i = 1; i <= n; ++i){
		g.resize(pw[i]),p.resize(pw[i]);
        for(int now = 0; now < pw[i] ; ++now) {
			int cur = get(now,i-1);
			p[now] = h[cur];
			int d = now/pw[i-1]%3;
			for (auto v : f[cur]){
				if(v == 'S') d = (d<<1)%3,add(g[now],v);
				else if(d == 2) d = 0,add(g[now],v);
				else d += 1;
			}
			p[now] += d*pw[i-1];
		}
		h.clear(),f.clear(),swap(f,g),swap(h,p);
	}
	for (i = 0; i < pw[n]; ++i) cout << h[i] << ((i<pw[n]-1) ? (' ') : ('\n'));
	return 0;
}

Measured memory_bytes: 45964
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

ll sum(ll left,ll right){
    ll r=right*(right+1)/2;
    ll l=(left-1)*left/2;
    return r-l;
}

int main (){
    ll n,k;
    ll ans=0;
    cin >> n >> k;
    for(ll i=k;i<=n+1;i++){
        ll left=sum(0,i-1);
        ll right=sum(n-i+1,n);
        ll sub=right-left+1;
        sub%=mod;
        ans+=sub;
        ans%=mod;

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


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

#define REP(i,s,N) for(int i=s;i<N;++i)

using VINT = vector<int>;

int search(const vector<int> &x, int key) {
	VINT::const_iterator it = lower_bound(x.begin(), x.end(), key);
	if (*it == key) return 1;
	return 0;
}

int main() {
	int n; cin >> n;
	vector<int> na(n,0);
	REP(i,0,n) cin >> na[i];
	int q; cin >> q;
	int ans = 0;
	REP(i,0,q) {
		int t; cin >> t;
		ans += search(na,t);
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 3108
import java.util.*;

public class Main {

	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		player playersArray[][]=new player[3][8];
		player threeArray[]=new player[3];
		for(int i=0;i<3;i++){
			for(int j=0;j<8;j++){
				playersArray[i][j]=new player(sc.nextInt(),sc.nextDouble());
			}
		}
		for(int i=0;i<3;i++){
			Arrays.sort(playersArray[i]);
		}
		for(int i=0;i<3;i++){
			threeArray[i]=playersArray[i][2];
		}
		Arrays.sort(threeArray);
		
		for(int i=0;i<3;i++){
			for(int j=0;j<2;j++){
				System.out.println(playersArray[i][j].toString());
			}
		}
		System.out.println(threeArray[0].toString());
		System.out.println(threeArray[1].toString());
	}
	static class player implements Comparable<player>{
		int number;
		double time;
		player(int number,double time){
			this.number=number;
			this.time=time;
		}
		@Override
		public String toString(){
			return number+" "+time;
		}
		@Override
		public int compareTo(player obj){
			if(this.time<obj.time)return -1; //自分よりもobjが大きければ-1
			if(this.time>obj.time)return 1;//自分よりもobjが小さければ1
			return 0;//自分と同じならば0
		}
	}

}

Measured memory_bytes: 20200
import sys
from itertools import accumulate
import bisect
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
sum_ls = [i for i in accumulate(a_ls[:-1])]
sum_a = sum(a_ls)
sum_ls.sort()
ind = bisect.bisect_left(sum_ls, sum_a / 2)
best = 10 ** 18
if ind < n - 1 and abs(sum_a / 2 - sum_ls[ind]) * 2 < best:
    best = abs(sum_a / 2 - sum_ls[ind]) * 2
if ind > 0 and abs(sum_a / 2 - sum_ls[ind - 1]) * 2 < best:
    best = abs(sum_a / 2 - sum_ls[ind - 1]) * 2
print(int(best))

Measured memory_bytes: 24388
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K;
	cin >> N >> K;

	cout << (N%K != 0 ? 1 : 0) << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		
		int max = 0;
		int keep = 0;
		for(int i=n-1;i>=0;i--) {
			if (max <= Math.min(a[i], a[n-1]-a[i])) {
				max = Math.min(a[i], a[n-1]-a[i]);
				keep = a[i];
			}
		}
		
		System.out.println(a[n-1]+" "+keep);
	}

}


Measured memory_bytes: 50072
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, K;
    cin >> N >> K;
    vector<pair<int, ll>> AB(N);
    rep(i, N) cin >> AB[i].first >> AB[i].second;

    int msb = 0;
    {
        int k = K;
        while (k) {
            k /= 2;
            msb++;
        }
        msb--;
    }

    ll ans = 0;
    rep(i, N) if ((AB[i].first | K) == K) ans += AB[i].second;

    int mask = 0;
    for (int b = 30; b > msb; --b) mask |= 1 << b;
    for (int b = msb; b >= 0; --b) {
        int m = 1 << b;

        if (K & m) {
            ll tmp = 0;
            rep(i, N) {
                if (((AB[i].first | K) & mask) == (K & mask) && (AB[i].first & m) == 0) {
                    tmp += AB[i].second;
                }
            }

            ans = max(ans, tmp);
        }

        mask |= m;
    }

    write(ans);
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	string s;cin>>s;
	bool flag=1;
	int ans=inf;
	rep(i,s.size()-1){
		if(s[i]!=s[i+1]){
			flag=0;
			break;
		}
	}
	if(flag){
		cout<<0<<"\n";
		return 0;
	}

	for(char c='a';c<='z';c++){
		string t=s;
		int current_size=t.size(),cnt=0;
		while(1){
			rep(i,current_size-1){
				if(t[i]==c||t[i+1]==c) t[i]=c;
			}
			//cout<<t<<"\n";
			cnt++;
			current_size--;

			flag=1;			
			rep(i,current_size-1){
				if(t[i]!=t[i+1]){
					flag=0;
					break;
				}
			}
			if(flag) break;
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<"\n";
}

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

//matrix chain multiplication

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

	long long a[n],dp[n][n],sum[n][n];

	memset(dp,0,sizeof(dp));
	memset(sum,0,sizeof(sum));

	for(long long i=0;i<n;i++){
		cin>>a[i];
	}

	for(long long i=0;i<n-1;i++){
		dp[i][i] = 0;
		dp[i][i+1] = a[i]+a[i+1];
	}
	dp[n-1][n-1] = 0;

	for(long long i=0;i<n;i++){
		sum[i][i] = a[i];
		for(long long j=i+1;j<n;j++){
			sum[i][j] = sum[i][j-1]+a[j];
		}
	}

	for(long long i=2;i<n;i++){
		for(long long j=0;j+i<n;j++){
			temp = 999999999999999; 
			for(long long k=0;k<i;k++){
				temp = min(temp,dp[j][j+k] + dp[j+k+1][j+i]);
			}
			dp[j][j+i] = temp+sum[j][j+i];
		}
	}

	cout<<dp[0][n-1]<<endl;
}

Measured memory_bytes: 2816
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "abc161_e.cpp"

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  vi l, r;
  REP(itr, n) {
    if (s[itr] != 'o')
      continue;
    l.push_back(itr);
    itr += c;
  }
  for (int itr = n - 1; itr >= 0; itr--) {
    if (s[itr] != 'o')
      continue;
    r.push_back(itr);
    itr -= c;
  }
  if ((int)l.size() > k) {
    return 0;
  }

  reverse(ALL(r));
  REP(i, (int)l.size()) {
    if (l[i] == r[i])
      cout << l[i] + 1 << "\n";
  }
  return 0;
}


Measured memory_bytes: 3448
N = int(input())
D = 100000
d = {i:[] for i in range(1, 2*D+1)}
cd = set()
used = [0]*(2*D+1)
ans = 0

for _ in range(N):
    x, y = map(int, input().split())
    y += D
    cd.add(x)
    d[x].append(y)
    d[y].append(x)

for x in cd:
    if used[x]:continue
    q = [x]
    used[x] = 1
    cx, sx = 0, 0

    while q:
        a = q.pop()
        if a<=D:
            cx += 1
        sx += 1
        for b in d[a]:
            if used[b]:continue
            used[b] = 1
            q.append(b)
    ans += cx*(sx-cx)

print(ans-N)


Measured memory_bytes: 79840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B, C, D;  
  cin >> N;

  A = N / 1000;
  B = (N % 1000) / 100;
  C = (N % 100) / 10;
  D = N % 10;
  
  if (((A == B) & (A == C)) || ((B == C) & (B == D)))
	cout << "Yes" << endl;
  else
	cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define nl cout<<'\n';
int main()
{
    int a,b,c,d;
    cin>>a>>b;
    c=(a+b)/2;
    if(abs(a-c)==abs(b-c))
    cout<<c;
    else
      cout<<"IMPOSSIBLE";
    nl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int SIZE_FACT = 2000100;
vector<ll> fact, invfact;
ll comb(int n, int k) {
	return fact[n] * invfact[k] % mod * invfact[n-k] % mod;
}
ll modpow(ll n, int k) {
	ll r = 1;
	while (k > 0) {
		if (k&1) (r *= n) %= mod;
		(n *= n) %= mod;
		k >>= 1;
	}
	return r;
}
ll f(int x, int y) {
	if (x == 0) return modpow(26, y);
	ll res = 0;
	for (int i = 0; y-1-i >= x-1; ++ i) {
		(res += modpow(25, i) * f(x-1, y-1-i)) %= mod;
	}
	return res;
}
int main() {
	fact.resize(SIZE_FACT);
	invfact.resize(SIZE_FACT);
	fact[0] = invfact[0] = 1;
	for (int i = 1; i < SIZE_FACT; ++ i) {
		fact[i] = fact[i-1] * i % mod;
		invfact[i] = modpow(fact[i], mod-2);
	}

	int K;
	string S;
	cin >> K >> S;
	int N = S.length();
	ll res = 0;
	for (int i = 0; i <= K; ++ i) {
		auto a = fact[N+i-1] * invfact[i] % mod * invfact[N-1] % mod;
		(res += modpow(25, i) * modpow(26, K-i) % mod * a % mod) %= mod;
	}
	cout << res << endl;
}


Measured memory_bytes: 36496
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod    1000000007
#define PI 2*acos(0.0)

bool dest[1005];

int32_t main()
{
    io;
    int n, x;
    cin>>n>>x;
    set<int> inp;
    for(int i = 0; i< x; i++)
    {
        int y;
        cin>>y;
        inp.insert(y);
    }
    if(inp.count(n) == 0)
        return cout<<n,0;
    int j  = 1;
    while(77)
    {
        int ac = n-j;
        if(!inp.count(ac))
            return cout<<ac, 0;
        ac = n+j;
        if(!inp.count(ac))
            return cout<<ac, 0;
        j++;
    }
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int n,k;
  cin>>n>>k;
  int i=0;
  while(true)
  {
    if(pow(k,i)<=n&&n<pow(k,i+1))
    {
      cout<<i+1<<endl;
      return 0;
    }
    i++;
  }
}

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

int main(){
    int a,b; cin >> a >> b;
    if(a-2*b<0) cout << 0 << endl;
    else cout << a-2*b << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        if(a==1 && b==2) {
            System.out.println(3);
        } else if(a==1 && b==3){
            System.out.println(2);
        } else if(a==2 && b==3){
            System.out.println(1);
        } else if (a==3 && b==1) {
            System.out.println(2);
        } else if(a==3 && b==2) {
            System.out.println(1);
        } else if (a==2 && b==1) {
            System.out.println(3);
        }

    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int mergecount(vector<int> &a) {
	int count = 0;
	int n = a.size();
	if (n > 1) {
		vector<int> b(a.begin(), a.begin() + n / 2);
		vector<int> c(a.begin() + n / 2, a.end());
		count += mergecount(b);
		count += mergecount(c);
		for (int i = 0, j = 0, k = 0; i < n; ++i)
			if (k == c.size())       a[i] = b[j++];
			else if (j == b.size())  a[i] = c[k++];
			else if (b[j] <= c[k])   a[i] = b[j++];
			else { a[i] = c[k++]; count += n / 2 - j; }
	}
	return count;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	int N = S.size();
	vector<int> C(26, 0);
	vector<int> B(26, 0);
	int res = 0;
	for (int i = 0; i < N; i++) {
		C[(S[i] - 'a')]++;
	}
	int o = 0;
	for (int i = 0; i < 26; i++) {
		if ((C[i] % 2) == 1) {
			o++;
		}
	}
	//cerr << o << endl;
	
	if (o > 1) {
		cout << "-";
		cout << 1 << endl;
	}
	else
	{
		vector<int> r;
		vector<int> l;
		for (int i = 0; i < N; i++) {
				B[S[i] - 'a']++;
				if (B[S[i] - 'a'] * 2 <= C[S[i] - 'a']) {

					res += i - (int)r.size();
					r.push_back(S[i] - 'a');
				}
				else {
					l.push_back(S[i] - 'a');
				}
			
		}
		for (int i = 0; i < l.size(); i++) {
			if ((C[l[i]] % 2) == 1) {
				res += i;
				l.erase(l.begin() + i);
				break;
			}
		}
		reverse(l.begin(), l.end());
		//cerr << r.size() << endl;
		//cerr << l.size() << endl;
		vector<vector<int> >X(26);
		for (int i = 0; i < 26; i++) {
			B[i] = 0;
		}
		for (int i = 0; i < r.size(); i++) {
			X[r[i]].push_back(i);
		}
		vector<int> rs;
		for (int i = 0; i < l.size(); i++) {
			rs.push_back(X[l[i]][B[l[i]]]);
			B[l[i]]++;
		}
		res += mergecount(rs);
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 5388
module.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)t.d(n,o,function(r){return e[r]}.bind(null,o));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){var n,o,u,i;n=t(1).readFileSync("/dev/stdin","UTF-8"),o=n.split(" "),u=Number(o[0]),i=Number(o[1]),u<=8&&i<=8?console.log("Yay!"):console.log(":(")},function(e,r){e.exports=require("fs")}]);

Measured memory_bytes: 8456
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int main() {
    ll N, K;
    cin >> N >> K;
    ll a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    ll M = (N * (N + 1)) / 2;
    ll b[M];
    ll mark = 0;
    for (int i = 0; i < N; i++) {
        ll sum = 0;
        for (int j = i; j < N; j++) {
            sum += a[j];
            b[mark] = sum;
            mark++;
        }
    }
    // for (int i = 0; i < M; i++) {
    //     cout << b[i] << " ";
    // }
    // cout << endl;
    bool use[M];
    fill(use, use + M, true);
    ll ans = 0;
    for (int i = 40; i >= 0; i--) {
        ll ketamark = 0;
        for (int j = 0; j < M; j++) {
            if (use[j] && (b[j] & ((ll)1 << i))) {
                ketamark++;
            }
        }
        if (ketamark >= K) {
            ans += (ll)1 << i;
            for (int j = 0; j < M; j++) {
                if (use[j] && !(b[j] & ((ll)1 << i))) {
                    use[j] = false;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4608
#include <iostream>

using namespace std;

int n,x,y;
int results[2020];
int yeet;

int main(){
	cin >> n >> x >> y;

	for (int i = 1; i <= n; i++){
		for (int j = i+1; j <= n; j++){
			yeet = j-i;
			yeet = min(yeet, abs(i-x)+abs(j-y)+1);
			yeet = min(yeet, abs(i-y)+abs(j-x)+1);
			results[yeet]++;
		}
	}
	for(int i=1;i<n;i++)
		cout<<results[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gotiusanosyaro(int x, int y) {
	int gotiusanokokoa = 0;
	if (x <= y) {
		gotiusanokokoa = y - x;
	} else {
		gotiusanokokoa = x - y;
		if (x != 0) gotiusanokokoa++;
		if (y != 0) gotiusanokokoa++;
	}
	return gotiusanokokoa;
}

int main(void) {
	int x, y;
	int gotiusanomegu, yorimoinokimari, rizeronoramu;
	int hamamie;
	if (scanf("%d%d", &x, &y) != 2) return 1;
	gotiusanomegu = gotiusanosyaro(x, y);
	yorimoinokimari = gotiusanosyaro(-x, y) + 1;
	rizeronoramu = gotiusanosyaro(x, -y) + 1;

	hamamie = gotiusanomegu <= yorimoinokimari ? gotiusanomegu : yorimoinokimari;
	printf("%d\n", hamamie <= rizeronoramu ? hamamie : rizeronoramu);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
	
	int A, B{};

	cin >> A >> B;

	int count_p = 1;
	int count_l = 0;

	while (count_p < B)
	{
		count_l++;
		count_p = count_p + A - 1;
	}

	cout << count_l << endl;

	return 0;
}

Measured memory_bytes: 256
<?php
list($n,$m,$l) = explode(" ",trim(fgets(STDIN)));
for($i = 0; $i < $n; $i++){
    $A[$i] = explode(" ",trim(fgets(STDIN)));
}
for($i = 0; $i < $m; $i++){
    $B[$i] = explode(" ",trim(fgets(STDIN)));
}
for($i = 0; $i < $n; $i++){
    for($j = 0; $j < $l; $j++){
        $C[$i][$j] = 0;
        for($k = 0; $k < $m; $k++){
            $C[$i][$j] += $A[$i][$k] * $B[$k][$j];
        }
    }
    echo implode(" ",$C[$i])."\n";
}

Measured memory_bytes: 20280
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int getInt(){int x;scanf("%d",&x);return x;}
template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const v(T)&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
typedef __int128_t l3;
typedef __uint128_t ul3;
std::ostream &operator<<(std::ostream &o, l3 x) {
  string s;
  bool sg = x < 0;
  ul3 ux = sg?-x:x;
  do {s += '0'+ux%10; ux /= 10;} while (ux);
  if (sg) s += '-';
  reverse(rng(s));
  return o<<s;
}
#include <atcoder/all>
using namespace atcoder;



int main() {
  ll n;
  cin>>n;
  ll ans = n*2;
  if (n%2 == 1) ans = n;
  auto f1 = [&](ll x, ll y) {
    auto p = crt({1,0},{x,y});
    // cerr<<x<<" "<<y<<" "<<p<<endl;
    if (p.fi > 1) mins(ans, p.fi-1);
  };
  auto f2 = [&](ll x, ll y) {
    auto p = crt({x-1,0},{x,y});
    // cerr<<x<<" "<<y<<" "<<p<<endl;
    if (p.fi > 1) mins(ans, p.fi);
  };
  auto f = [&](ll x) {
    ll y = n/x;
    x *= 2;
    if (gcd(x,y) != 1) return;
    f1(x,y);
    f2(x,y);
  };
  for (ll i = 1; i*i <= n; ++i) {
    if (n%i == 0) {
      f(i);
      f(n/i);
    }
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    int A,B;
    cin>>A>>B;
    int P[N];
    int a=0,b=0,c=0;
    rep(i,0,N){
        cin>>P[i];
        if(P[i]<=A) a++;
        if(A<P[i]&&P[i]<=B) b++;
        if(P[i]>B) c++;
    }
    cout <<min(a,min(b,c))<<"\n";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	static long Examine(long countM,long countA,long countR,long countC,long countH) {
		long count = 0;
		count += countR * countC * countH;
		count += countA * countC * countH;
		count += countA * countR * countH;
		count += countA * countR * countC;
		
		count += countM * countC * countH;
		count += countM * countR * countH;
		count += countM * countR * countC;
		
		count += countM * countA * countH;
		count += countM * countA * countC;
		
		count += countM * countA * countR;

		return count;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] names = new String[N];
		long countM = 0;
		long countA = 0;
		long countR = 0;
		long countC = 0;
		long countH = 0;
		String[] I = new String[N];
		for(int i = 0;i < N;i++) {
			names[i] = sc.next();
			I[i] = names[i].substring(0,1);
		}
		for(int k = 0;k < N;k++) {
			if(I[k].equals("M")) countM++;
			else if(I[k].equals("A")) countA++;
			else if(I[k].equals("R")) countR++;
			else if(I[k].equals("C")) countC++;
			else if(I[k].equals("H")) countH++;
		}
		System.out.println(Examine(countM,countA,countR,countC,countH));
		sc.close();
	}

}

Measured memory_bytes: 56080