akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  vector<int>c(n);
  int sum = 0;
for(int i = 0;i<n;i++) cin >> a[i];
for(int i = 0;i<n;i++) {
  cin >> b[i];
  sum += b[i];}
for(int i = 0;i<n-1;i++) cin >> c[i];
for(int i = 0;i<n-1;i++){
  if(a[i]+1==a[i+1])
  sum += c[a[i]-1];
}
cout << sum;
return 0;

}

Measured memory_bytes: 256
#include <iostream>                            
using namespace std;                           
                                               
int main(){                                    
        int n,m;                               
        cin >> n >> m;                         
        if(n%3==0 || m%3==0||(n+m)%3==0){      
                cout << "Possible" << endl;    
        }                                      
        else cout << "Impossible" << endl;     
        return 0;                              
} 

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

#define ll long long

int cost[200005];
int harr[200005];
ll int dp[200005];
ll int seg[800005];


void build(int node, int start, int end)
{
  if(start == end)
    seg[node] = 0;
  else
  {
    int mid = (start + end) / 2;
    build(node*2, start, mid);
    build(node*2 + 1, mid+1, end);
    seg[node] = max(seg[node*2], seg[node*2 + 1]);
  }
  return;
}

void update(int node, int start, int end, int l, int r, ll int val)
{
  if(end < l || start > r)
    return;

  if(start == end)
    seg[node] = val;
  else
  {
    int mid = (start + end) / 2;
    update(node*2, start, mid, l, r, val);
    update(node*2 + 1, mid+1, end, l, r, val);
    seg[node] = max(seg[node*2], seg[node*2+1]);
  }
  return;
}

ll int query(int node, int start, int end, int l, int r)
{
  if(end < l || start > r)
    return 0;

  if(start >= l && end <= r)
    return seg[node];

  ll int q1, q2;
  int mid = (start + end) / 2;
  q1 = query(node*2, start, mid, l, r);
  q2 = query(node*2+1, mid+1, end, l, r);

  return max(q1, q2);
}


int main()
{
  int n;
  ll int y;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>harr[i];
  for(int i=0;i<n;i++)
    cin>>cost[i];

  for(int i=0;i<n;i++)
  {
    y = query(1, 0, n, 0, harr[i]);
    dp[i] = y + cost[i];
    update(1, 0, n, harr[i], harr[i], dp[i]);
  }

  for(int i=0;i<=n;i++)
    y = max(y, dp[i]);

  cout<<y<<endl;
  return 0;
}


Measured memory_bytes: 9600
n=gets.chomp.to_i
v=gets.chomp.split(" ").map{|s| s.to_i}
c=gets.chomp.split(" ").map{|s| s.to_i}
ans=0

for i in 0..n-1
  if v[i]-c[i] > 0
    ans+=v[i]-c[i]
  end
end
puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
long long dp[100005][2];
int main()
{
    char s[100005];
    cin>>s+1;
    dp[0][1]=1;
    dp[0][0]=0;
    int n=strlen(s+1);
    for(int i=1;s[i];i++)
    {
        dp[i][0]=(dp[i-1][0]*3)%mod;
        if(s[i]=='1')
        {
            dp[i][1]=(dp[i-1][1]*2)%mod;
            dp[i][0]+=dp[i-1][1];
            dp[i][0]=(dp[i][0])%mod;
        }
        else
        {
            dp[i][1]=dp[i-1][1];
        }
    }
    printf("%lld\n",(dp[n][1]+dp[n][0])%mod);
}

Measured memory_bytes: 5388
#include <bits/stdc++.h>
using namespace std;
int flag[100000];
vector<int> G[100000];
int color = 0;

