akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<vector>

int main(){
  int N; std::cin >> N;
  std::vector<long long unsigned> v(N);
  for(auto i=0; i<N; ++i)
    std::cin >> v[i];
  int M; std::cin >> M;
  std::vector<long long unsigned> vv(M);
  for(auto i=0; i<M; ++i)
    std::cin >> vv[i];
  std::sort(v.begin(), v.end());
  std::sort(vv.begin(), vv.end());
  auto j = 0;
  for(auto i=0; i<N; ++i){
    if(v[i] == vv[j])
      ++j;
    if(j==M){
      std::cout << "YES\n";
      return 0;
    }
  }
  std::cout << "NO\n";
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
int c[]={500,100,50,10,5,1};
int cn[6];

int main(){
	int a;
	cin>>a;
	while(a){
		a=1000-a;
		FOR(i,0,6){
			cn[i]=a/c[i];
			a-=cn[i]*c[i];
		}
		int ans=0;
		FOR(i,0,6)ans+=cn[i];
		cout<<ans<<endl;
		cin>>a;
	}

	
	return 0;
}



Measured memory_bytes: 3004
from functools import lru_cache, reduce


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    # if N == 2:
    # memG = gcd(As[0], As[1])
    # if N < 3:
    #     for i in range(N):
    #         tmp = As[:i] + As[i + 1 :]
    #         g = reduce(gcd, tmp)
    #         if g > memG:
    #             memG = g
    if N == 2:
        memG = max(As)
    else:
        gLeft = {0: As[0], 1: gcd(As[0], As[1])}
        for i in range(2, N):
            gI = gcd(gLeft[i - 1], As[i])
            gLeft[i] = gI
        gRight = {N - 1: As[N - 1], N - 2: gcd(As[N - 1], As[N - 2])}
        for i in range(2, N):
            gI = gcd(gRight[N - i], As[N - 1 - i])
            gRight[N - 1 - i] = gI

        buf = []
        for i in range(N):
            leftG = None
            if (i - 1) in gLeft:
                leftG = gLeft[i - 1]
            rightG = None
            if (i + 1) in gRight:
                rightG = gRight[i + 1]
            # tmpG = None
            if leftG is None:
                leftG = rightG
            elif rightG is None:
                rightG = leftG
            buf.append(gcd(leftG, rightG))
            # tmpG = gcd(leftG, rightG)
            # if tmpG > memG:
            #     memG = tmpG
        memG = max(buf)

    print("{}".format(memG))


sub()


Measured memory_bytes: 32336
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    cout<<*max_element(a.begin(),a.end())-*min_element(a.begin(),a.end());//最大,最小はこれが簡単
    //max_elementはポインタを返すので*をつけて値を引っ張る
}

Measured memory_bytes: 256
L, R = map(int, input().split())
d = R-L
k = min(d, 2019)
ans = 2019
for i in range(L, L+k):
    for j in range(i+1, L+k+1):
        a = i*j % 2019
        if ans > a:
            ans = a
