akhauriyash/Code-Regression huggingface dataset:
package main
import (
  "fmt"
  "strconv"
)
var mod int64
func main() {
  var l,a,b,m int64
  fmt.Scan(&l,&a,&b,&m)
  mod = m
  c := make([]int64,19)
  t := int64(1)
  k := len(strconv.FormatInt(a,10))
  for d:=0;d<k;d++ { t *= 10 }
  for d:=k;d<19;d++ {
    if t-1 >= a+b*(l-1) { c[d] = l;break }
    c[d] = (t-a-1)/b+1
    t *= 10
  }
  for d:=18;d>0;d-- {
    if c[d] > 0 { c[d] -= c[d-1] }
  }
  t = 1
  y := Identity(3)
  for d:=1;d<19;d++ {
    t = (10*t)%mod
    z := NewMatrix(3)
    z[0].v[0] = t
    z[1].v[0] = 1
    z[1].v[1] = 1
    z[2].v[1] = b%mod
    z[2].v[2] = 1
    y = y.MatMul(z.Pow(c[d]))
  }
  x := Vector{[]int64{0,a%mod,1}}
  fmt.Println(x.DotProduct(y.ColVec(0)))
}
type Vector struct { v []int64 }
func(x Vector) DotProduct(y Vector) int64 {
  if len(x.v) != len(y.v) || len(x.v) == 0 { return 0 }
  d := (x.v[0]*y.v[0])%mod
  for i:=1;i<len(x.v);i++ { d = (d+x.v[i]*y.v[i])%mod }
  return d
}
type Matrix []Vector
func NewMatrix(n int) Matrix {
  m := Matrix{}
  for i:=0;i<n;i++ { m = append(m,Vector{make([]int64,n)}) }
  return m
}
func Identity(n int) Matrix {
  e := NewMatrix(n)
  for i:=0;i<n;i++ { e[i].v[i] = 1 }
  return e
}
func(a Matrix) ColVec(j int) Vector {
  if len(a) == 0 || j >= len(a[0].v) { return Vector{nil} }
  v := make([]int64,len(a))
  for i:=0;i<len(a);i++ { v[i] = a[i].v[j] }
  return Vector{v}
}
func(a Matrix) Transpose() Matrix {
  if len(a) == 0 || len(a[0].v) == 0 { return Matrix{Vector{nil}} }
  m := Matrix{}
  for j:=0;j<len(a[0].v);j++ { m = append(m,a.ColVec(j)) }
  return m
}
func(a Matrix) VecMul(x Vector) Vector {
  if len(a) == 0 || len(a[0].v) != len(x.v) ||
  len(x.v) == 0 { return Vector{nil} }
  v := make([]int64,len(a))
  for i:=0;i<len(a);i++ { v[i] = a[i].DotProduct(x) }
  return Vector{v}
}
func(a Matrix) MatMul(b Matrix) Matrix {
  if len(a) == 0 || len(a[0].v) == 0 || len(b) == 0 || len(b[0].v) == 0 ||
  len(a[0].v) != len(b) { return Matrix{Vector{nil}} }
  m := Matrix{}
  for j:=0;j<len(b[0].v);j++ { m = append(m,a.VecMul(b.ColVec(j))) }
  return m.Transpose()
}
func(a Matrix) Pow(n int64) Matrix {
  if len(a) == 0 || len(a[0].v) == 0 ||
  len(a) != len(a[0].v) { return Matrix{Vector{nil}} }
  if n == 0 { return Identity(len(a)) }
  if n%2 == 0 { c := a.Pow(n/2);return c.MatMul(c) }
  return a.MatMul(a.Pow(n-1))
}

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

using namespace std;

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

  int n, m, a, b;
  cin >> n >> m;
  vector<set<int>> adj(n+1);
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    adj[a].insert(b);
    adj[b].insert(a);
  }
  bool ok = false;
  for (int i = 1; i < n+1; ++i) {
    if (adj[1].find(i) != adj[1].end() && 
        adj[n].find(i) != adj[n].end()) {
      ok = true;
      break;
    }
  }
  cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;

  return 0;
}



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