void dfs(int f)
{
    for (int i = 0; i < G[f].size(); i++)
    {
        if (flag[G[f][i]] == -1)
        {
            flag[G[f][i]] = color;
            dfs(G[f][i]);
        }
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    int f, g;
    for (int i = 0; i < m; i++)
    {

        cin >> f >> g;
        G[f].push_back(g);
        G[g].push_back(f);
    }

    for (int i = 0; i < n; i++)
        flag[i] = -1;

    for (int i = 0; i < n; i++)
    {
        if (flag[i] == -1)
        {
            color = i;
            flag[i] = color;
            dfs(i);
        }
    }
    int q;
    cin >> q;
    while (q--)
    {
        cin >> f >> g;
        if (flag[f] == flag[g])
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
}


Measured memory_bytes: 12096
program abc119d
  implicit none
  integer a, b, q, i, si, ti
  integer(8) s_west, s_east, t_west, t_east, d(4)
  integer(8), dimension(:), allocatable :: s, t, x
  integer(8), parameter :: inf = 10_8**11

  read *, a, b, q
  allocate(s(a), t(b), x(q))
  read *, s, t, x
  s = [-inf, s, inf]
  t = [-inf, t, inf]
  do i = 1, q
     si = bsrch(s, x(i))
     ti = bsrch(t, x(i))
     s_west = x(i) - s(si - 1)
     s_east = s(si) - x(i)
     t_west = x(i) - t(ti - 1)
     t_east = t(ti) - x(i)
     d(1) = merge(s_west, t_west, s_west > t_west)
     d(2) = merge(s_east, t_east, s_east > t_east)
     d(3) = merge(s_west + t_east * 2, s_west * 2 + t_east, s_west > t_east)
     d(4) = merge(t_west + s_east * 2, t_west * 2 + s_east, t_west > s_east)
     print *, minval(d)
  end do
contains
  integer function bsrch(ary, v)
    integer(8), intent(in) :: ary(:), v
    integer low, mid, high

    low = lbound(ary, 1)
    high = ubound(ary, 1)

    do while (low < high)
       mid = low + (high - low) / 2
       if (ary(mid) < v) then
          low = mid + 1
       else
          high = mid
       end if
    end do
    bsrch = low
  end function bsrch
end program abc119d


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

void test(vector<int> v)
{
  const int X = v[v.size() / 2];
  while (1 < v.size()) {
    vector<int> u;
    for (int i = 1; i + 1 < v.size(); ++i) {
      u.push_back(
        v[i - 1] + v[i] + v[i + 1]
        - min({v[i - 1], v[i], v[i + 1]})
        - max({v[i - 1], v[i], v[i + 1]})
        );
    }
    assert(v.size() - 2 == u.size());
    v = u;
  }

  assert(X == v[0]);
}

vector<int> f(int n, int x)
{
  const int N = n * 2 - 1;
  if (x == 1) {
    return {};
  }
  if (x == N) {
    return {};
  }

  vector<int> v;
  for (int i = 1; i <= N; ++i) {
    v.push_back(i);
  }
  
  int y = v.size() / 2;
  swap(v[x - 1], v[y]);
  swap(v[0], v[y - 1]);
  swap(v[v.size() - 1], v[y + 1]);
  
  return v;
}

int main(int argc, char *argv[])
{
  // const int N = 1000;
  // for (int i = 1; i <= 2 * N - 1; ++i) {
  //   vector<int> v = f(N, i);
  //   if (v.empty()) {
  //     cout << "IGNORE: " << i << endl;
  //     continue;
  //   }
  //   cout << i << endl;
  //   test(v);
  // }
  // return 0;
  
  int n, x;
  while (cin >> n >> x) {
    vector<int> v = f(n, x);
    if (v.size()) {
      cout << "Yes" << endl;
      each (i, v) cout << i << endl;
    } else {
      cout << "No" << endl;
    }
  }
  
  return 0;
}


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


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


N, K = readnums()
d = []
A = []
for _ in range(K):
    d = readint()
    a = list(readnums())
    for x in a:
        A.append(x)

print(N - len(set(A)))


Measured memory_bytes: 9240
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
using vii = vector<vector<int>>;
using vi = vector<int>;


int main()
{
    char x;
    cin >> x;
    x++;
    cout << x << endl;
    return 0;
}

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

using namespace std;
#define ull unsigned long long
#define ll long long
const int inf = 1e9;
const int MAXN = 4e6+4;

vector<vector<int>> vect(3e5+1, vector<int>(0));
vector<bool> was(3e5+1, false);
vector<int> dp(3e5+1, 0);
vector<int> depth(3e5+1, 0);


void solve(){
    int n;
    string s;
    cin>>n>>s;
    int arr[3];
    int ans=0;
    for(int i=0;i<=999;i++){
        int tmp=i;
        arr[2]=tmp%10;
        tmp/=10;
        arr[1]=tmp%10;
        tmp/=10;
        arr[0]=tmp%10;
        bool a=false, b=false, c=false;
        for(int j=0;j<n;j++){
            if(!a ){
               if((s[j]-'0')==arr[0]) a=true;
            }
            else if(!b){
                if((s[j]-'0')==arr[1]) b=true;
            }
            else if(!c){
                if((s[j]-'0')==arr[2]) c=true;
            }
        }
        if(c){
            ans++;
        }
    }
    cout<<ans;

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n=1;
    for(int i=0;i<n;i++) solve();
    return 0;
}

Measured memory_bytes: 9728
n=int(input())
h=[int(i) for i in input().split()]
dp=[100000 for i in range(n+1)]
dp[0],dp[1]=0,0
for i in range(2,n+1):
    dp[i]=min(dp[i-2]+abs(h[i-1]-h[max(0,i-3)]),dp[i-1]+abs(h[i-1]-h[i-2]))
print(dp[n])

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

struct QueueItem
{
  uint64_t s, x, y, z;
  
  QueueItem(uint64_t s, uint64_t x, uint64_t y, uint64_t z)
    : s(s), x(x), y(y), z(z) {}
  bool operator<(const QueueItem &item) const { return s < item.s; }
};

int main()
{
  uint64_t X, Y, Z, K;
  std::cin >> X >> Y >> Z >> K;
  
  std::vector<uint64_t> A(X), B(Y), C(Z);
  for (uint64_t x = 0; x < X; ++x) { std::cin >> A[x]; }
  for (uint64_t y = 0; y < Y; ++y) { std::cin >> B[y]; }
  for (uint64_t z = 0; z < Z; ++z) { std::cin >> C[z]; }
  
  std::sort(A.begin(), A.end(), std::greater<uint64_t>());
  std::sort(B.begin(), B.end(), std::greater<uint64_t>());
  std::sort(C.begin(), C.end(), std::greater<uint64_t>());
  
  std::vector<std::bitset<1000>> visited(1000000, 0);
  uint64_t count = 0;
  std::priority_queue<QueueItem> q;
  q.emplace(A[0] + B[0] + C[0], 0, 0, 0);
  visited[0][0] = true;
  while (count < K) {
    QueueItem item = q.top(); q.pop();
    std::cout << item.s << std::endl;
    ++count;
    
    if (item.x + 1 < X && !visited[(item.x + 1) * 1000 + item.y][item.z]) {
      q.emplace(A[item.x + 1] + B[item.y] + C[item.z], item.x + 1, item.y, item.z);
      visited[(item.x + 1) * 1000 + item.y][item.z] = true;
    }
    
    if (item.y + 1 < Y && !visited[item.x * 1000 + (item.y + 1)][item.z]) {
      q.emplace(A[item.x] + B[item.y + 1] + C[item.z], item.x, item.y + 1, item.z);
      visited[item.x * 1000 + (item.y + 1)][item.z] = true;
    }
    
    if (item.z + 1 < Z && !visited[item.x * 1000 + item.y][item.z + 1]) {
      q.emplace(A[item.x] + B[item.y] + C[item.z + 1], item.x, item.y, item.z + 1);
      visited[item.x * 1000 + item.y][item.z + 1] = true;
    }
  }
  
  return 0;
}

Measured memory_bytes: 125568
// atcoder/abc133/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, d;
  while (cin >> n >> d) {
    vector<vector<int>> v;
    for (int i = 0; i < n; ++i) {
      vector<int> u(d);
      cin >> u;
      v.push_back(u);
    }

    auto fn = [] (int n) {
      for (int i = 0; i * i <= n; ++i) {
        if (i * i == n) {
          return true;
        }
      }
      return false;
    };

    int cnt = 0;
    for (int i = 0; i < v.size(); ++i) {
      for (int j = i + 1; j < v.size(); ++j) {
        int x = 0;
        for (int k = 0; k < v[i].size(); ++k) {
          int a = v[i][k] - v[j][k];
          x += a * a;
        }
        assert(0 <= x);
        cnt += fn(x);
      }
    }
    cout << cnt << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using tpl = tuple<char, int>;
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int N, K;
int main(){

    cin >> K >> N;
    if(K % 2 == 0){
        // 最初は K / 2、あとは K
        cout << K / 2 << " ";
        for(int i = 1; i < N; i++){
            cout << K << " ";
        }
        cout << endl;
    }
    else{
        // (K + 1) / 2 からceil((N-1)/2)個前に戻ったところが答え
        vector<int> ans(N, (K + 1) / 2);
        for(int i = 0; i < N / 2; i++){
            if(ans.back() > 1){
                ans.back()--;
                while((int)ans.size() < N) 
                    ans.push_back(K);
            }
            else{
                ans.pop_back();
            }
        }
        for(int a : ans){
            cout << a << " ";
        }
        cout << endl;
    }

    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = 0;
		
		if(a % 2 == 0  && b % 2 == 1)
			out.println("IMPOSSIBLE");
		else if(a % 2 == 1 && b % 2 == 0)
			out.println("IMPOSSIBLE");
		else {
			int n = Math.abs(a - b) / 2;
			ans = Math.max(a, b) - n;
			out.println(ans);
		}		
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

vector<pair<ll, ll>> prime_factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll p = 2; n >= p * p; p++) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            num++;
            n /= p;
        }
        res.push_back(make_pair(n, num));
    }

    if (n != 1)res.push_back(make_pair(n, 1)); 
    return res;
}