print(ans)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define line cout<<"----------------------------------"<<endl
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
ll ara[100009];
vector<pair<ll,ll> > v;
typedef pair<ll,ll>pa ;
bool cmp(pa a, pa b)
{
    return a.second>b.second;
}
ll sum[100009];
int  main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    ll ans=0;
    for(ll i=0;i<n;i++)
    {
        scanf("%lld",&ara[i]),ans+=ara[i];
    }
    sort(ara,ara+n);
    while(m--)
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        v.pb(mp(a,b));
    }
    sort(v.begin(),v.end(),cmp);
    ll range=-1;
    for(ll i=0;i<v.size();i++)
    {
        ll a=v[i].first;
        ll b=v[i].second;
        ll k=a;
        for(ll i=range+1;i<n and k;i++,k--)
        {
            if(ara[i]>=b) break;
            ans-=ara[i];
            ans+=b;
            range=i;
        }
    }
    printf("%lld\n",ans);
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
using namespace std;
typedef long long ll;
int main() {
  char a, b;
	cin >> a >> b;
	string ans;
	if(a > b){
		ans = ">";
	}else if(a == b){
		ans = "=";
	}else if(a < b){
		ans = "<";
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=200005;
long long num[maxn];
long long calc(long long n)
{
    return n*(n-1)/2;
}
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF){
        memset(num,0,sizeof(num));
        for(int i=0;i<n;i++){
            scanf("%lld",&num[i]);
            if(i)
                num[i]+=num[i-1];
        }
        sort(num,num+n);
        long long cnt=0;
        if(!num[0]){
            cnt=1;
        }
        long long flag=0;
        for(int i=1;i<n;i++){
            if(num[i]==0){
                cnt++;
            }
            if(num[i]==num[i-1]){
                flag++;
            }
            if((num[i]!=num[i-1]&&flag)||(i==n-1&&flag)){
                cnt+=calc(flag+1);
                flag=0;
            }
        }
        printf("%lld\n",cnt);
    }
    return 0;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W;
char fld[510][510];
bool ex[26];
int x[26],y[26],xx[26],yy[26];
vector<int>vec[26][2];
signed main(){
    cin>>H>>W;
    rep(i,H)cin>>fld[i];

    rep(i,H)rep(j,W){
        if(fld[i][j]=='.')continue;
        int t=fld[i][j]-'A';
        if(!ex[t]){
            ex[t]=true;
            x[t]=j;y[t]=i;
        }
        else{
            xx[t]=j;yy[t]=i;
        }
    }

    rep(i,26){
        if(!ex[i])continue;
        if((x[i]==xx[i]&&abs(y[i]-yy[i])==1)||(y[i]==yy[i]&&abs(x[i]-xx[i])==1)){
            vec[i][0].pb(i);vec[i][1].pb(i);
            continue;
        }
        for(int j=min(y[i],yy[i]);j<=max(y[i],yy[i]);j++){
            if(fld[j][x[i]]!='.'&&fld[j][x[i]]!='A'+i)vec[i][0].pb(fld[j][x[i]]-'A');
            if(fld[j][xx[i]]!='.'&&fld[j][xx[i]]!='A'+i)vec[i][1].pb(fld[j][xx[i]]-'A');
        }
        for(int j=min(x[i],xx[i]);j<=max(x[i],xx[i]);j++){
            if(fld[yy[i]][j]!='.'&&fld[yy[i]][j]!='A'+i)vec[i][0].pb(fld[yy[i]][j]-'A');
            if(fld[y[i]][j]!='.'&&fld[y[i]][j]!='A'+i)vec[i][1].pb(fld[y[i]][j]-'A');
        }
    }

    rep(i,26){
        rep(j,2){
            sort(all(vec[i][j]));
            vec[i][j].erase(unique(all(vec[i][j])),vec[i][j].end());
        }
    }
    int ans=0;
    while(true){
        bool update=false;
        rep(i,26){
            if(!ex[i])continue;
            rep(j,2){
                bool ok=true;
                for(auto k:vec[i][j]){
                    if(ex[k])ok=false;
                }
                if(!ok)continue;
                ans++;
                ex[i]=false;
                update=true;
                break;
            }
        }
        if(!update)break;
    }
    cout<<ans*2<<endl;
    return 0;
}

Measured memory_bytes: 3384
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] a = new int[n];
      int cnt = 0;
      int sum = 0;
      for(int i = 0;i < n;i++)a[i]=sc.nextInt();
      for(int i = 0;i < n-1;i++){
      	if(a[i]==a[i+1])cnt++;
        else{
          sum+=(cnt+1)/2;
          cnt = 0;
        }
      }
      if(cnt>0)sum+=(cnt+1)/2;
      System.out.println(sum);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int a,b,x;cin>>a>>b>>x;
  Ans(a+b>=x&&a<=x);
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    s: chars,
  }
  if s[2] == s[3] && s[4] == s[5] {
    puts!("Yes\n");
  } else {
    puts!("No\n");
  }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <map>
#include <string>
#include <utility>

using namespace std;

typedef long long LL;

int N;
char S[50];
char R[50];
map<pair<string, string>, int> sp, rp;

int main(void) {
    scanf("%d%s", &N, S);
    for (int i = 0; i < N; i++) {
        R[i] = S[2 * N - 1 - i];
    }
    S[N] = 0;
    R[N] = 0;
    for (int i = 0; i < (1 << N); i++) {
        string s0, s1;
        string r0, r1;
        int b = 1;
        for (int j = 0; j < N; j++) {
            if (i & b) {
                s0 += S[j];
                r0 += R[j];
            } else {
                s1 += S[j];
                r1 += R[j];
            }
            b <<= 1;
        }
        if (sp.find(make_pair(s0, s1)) == sp.end()) {
            sp[make_pair(s0, s1)] = 1;
        } else {
            sp[make_pair(s0, s1)] += 1;
        }
        if (rp.find(make_pair(r0, r1)) == rp.end()) {
            rp[make_pair(r0, r1)] = 1;
        } else {
            rp[make_pair(r0, r1)] += 1;
        }
    }
    LL dap = 0;
    for (auto& x : sp) {
        auto it = rp.find(make_pair(x.first.second, x.first.first));
        if (it != rp.end()) {
            dap += (LL)x.second * it->second;
        }
    }
    printf("%lld\n", dap);
    return 0;
}


Measured memory_bytes: 91904
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

const int MOD = (int) 1e9 + 7;
const int INF = 0x3f3f3f3f;

vector<int> fact, invFact;

int Pow(int x, int y) {
    int ret = 1;
    for (; y > 0; y /= 2) {
        if (y & 1) {
            ret = (int64_t) ret * x % MOD;
        }
        x = (int64_t) x * x % MOD;
    }
    return ret;
}

int invMod(int x) {
    return Pow(x, MOD - 2);
}

void precalc(int n) {
    fact = vector<int>(n + 1);
    fact[0] = 1; 
    for (int i = 1; i <= n; ++i) {
        fact[i] = (int64_t) fact[i - 1] * i % MOD;
    }
    invFact = vector<int>(n + 1);
    invFact[n] = invMod(fact[n]);
    for (int i = n - 1; i >= 0; --i) {
        invFact[i] = (int64_t) invFact[i + 1] * (i + 1) % MOD;
    }
}