int main() {
  long long n;
  cin >> n;
  long long i = 0;
  long long ans = 0;
  while (true) {
    i++;
    long long j = n / i;
    if ((i * j) == n) {
      ans += j - 1;
    } else {
      ans += j;
    }
    if (i >= n) {
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = Integer.parseInt(sc.next());
		int X = Integer.parseInt(sc.next());
		sc.close();

		if(500 * K >= X) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

int A[111][111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int a, b; cin>>a>>b;
	//(1 red, b - 1 white)
	int h = 100; int w = 100;
	for(int i = 0; i <= h/2; i++)
	{
		if(i%2==0)
		{
			for(int j=0;j<w;j++) A[i][j] = 1;
		}
		else
		{
			for(int j=0;j<w;j++)
			{
				if(j%2==0||b==1) A[i][j]=1;
				else
				{
					A[i][j]=0; b--;
				}
			}
		}
	}
	//(a - 1 red, 1 white)
	for(int i = h/2 + 1; i < h; i++)
	{
		if(i%2==1)
		{
			for(int j=0;j<w;j++) A[i][j] = 0;
		}
		else
		{
			for(int j=0;j<w;j++)
			{
				if(j%2==0||a==1) A[i][j]=0;
				else
				{
					A[i][j]=1; a--;
				}
			}
		}
	}	
	cout<<h<<' '<<w<<'\n';
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cout<<(A[i][j]?'.':'#');
		}
		cout<<'\n';
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    long test=1;
    // cin>>test;
    while(test--)
    {
	long long n,m,i,j,a,b,c,d,ans=0;
	cin>>n>>m;
	if(m+n<10)cout<<m+n;
	else cout<<"error";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

       int n;
        long long int k;

          cin>>n>>k;

          int arr[n+1];
          long long int f = k;

           for(int i=1;i<=n;i++)
             cin>>arr[i];

           int visited[n+1]={0};

          long long int period=0;
           int i=1;
           vector<int>y;
            int value;

            while(1){

                  if(visited[i]==0)
                  {
                    y.push_back(i);
                     visited[i]=1;
                      i=arr[i];
                  }
                  else
                  {
                     y.push_back(i);
                     value = i;
                     break;
                  }
            }

             int count=0;

              for(int i = 0;i<y.size();i++)
              {
                 if(y[i]==value)
                  break;

                  else
                  count++;
              }
          period = y.size()-1-count;


             if(f <= count)
              cout<<y[f]<<endl;

             else
           cout<<y[count + (f - count)%period];

}


Measured memory_bytes: 5828
p=lambda x:print(x,end=' ')
n=input()
p(n+':')
n=int(n)
s=n**.5
while n%2==0 and n>3:p(2);n//=2
d=3
while s>d and n>d:
 if n%d>0:d+=2
 else:p(d);n//=d
print(n)


Measured memory_bytes: 5632
import sys
#sys.setrecursionlimit(10**6)
input=sys.stdin.readline

d=int(input().rstrip())
c=[int(i)for i in input().split()]
s=[[int(i)for i in input().split()]for _ in range(d)]
last=[0]*26
for i in range(d):
    now=[s[i][j]-(c[j]*(i-last[j]))for j in range(26)]
    #print(now)
    kouho=now.index(max(now))+1
    print(kouho)
    last[kouho-1]=i
    #print(last)

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

using namespace std;

int main(){  
  int H, W;
  while(1){
    cin >> H >> W;
    if( (H == 0) && (W == 0)){
      break;
    }
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if( i == 0 || i == (H-1)){
          cout << "#";
        } else {
          if( j == 0 || j == (W-1)){
            cout << "#";
          } else {
            cout << ".";
          }
        }
      }
      cout << "" << endl;
    }
    cout << "" << endl;
  }
  return 0;
}


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

int yakusuu_num(int n){
  int x=1;
  int N=n;
  int b[210]={0};
  
  while(n>1){
    for(int i=2;i<=n;++i){
      if(n%i==0){
      ++b[i];
      n=n/i;
      }
    }
  }
  
  for(int i=2;i<=N;++i){
  	x=x*(b[i]+1);
  }
  
  return x;
}

int main() {
  int N;
  cin>>N;
  
  int ans=0;
  for(int i=1;i<=N;i=i+2){
    if(yakusuu_num(i)==8)
      ++ans;
  }
 
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    char cmp;
    int cnt=1;
    for(int i=1;i<s.size();i++){
        cmp=s[i-1];
        if(cmp!=s[i]){
            cnt++;
        }
        else continue;
    }
    cout << cnt-1 << endl;

    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
    int a, b, c;
    int count = 0;
    scanf("%d %d %d", &a, &b, &c);
    if(a == b)
        count++;
    if(a == c)
        count++;
    if(b == c)
        count++;
    if(count == 1)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N, L;
  cin >> N >> L;
  vector<i64> A(N);
  for (auto& x : A) cin >> x;
  int p = -1;
  for (int i = 0; i < N - 1; ++i) {
    if (A[i] + A[i + 1] >= L) {
      p = i;
      break;
    }
  }
  if (p == -1) {
    cout << "Impossible\n";
    return 0;
  }
  cout << "Possible\n";
  for (int i = 0; i < p; ++i) {
    cout << (i + 1) << "\n";
  }
  for (int i = N - 2; i >= p; --i) {
    cout << (i + 1) << "\n";
  }
}


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

int main() {
  long long int x;
  cin>>x;
  if(x%11==0){
    cout<<x/11*2<<endl;
    return 0;
  }
  if(x%11<=6){
    cout<<x/11*2+1<<endl;
    return 0;
  }
  cout<<x/11*2+2<<endl;
}

Measured memory_bytes: 256
n, l = map(int, input().split())
v = [l+i-1 for i in range(1,n+1)]
all_v = sum(v)

res = 10 ** 9
res_abs = 10 ** 9
for i in range(n):
  part_v = all_v - v[i]
  if abs(all_v - part_v) < res_abs:
    res = part_v
    res_abs = abs(all_v - part_v)
print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

using VLL = vector <long long>;
using VPILL = vector < pair<long long, int> >;
int N;
VLL X;
VLL Y;
VLL P;
VLL ans;
VPILL PX;
VPILL PY;
int xcho;
int ycho;

const long long INF = 1000000000LL * 1000000000LL;

void solve(int now, int chosen) {
    if (now == N) {
        VLL minDist(N, INF);

        long long res = 0;
        long long lastX = -INF;
        long long lastY = -INF;

        for (int i = 0; i < N; ++i) {
            // default
            minDist[i] = min(minDist[i], min(abs(X[i]), abs(Y[i])));

            // x axis
            if (xcho & (1 << PX[i].second)) {
                lastX = PX[i].first;
            }

            minDist[PX[i].second] = min(minDist[PX[i].second], PX[i].first-lastX);

            // y axis
            if (ycho & (1 << PY[i].second)) {
                lastY = PY[i].first;
            }

            minDist[PY[i].second] = min(minDist[PY[i].second], PY[i].first-lastY);
        }

        // backward
        lastX = INF;
        lastY = INF;

        for (int i = N-1; i >= 0; --i) {
            // x axis
            if (xcho & (1 << PX[i].second)) {
                lastX = PX[i].first;
            }

            minDist[PX[i].second] = min(minDist[PX[i].second], lastX-PX[i].first);

            // y axis
            if (ycho & (1 << PY[i].second)) {
                lastY = PY[i].first;
            }

            minDist[PY[i].second] = min(minDist[PY[i].second], lastY - PY[i].first);
        }

        for (int i = 0; i < N; ++i) {
            res += P[i] * minDist[i];
        }

        ans[chosen] = min(ans[chosen], res);
        return ;
    }

    solve(now+1, chosen);

    xcho |= (1<<now);
    solve(now+1, chosen+1);
    xcho &= ~(1<<now);

    ycho |= (1<<now);
    solve(now+1, chosen+1);
    ycho &= ~(1<<now);
}

int main() {
    cin >> N;

    X = VLL(N);
    Y = VLL(N);
    P = VLL(N);

    PX = VPILL(N);
    PY = VPILL(N);

    for (int i = 0; i < N; ++i) {
        cin >> X[i] >> Y[i] >> P[i];
        PX[i] = make_pair(X[i], i);
        PY[i] = make_pair(Y[i], i);
    }

    ans = VLL(N+1, INF);
    xcho = 0;
    ycho = 0;

    sort(PX.begin(), PX.end());
    sort(PY.begin(), PY.end());
    solve(0, 0);

    for (int k = 0; k <= N; ++k) {
        cout << ans[k] << endl;
    }

    return 0;
}

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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 100010 };