int main() {
    ll a, b; cin >> a >> b;
    ll g = gcd(a, b);
    auto v = prime_factorize(g);
    cout << v.size() + 1 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n,i,j;
  scanf("%d",&n);
  int arr[n];
  for(i=0;i<n;i++)scanf("%d",&arr[i]);
  int sum=0;
  for(i=0;i<n;i++)
  {
    if(i%2==0 && arr[i]%2==1)
      sum++;
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 1724
using System;
using System.Linq;

namespace ABC087_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var Ai = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var Aj = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var max = 0;
            for (int i = 0; i < N; i++)
            {
                var sum = Ai.Take(i+1).Sum() + Aj.Skip(i).Sum();
                if (max < sum) max = sum;
            }
            Console.WriteLine(max);
        }
    }
}



Measured memory_bytes: 13780
open System

[<EntryPoint>]
let main argv =
    let n = Console.ReadLine() |> int
    let a = Console.ReadLine().Split(' ') |> Array.map int
    let mutable ans, target = 0, 1
    for x in a do
        if x = target then
            ans <- ans + 1
            target <- target + 1

    printfn "%d" (if ans = 0 then -1 else (n - ans))
    0


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

#define F first
#define S second

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 = 55, M = 1010, INF = 0x3f3f3f3f;

int n;
int a[N];
vector<PII> res;