int comb(int n, int k) {
    return (int64_t) fact[n] * invFact[k] % MOD * invFact[n - k] % MOD;
}

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, X, Y;
    cin >> n >> X >> Y;
    
    precalc(5 * n);

    vector<vector<pair<int, int>>> A(n + 1);
    for (int i = 1; i <= n; ++i) {
        int c, w;
        cin >> c >> w;
        A[c].push_back(make_pair(w, 1));
    }
    for (int i = 1; i <= n; ++i) {
        if (A[i].empty()) continue;
        sort(A[i].begin(), A[i].end());
        vector<pair<int, int>> B = {{A[i][0].first, 1}};
        for (int j = 1; j < SZ(A[i]); ++j) {
            if (A[i][j].first + A[i][0].first <= X) {
                B.back().second++;
            } else {
                B.push_back(A[i][j]);
            }
        }
        A[i] = B;
    }
    int vmin1 = INF, pos = 0, vmin2 = INF;
    int xcnt = 0;
    for (int i = 1; i <= n; ++i) {
        if (A[i].empty()) continue;
        if (A[i][0].first < vmin1) {
            vmin2 = vmin1;
            vmin1 = A[i][0].first;
            xcnt = A[i][0].second;
            pos = i;
        } else if (A[i][0].first < vmin2) {
            vmin2 = A[i][0].first;
        }
    }
    int total = 0;
    int ans = 1;
    for (int i = 1; i <= n; ++i) {
        if (pos == i) continue;
        int add = 0;
        for (const pair<int, int>& p: A[i]) {
            if (p.first + vmin1 <= Y) {
                add += p.second;
            }
        }
        ans = (int64_t) ans * comb(total + add, add) % MOD;
        total += add;
    }
    for (int i = 1; i < SZ(A[pos]); ++i) {
        pair<int, int> p = A[pos][i];
        if (p.first + vmin2 <= Y) {
            xcnt += p.second;
        }
    }
    ans = (int64_t) ans * comb(total + xcnt, xcnt) % MOD;

    ans %= MOD;
    if (ans < 0) ans += MOD;

    cout << ans << '\n';
}


Measured memory_bytes: 18164
#include <stdio.h>
int main(){
    int al[26]={};
    char b[1200]={};
    int i,n;
    i=0;
    while(scanf("%c",&b[i])!=EOF){
        if(b[i]>='A'&&b[i]<='Z'){
            n=b[i]-'A';
            al[n]++;
        }
        else if(b[i]>='a'&&b[i]<='z'){
            n=b[i]-'a';
            al[n]++;
        }
    }
    
    for(i=0;i<26;i++)
        printf("%c : %d\n",'a'+i,al[i]);
    
    
}



Measured memory_bytes: 2140
import math
A, B = map(int, input().split())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def trial_division(target):
    if target == 1: return False
    dest = int(math.sqrt(target)) + 1
    #print(dest)
    for i in range(2,dest):
        #print(f'i :{i} target: {target}')
        if target % i == 0:
            return False

    return True

A_div = set(make_divisors(A))
B_div = set(make_divisors(B))
AB_div = A_div & B_div
#print(AB_div)
count=1

for i in AB_div:
    #print(i)
    #print(trial_division(i))
    if(trial_division(i)):
        count+=1
print(count)

Measured memory_bytes: 5080
from collections import defaultdict
Lineger_Dict = defaultdict(int)
N = int(input())
N_List = list(map(int,input().split()))
for i in N_List:
    Lineger_Dict[i] += 1

    
Rec = sorted([k for k,v in Lineger_Dict.items() if v >= 2] + [k for k,v in Lineger_Dict.items() if v >= 4])
if len(Rec) < 2:
    print(0)
else:
    print(Rec[-1]*Rec[-2])

Measured memory_bytes: 22076
import numpy as np
N, K = map(int, input().split())
hights = np.array(list(map(int,input().split())))
steps=np.array([0]*N)
steps[0]=0

for i in range(1, N):
    gaps = hights[max(0, i-K):i] - hights[i]
    gaps = np.abs(gaps)
    gaps += steps[max(0, i-K):i]
    steps[i] = np.min(gaps)
    
print(int(steps[N-1]))

Measured memory_bytes: 24600
import java.util.*;
 
public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] freq = new int[10][10];
        for (int i = 1; i <= N; i++) {
            int l = mostLeft(i);
            int r = i%10;
            freq[l][r]++;
        }

        int ans = 0;
        for (int i = 1; i <= N; i++) {
            int l = mostLeft(i);
            int r = i%10;
            ans += freq[r][l];
        }

        System.out.println(ans);
    }

    private static int mostLeft(int x) {

        int a = x;
        while (x > 0) {
            a = x;
            x /= 10;
        }

        return a;
    }
}


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

using namespace std;