vector<int> adj[MAX];

struct UFDS {
    vector<int> ps, rs, size;

    UFDS(int N) : ps(N + 1), rs(N + 1, 0), size(N + 1, 1)
    {
        iota(ps.begin(), ps.end(), 0);
    }

    ll set_size(int u)
    {
        return size[find_set(u)];
    }

    int find_set(int u)
    {
        return ps[u] == u ? u : (ps[u] = find_set(ps[u]));
    }

    bool same_set(int u, int v)
    {
        return find_set(u) == find_set(v);
    }

    void union_set(int u, int v)
    {
        if (same_set(u, v))
            return;

        auto p = find_set(u);
        auto q = find_set(v);

        if (rs[p] > rs[q])
        {
            ps[q] = p;
            size[p] += size[q];
        }
        else if (rs[p] < rs[q])
        {
            ps[p] = q;
            size[q] += size[p];
        } else
        {
            ps[q] = p;
            ++rs[p];
            size[p] += size[q];
        }
    }
};

vector<ll> solve(ll N, int M, const vector<ii>& es)
{
    vector<ll> ans;
    UFDS ufds(N);

    // Sem nenhuma ponte nem par é alcancável
    ans.push_back(N*(N - 1)/2);

    // O problema será resolvido ao contrário: serão adicionadas as arestas,
    // em ordem reversa
    for (int i = M - 1; i > 0; --i)
    {
        auto u = es[i].first, v = es[i].second;
        auto p = ufds.find_set(u);
        auto q = ufds.find_set(v);
        auto last = ans.back();

        if (ufds.same_set(u, v))
        {
            ans.push_back(last);
            continue;
        }

        auto a = ufds.set_size(p);
        auto b = ufds.set_size(q);

        ans.push_back(last - a*b);
        ufds.union_set(p, q);
    }
 
    reverse(ans.begin(), ans.end());

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;

    vector<ii> es(M);

    for (int i = 0; i < M; ++i)
        cin >> es[i].first >> es[i].second;

    auto ans = solve(N, M, es);

    for (auto x : ans)
        cout << x << '\n';

    return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;

using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

vector<ll> g[100001];
set<int> st;
deque<ll> ans;

bool check(){
  for (auto&& n : g[ans[0]]) {
    if(st.find(n) == st.end()){
      return false;
    }
  }
  for (auto&& n : g[ans.back()]) {
    if(st.find(n) == st.end()){
      return false;
    }
  }
  return true;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  cin >> n >> m;
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ans.push_back(1);
  st.insert(1);
  while(!check()){
    int f = ans[0];
    int b = ans.back();
    for(int i = 0; i < g[f].size();++i){
      if(st.find(g[f][i]) == st.end()){
        ans.push_front(g[f][i]);
        st.insert(g[f][i]);
        break;
      }
    }
    for(int i = 0; i < g[b].size();++i){
      if(st.find(g[b][i]) == st.end()){
        ans.push_back(g[b][i]);
        st.insert(g[b][i]);
        break;
      }
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    if(i) cout << ' ';
    cout << ans[i] ;
  }
  cout << endl;
  return 0;
}


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

ll gcd(ll a, ll b){
    // 最大公約数を求める
    if(a%b==0) return b;
    else{
        return (gcd(b, a%b));
    }
}

ll lcm(ll a ,ll b){
    return a * b / gcd(a, b);
}

int main(){
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll sum = b - a + 1;
    ll c_cnt= b/c - a/c, d_cnt= b/d - a/d;
    ll cd = lcm(c, d);
    ll cd_cnt = b/cd - a/cd;
    
    if(a%c==0) c_cnt++;
    if(a%d==0) d_cnt++;
    if(a%cd==0) cd_cnt++;

    ll ans = sum - c_cnt -d_cnt + cd_cnt;
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 2e5 + 9, M = 1e7 + 9, OO = 1e9 + 7, MOD = 1e9 + 7, MOD2 = 998244353;
const ll INF = 1e18;

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	ll x;
	cin >> x;
	ll total = 0;
	ll req = x / 500;
	total += req * 1000;
	x -= req * 500;
	req = x / 5;
	total += req * 5;
	cout << total;
	return 0;
}


Measured memory_bytes: 256
def SelectionSort(A):
    n = len(A)
    for i in range(n-1):
        mini = i
        for j in range(i+1, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        if i != mini:
            A[i], A[mini] = A[mini], A[i]
    print(' '.join(A))
    return A

def BubbleSort(A):
    n = len(A)
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(A[j][1]) < int(A[j-1][1]):
                A[j], A[j-1] = A[j-1], A[j]
    print(' '.join(A))
    return A

_ = input()
lines = input().split()
a = BubbleSort(lines.copy())
print('Stable')
b = SelectionSort(lines.copy())
ans = 'Stable' if a == b else 'Not stable'
print(ans)



Measured memory_bytes: 5608
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = [tuple(map(int,input().split())) for i in range(M)]

es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)
ans = 0
for i in range(N):
    for to in es[i]:
        if H[to] >= H[i]:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 42920
#include <cstdio>

using namespace std;

int main(void)
{
	int N;
	static int sum[100001];
	
	scanf("%d", &N);
	
	for (int i = 0; i < N; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		sum[--a]++;
		sum[b]--;
	}
	
	int ans = 0;
	for (int i = 1; i < 100001; i++){
		sum[i] += sum[i - 1];
		if (sum[i] >= i) ans = i;
	}
	
	printf("%d\n", ans);
	
	return (0);
}

Measured memory_bytes: 1412
#include<stdio.h>

#define N 100

int min(int ,int );

int main(){
  int n,p[N+1],m[N+1][N+1],i;

  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d %d",&p[i-1],&p[i]);
  for(i=1;i<=n;i++) m[i][i]=0;

  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j=i+l-1;
      m[i][j]= (1<<21);
      for(int k=i;k<=j-1;k++) m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
    }
  }

printf("%d\n",m[1][n]);

 return  0;
   
}
int min(int a,int b){
  if(a>b) return b;
  else return a;
}