int main()
{
	cin >> n;
	
	bool flag = false;
	int maxa = -INF, mina = INF, axi, ini;
	
	for (int i = 1; i <= n; i ++ )
	{
		cin >> a[i];
		if (a[i] < mina) mina = a[i], ini = i;
		if (a[i] > maxa) maxa = a[i], axi = i;
		if (a[i] < 0) flag = true;
	}
	
	if (!flag)
	{
		for (int i = 1; i < n; i ++ ) res.push_back({i, i + 1});
	}
	else if (maxa > -mina)
	{
		for (int i = 1; i <= n; i ++ ) res.push_back({axi, i});
		for (int i = 1; i < n; i ++ ) res.push_back({i, i + 1});
	}
	else
	{
		for (int i = 1; i <= n; i ++ ) res.push_back({ini, i});
		for (int i = n; i > 1; i -- ) res.push_back({i, i - 1});
	}
	
	cout << res.size() << endl;
	for (auto u : res) cout << u.F << ' ' << u.S << endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 0
for i in range(N):
    if A[i] < B[i]:
        ans += A[i]
        tmp = min(A[i+1], B[i]-A[i])
        ans += tmp
        A[i+1] -= tmp
    else:
        ans += B[i]
print(ans)

Measured memory_bytes: 18624
main :: IO()
main = do
    [a,b] <- map read . words <$> getLine
    putStrLn $ show $ ans [a,b]

ans :: [Int] -> Int
ans [a,b]
    | a + 1 < b				= 2 * b - 1
    | b + 1 < a				= 2 * a - 1
    | otherwise				= a + b
ans ls = 0

Measured memory_bytes: 508
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long k = sc.nextLong();
		long answer = 0;
		if(a>=k) {
			answer=k;
		}
		else {
			answer+=a;
			k=k-a;
			k=k-b;
			answer-=(k*1);
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 35960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5,mod=998244353;
ll n,a,b;
ll k,f[N],invf[N];
ll C(int n,int m)
{
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
int main()
{
    f[0]=f[1]=invf[0]=invf[1]=1;
    for(int i=2;i<N;i++) f[i]=f[i-1]*i%mod,invf[i]=(mod-mod/i)*invf[mod%i]%mod;
    for(int i=2;i<N;i++) invf[i]=invf[i-1]*invf[i]%mod;
    scanf("%lld%lld%lld",&n,&a,&b);
    scanf("%lld",&k);
    ll ans=0;
    for(int i=0;i*a<=k&&i<=n;i++)
    {
        if((k-i*a)%b) continue;
        ll s=(k-i*a)/b;
        if(s>n) continue;
        ans=(ans+C(n,i)*C(n,s))%mod;
    }
    printf("%lld\n",ans);
}


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

const ll INF = 1e17;

int main()
{
	int L;
	cin >> L;
	vector<ll> A(L);
	for (int i = 0; i < L; i++) {
		cin >> A[i];
	}
	vector<vector<ll>> ldp(3, vector<ll>(L + 1, INF));
	ldp[0][0] = ldp[1][0] = ldp[2][0] = 0;
	for (int i = 0; i < L; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k <= j; k++) {
				if (j == 0) {
					ldp[j][i + 1] = min(ldp[j][i + 1], ldp[k][i] + A[i]);
				}
				else if (j == 1) {
					ldp[j][i + 1] = min(ldp[j][i + 1], ldp[k][i] + (A[i] <= 2 ? 2 - A[i] : A[i] % 2));
				}
				else {
					ldp[j][i + 1] = min(ldp[j][i + 1], ldp[k][i] + (A[i] <= 1 ? 1 - A[i] : (A[i] - 1) % 2));
				}
			}
		}
	}
	vector<vector<ll>> rdp(3, vector<ll>(L + 1, INF));
	rdp[0][L] = rdp[1][L] = rdp[2][L] = 0;
	for (int i = L - 1; i >= 0; i--) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k <= j; k++) {
				if (j == 0) {
					rdp[j][i] = min(rdp[j][i], rdp[k][i + 1] + A[i]);
				}
				else if (j == 1) {
					rdp[j][i] = min(rdp[j][i], rdp[k][i + 1] + (A[i] <= 2 ? 2 - A[i] : A[i] % 2));
				}
				else {
					rdp[j][i] = min(rdp[j][i], rdp[k][i + 1] + (A[i] <= 1 ? 1 - A[i] : (A[i] - 1) % 2));
				}
			}
		}
	}
	ll res = INF;
	for (int i = 0; i <= L; i++) {
		ll lv = INF, rv = INF;
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				lv = min(lv, ldp[j][i]);
				rv = min(rv, rdp[k][i]);
			}
		}
		res = min(res, lv + rv);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 12772
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    rep(i, 2000) {
        if (floor((double)i * 0.08) == a && floor((double)i * 0.1) == b) {
            cout << i << endl;
            return 0;
        }
        else continue;
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  rep (i, m) cin >> a[i];
  vector<int> dis(m - 1);
  sort(a.begin(), a.end());
  rep (i, m - 1) dis[i] = abs(a[i] - a[i + 1]);

  vector<int> sorted_dis = dis;
  sort(sorted_dis.begin(), sorted_dis.end());
  reverse(sorted_dis.begin(), sorted_dis.end());

  ll ans = accumulate(dis.begin(), dis.end(), 0);
  for (int i = 0; i < n - 1 && i < m - 1; i++) ans -= sorted_dis[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4184
#include<stdio.h>
#include<iostream>
using namespace std;

string W;
int main (){
    cin >> W;
    int l = W.length();
    int a[100] = {0};
    for(int i=0; i<l; i++){
        int x = W[i] - '0';
        a[x]++;
    }
    for(int i=0; i<l; i++){
        int x = W[i] - '0';
        if ( a[x] % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD = 1000000007>
struct Mint{
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }
  
  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}
  
  Mint inv(){return pow(MOD-2);}
  
  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}
  
  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  // find x s.t. a^x = b
  static T log(Mint a,Mint b){
    const T sq=40000;
    unordered_map<T, T> dp;
    dp.reserve(sq);
    Mint res(1);
    for(Int r=0;r<sq;r++){
      if(!dp.count(res.v)) dp[res.v]=r;
      res*=a;
    }
    Mint p=a.inv().pow(sq);
    res=b;
    for(Int q=0;q<=MOD/sq+1;q++){
      if(dp.count(res.v)){
        T idx=q*sq+dp[res.v];
        if(idx>0) return idx;
      }
      res*=p;
    }
    assert(0);
    return T(-1);
  }
  
  static Mint comb(long long n,Int k){
    Mint res(1);
    for(Int i=0;i<k;i++){
      res*=Mint(n-i);
      res/=Mint(i+1);
    }
    return res;
  }
};

//INSERT ABOVE HERE
signed main(){
  Int h,w,k;
  cin>>h>>w>>k;
  using M = Mint<Int>;

  M ans{0};
  for(Int d=1;d<h;d++)
    ans+=M(d)*M(h-d)*M(w)*M(w);

  for(Int d=1;d<w;d++)
    ans+=M(d)*M(w-d)*M(h)*M(h);
  
  ans*=M::comb(h*w-2,k-2);
  cout<<ans.v<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    char s[100001];

    if (scanf("%s", s) < 1) return 0;

    int len = strlen(s);

    for (int i = 0; i < len; i++)
    {
        if ((i + 1) % 2 == 1) printf("%c", s[i]);
    }

    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;


int main(){
    int N,min,d,max_x,min_x;
    cin>>N;
    vector<int> X(N);
    for(int i=0; i<N;i++){
        cin>>X[i];
    }
    auto m=minmax_element(X.begin(),X.end());
    min_x=*m.first;
    max_x=*m.second;

    min=1000000000;
    for(int i=min_x;i<=max_x;i++){
        d=0;
        for(int j=0;j<N;j++){
            d=d+pow(i-X[j],2);
        }
        if(d<min){
            min=d;
        }
    }
    cout<<min<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int main(){
  int n;
  long long int ans=0;
  std::cin>>n;
  std::vector<int>a(n);
  for(int i=0;i<n;i++){
    std::cin>>a[i];
  }
  std::sort(a.begin(),a.end());
  std::reverse(a.begin(),a.end());
  ans+=a[0];
  for(int i=0;i<n/2-1;i++){
    ans+=a[i+1]*2;
  }
  if(n%2==1){
    ans+=a[n/2];
  }
  std::cout<<ans<<std::endl;
  return 0;
}

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

typedef long long ll;

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


int main(){
    ios::sync_with_stdio(false);
    int x,y;
    cin >> x >> y;

    cout << gcd(x,y) << endl;
}



Measured memory_bytes: 3160
#include<stdio.h>

int main(void) {
	int N;

	scanf("%d", &N);

	int i;
	int v[N], c[N];
	int rv[N];
	int max;

	for (i = 0;i < N;i++) {
		scanf("%d", &v[i]);
	}
	for (i = 0;i < N;i++) {
		scanf("%d", &c[i]);
	}
	for (i = 0;i < N;i++) {
		rv[i] = v[i] - c[i];
		if (rv[i] > 0) {
			max += rv[i];
		}
	}

	printf("%d", max);

	return 0;

}

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

int main(void){
    vector<int> Time(5);
    for (int i = 0; i < 5; i++) cin >> Time[i];
    vector<int> NextTime(5);
    for (int i = 0; i < 5; i++){
        if (Time[i] % 10 == 0) NextTime[i] = Time[i];
        else NextTime[i] = Time[i] - Time[i] % 10 + 10;
    }
    
    int ans = 999999999;
    for (int i = 0; i < 5; i++){
        int totaltime = 0;
        for (int j = 0; j < 5; j++){
            if (i == j) totaltime += Time[i];
            else totaltime += NextTime[j];
        }
        ans = min(ans, totaltime);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}


void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> x(n, -1);
  rep(i, m) {
    int s, c;
    cin >> s >> c;
    s--;
    if (x[s] != -1 && x[s] != c) {
      cout << -1 << endl;
      return;
    }
    x[s] = c;
  }

  // 最初 0 じゃないのにしなくていい
  if (n == 1 && (x[0] == -1 || x[0] == 0)) {
    cout << 0 << endl;
    return;
  }

  rep(i, n) { // 最初 0 が続く
    if (x[i] != 0) break;
    cout << -1 << endl;
    return;
  }

  rep(i, n) { // 最初 0 じゃないのにする
    if (x[i] != -1) break;
    x[i] = 1;
    break;
  }

  rep(i, n) {
    if (x[i] == -1) x[i] = 0;
  }

  rep(i, n) cout << x[i]; cout << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Ohgas' Fortune
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		while(m--!=0){
			int a = sc.nextInt();
			int t = sc.nextInt();
			int n = sc.nextInt();
			int max = a;
			while(n--!=0){
				int k = sc.nextInt();
				double r = sc.nextDouble();
				int b = sc.nextInt();
				if(k==0){
					int x = a;
					int rishi = 0;
					for(int i=0;i<t;i++){
						rishi += x*r;
						x -= b;
					}
					max = Math.max(max, x+rishi);
				}
				else{
					int x = a;
					for(int i=0;i<t;i++)x = (int) (x + x*r - b);
					max = Math.max(max, x);
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 13000
main = interact $ unlines . map (show . itp1_10_c) . read' . lines
 where read' xs = case xs of {["0"] -> []; (n:ss:xs') -> (read n, map read (words ss)) : read' xs'} 

itp1_10_c (n,ss) = sqrt $ sum (map (\s -> (s - med ss)^2) ss) / fromIntegral n
 where med ss = sum ss / fromIntegral n

Measured memory_bytes: 5548
import java.util.*;
 
public class Main{
  public static void main(String args[]){
    int[] a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    System.out.println(a[n-1]);
  }
}

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

const int md = 998244353;

inline int add(int a, int b) 
{
	a += b;
	if (a >= md) a -= md;
	return a;
}
inline int mul(int a, int b) 
{
	return (int)((long long)a * b % md);
}
inline int po(int a, int b) 
{
	int r = 1;
	while (b) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}
inline int inv(int a) 
{
	return po(a, md - 2);
}
inline int di(int a, int b) 
{
	return mul(a, inv(b));
}

const int N = 200000;
int fact[N];
void fact_init() 
{
	fact[0] = 1;
	for (int i = 1; i < N; ++i) fact[i] = mul(fact[i - 1], i);
}

int Cnk(int n, int k) 
{
	return di(fact[n], mul(fact[k], fact[n - k]));
}

int n, m, k;

int main() 
{
	fact_init();
	scanf("%d%d%d", &n, &m, &k);
	int ans = 0;
	for (int i = 0; i <= k; ++i) {
		ans = add(ans, mul(Cnk(n - 1, i), mul(m, po(m - 1, n - i - 1))));
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2484
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<u32>();
    let H = v[0];
    let W = v[1];

    let v2 = read_vec::<u32>();
    let h = v2[0];
    let w = v2[1];

    println!("{}", H * W + h * w - h * W - w * H);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;





int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) ans++;
    }
    
    cout << ans;


}


Measured memory_bytes: 764
#include <stdio.h>

int main()
{
    int n, a;
    int i;
    int min;
    int max;
    long long sum;

    scanf("%d", &n);

    min = 0;
    max = 0;
    sum = 0;
    for(i = 0; i < n; i++) {
        scanf("%d", &a);
        if(i == 0) {
            min = a;
            max = a;
        } else if(a < min) {
            min = a;
        } else if(a > max) {
            max = a;
        }
        sum += a;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


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

typedef long long ll;
bool palin(string str)
{
	bool cond = true;
	for(int i=0;i<str.length();i++){
		if(str[i] != str[str.length()-1-i])
		return false;
	}

	return true;
}

int main()
{
	string str; cin >> str;
	int len = str.length();
	int rem = len+1-(len+3)/2;
	string str1=str.substr(0,(len-1)/2);
	string str2=str.substr(((len+3)/2)-1, rem);
	//cout<<str<<'\n';
	//cout<<str1<<'\n';
	//cout<<str2<<'\n';
	if(palin(str))
	{
		if(palin(str1) && palin(str2)) cout<<"Yes";
		else cout << "No";
	}

	else cout << "No";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF (2e9)
#define EPS (1e-7)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if ((a == b) && (b==c)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
let lines = [];
reader.on("line", line => {
  lines.push(line);
});
reader.on("close", () => {
  const pai = 3.1415926535
  let ans = pai * lines[0] * 2
  console.log(ans);
});

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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define ANTHRO(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define ANTHRO(x...)
#endif


#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define EPS 1e-9
/*
	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    No, nothing good starts in a getaway car
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n; cin>>n;
    vector<ll> inp(n),op(n+1,0);
    for(ll i=1;i<n;i++){
		cin>>inp[i];
		op[inp[i]]++;
	}
	for(ll i=1;i<=n;i++){
		cout<<op[i]<<endl;
	}
    return 0;
}


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

int main() {
int n;
cin >> n;
vector<int> b(n-1);
vector<int> a(n);
rep(i,n-1) cin >> b.at(i);
a.at(0) = b.at(0);
a.at(n-1) = b.at(n-2);
for (int i = 1; i < n-1; i++) {
  if(b.at(i) <= b.at(i-1)) a.at(i) = b.at(i);
  else a.at(i) = b.at(i-1);
}
int ans = 0;
rep(i,n){
  ans += a.at(i);
}
cout << ans << endl;

}


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

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v)
{
    for (auto& e : v) {
        is >> e;
    }
    return is;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;

class DisjointSets
{
public:
    DisjointSets(const int v)
    {
        m_parent.resize(v);
        m_rank.resize(v);
        m_size.resize(v);
        for (int i = 0; i < v; i++) {
            m_parent[i] = i;
            m_rank[i] = 0;
            m_size[i] = 1;
        }
    }

    bool same(const int a, const int b)
    {
        return find(a) == find(b);
    }


    int find(const int a)
    {
        if (m_parent[a] == a) {
            return a;
        } else {
            return m_parent[a] = find(m_parent[a]);
        }
    }

    void unite(const int a_, const int b_)
    {
        const int a = find(a_);
        const int b = find(b_);
        if (a == b) {
            return;
        }
        if (m_rank[a] > m_rank[b]) {
            m_parent[b] = a;
            m_size[a] += m_size[b];
        } else {
            m_parent[a] = b;
            m_size[b] += m_size[a];
        }
        if (m_rank[a] == m_rank[b]) {
            m_rank[b]++;
        }
    }

    int getSize(const int a)
    {
        return m_size[m_parent[a]];
    }

private:
    vector<int> m_parent;
    vector<int> m_rank;
    vector<int> m_size;
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    DisjointSets uf(N);
    for (int i = 0; i < M; i++) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
    }
    if (uf.same(0, 1)) {
        assert(false);
    }
    const ll s = uf.getSize(0);
    const ll t = uf.getSize(1);
    const ll m = min(s * (N - s), t * (N - t));
    cout << N * (N - 1) / 2 - m - M << endl;

    return 0;
}


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

int main(){
    string S;
    cin >> S;

    int a, b;
    a = 10*(S[0]-'0') + (S[1]-'0');
    b = 10*(S[2]-'0') + (S[3]-'0');

    if ((0 < a && a <= 12) && (0 < b && b <= 12)) cout << "AMBIGUOUS" << endl;
    else if ((a==0 || a > 12) && (b==0 || b > 12)) cout << "NA" << endl;
    else if (a==0 || a > 12) cout << "YYMM" << endl;
    else cout << "MMYY" << endl;

}


Measured memory_bytes: 256
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = 1000000000

for i in range(n - k + 1):
  l = i
  r = i + k - 1
  cost = min(abs(x[r]) + abs(x[r] - x[l]), abs(x[l]) + abs(x[r] - x[l]))
  ans = min(ans, cost)

print(ans)



Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	int ans = 0;
	int cnt = 0;
	int curr = H.back();
	for (int i = N - 2; i >= 0; --i) {
		if (H[i] >= curr) {
			++cnt;
		} else {
			ans = max(ans, cnt);
			cnt = 0;
		}
		curr = H[i];
	}
	ans = max(ans, cnt);
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  string S;
  cin>>S;

  string T="";
  rep(i,3) T+=S[i];
  cout<<T<<endl;

  return 0;
}


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


int main() {

	int N,A,B,C,X;
	int *Y;
	int i,count,pos;
	int Answer[1000],a=0;

	for(;;) {
		scanf("%d %d %d %d %d",&N,&A,&B,&C,&X);
		if(N==0&&A==0&&B==0&&C==0&&X==0) break;
		Y=(int *)malloc(N*sizeof(int));

		for(i=0;i<N;i++)
			scanf("%d",&Y[i]);

		count=-1,pos=0;
		while(pos<N) {
			//printf("%d %d %d\n",pos,X,Y[pos]);
			if(X==Y[pos])
				pos++;
			X=(A*X+B)%C;
			count++;
			if(count>10000) {
				count=-1;
				break;
			}
		}
		Answer[a]=count;
		a++;
	}
	for(i=0;i<a;i++)
		printf("%d\n",Answer[i]);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n;
    double m;
    cin>>n>>m;
    double arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    double sum = 0;
    for(ll i=0;i<n;i++)
        sum += arr[i];
    sum /=(4*1.0*m);
    ll cnt = 0;
    for(ll i=0;i<n;i++)
    {
        if(sum <= arr[i])
            cnt++;
    }
    if(cnt>=m)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
#define MOD 1000000007

ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}

int main(){
    ll S,M;cin>>S>>M;
    if((S+M)%2==0){
        cout<<(S+M)/2<<endl;
    }
    else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

int main(void)
{
  int n,tmp,sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>tmp;
    sum+=tmp;
  }
  sum-=n;
  cout<<sum<<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 n = scan.nextInt();
		int m = scan.nextInt();
		
		if(n == m) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

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

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


// Sieve of Eratosthenes
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main(){
    Sieve sieve(1e6);
    int n; cin>>n;
    vector<int> a(n);
    map<int,int> mp;

    rep(i,n){
        cin>>a[i];
        auto f = sieve.factor(a[i]);
        for(auto p : f){
            mp[p.first] = max(mp[p.first],p.second);
        }
    }

    mint lcm = 1;
    for(auto p : mp){
        rep(i,p.second){
            lcm *= p.first;
        }
    }

    mint ans;
    rep(i,n) ans += lcm / a[i];
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 7776
#include<bits/stdc++.h>
#define maxn 5005
#define ll long long
using namespace std;
int arr[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int k,q;
	cin >> k >> q;
	for(int i=1;i<=k;i++)
		cin >> arr[i];
	while(q--) {
		int n,x,m;
		cin >> n >> x >> m;
		ll ans = n - 1, rmd = x % m;
		n--;
		for(int i=1;i<=k;i++) {
			int num = n / k + (i <= n % k ? 1 : 0) , val = arr[i] % m;
			rmd = rmd + (ll)val * num;
			ans -= rmd / m;
			rmd %= m;
			if(val == 0)	ans -= num;
		}
		cout << ans << endl;
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	ll ans = 0;
	string s;
	map<string ,int>mp;
	while(n--)
	{
		cin>>s;
		sort(s.begin(),s.end());
		mp[s]++;
	}
//	map<string, int>::iterator iter;
	for(auto iter = mp.begin();iter != mp.end();iter++)
	{
		int a = iter->second;
		ans += (ll)a*(a-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11776
#include<iostream>
#include<stdio.h>
#include<vector>
#include<math.h>
#include<algorithm>

using namespace std;



int main()
{
	int n;
	cin >> n;
	cout << n << ":";
	int ren = n;
	for (int i = 1; i <= sqrt(n); i++)
	{
		while (ren != 1)
		{
			if (ren % (i + 1) == 0)
			{
				cout << " " <<i + 1;
				ren = ren / (i + 1);
			}
			else break;
		}
	}

	if (ren != 1)
	{
		cout << " " << ren;
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 1164