int main(){
    int N;
    cin >> N;
    int H[N];
    for(int i=0;i<N;i++){
        cin >> H[i];
    }

    int now=H[0],ans=0,res=0;
    for(int i=1;i<N;i++){
        if(now>=H[i]){
            now = H[i];
            ans++;
            res = max(ans,res);
        }else{
            res = max(ans,res);
            now = H[i];
            ans = 0;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[105][100005];
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	ll n,i,j,k;
	cin >> n >> k;
	ll a[n],w[n];
	vector<pair<ll,ll> >v;
	for(i=0;i<n;i++)
	{
		cin >> w[i] >> a[i];
		v.push_back({w[i],a[i]});
	}
	sort(v.begin(),v.end());
	for(i=0;i<n;i++)
		dp[i][0]=0;
		
	for(i=1;i<=k;i++)
	{
		if(i>=v[0].first)
			dp[0][i]=v[0].second;
		else
			dp[0][i]=0;
	}
	for(i=1;i<n;i++)
	{
		for(j=0;j<=k;j++)
		{
			if(j>=v[i].first)
				dp[i][j]=max(v[i].second + dp[i-1][j-v[i].first],dp[i-1][j]);
			else
				dp[i][j]=dp[i-1][j];
		}
			
	}
	cout<<dp[n-1][k]<<"\n"<<"\n";
	
		
	
}

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

signed main() {
    int a, b;
    char op;
    
    while (cin >> a >> op >> b and op != '?') {
        if (op == '+') {
            cout << a + b << endl;
        }
        else if (op == '-') {
            cout << a - b << endl;
        }
        else if (op == '*') {
            cout << a * b << endl;
        }
        else if (op == '/') {
            cout << a / b << endl;
        }
    }
}


Measured memory_bytes: 3104
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph)
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse import csr_matrix

#from collections import* #defaultdict Counter deque appendleft
#from fractions import gcd
#from functools import* #reduce
#from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
#from operator import mul,itemgetter
#from bisect import* #bisect_left bisect_right
#from heapq import* #heapify heappop heappushpop
#from math import factorial,pi
#from copy import deepcopy
import sys
#sys.setrecursionlimit(10**8)
input=sys.stdin.readline  #危険！基本オフにしろ！

class UNION_FIND(object):
    def __init__(self,n):
        self.parent=[-1 for i in range(n)]
        
    def root(self,x):
        if self.parent[x]<0:
            return x
        else:
            self.parent[x]=self.root(self.parent[x])
            return self.parent[x]
 
    def size(self,x):
        return -self.parent[self.root(x)]
    def union(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x==y:
            return False
        if self.size(x)<self.size(y):
            x,y=y,x
        self.parent[x]+=self.parent[y]
        self.parent[y]=x
        return True

def compute_mst_kruskal(max_v, edges, flip):
    edges.sort(key=lambda x: x[2],reverse=flip)
    uf = UNION_FIND(max_v)
    mst = []
    for (a,b,c) in edges:
        if uf.root(a)!= uf.root(b):
            uf.union(a,b)
            mst.append(c)
    return mst


def main():
    n=int(input())
    inp=[[i]+list(map(int,input().split()))for i in range(n)]
    inpX=sorted(inp,key=lambda x:x[1])
    inpY=sorted(inp,key=lambda x:x[2])
    edges=[]
    for i in range(1,n):
        a,b,c=inpX[i]
        d,e,f=inpX[i-1]
        edges.append((a,d,min(abs(b-e),abs(c-f))))
        a,b,c=inpY[i]
        d,e,f=inpY[i-1]
        edges.append((a,d,min(abs(b-e),abs(c-f))))
    
    print(sum(compute_mst_kruskal(n, edges, 0)))
        
    
if __name__ == '__main__':
    main()

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

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

    if ((a+b) % 2 == 0)
        cout << ((a + b) / 2) << endl;
    else
        cout << "IMPOSSIBLE" << endl;
        
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include<limits.h>

int check2(char *a, char *b, int *i, int *j)
{
    int now = 0;
    for(; *i < 200 && *j < 200;)
    {
        //printf("A %c %c %d %d %d\n", a[*i], b[*j], a[*i] != b[*j], *i, *j);
        if(a[*i] != b[*j]) now = 1;
        if(a[*i] == '"' && b[*j] == '"')
        {
            return now;
        }
        if(a[*i] != '"') *i += 1;
        if(b[*j] != '"') *j += 1;
    }
}

int check(char *a, char *b, int *i, int *j)
{
    int now = 0;
    for(; *i < 200 && *j < 200;)
    {
        //printf("B %c %c %d %d %d\n", a[*i], b[*j], a[*i] != b[*j], *i, *j);
        if(a[*i] == '\0' && b[*j] == '\0') return now;
        if(a[*i] != b[*j]) return 404;
        if(a[*i] == '\"' && b[*j] == '\"') 
        {
            *i += 1;
            *j += 1;
            now += check2(a, b, i, j);
        }
        *i += 1;
        *j += 1;
    }
    return now;
}

int main()
{
    char a[201];
    char b[201];
    while(1)
    {
        scanf("%s", a);
        if(a[0] == '.' && a[1] == '\0') return 0;
        scanf("%s", b);
        int i = 0;
        int j = 0;
        int k = check(a, b, &i, &j);
        //printf("%d\n", k);
        if(k == 0) printf("IDENTICAL\n");
        else if(k == 1) printf("CLOSE\n");
        else printf("DIFFERENT\n");
    }
}


Measured memory_bytes: 2508
#include<iostream>
using namespace std;
int main(){
    int a, b;
    
    while(1<23){
        cin >> a >> b;
        if(a==0 && b==0){
            break;
        }else if(a>b){
            cout << b << " " << a << endl;
        }else{
            cout << a << " " << b << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
ll mod=1e9+7;
int main() {
   /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    ll dp[n][m];
    dp[n-1][m-1]=1;
    for(int i=n-1;i>=0;i--){
        for(int j=m-1;j>=0;j--){
            if(i==n-1 && j==m-1) continue;
            dp[i][j]=0;
            if(s[i][j]=='#') continue;
            if(i+1<=n-1){
                dp[i][j]=dp[i+1][j];
            }
            if(j+1<=m-1){
                dp[i][j]=(dp[i][j]+dp[i][j+1])%mod;
            }
        }
    }
    cout<<dp[0][0];
}

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

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    // Failed to predict input format
    string s;
    long long count = 0;
    cin >> s;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == '1')
            count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<string>
#include<map>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
long long int s[210000],a[201000];
long long int cal(long long int x){
    if(x < 0)
        return -x;
    return x;
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n ; i++)
        scanf("%lld",&a[i]);
    for(int i = 1; i <= n; i ++)
        s[i] = s[i-1] + a[i];
    long long int ans = 20161001010220000;
    for(int i = 1; i < n; i ++){
        ans = ans < cal(s[n]-2*s[i]) ? ans : cal(s[n]-2*s[i]);
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
int main(void){
int r,c,i,f,asum=0,sum=0,n;
int z[100];
for(i=0;i<100;i++){z[i]=0;}
scanf("%d %d",&r,&c);
for(i=0;i<r;i++){
for(f=0;f<c;f++){
scanf("%d",&n);
z[f]+=n;
sum+=n;
printf("%d ",n);
}
printf("%d\n",sum);
sum=0;
}
for(i=0;i<c;i++){
asum+=z[i];
if(i!=c-1){
printf("%d ",z[i]);
}else{printf("%d ",z[i]);printf("%d\n",asum);
}
}
return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
	char op;
	int a, b;
	int c;

	while (1){
		cin >> a >> op >> b;

		if (op == '?'){
			break;
		}

		switch (op){
		case '+':cout << a + b << endl;
			break;
		case '-':cout << a - b << endl;
			break;
		case '*':cout << a*b << endl;
			break;
		case '/':cout << a / b << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3088
n=int(input())
arr=list(map(int,input().split()))
arr2=[0]*n
for i in range(0,2*n,2):
  arr2[i//2]=arr[i%n]
ans=[0]*n
s=sum(arr)//2
cum=[0]*n
start=sum(arr2[:n//2])
cum[0]=start
l=n//2
for i in range(n):
  start=start+arr2[(i+l)%n]-arr2[i]
  cum[(i+1)%n]=start
for i in range(n):
  ans[(n-1+i*2)%n]=(s-cum[i])*2
print(*ans)

Measured memory_bytes: 66660
#include<iostream>
using namespace std;
 
int main(){
int a,c;
char b;
while(1){
cin>>a>>b>>c;
if(b == '?') break;
else if(b == '+') cout<<a+c<<endl;
else if(b == '-') cout<<a-c<<endl;
else if(b == '*') cout<<a*c<<endl;
else if(b == '/') cout<<a/c<<endl;
}}

Measured memory_bytes: 1160
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,b,*a=map(int,open(0).read().split())\n"
"a=set(a)\n"
"d=i=0\n"
"c=1\n"
"while i<n:i+=1;b=(c+d)%(10**9+7)*(not{i}&a);c,d=b,c\n"
"print(b)\n"
"\"";
  system(s);
  return 0;
}            

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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e9;
const int N = (int)1e5+5;
const int K = 105;
void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int n;
int k;
int dp[N];
int a[N];
int solve(int idx){
    if(idx>n)return OO;
    if(idx==n-1)
        return 0;
    int &ret = dp[idx];
    if(~ret)
        return ret;
    ret =OO;
    for (int i = 1; i <= k; i++){
        ret = min(ret, solve(idx + i) + abs(a[idx + i] - a[idx]));
    }
    return ret;
}   
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    scanf("%d",&n);
    scanf("%d",&k);
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    printf("%d\n",solve(0));
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
 
int main() 
{
    int a, b;
    int area, length;
     
    scanf("%d %d", &a, &b);
     
    area = a * b;
    length = 2 * (a + b);
     
    printf("%d %d\n", area, length);
     
    return 0;
}

Measured memory_bytes: 596
from collections import Counter
N = int(input())
S = input()
def char_kinds(s1,s2):
    set1 = set(Counter(s1).keys())
    set2 = set(Counter(s2).keys())
    return len(set1 & set2)

# s1 = "aaasdd"
# s2 = "aaaasa"
# print(char_kinds(s1,s
ans = 0
for i in range(len(S)):
    if char_kinds(S[:i],S[i:]) >= ans:
        ans = char_kinds(S[:i],S[i:])
print(ans)


Measured memory_bytes: 3316
# include <stdio.h>

int main()
{
int A,B,C,D;
  A <= 10000 ;
  B <= 10000 ;
  C <= 10000 ;
  D <= 10000 ;
 A >= 1 ;
B >= 1 ;
C >= 1 ;
D >= 1 ;


scanf(" %d %d %d %d",&A,&B,&C,&D ) ;
int E = A*B,F=C*D;
if(E>F)
{printf("%d \n",E ) ;}
else
printf("%d \n",F )  ;
return 0;}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int p[200000];
int pindex[200000];

int main()
{
	int n;
	int cnt=0;
	int cntm=0;
	bool f=true;
	ll ans=0;
	
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int pp;
		cin>>pp;
		pp--;
		p[i]=pp;
		pindex[pp]=i;
		if(pp!=i)
			f=false;
	}
	//もとから昇順の場合は答え0
	if(f)
	{
		cout<<0<<endl;
		return 0;
	}
	//増加部分列を求める
	cnt=1;
	for(int i=1;i<n;i++)
	{
		if(pindex[i]>pindex[i-1])
			cnt++;
		else{
			cntm=max(cnt,cntm);
			cnt=1;
		}
	}
	
	ans = n-cntm;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>


using namespace std;
using ll = long long;

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

ll num[201][201][201];

int main()
{
	ll sum = 0;
	ll K;
	cin >> K;
	for (ll i = 1; i <= K; i++) {
		for (ll j = 1; j <= i; j++) {
			for (ll k = i; k <= K; k++)
			{
				if (i == j && j == k) {
					sum += gcd(gcd(i, j), k);
				}
				else if (i == j || j == k || k == i) {
					sum += gcd(gcd(i, j), k) * 3;
				}
				else {
					sum += gcd(gcd(i, j), k) * 6;
				}
			}
		}
	}
	cout << sum << endl;

}

Measured memory_bytes: 3592
# -*- coding: utf-8 -*-


def main():
    from itertools import permutations
    from math import sqrt

    n = int(input())
    x = [0 for _ in range(n)]
    y = [0 for _ in range(n)]

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

    path = list(permutations(range(n)))
    path_count = len(path)
    length = 0

    for p in path:
        for i, j in zip(p, p[1:]):
            length += sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)

    print(length / path_count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 13708
#include <stdio.h>

int main()
{
  int n,q,i,j,l,r,m,key,count = 0,temp;
  scanf("%d",&n);
  int S[n];
  for(i = 0;i < n;i++)
    {
      scanf("%d",&S[i]);
    }
  scanf("%d",&q);
  int T[q];
  for(i = 0;i < q;i++)
    {
      scanf("%d",&T[i]);
      //printf("test1\n");
    }
  //printf("%d",q);

  /*for(i = 0;i<q;i++)
    {
      printf("%d",T[i]);
      }*/

  for(i = 0;i < q;i++)
    {
      key =T[i];
      l = 0;
      r = n;
      while(l < r)
	{
	  m = (l + r)/2;
	  //printf("m=%d\n",m);
	  if(key == S[m])
	    {
	      //printf(" %d ",S[m]);
	      count++;
	      break;
	    }
	  if(key > S[m])
	    {
	      l = m + 1;
	    }
	  else if(key <S[m])
	    {
	      r = m;
	    }
	}
      //printf("count%d",count);
    }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2308
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	string s;
	cin >> s;
	if (s == "SUN") {
		cout << 7;
		return 0;
	}
	if (s == "MON") {
		cout << 6;
		return 0;
	}
	if (s == "TUE") {
		cout << 5;
		return 0;
	}
	if (s == "WED") {
		cout << 4;
		return 0;
	}
	if (s =="THU") {
		cout << 3;
		return 0;
	}
	if (s =="FRI") {
		cout << 2;
		return 0;
	}
	if (s =="SAT") {
		cout << 1;
		return 0;
	}
}

Measured memory_bytes: 256
"use strict";
function main(input) {
  const k = parseInt(input[0]);
  let sum = 0;

  function gcd(a, b) {
    if (b === 0){
        return a
    }
    return gcd(b, a % b)
  }

  for(let a=1;a<=k;a++){
    for(let b=1;b<=k;b++){
      for(let c=1;c<=k;c++){
        let gcd_now = gcd(gcd(a,b),c);
        sum += gcd_now;
      }
    }
  }
  console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 31692
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    val card = Array(3) { Array(3) { 0 } }
    for (i in 0 until 3) {
        val row = readIntList()
        for (j in 0 until 3)  {
            card[i][j] = row[j]
        }
    }
    val n = readInt()
    val b = mutableListOf<Int>()
    for (i in 0 until n) {
        b.add(readInt())
    }

    // たて
    for (j in 0 until 3) {
        if (card[0][j] in b && card[1][j] in b && card[2][j] in b) {
            println("Yes")
            return
        }
    }

    // よこ
    for (i in 0 until 3) {
        if (card[i][0] in b && card[i][1] in b && card[i][2] in b) {
            println("Yes")
            return
        }
    }

    // 斜め
    if (card[0][0] in b && card[1][1] in b && card[2][2] in b || card[0][2] in b && card[1][1] in b && card[2][0] in b) {
        println("Yes")
        return
    }

    println("No")
}


Measured memory_bytes: 36508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int a[4][4],n,b;
    bool A[4][4]={};
    for(int i=1;i<=3;i++){
        cin>>a[i][1]>>a[i][2]>>a[i][3];
    }
    cin>>n;
    for(int z=0;z<n;z++){
        cin>>b;
        for(int i=1;i<=3;i++){
            for(int j=1;j<=3;j++){
                if(a[i][j]==b) A[i][j]=true;
            }
        }
    }
    bool ans=false;
    for(int i=1;i<=3;i++){
        if(A[i][1]&&A[i][2]&&A[i][3]) ans=true;
        if(A[1][i]&&A[2][i]&&A[3][i]) ans=true;
    }
    if(A[1][1]&&A[2][2]&&A[3][3]) ans=true;
    if(A[1][3]&&A[2][2]&&A[3][1]) ans=true;
    if(ans) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
import static java.lang.System.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        
        out.println(Math.max(Math.max(a+a-1, a+b),b+b-1));
    }
}


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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N;
    std::cin >> N;

    string ans = "Yes";
    int max_h = 0;
    REP(i, N) {
        int H;
        std::cin >> H;
        if(H < max_h - 1) {
            ans = "No";
            break;
        }
        max_h = max(H, max_h);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();
        if (a * b % 2 == 0) {
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }

    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cstring>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using ll = long long;

int main() {
  int sx, sy, tx, ty;
  std::string ans = "";

  cin >> sx >> sy >> tx >> ty;

  for (int i = 0; i < tx - sx; ++i) {
    ans += "R";
  }

  for (int i = 0; i < ty - sy; ++i) {
    ans += "U";
  }

  for (int i = 0; i < tx - sx; ++i) {
    ans += "L";
  }

  for (int i = 0; i < ty - sy; ++i) {
    ans += "D";
  }

  ans += "D";

  for (int i = 0; i < tx - sx + 1; ++i) {
    ans += "R";
  }

  for (int i = 0; i < ty - sy + 1; ++i) {
    ans += "U";
  }

  ans += "LU";

  for (int i = 0; i < tx - sx + 1; ++i) {
    ans += "L";
  }

  for (int i = 0; i < ty - sy + 1; ++i) {
    ans += "D";
  }

  ans += "R";

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
X, N = list(map(int, input().split()))
P = list(map(int, input().split()))

D = 10000
res = 0
for i in range(-100,200):
  if i in P:
    continue
  X2 = abs(X-i)
  if X2 < D:
    D = X2
    res = i
#
print(res)


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

int n,k,i,ar[200002],freq[200002],idx;

int main(){
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&ar[i]);
        freq[ar[i]]++;
    }
    sort(freq,freq+200000);
    idx=199999;
    while(k>0){
        n-=freq[idx];
        k--;
        idx--;
    }
    cout<<n<<endl;
}


Measured memory_bytes: 1792
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    S, W = MAP()

    print("unsafe" if W >= S else "safe")


if __name__ == '__main__':
    main()


Measured memory_bytes: 10040
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solveA(){
    ll res = 0;
    ll A,B; cin >> A >> B;
    res = A*B - A - B + 1;
    return res;
}


ll solveB(){
    ll res = 0;
    ll N; cin >> N;
    if(N>=105) res++;
    return res;
}

ll solveC(){
    ll res = 0;
    string S; cin >> S; ll K; cin >> K;
    res = 1;
    for(int i = 0; S.length();i++){
        if(S[i] == '1') continue;
        else{
            res = S[i] - '0';
            break;
        }
    }
    return res;
}

ll solveD(){
    ll res = 0;
    ll N,M,Q; cin >> N >> M >> Q;
    vector<ll> L(M),R(M);
    vector<vector<ll>> G(N);
    for(int i = 0; i < M;i++){
        cin >> L[i] >> R[i]; L[i]--; R[i]--;
        G[L[i]].push_back(R[i]);
    }
    for(int i = 0; i < N;i++){
        sort(G[i].begin(),G[i].end());
    }
    while(Q--){
        ll p,q; cin >> p >> q;
        p--; q--;
        
        ll Ans = 0;
        for(ll x = p; x <= q;x++){
            Ans += (upper_bound(G[x].begin(), G[x].end(), q) - G[x].begin());
        }
        cout << Ans << endl;
    }
    return 0;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    //cout << solveA() << endl;
    //cout << solveB() << endl;
    //cout << solveC() << endl;
    solveD();
    return 0;
}


Measured memory_bytes: 6656
N = int(input())
h = list(map(int, input().split()))

# dp[i] := iからN-1までいく最小コスト
dp = [-1] * N

dp[N-1] = 0
dp[N-2] = abs(h[N-1] - h[N-2])

for i in range(N-3, -1, -1):
  dp[i] = min(abs(h[i] - h[i+1]) + dp[i+1], abs(h[i] - h[i+2]) + dp[i+2])

print(dp[0])

Measured memory_bytes: 13928
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int a[100005];
int b[100005];
int c[100005];
int d[100005];
int aa,bb,n;
int main(){
    scanf("%d %d %d",&aa,&bb,&n);
    for(int i=0;i<aa;i++) scanf("%d",&a[i]),c[i]=a[i];
    for(int j=0;j<bb;j++) scanf("%d",&b[j]),d[j]=b[j];
    sort(c,c+aa);
    sort(d,d+bb);
    int mn=c[0]+d[0];
    for(int i=0;i<n;i++){
        int x,y,c;
        scanf("%d %d %d",&x,&y,&c);
        mn=min(mn,max(0,a[x-1]+b[y-1]-c));
    }
    printf("%d\n",mn);
    return 0;
}

Measured memory_bytes: 1792
// Reads multiple ints in a line, separate by a space.
// It works even if the actual number of ints is smaller than n.
// WARNING: This function does not work for -2^31.
// NOTE: This function does not handle error cases.
fun fastReadInts(n: Int): IntArray {
  val xs = IntArray(n)
  val s = readLine()!!
  var currentValue = 0
  var isNegative = false
  var currentIndex = 0
  for (c in s) {
    if (c == ' ') {
      xs[currentIndex] = currentValue * if (isNegative) -1 else 1
      currentValue = 0
      isNegative = false
      currentIndex++
    } else if (c == '-') {
      isNegative = true
    } else {
      currentValue *= 10
      currentValue += c - '0'
    }
  }
  xs[currentIndex] = currentValue * if (isNegative) -1 else 1
  return xs
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val matrix = Array(n, { fastReadInts(n) })
  for (x in 0 until n) {
    for (y in 0 until n) {
      for (z in 0 until n) {
        if (x == y || x == z || y == z) continue
        if (matrix[x][y] + matrix[y][z] < matrix[x][z]) {
          println(-1)
          return
        }
      }
    }
  }

  var ans = 0L
  for (x in 0 until n) {
    for (y in x + 1 until n) {
      val removable = (0 until n).filter { p -> p != x && p != y }
          .any { p -> matrix[x][p] + matrix[p][y] == matrix[x][y] }
      if (!removable) {
        ans += matrix[x][y]
      }
    }
  }
  println(ans)
}


Measured memory_bytes: 108716
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >> x;
 
  if (x>=1&&x<=10) {
    cout <<x+x*x+x*x*x << endl;
  }
 
  else {
    cout << "error" << endl;
  }
}


  
 

 



Measured memory_bytes: 3632
import java.io.*;
import java.util.StringTokenizer;

import static java.lang.Math.*;

public class Main {
  public static void main(String[] args) {
    new Main().solve();
  }

  private void solve() {
    try(InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {

      String s = in.next();

      boolean isGood =
        s.charAt(0) != s.charAt(1) && s.charAt(1) != s.charAt(2) && s.charAt(2) != s.charAt(3)
        ? true : false;

      String ans = isGood ? "Good" : "Bad";
      out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  int atoi(String s) { return Integer.parseInt(s); }
  long atol(String s) { return Long.parseLong(s); }

  static class InputReader implements AutoCloseable {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream), 32768);
      st = null;
    }
    public String next() {
      if (st == null || !st.hasMoreTokens()) {
        try { st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      }
      return st.nextToken();
    }
    public int nextInt() { return Integer.parseInt(next()); }
    public long nextLong() { return Long.parseLong(next()); }
    int[] mapInt(int len) {
      int[] ret = new int[len];
      for (int i = 0; i < len; i++) ret[i] = Integer.parseInt(next());
      return ret;
    }
    long[] mapLong(int len) {
      long[] ret = new long[len];
      for (int i = 0; i < len; i++) ret[i] = Long.parseLong(next());
      return ret;
    }
    @Override public void close() throws IOException { br.close(); }
  }
}

Measured memory_bytes: 21332
import java.lang.Integer.min
import java.util.*

fun readInt(): Int = readLine()!!.toInt()
fun readInts(): List<Int> = readLine()!!.split(" ").map { it.toInt() }

fun parseInt(): Int {
    var digit = System.`in`.read()
    while(digit <= 32) {
        digit = System.`in`.read()
    }

    val negative = digit == '-'.toInt()
    if (negative) {
        digit = System.`in`.read()
    }
    var res = 0
    while (digit in '0'.toInt()..'9'.toInt()) {
        res *= 10
        res += digit - '0'.toInt()
        digit = System.`in`.read()
    }
    return if (negative) -res else res
}

fun gcd(x : Int, y : Int) : Int {
    var a = x
    var b = y
    var r = 0
    while(b > 0) {
        r = a % b
        a = b
        b = r
    }
    return a
}

fun main() {
//    val t = readLine()!!.toInt()
    val t = 1

    for(testNumber in 1..t) {
        val a = readInt()
        println(a + a * a + a * a * a)
    }
}

Measured memory_bytes: 34460
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define ll long long int 

ll tree[500050][29];
 
void update(ll idx,ll x,ll n,ll c)
{
    while(idx <= n)
    {
        tree[idx][c] += x;
        idx += idx&(-idx);
    }
}
 
ll query(ll idx,ll c)
{
    int sum = 0;
    while(idx>0)
    {
        sum += tree[idx][c];
        idx -= idx & (-idx);
    }
    return sum;
}
 
int main()
{
    ll n;
    string s;
    cin>>n>>s;
    for(ll i=1; i<=s.size(); i++)
    {
        update(i,1,s.size(),s[i-1]-'a');
    }
 
    ll q;
    char c;
    // scanf("%d",&q);
    cin>>q;
    for(ll rt=0;rt<q;rt++)
    {
       	ll type;
        cin>>type;
        if(type==2)
        {
            // scanf("%d %d",&l,&r);
            ll l,r;
          	ll ans=0;
            cin>>l>>r;
            for(ll k=0; k<26; k++)
            {
                ll r1 = query(r,k);
                ll l1 = query(l-1,k);
                if(r1-l1>0) ans++;
            }
            // printf("%d\n",ans);
            cout<<ans<<"\n";
        }
        else{
        	ll index;
        	char val;
        	cin>>index;
        	cin>>val;
        	// s[index-1]=val;
        	if(s[index-1]==val){
        		continue;
        	}
        	else{
        		update(index,-1,s.size(),s[index-1]-'a');
        		s[index-1]=val;
        		update(index,1,s.size(),val-'a');
        	}
        }
    }
    return 0;
}

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

using namespace std;

int main() {

    int N;
    cin >> N; 

    vector<int> members;

    for (int i = 1; i <= N; i++) {
        if (i % 3 != 0) {
            if (i % 5 != 0){
                members.push_back(i);
            }
        }
    }

    cout << accumulate(members.begin(), members.end(), 0LL) << endl;

    return 0;
}

Measured memory_bytes: 7408