Measured memory_bytes: 2056
import java.util.*;
import java.io.*;

public class Main {

	int MOD = 1_000_000_007;
	
	void solve() {
		int n = in.nextInt();
		char[] s1 = in.nextToken().toCharArray();
		char[] s2 = in.nextToken().toCharArray();
		
		if (n == 1) {
			out.println(3);
			return;
		}
		
		int[][][] dp = new int[3][3][n + 1];
		
		int start = -1;
		if (s1[0] == s1[1]) {
			start = 2;
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					if (i != j) {
						dp[i][j][start] = 1;
					}
				}
			}
		} else {
			start = 1;
			for (int i = 0; i < 3; i++) {
				dp[i][i][start] = 1;
			}
		}
		
		for (int pos = start; pos < n; pos++) {
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j < 3; j++) {
					int val = dp[i][j][pos];
					if (val == 0) {
						continue;
					}
					if (pos + 1 < n && s1[pos] == s1[pos + 1]) {
						for (int x = 0; x < 3; x++) {
							for (int y = 0; y < 3; y++) {
								if (x != y && x != i && y != j) {
									dp[x][y][pos + 2] += val;
									dp[x][y][pos + 2] %= MOD;
								}
							}
						}
						
					} else {
						for (int x = 0; x < 3; x++) {
							if (x != i && x != j) {
								dp[x][x][pos + 1] += val;
								dp[x][x][pos + 1] %= MOD;
							}
						}
						
					}
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				ans = (ans + dp[i][j][n]) % MOD;
			}
		}
		out.println(ans);
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public String nextToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	while(true){
		c-=b;
		if(c<=0){
			cout << "Yes";
			return 0;
		}
		a-=d;
		if(a<=0){
			cout << "No";
			return 0;
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3568
#[allow(unused_imports)]
use std::cmp::*;

#[allow(unused_imports)]
use std::collections::*;

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()
}

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

fn main() {
    let N: usize = read();
    let V: Vec<i32> = read_vec();
    let C: Vec<i32> = read_vec();
    let mut ans: i32 = 0;
    for i in 0..N {
        let tmp = V[i] - C[i];
        if tmp > 0 {
            ans += tmp;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
char c[100001];
int la=0;
int main() 
{
    scanf("%s",&c);
    int la=strlen(c);
    for(int i=0;i<la;i+=2)
    {
    cout<<c[i];
    }
	cout<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 50;

int main(){
    int N;
    string S;
    int ans = 1;

    cin >> N;
    cin >> S;

    for(int i = 1;i < N;i++){
        if(S[i] != S[i - 1])ans++;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef double ld;

ll n;
ld res = 0.0;

int main() {
	cin >> n;
	while (n--) {
		ld x; string y;
		cin >> x >> y;
		if (y == "JPY") res += x;
		else res += x * 380000.0;
	}
	printf("%lf", res);
	
	return 0;
}


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

// スマホコーディング@バンコク

int judge(int x, int K, vector<int>A){
	int modSum = 0;
	for(int i=0; i < A.size(); ++i) {
		A[i] %= x;
		modSum += A[i];
	}
	sort(A.begin(), A.end(), greater<int>());
	// modSumはxの倍数
	modSum = modSum / x; 
	for(int i=0; i < modSum; ++i) {
		K = K - (x - A[i]);
	}
	if(K >= 0) return 1;
	return 0;
}

int main() {
	int N, K;
	cin >> N >> K;
	vector<int>A(N);
	for(int i=0; i < N; ++i) {
		cin >> A[i];
	}
	int sum = 0;
	for(int i=0; i < N; ++i) {
		sum += A[i];
	}
	stack<int> divisor; // 約数
	for(int i=1; i < sqrt(sum) + 1; ++i) {
		if(sum % i == 0){
			divisor.push(i);
			divisor.push(sum/i);
		}
	}
	int ans = 1; // 1は条件を満たす
	while(! divisor.empty()){
		int i = divisor.top();
		divisor.pop();
		if(judge(i, K, A)){
			if(ans < i) ans = i;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned 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 dm;
struct matrix
{
    ll  mat[55][55];
    matrix()
    {
        memset(mat,0,sizeof mat);
    }
    matrix operator *(const matrix &a) const
    {
        matrix d;
        for(ll i=0;i<dm;i++)
        {
            for(ll j=0;j<dm;j++)
            {
                for(ll k=0;k<dm;k++)
                {
                    d.mat[i][j]+=(mat[i][k]*a.mat[k][j])%mod;
                    d.mat[i][j]%=mod;
                }
            }
        }
        return d;
    }
    void identity()
    {
        for(ll  i=0;i<dm;i++)
        {
            mat[i][i]=1;
        }
    }
};
matrix power(matrix c,ll b)
{
    matrix d;
    d.identity();
    while(b)
    {
        if(b&1) d=d*c;
        b>>=1;  c=c*c;
    }
    return d;
}
int main()
{
    ll  n,k;
    cin>>n>>k;
    dm=n;
    matrix a ;
    for(ll  i=0;i<n;i++)
    {
        for(ll  j=0;j<n;j++) cin>>a.mat[i][j];
    }
    a=power(a,k);
    ll ans=0;
    for(ll  i=0;i<n;i++)
    {
        for(ll  j=0;j<n;j++)
        {
            ans+=a.mat[i][j];
            ans%=mod;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int H, W, h, w; cin >> H >> W >> h >> w;
    cout << H*W - (h*W + H*w - h*w) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX=200001;
int main()
{
  long long n,k,t,i,res;
  long long a[N_MAX],b[N_MAX],c[N_MAX];
  cin >> n >> k;
  for(i=1;i<=n;i++)
    cin >> a[i];
  b[0]=1;
  fill(c+1,c+n+1,-1);
  c[1]=0;
  for(i=1;i<=k;i++){
    b[i]=a[b[i-1]];
    if(c[b[i]]==(-1)){
      c[b[i]]=i;
    }else{
      t=i-c[b[i]];
      k=(k-i)%t+c[b[i]];
      break;
    }
  }
  cout << b[k] << endl;
  return 0;
}

Measured memory_bytes: 7384
a = int(input())
b = int(input())
c = int(input())
d = int(input())
count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if (500*i + 100*j + 50*k) == d:
                count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int h,a;
  cin>>h>>a;
  if(h%a==0) cout<<h/a<<endl;
  else cout<<h/a+1<<endl;
}

Measured memory_bytes: 256
/************
* 	@Just Another Source code by: ankit.sangwan1999
*	@created on: 23 Apr 2020
*/

#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long

int DP[100005];

int fun(vector<int>&H, int ind){
	if(DP[ind] != -1){
		return DP[ind];
	}
	if(ind==0){
		return 0;
	}
	int pos1=INT_MAX, pos2 = INT_MAX;
	if(ind-1>=0){
		int val1 = abs(H[ind] - H[ind-1]);
		pos1 = val1 + fun(H,ind-1);
	}
	if(ind-2>=0){
		int val2 = abs(H[ind] - H[ind-2]);
		pos2 = val2 + fun(H,ind-2);
	}

	return DP[ind] = min(pos1, pos2);
}


signed main(){
    fastio;
    int t=1;
    // cin>>t;
    while(--t>=0){
    	int n;
    	cin>>n;
    	vector<int>H(n);
    	memset(DP,-1,sizeof(DP));
    	for(int i=0;i<n;i++) cin>>H[i];
    	cout<<fun(H,n-1);


    }


    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll N,X,T;
    cin >> N >> X >> T;
    ll C = (N+X-1)/X;
    cout << C*T << "\n";
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> input(n);
    for (int i = 0; i < n; i++)
        cin >> input[i];
    sort(input.rbegin(), input.rend());
    int answer = 0;
    for (int i = 0; i < k; i++)
        answer += input[i];
    cout << answer;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  string s;
  cin >> s;

  string ans = "";
  rep(i,s.size()) {
    if (s[i] == '0') ans += '0';
    else if (s[i] == '1') ans += '1';
    else {
      if (ans.size() == 0) continue;
      else ans = ans.substr(0,ans.size()-1);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
using System;
using System.Linq;
using static System.Console;

static class Extensions {
   public static int ToInt(this string str) => int.Parse(str);
}

class Program {
   static int[] h;
   static int[] memo;

   // i番目の足場までの最小コストを求めるには、
   // i-1番目と i-2番目の足場までの最小コストが分かれば良い
   //
   // i番目の足場までの最小コストを求める関数。
   static int rec(int i) {
      if (i == 0) return 0;
      if (i == 1) return Math.Abs(h[0] - h[1]);

      var cost1 = memorec(i - 1) + Math.Abs(h[i - 1] - h[i]);
      var cost2 = memorec(i - 2) + Math.Abs(h[i - 2] - h[i]);

      return Math.Min(cost1, cost2);
   }

   // recをメモ化した関数
   static int memorec(int i) {
      if (memo[i] >= 0) return memo[i];

      var result = rec(i);
      memo[i] = result;
      return result;
   }

   public static void Main(string[] args) {
      var n = ReadLine().ToInt();
      h = ReadLine().Split(' ').Select(int.Parse).ToArray();

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

      WriteLine(memorec(n - 1));
   }
}


Measured memory_bytes: 27488
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=100010;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int K,inq[N],dis[N];
int main()
{
	file();
	read(K);
	queue<int>q;
	mem(dis,inf);
	dis[1]=1;
	q.push(1);
	while(!q.empty())
	{
		int u=q.front(),v;q.pop();inq[u]=0;
		if(chkmin(dis[v=(u+1)%K],dis[u]+1))
			if(!inq[v])q.push(v),inq[v]=1;
		if(chkmin(dis[v=u*10%K],dis[u]))
			if(!inq[v])q.push(v),inq[v]=1;
	}
	printf("%d\n",dis[0]);
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
vector<int> v[100005];
bool vi[100005];
void df(int s){
    vi[s]=true;
    for(auto i:v[s]){
        if(!vi[i])
        df(i);
    }
}
int main(){
    int n,m,co=0,x,y;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        v[x-1].push_back(y-1);
        v[y-1].push_back(x-1);
    }
    for(int i=0;i<n;i++){
        if(!vi[i]){
            co++;
            df(i);
        }
    }
    if(co)
    cout<<(co-1);
    else
    cout<<"0";
}

Measured memory_bytes: 9736
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

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

	int d =  (b / c) - (a / c);

	if ( a % c == 0)
		d++;

	cout << d;


	return 0;
}

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


int main(){
	ll h,ans=1;
	cin>>h;
	ll a=1;
	while(h>1){
		h/=2;
		a*=2;
		ans+=a;
	}
	cout<<ans<<endl;
}

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

int main() {
   int n;
   cin >> n;
   long long ans = 0;
   for (int i=1; i<=n; i++) {
      if ((i % 3 != 0) && (i % 5 != 0)) {
         ans += i;
      }
   }
   cout << ans << endl;
   return 0;
}

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

// Return the maximum volume. 
 

// Driven Program 
int main() 
{ 
	int n;
	cin>>n;
    std::cout<<std::fixed;

   std::cout<<std::setprecision(6);
    double s=n;
	double length = (double)s / 3; 
	

	s -= length; 
    
	// finding breadth 
	double breadth = s / 2; 
    
	// finding height 
	double height = s - breadth; 
	
	double maxvalue= length * breadth * height; 
printf("%lf\n", maxvalue); 
	return 0; 
} 


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

int main() {
  string S;
  cin >> S;
  int a;
  a = S.size();
  int count = 0;
  for(int i = 0; i < a; i++){
  if (i % 2 == 1 && S.at(i) == 'R'){
  count += 1;
  }else if (i % 2 == 0 && S.at(i) == 'L'){
  count += 1;
  }
  }
  if(count >= 1){
  cout << "No";
  }else{
  cout << "Yes";
  }
}

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

int main()
{
    int x,y;

    cin >> x >> y;

    int j = 0;
    for (int i = x; i >= 0 ; i--)
    {
        j = x - i;
        if ((i*2 + j*4) == y)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define asll unsigned long long
#define pii pair<int,int>
#define st first
#define nd second

asll M=1e9+7;//20190518
asll a[100100];
asll b[100100];
asll s=0;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	srand(time(0));//20190709
	int n;cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		s+=a[i];
	}
	
	asll jml=0;
	for(int i=0;i<n;i++){
		if(i%2==1){
			jml+=2*a[i];
		}
	}
	s=s-jml;//ketemu solusi 1
	b[0]=s;
	for(int i=1;i<n;i++){
		b[i]=a[i-1]*2-b[i-1];
	}
	for(int i=0;i<n;i++){
		cout<<b[i]<<" ";
	}
	cout<<endl;
	
}



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

int main(){
 int n, k;
 cin >> n >> k;
 vector<int> d(n);
 rep(i,k){
 	int m;
 	cin >> m;
 	rep(j,m){
 		int a;
 		cin >> a;
 		d.at(a-1) = 1;
 	}
 }
 int ans = 0;
 rep(i,n) if(d.at(i) == 0) ans++;
 cout << ans << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,x,d;cin>>n>>x>>d;
  if(d<0){
    x=-x;
    d=-d;
  }
  if(d==0){
    if(x==0){
      cout<<1<<endl;
      return 0;
    }
    cout<<n+1<<endl;
    return 0;
  }

  vector<vector<ll>>ama(n+2);
  unordered_map<ll,ll>id,rid;
  rep(sz,n+1){
    ll a=sz*x%d;
    if(a<0)a+=d;
    if(!id.count(a)){id[a]=id.size();}
    ama[id[a]].push_back(sz);
  }
  ll res=0;
  rep(i,ama.size()){
    vector<pair<ll,ll>>ran;
    for(auto sz:ama[i]){
      ll l;
      ll r;
      if(x!=0){
        ll a=sz*x%d;
        if(a<0)a+=d;
        l=((sz*x)/d-a)+sz*(sz-1)/2;
        r=((sz*x)/d-a)+sz*(2*n-sz-1)/2+1;
      }
      else {
        l=sz*(sz-1)/2;
        r=sz*(2*n-sz-1)/2+1;
      }

      //cout<<"sz "<<sz<<" "<<l<<" "<<r<<endl;
      ran.push_back({l,r});
    }
    sort(all(ran));
    ll len=ran.size();
    ll cnt=0;
    ll tl=-1e17,tr=-1e17;
    rep(j,len){
      if(ran[j].first<=tr){
        chmax(tr,ran[j].second);
      }
      else {
        cnt+=tr-tl;
        tl=ran[j].first;
        tr=ran[j].second;
      }
    }
    cnt+=tr-tl;
    res+=cnt;
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 19400
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    k = f()[0]
    x = f()

    ans = 0
    for i in range(n):
        ans += 2*min(abs(x[i]-k), abs(x[i]))

    print(ans)

solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define int long long
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

vector<LL> a, b;
LL n, m;


LL f(LL k){
    LL ct = 0;
    rep(i, n){
        LL tmp = (a.end()-lower_bound(all(a), k-b[i]));
        ct += tmp;
    }
    return ct;
}

signed main(){
    fastcin();

    cin >> n >> m;
    a.assign(n, 0);
    rep(i, n) cin >> a[i];
    sort(all(a));
    b = a;
    reverse(all(b));
    // M個以下を達成する幸福度の組の最大値
    LL ok = LLINF, ng = 0;
    LL okct = -1;
    while (abs(ok - ng) > 1) {
        LL mid = (ok + ng) / 2;
        LL nowct = f(mid);
        if(nowct <= m){
            ok = mid;
            okct = nowct;
        }
        else ng = mid;
    }
    // cout << ok << " " << okct << endl;
    LL rem = m-okct;
    
    LL ok2 = ok, ng2 = 0;
    while (abs(ok2 - ng2) > 1) {
        LL mid = (ok2 + ng2) / 2;
        LL nowct = f(mid);
        // cout<<nowct<< " " << mid << endl;
        if(nowct-okct==rem){
            ok2 = mid;
        }
        else ng2 = mid;
    }
    // cout << ok2 << endl;
    ok2--;
    LL ans = 0;
    vector<LL> as(n+1, 0);
    rep(i, n) as[i+1] = as[i]+a[i];
    rep(i, n){
        int idx = lower_bound(all(a), ok-b[i])-a.begin();
        ans += as[n]-as[idx];
        ans += b[i]*(n-idx);
    }
    // cout << ans << endl;
    ans += rem*ok2;

    cout << ans << endl;

}

Measured memory_bytes: 2688
import sys

input = sys.stdin.readline


def main():
    n = input().strip()
    int_n = int(n)
    keta = len(n)
    # 桁ごとにマックスの数が決っている
    # あとは、指定された数から規定数を引けばいいはず
    # 1 -> 9 -> 9
    # 100 -> 999 -> 899
    # full - 100 -> x
    cnt = 0
    for i in range(1, keta + 1, 2):
        max_num = 10 ** (i) - 1
        min_num = 10 ** (i - 1) - 1
        cnt += max_num - min_num
        if keta == i:
            cnt -= max_num - int_n
    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    char c;
    cin >> c;
    char v[5] = {'a', 'e', 'i', 'o', 'u'};
    for (int i = 0; i < 5; i++) {
        if (c == v[i]) {
            cout << "vowel" << endl;
            return 0;
        }
    }
    cout << "consonant" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
    ll n;
    cin>>n;
    int a[n],dp[100001];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
        dp[i]=1000000001;
        for(int j=i-1;max(0,i-2)<=j;j--){
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
    }
    cout<<dp[n-1]<<endl;
return 0;
}


Measured memory_bytes: 1024
/*
RAone00
Rohit sharma
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef vector < vector < ll > > matrix;
typedef vector < ll > vll;

#define pb push_back
#define debug(x) cout << (#x) << " is " << (x) << endl
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll mod = 1e9 + 7;
const ll inf = LLONG_MAX;
const ll N = 1e5 + 10;

int main() {
    fast_io();
    int a;
    double f = 0;
    cin >> a;
    double s[a], d[a];
    for (int i = 0; i < a; ++i) {
      cin >> s[i];
      d[i] = 1 / s[i];
    }
    for (int i = 0; i < a; ++i) {
      f += d[i];
    }
    cout << fixed << setprecision(5);
    cout << 1 / f << "\n";
    return 0;
}


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

typedef long long ll;
const int maxn = 200005, maxm = 200005;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

#define pb push_back

int n, m, d[maxn];

struct edge
{
	int to, next;
} e[maxm * 2];
int h[maxn], tot = 1;
int w[maxm], col[maxn], fa[maxn], fe[maxn];
vector<int> vec[maxn];

inline void add(int u, int v)
{
	e[++tot] = (edge) {v, h[u]}; h[u] = tot;
	e[++tot] = (edge) {u, h[v]}; h[v] = tot;
}

void dfs(int u)
{
	for (int v : vec[u]) {
		w[fe[v]] = d[v];
		if (col[v] == -1) col[v] = col[u] ^ 1, dfs(v);
	}
}

int main()
{
	n = gi(); m = gi();
	for (int i = 1; i <= n; ++i) d[i] = gi();
	for (int i = 1; i <= m; ++i) add(gi(), gi());
	fill(w + 1, w + m + 1, 1e9);

	d[0] = 2e9;
	for (int u = 1; u <= n; ++u) {
		int p = h[u] >> 1, mn = e[h[u]].to;
		for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
			if (d[v] < d[mn] || (d[v] == d[mn] && v < mn)) mn = v, p = i >> 1;
		if (d[mn] > d[u]) return puts("-1"), 0;
		fe[u] = p; fa[u] = mn; vec[mn].pb(u);
	}
	
	fill(col + 1, col + n + 1, -1);
	for (int i = 1; i <= n; ++i) if (fa[fa[i]] == i && col[i] == -1) col[i] = 0, dfs(i); 
	for (int i = 1; i <= n; ++i) putchar(col[i] == 0 ? 'B' : 'W');
	puts("");
	for (int i = 1; i <= m; ++i) printf("%d\n", w[i]);
	
	return 0;
}


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

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

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

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }
}

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

    const MOD: i64 = 1000_000_000 + 7;

    let n: i64 = sc.input();
    let a: Vec<i64> = (0..n).map(|_| sc.input()).collect();

    let mut map = BTreeMap::new();

    for x in a {
        let count = map.entry(x).or_insert(0);
        *count += 1;
    }

    let mut ans = 1_i64;
    let mut index = if n % 2 == 0 { 1 } else { 0 };

    for (key, cnt) in map {
        if (key != index || cnt != 2) && !(key == 0 && cnt == 1){
            ans = 0;
            break;
        }

        index += 2;
        ans = (ans * cnt) % MOD;
    }

    println!("{}", ans);
}


Measured memory_bytes: 6396
#include<iostream>
#include<string>
#include<vector>
using namespace std ;

string s ;
char ans[200] ;

int main(){
	
	char t ;
	
	while( cin >> s >> t ){
		if( t == 'X' ) break ;
		
		int p = 1 ;
		
		if( s[0] <= 90 && t != 'U' ) ans[0] = s[0] +32 ;
		else if( s[0] >= 97 && t == 'U' ) ans[0] = s[0] -32 ;
		else ans[0] = s[0] ;
		for( int i=1 ; i<s.size() ; i++ ){
			if( s[i] == '_' && t != 'D' ){
				ans[p] = s[i+1] -32 ;
				i++ ;
			}
			else if( s[i] <= 90 && t == 'D' ){
				ans[p] = '_' ;
				ans[p+1] = s[i] +32 ;
				p++ ;
			} else ans[p] = s[i] ;
			
			p++ ;
		}
		
		for( int i=0 ; i<p ; i++ ){
			cout << ans[i] ;
		}cout << endl ;
	}
	
return 0 ;
}

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

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

    int N = scanner.nextInt();
    int[] a = new int[N];
    int[] b = new int[N];
    int[] c = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt();
    for (int i = 0; i < N; i++) b[i] = scanner.nextInt();
    for (int i = 0; i < N; i++) c[i] = scanner.nextInt();

    Arrays.sort(a);
    Arrays.sort(b);
    Arrays.sort(c);

    long[] bc = new long[N + 1];
    int j = 0;
    for (int i = 0; i < N; i++) {
      while (j < N && c[j] <= b[i]) j++;
      bc[i] = N - j;
    }
    for (int i = N - 1; i > 0; i--) bc[i - 1] += bc[i];

    long total = 0;
    j = 0;
    for (int i = 0; i < N; i++) {
      while (j < N && b[j] <= a[i]) j++;
      total += bc[j];
    }
    System.out.println(total);
  }
}


Measured memory_bytes: 95176