akhauriyash/Code-Regression huggingface dataset:
// AOJ 2581 Derangement
// 2018.3.9 bal4u

#include <stdio.h>
#include <string.h>

#define QMAX 10000
typedef struct { int t, s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 0x10101010
#define MAX 205
typedef struct { int to, rev; int cap, cost; } EDGE;
EDGE edge[MAX][MAX]; int hi[MAX];
int V;				// 頂点数
int potential[MAX], dist[MAX], prevv[MAX], preve[MAX];

void add_edge(int from, int to, int cap, int cost)
{
	int f, t;
	EDGE *ep;

	f = hi[from]++, t = hi[to]++;
	ep = &edge[from][f], ep->to = to, ep->cap = cap, ep->cost = cost, ep->rev = t; 
	ep = &edge[to][t], ep->to = from, ep->cap = 0, ep->cost = -cost, ep->rev = f;
}

int minCostFlow(int S, int T, int F)
{
	int i, v, nv, t, nt, ret;
	EDGE *ep;

	ret = 0;
//	memset(potential, 0, V << 2);
  
	while (F > 0) {
		memset(dist, INF, V << 2);
		qsize = 0;
		enq(S, 0), dist[S] = 0;
		while (qsize) {
			v = que[0].s, t = que[0].t, deq();
			if (dist[v] < t) continue;
			for (i = 0; i < hi[v]; i++) {
				ep = &edge[v][i];
				if (ep->cap <= 0) continue;
				nv = ep->to;
				nt = t + ep->cost - potential[nv] + potential[v];
				if(dist[nv] > nt) {
					dist[nv] = nt;
					prevv[nv] = v, preve[nv] = i;
					enq(nv, nt);
				}
			}
		}
		if (dist[T] == INF) return -1;
		for (v = 0; v < V; v++) potential[v] += dist[v];

		t = F;
		for (v = T; v != S; v = prevv[v]) {
			ep = &edge[prevv[v]][preve[v]];
			if (t > ep->cap) t = ep->cap;
		}
		F -= t;

		ret += t * potential[T];
		for (v = T; v != S; v = prevv[v]) {
			ep = &edge[prevv[v]][preve[v]];
			ep->cap -= t;
			edge[v][ep->rev].cap += t;
		}
	}
	return ret;
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int p[102];

int main()
{
	int n, i, j;
	int source, sink;

	n = in();
	source = n << 1, sink = source+1, V = sink+1;

	for (i = 0; i < n; i++) p[i] = in();

	for (i = 0; i < n; i++) {
		add_edge(source, i, 1, 0);

		for (j = 0; j < i; j++) if (p[i] != j+1)
			add_edge(i, n+j, 1, (i-j)*p[i]);
		for ( ; j < n; j++) if (p[i] != j+1)
			add_edge(i, n+j, 1, (j-i)*p[i]);

		add_edge(n+i, sink, 1, 0);
	}

	printf("%d\n", minCostFlow(source, sink, n));
	return 0;
}


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

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

#define pow CHANGETHENAMESTUPID

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

void load() {
	int x, y, a, b, c;
	scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
	int p[a], q[b], r[c];
	FOR(i, a) scanf("%d", p + i);
	FOR(i, b) scanf("%d", q + i);
	FOR(i, c) scanf("%d", r + i);
	sort(p, p + a, std::greater<int>());
	sort(q, q + b, std::greater<int>());
	sort(r, r + c, std::greater<int>());

	vector<int> v;
	FOR(i, x) v.push_back(p[i]);
	FOR(i, y) v.push_back(q[i]);
	FOR(i, c) v.push_back(r[i]);
	sort(v.begin(), v.end(), std::greater<int>());

	ll maxi = 0;
	FOR(i, (x + y)) maxi += v[i];
	printf("%lld\n", maxi);
}

void solve() {

}

int main() {
	load();
	solve();
	return 0;
}


Measured memory_bytes: 3572
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

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

  vll as(n);
  rep(i, n) cin >> as[i];

  ll ans = LONG_LONG_MAX;
  rep(s, 1LL << n) {
    ll pcnt = __builtin_popcount(s);
    if (pcnt != k) continue;
    ll ctot = 0;  // cost total
    ll cht = 0;   // current hight
    rep(i, n) {
      bool cond = (s >> i & 1);
      if (cond) {
        if (as[i] <= cht) {
          ctot += cht - as[i] + 1;
          cht++;
          continue;
        }
      }
      chmax(cht, as[i]);
    }  // i
    chmin(ans, ctot);
  }  // s

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

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


signed main() {
	int n,m;
	std::cin >> n >> m;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	rep(i,n) a[i]/=2;
	int x = a[0];
	rep(i,n) x = x*a[i]/gcd(x,a[i]);
	rep(i,n) {
		if(x/a[i]%2==0) {
			print(0);
			return 0;
		}
	}
	if(m>=x) print((m-x)/x/2+1);
	else print(0);
	return 0;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
	"sort"
)

func main() {
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)

	if s == t {
		fmt.Print("No")
		return
	}

	var ss []rune
	var is []int
	ss = []rune(s)
	for i := range ss {
		is = append(is, int(ss[i]))
	}

	var st []rune
	var it []int
	st = []rune(t)
	for i := range st {
		it = append(it, int(st[i]))
	}

	sort.Ints(is)
	sort.Ints(it)

	for i := range is {
		if i >= len(it) {
			fmt.Print("No")
			return
		}
		if is[i] > it[len(it)-i-1] {
			fmt.Print("No")
			return
		} else if is[i] < it[len(it)-i-1] {
			fmt.Print("Yes")
			return
		}
	}

	fmt.Print("Yes")
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
void revs(string s)
{
    for(int i=s.length() -1;i>=0;i--)
    {
        cout<<s[i];
    }
}
int main()
{
    ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
    string s;
    cin>>s;
    int q;
    cin>>q;
    int rev=0;
    string a,b; 
    while(q--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            rev++;
        }
        else
        {
            int f;
            char c;
            cin>>f>>c;
            if((f+rev)%2==1)
            {
                a+=c;
            }
            else
            {
                b+=c;
            }
        }
    }
    if(rev%2==0)
    {
        revs(a);
        cout<<s<<b;
    }
    else
    {
        revs(b);
        revs(s);
        cout<<a;
    }
    return 0;
}    

Measured memory_bytes: 1104
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin>>n;
ll a1[n-1];
for(ll i=1;i<=n-1;i++)
{
    cin>>a1[i];
}
ll b[n]={0};

unordered_map<ll,ll>a;
for(ll i=1;i<=n-1;i++)
{
    a[a1[i]]++;
}
for(auto x:a)
{
    if(x.second>=1)
    {    
        b[x.first]=x.second;
        //cout<<x.first<<" "<<x.second<<endl;
    }
}
b[n]=0;
for(ll i=1;i<=n;i++)
{
    cout<<b[i]<<endl;
}
return 0;
}


Measured memory_bytes: 14548
import networkx as nx


def solve(n, m, ab_list):
    g = nx.Graph()
    g.add_nodes_from(list(range(1, n + 1)))
    g.add_edges_from(ab_list)
    res = nx.algorithms.components.number_connected_components(g) - 1
    return res


def main():
    n, m = map(int, input().split())
    ab_list = []
    for _ in range(m):
        ab_list.append(tuple(map(int, input().split())))
    res = solve(n, m, ab_list)
    print(res)


def test():
    assert solve(3, 1, [(1, 2)]) == 1


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 166196
N,M=map(int,input().split())

l=[list(map(int,input().split())) for i in range(M)]
inf=10**20
a=[[inf]*N for i in range(N)]
e=[[0]*N for i in range(N)]
for i,j,k in l:
    a[i-1][j-1]=k
    a[j-1][i-1]=k
    e[i-1][j-1]=1
    e[j-1][i-1]=1

ans=0
for k in range(N):
    for i in range(N):
        for j in range(N):
            if a[i][j]>a[i][k]+a[k][j]:
                if e[i][j]==1:
                    ans+=1
                    e[i][j]=e[j][i]=0
                a[i][j]=a[i][k]+a[k][j]

print(ans)




Measured memory_bytes: 3568
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, k; readV(n, k);
  int[] x; readA(n, x);

  auto s = x.assumeSorted.trisect(0);

  auto a = s[0].array, na = a.length, b = s[2].array, nb = b.length;
  if (!s[1].empty) --k;

  a ~= 0;
  foreach (ref ai; a) ai = -ai;
  a.reverse();

  b = 0 ~ b;

  auto r = 10^^9;
  foreach (i; 0..k+1) {
    if (i > na || k-i > nb) continue;
    r = min(r, a[i]*2+b[k-i], a[i]+b[k-i]*2);
  }

  writeln(r);
}


Measured memory_bytes: 4732
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
template<class T>
inline T qread(T &IEE){
	register T x = 0, f = 1;
	register char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-'){
			f = -f;
		}
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return IEE = x * f;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
ll a, m, n, k;
bool f[maxn];
int main(){
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	qread(n);
	qread(k);
	for(int i = 1;i <= k;i++){
		qread(m);
		for(int j = 1;j <= m;j++){
			qread(a);
			f[a] = 1;
		}
	}
	ll cnt = 0;
	for(int i = 1;i <= n;i++){
		if(!f[i]) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >>n;
    bool ok=0;
    while(1)
    {
        if(!n){ok=1;break;}
        if(n<4){ok=0;break;}
        else if(n%4==0){n/=4;ok=1;break;}
        else if(n%7==0){n/=7;ok=1;break;}
        else if(n>=7){n-=7;}
        else if(n>=4){n-=4;}
    }
    cout <<((ok)?"Yes":"No")<<endl;
}


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

struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n) {
        init(n);
    }
    
    void init(int n) {
        par.assign(n, -1);
    }
    
    int root(int x) {
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    void merge(int x, int y) {
        x = root(x); y = root(y);
        if(x == y) return;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    long long N, M; cin >> N >> M;
    vector<int> A(M), B(M);
    for(int i = 0; i < M; ++i) {
        cin >> A[i] >> B[i];
        --A[i], --B[i];
    }
    
    UnionFind uf(N);
    long long cur = N * (N - 1) / 2;
    vector<long long> res(M);
    for(int i = 0; i < M; ++i) {
        res[i] = cur;
        int a = A[M-1-i], b = B[M-1-i];
        if(uf.issame(a, b)) continue;
        
        long long sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.merge(a, b);
    }
    
    reverse(res.begin(), res.end());
    for(int i = 0; i < M; ++i) cout << res[i] << endl;
}


Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;

static long long R[100010] = {}, RS[100010] = {}, MOD = 1000000007;

long long Calc(long long A, long long B) {
	if (B == 0) return 1;
	if (B % 2 == 0) {
		long long C = Calc(A, B / 2);
		return (C * C) % MOD;
	}
	return (A * Calc(A, B - 1)) % MOD;
}

void init(long long N) {
	for (int i = 1; i <= N; i++) R[i] = Calc(i, MOD - 2);
	for (int i = 1; i <= N; i++) RS[i] = (RS[i - 1] + R[i]) % MOD;
}

int main() {
	static long long N, A[100000], ANS = 0;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	init(N);
	for (int i = 0; i < N; i++) {
		ANS = (ANS + A[i] * (RS[i + 1] + RS[N - i] + MOD - 1) % MOD) % MOD;
	}
	for (int i = 1; i <= N; i++) {
		ANS = (ANS * i) % MOD;
	}
	cout << ANS << endl;
}

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

int main() {
    int N, M, Q;
    cin>>N>>M>>Q;
    vector<int> L, R;
    int p[Q], q[Q];
    int tmpl, tmpr;
    for(int i=0;i<M;++i){
        cin>>tmpl>>tmpr;
        tmpl--;
        tmpr--;
        L.push_back(tmpl);
        R.push_back(tmpr);
    }
    for(int i=0;i<Q;++i){
        cin>>p[i]>>q[i];
        p[i]--;
        q[i]--;
    }
    int trainmap[N][N];
    for(int i=0;i<N;++i){
        for(int j=0;j<N;++j){
            trainmap[i][j] = 0;
        }
    }
    for(int i=0;i<M;++i){
        trainmap[L[i]][R[i]]++;
    }
    for(int i=0;i<N;++i){
        for(int j=1;j<N;++j){
            trainmap[i][j] += trainmap[i][j-1];
        }
    }
    /**
    for(int i=0;i<N;++i){
        for(int j=0;j<N;++j){
            cout<<trainmap[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;
    **/
    for(int i=0;i<Q;++i){
        int ans = 0;
        for(int j=p[i];j<=q[i];++j){
            if(p[i]==0){
                ans += trainmap[j][q[i]];
            }
            else{
                ans += trainmap[j][q[i]] - trainmap[j][p[i]-1];
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 4460
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int n,m,x; cin >> n >> m >> x;
	vector<int> v(m);
	int count = 0;
	rep(i,m){
		 cin >> v[i];
		 if (v[i] < x){
			 count++;
		 }
	}
	cout << min(count, (int)v.size()-count) << endl;
}

Measured memory_bytes: 256
n,k = gets.split.map(&:to_i)
v = gets.split.map(&:to_i)
max = -10**9
m = [n,k].min
for i in 0..m
  for j in 0..i
    z = (n-i+j-1)
    h = v.select.with_index{|num,i| i < j || i > z}
    h.sort!
    h != [] ? a = h.inject(:+) : a = 0
    h.each_with_index do |o,l|
      a -= o if o < 0 && l+1 <= (k-i)
    end
    max = a if max < a
  end
end
puts max

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

int main(){

  int m, d, cnt, d1[12];
  int p[12] = {31, 29, 31, 30, 31, 30,
               31, 31, 30, 31, 30, 31};
  string str[7] = {"Monday", "Tuesday", "Wednesday",
                   "Thursday", "Friday", "Saturday",
                   "Sunday"};
  
  d1[0] = 3;
  for(int i=1; i<12; i++){
    d1[i] = (d1[i-1] + p[i-1]) % 7;
  }

  while(1){
    cin >> m >> d;
    if(m == 0 && d == 0){
      break;
    }
    cout << str[(d1[m-1] + d - 1) % 7] << endl;
  }

  return 0;

}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include <cmath>
using namespace std;
int a, b, c;
int main() {
    cin >> a >> b >> c;
    if(a>=b&&a>=c) cout << b+c << endl;
    else if(b>=a&&b>=c) cout << a+c << endl;
    else if(c>=a&&c>=b) cout << a+b << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[]ss = S.toCharArray();
        
        if(ss[0]-0<91){
            System.out.println('A');
        }else{
        System.out.println('a');
        }
    }         
}


Measured memory_bytes: 35620
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *a,int n){
	for(int i=0;i<n;i++)printf("%d%c",a[i],(i!=n-1?' ':'\n'));
}
void array_show(LL *a,int n){
	for(int i=0;i<n;i++)printf("%lld%c",a[i],(i!=n-1?' ':'\n'));
}

vector<int> path[100005];
int pa[100005];
LL num[100005][2];

void parent_check(int a,int p){
	pa[a]=p;
	for(int i=0;i<path[a].size();i++){
		if(path[a][i]==p)continue;
		parent_check(path[a][i],a);
	}
}

void check(int a){
	if(num[a][0]!=-1)return;
	LL b=1,c=1;
	for(int i=0;i<path[a].size();i++){
		if(path[a][i]==pa[a])continue;
		check(path[a][i]);
		b*=num[path[a][i]][1];
		c*=(num[path[a][i]][0]+num[path[a][i]][1]);
		if(b>=MAX)b%=MAX;
		if(c>=MAX)c%=MAX;
	}
	num[a][0]=b,num[a][1]=c;
}

int main(){
	int n;
	int i,j,k;
	LL a,b,c;
	cin>>n;
	for(i=0;i<n-1;i++){
		cin>>a>>b;
		a--,b--;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	parent_check(0,-1);
	memset(num,-1,sizeof(num));
	check(0);
	a=(num[0][0]+num[0][1])%MAX;
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 13184
a,b,c,d=map(int,input().split())
x=c-a
y=d-b
print("U"*y+"R"*x+"D"*y+"L"*x+"L"+"U"*(y+1)+"R"*(x+1)+"D"+"R"+"D"*(y+1)+"L"*(x+1)+"U")

Measured memory_bytes: 3060
import math
N = int(input())
X = list(map(int,input().split()))
P = math.ceil(sum(X)/N)
P1 = P - 1
hp = 0
hp2 = 0

for x in X:
  hp_x = (P-x)**2
  hp2_x = (P1 - x)**2
  hp = hp + hp_x
  hp2 = hp2 + hp2_x
print(min(hp,hp2))


Measured memory_bytes: 3060
import collections
import math

n=int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = collections.Counter(prime_factorize(n))
ans=0
for i in c.keys():
    count=0
    z=c[i]
    for i in range(55):
        z-=i
        if z>=0:
            count=i
        else:
            break
    ans+=count
print(ans)

Measured memory_bytes: 9488
S = input()
A = int(S[0:2])
B = int(S[2:4])

if 0 < A and A <= 12:
  if 0 < B and B <= 12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 0 < B and B <= 12:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define N 300005
using namespace std;
int n,a[N],x,b[N],y,c[N],tmp[N];
int merge(int *a,int l,int r){
	if(l==r)return 0;
	int mid=(l+r)>>1;
	int res=merge(a,l,mid)+merge(a,mid+1,r);
	int pl=l,pr=mid+1;
	for(int i=l;i<=r;i++){
		if(pl<=mid&&(a[pl]<a[pr]||pr>r))tmp[i]=a[pl++],res+=pr-mid-1;
		else tmp[i]=a[pr++];
	}
	for(int i=l;i<=r;i++)a[i]=tmp[i];
	return res;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i),i&1?b[++x]=a[i]:c[++y]=a[i];
	puts(merge(a,1,n)==3*(merge(b,1,x)+merge(c,1,y))?"Yes":"No");
	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15



int main() {
	char a, b;
	cin >> a >> b;
	if(a-'A' < b-'A')
		cout << "<" << endl;
	else if(a-'A' > b-'A')
		cout << ">" << endl;
	else
		cout << "=" << endl;
	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
using namespace std;
list<int> L;    //??????????????????????????????????????????????????????????????????
bool DAG_check = false;

void visit(int n, vector<vector<int>>& graph, vector<int>& mark) {
	if (DAG_check == true) {
		return;
	}
	if (mark[n] == 1) {
		DAG_check = true; return;
	}
	else {
		if (mark[n] == 0) {
			mark[n] = 1;
			for (int i = 0; i < graph[n].size();i++) {
				visit(graph[n][i], graph, mark);
			}
			mark[n] = 2;
			L.emplace_back(n);
		}
	}
}

int main() {
	int V, E; cin >> V >> E;
	vector<vector<int>> graph(V);
	vector<int> mark(V, 0); //????????????????????°    1???????????????????????????2??\??\??\?????????
	for (int i = 0; i < E;i++) {
		int s, t; cin >> s >> t;
		graph[s].emplace_back(t);
	}

	for (int i = 0; i < V;i++) {
		if (mark[i] == 0) {
			visit(i, graph, mark);
		}
	}

	//List???????????????????´????????????????
	for (auto i = L.rbegin(); i != L.rend(); i++) {
		cout << *i << endl;
	}

	return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <math.h>
#include <bitset>
#include <queue>

using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    if(n == m) cout << "Yes";
    else cout << "No";

}

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(i, 0, N) {
        cin >> A[i] >> B[i];
    }
    ll ans = 0;
    ll cumsum = 0;
    rrep(i, N, 0) {
        ll cnt = ((A[i] + cumsum + B[i] - 1) / B[i]) * B[i] - A[i] - cumsum;
        ans += cnt;
        cumsum += cnt;
    }
    cout << ans << endl;
    return 0;
}

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

"""
参考：https://qiita.com/drken/items/03c7db44ccd27820ea0d
・最長共通部分列問題
・i側とj側の両方向に配るDP
・復元
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()
t = input()

dp = [[0] * (len(t)+1) for i in range(len(s)+1)]

for i in range(len(s)+1):
    for j in range(len(t)+1):
        # 下に送る
        if i < len(s):
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        # 右に送る
        if j < len(t):
            dp[i][j+1] = max(dp[i][j+1], dp[i][j])
        # 今回増やす文字が一致するなら、LCSが1文字増える
        if i < len(s) and j < len(t) and s[i] == t[j]:
            # 右下に送る
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1)

# 復元(DPテーブルを遡る)
i = len(s)
j = len(t)
ans = ''
while i > 0 and j > 0:
    # 上が同じ値なら上に移動
    if dp[i-1][j] == dp[i][j]:
        i -= 1
    # 左が同じ値なら左に移動
    elif dp[i][j-1] == dp[i][j]:
        j -= 1
    # 上も左も値が異なれば、そこが更新箇所なので、該当位置の文字を取得
    else:
        ans = s[i-1] + ans
        i -= 1
        j -= 1
print(ans)


Measured memory_bytes: 137176
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cassert>
#include <map>
#include <set>
using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  std::vector<int> v(n);
  for (auto& el : v) {
    cin >> el;
  }

  auto ind = std::min_element(v.begin(), v.end()) - v.begin();
  auto ans = (int64_t)1e18;
  for (int k = 0; k < n; k++) {
    int64_t sum = 0LL;
    multiset<int> st;
    for (int i = 0; i < k; i++) {
      st.insert(v[i]);
    }
    int cur = k;
    for (int i = 0; i < n; i++) {
      st.insert(v[cur]);
      sum += *st.begin();
      st.erase(st.find(v[(cur - k + n) % n]));
      cur++;
      cur %= n;
    }
    ans = min(ans, sum + (int64_t)x * k);

  }

  cout << ans << endl;




  return 0;
}

Measured memory_bytes: 384
n = int(input())
s = input()
k = int(input())
l = []
a = ''

for i in range(n):
    l += s[i]

for i in range(n):
    if l[k-1] != l[i]:
        l[i] = '*'

for i in range(n):
    a += ''.join(l[i])
    
print(a)

Measured memory_bytes: 3188
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main(void){
  long long N, A, B;
  cin >> N >> A >> B;
  long long X[N];
  for(long long i=0;i<N;++i) cin >> X[i];


  long long move, teleport, ans = 0;
  for(long long i=1;i<N;i++){
    move = (X[i]-X[i-1])*A;
    teleport = B;
    ans += min(move, teleport);
  }

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


Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int flag1 = 0;
		int flag2 = 0;
		int count = 0;
		String S = sc.nextLine();
		String[] step = S.split("");
		
		for(int j=0; j<step.length; j++){
			if(j%2 == 0){
				flag1 = stepJugeB(step[j]);
				if(flag1 == 0){
					count++;
				}
			}
			else{
				flag2 = stepJugeA(step[j]);
				if(flag2 == 0){
					count++;
				}
			}
		}
		
		if(count == 0){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
	public static int stepJugeA(String x){
		int flag = 0;
		if(x.equals("L") || x.equals("U") || x.equals("D")){
			flag = 1;
		}
		else{
			flag = 0;
		}
		return flag;
	}
	public static int stepJugeB(String x){
		int flag = 0;
		if(x.equals("R") || x.equals("U") || x.equals("D")){
			flag = 1;
		}
		else{
			flag = 0;
		}
		return flag;
	}
}

Measured memory_bytes: 22996
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    exams=[]
    sorted_exams=[]
    n = int(input())
    exams=list(map(int,input().split()))
    sorted_exams=sorted(exams)
    half=n//2

    start=sorted_exams[half-1]
    end=sorted_exams[half]

    print(end-start)

if __name__=="__main__":
    main()

Measured memory_bytes: 20660
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a) for(int i = 0;i < (a); i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())
#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int N;
vector<pair<int,int> > V;

int dp[1024][1024];

int solve()
{
    rep(i,1024) rep(j,1024) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,N) {
	int A = V[i].second;
	int B = V[i].first;
	rep(j,i+1) {
	    dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
	    if (dp[i][j] + A <= B)
		dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + A);
	}
    }
    for (int i = N; i >= 0; --i)
	if (dp[N][i] < INF)
	    return i;
    return 0;
}

int main() {
    cin >> N;
    rep(i,N) {
	int A, B;
	cin >> A >> B;
	V.pb(mp(B, A));
    }
    sort(all(V));

    cout << solve() << endl;
    
    return 0;
}

Measured memory_bytes: 5300
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans[ohara], a[ohara], b[ohara], c, d[ohara], tmp, m, h, w, x, y, sum,
    k, q;
struct edge {
  ll to, cost;
};
vector<edge> g[1000000];
bool vi[ohara];

void dijkstra(ll s) {
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que;
  fill(d, d + n, LINF);
  d[s] = 0;
  que.push(pair<ll, ll>(0LL, s));
  while (!que.empty()) {
    pair<ll, ll> p = que.top();
    que.pop();
    ll v = p.second;
    if (d[v] < p.first) continue;
    rep(i, Size(g[v])) {
      edge e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(pair<ll, ll>(d[e.to], e.to));
      }
    }
  }
}

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

  cin >> n >> m;
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]].p_b({b[i], 1LL});
    g[b[i]].p_b({a[i], 1LL});
  }
  dijkstra(0);
  rrep(i, 1, n) {
    ll dis = LINF;
    rep(j, Size(g[i])) {
      edge e = g[i][j];
      ll t = e.to;
      if (dis > d[t]) {
        dis = d[t];
        tmp = t;
      }
    }
    ans[i] = tmp;
  }
  Cout("Yes");
  rrep(i, 1, n) Cout(ans[i] + 1);
  return 0;
}


Measured memory_bytes: 42924
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int a[1001] = {};
	for (int i = 1; i <= 1000; i++)
		a[i] = a[i - 1] + i;

	for (int N; cin >> N&&N;) {
		int cnt = 0;
		for (int i = 0; i <= 1000; i++)
			for (int j = i + 2; j <= 1000; j++)
				if (a[j] - a[i] > N)
					break;
				else if (a[j] - a[i] == N)
					cnt++;
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input! {
        a: i64,
        b: i64,
    }

    let answer = if b % a == 0 { a + b } else { b - a };

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


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

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

    auto flips = 0;
    auto deque = std::deque<char>(begin(S), end(S));
    for (auto i = 0; K != 0 && i < 2*N; i++, K--)
    {
        auto A = 'A', B = 'B';
        if (flips % 2 == 1) swap(A, B);

        if (deque.front() == A) deque.front() = B;
        else
        {
            deque.pop_front();
            deque.push_back(B);
            flips++;
        }
    }

    S = string(begin(deque), end(deque));
    if (flips % 2 == 1)
        for (auto& c : S)
            c = (c == 'A' ? 'B' : 'A');

    if (K == 0) cout << S << endl;
    else
    {
        if (N % 2 == 1 && K % 2 == 1)
            S[0] = (S[0] == 'A' ? 'B' : 'A');
        cout << S << endl;
    }
}


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

class Program
{
  static int Main()
  {
    var buf = Console.ReadLine().Split().ToList().ConvertAll(int.Parse);
    var seq = buf.OrderByDescending(x=>x).ToList();
//    foreach(var n in seq)
      
      Console.WriteLine("{0}",seq[0] * 10 + seq[1] + seq[2]);

    return 0;
  }
}

Measured memory_bytes: 13396
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	char s[200010];
	scanf("%s", s);
	int i = 0, an = 0, j, a = 0;
	while (s[i] != '\0') {
		if (s[i] == 'A' && a == 0) {
			j = i;
			a = 1;
		}
		if (s[i] == 'Z' && a == 1) {
			an = i - j + 1;
		}
		i++;
	}
	printf("%d", an);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <limits>

using namespace std;
int a[100], b[100], n, i, j;
string s, k;

int main(){
	cin>>n;
	for(i=0; i<n; i++){
		cin>>a[i]>>b[i];
}
	
	for(i=0; i<=n-3; i++){
		if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2]){
			cout<<"Yes";
			return 0;
		}
	}	
	cout<<"No";
	return 0;
}



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

using namespace std;
int main() {
 int a, b ,c;
  cin>>a >>b >>c;
  
  if(a==7&&b==5&&c==5)
    cout<<"YES";
  else if(a==5&&b==7&&c==5)
    cout<<"YES";
  else if(a==5&&b==5&&c==7) 
     cout<<"YES";
    
  else
    cout<<"NO";
    
}

Measured memory_bytes: 3556
main = getLine >> interact (f 0 0 0 . map ((`mod` 4) . read) . words)
 
f x y z []
  | y + 2 > x + z = "Yes"
  | otherwise = "No"
f x y z (0:as) = f x (succ y) z as
f x y _ (2:as) = f x y 1 as
f x y z (_:as) = f (succ x) y z as

Measured memory_bytes: 2428
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

// BEGIN NO SAD
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// END NO SAD

typedef long long ll;
typedef pair<int, int> pii;

ll amt[10][10];
void solve() {
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    string s = to_string(i);
    amt[s[0]-'0'][s[sz(s)-1]-'0']++;
  }
  ll ret = 0;
  for(int i = 0; i < 10; i++) for(int j = 0; j < 10; j++) ret += amt[i][j] * amt[j][i];
  cout << ret << "\n";
}

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


Measured memory_bytes: 256
import copy
import math
import time
import statistics
import math
import itertools

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()
    n = get_int()
    p = get_int_list()
    q = get_int_list()

    a = []
    for i in range(1, n+1):
        a.append(i)

    count = 0
    count_p = 0
    count_q = 0
    for keiro in list(itertools.permutations(a)):
        if list(keiro) == p:
            count_p = count
        if list(keiro) == q:
            count_q = count
        count += 1

    print(abs(count_p - count_q))


if __name__ == '__main__':
    main()




Measured memory_bytes: 15740
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main() {
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	double A = pow((x2 - x1), 2);
	double B = pow((y2 - y1), 2);
	cout << fixed << setprecision(8) << sqrt(A + B) << endl;
}


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

int main(void){
    string s;
    cin>>s;
    int l=0,r=s.size()-1,cnt=0;
    while(l<r){
        if(s[l]==s[r])l++,r--;
        else if(s[l]=='x')l++,cnt++;
        else if(s[r]=='x')r--,cnt++;
        else{
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#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++)
#define pi 3.14159265359
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyg"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYG";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N,K;
  cin>>N>>K;
  vl a(N);
  rep(i,N) cin>>a[i];
  sort(a.begin(),a.end());
  ll ans=0;
  rep(i,K) ans+=a[i];
  cout<<ans<<endl;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

bool check(char a, char b) {
	return a > b;
}

int kuraiwa(int n) {
	int ans = 0;
	while (n > 0) {
		ans += n % 10;
		n /= 10;
	}
	return ans;
}

bool kaibun(int n) {
	int a[5];
	for (int i = 0; i < 5; i++) {
		a[i] = n % 10;
		n /= 10;
	}
	if (a[0] == a[4] && a[1] == a[3]) {
		return true;
	}
	else {
		return false;
	}
}

int main() {
	int a, b;
	cin >> a >> b;
	int cnt = 0;
	rep(i, b - a + 1){
		cnt += i;
	}
	cout << cnt - b << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long cou (long s, long t) {
	string ts=to_string(t);
	long total = s+t;
	for(int i = 1; i < ts.size();i++) {
		long t2 = t / (long)pow(10,ts.size() - i);
		long t3 = t % (long)pow(10,ts.size() - i);
		total += cou(t2+s,t3);
	}
	return total;
}

int main(){
	long a;
	long total;
	cin >> a;
	total = a;
	string s = to_string( a);
	for(int i = 1; i < s.size(); i++) {
		long t = a / pow(10,s.size() - i);
		long t2 = a % (long)pow(10,s.size() - i);
		total += cou(t,t2);
	}
	
	cout << total<< endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

//static const long long MOD = 1000000007;

int main() {
    long long N, answer = 0;

    // input
    cin >> N;

    // process
    if (N < 10) {
        answer = N;
    } else if (N >= 10 && N < 100) {
        answer = 9;
    } else if (N >= 100 && N < 1000) {
        answer = 9 + (N - 99);
    } else if (N >= 1000 && N < 10000) {
        answer = 909;
    } else if (N >= 10000 && N < 100000) {
        answer = 909 + (N - 9999);
    } else {
        answer = 90909;
    }

    // output
    cout << answer;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RREP(i,n) for (int i=n-1;i>=0;i--)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

vector<int> e[MAXn];
int p[MAXn];
int ok[MAXn];
vector<int> a,b;
void dfs(int x,int par,bool col){
    if (!col) a.eb(x);
    else b.eb(x);
    for (auto i:e[x]) {
        if (i == par) continue;
        dfs(i,x,!col);
    }
}
int main(){
    IOS();
    int n;
    cin >> n;
    REP (i,n-1) {
        int u,v;
        cin >> u >> v;
        e[u].eb(v);
        e[v].eb(u);
    }
    dfs(1,1,0);
    if (SZ(a) > SZ(b)) swap(a,b);
    int t1 = n/3, t2 = n/3;
    if (n % 3 == 1) t1++;
    if (n % 3 == 2) t1++, t2++;
    if (t1 <= SZ(a) && t2 <= SZ(b)) {
        REP (i,t1) ok[a[i]] = 1;
        REP (i,t2) ok[b[i]] = 2;
    }
    else {
        REP (i,t1) ok[b[i]] = 1;
        for (int i=t1;i<t1+t2;i++) ok[b[i]] = 2;
    }
    int c0 = 3, c1 = 1, c2 = 2;
    REP1 (i,n) {
        if (ok[i] == 0) {
            p[i] = c0;
            c0 += 3;
        }
        else if (ok[i] == 1) {
            p[i] = c1;
            c1 += 3;
        }
        else {
            p[i] = c2;
            c2 += 3;
        }
    }
    REP1 (i,n) cout << p[i] << " \n"[i==n];
}


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

int main(void) {
  ll N;
  cin >> N;
  ll A[1LL << 18];
  REP(i, 0, 1LL << N) scanf("%lld", A + i);

  ll ans = 0;
  REP(k, 1, 1LL << N) {
    ll p = 0, q = 0;
    ll i = k;
    do {
      ll w = max(max(p, q), A[i]);
      q = p + q + A[i] - w - min(min(p, q), A[i]);
      p = w;
      i = (i - 1) & k;
    } while(i != k);
    ans = max(ans, p + q);
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define ll long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
ll cl(ll a,ll b)
{
    return (a/b)+(!(!(a%b)));
}ll ans;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x;cin >> x;
    ll d=100;
    while(d<x)
    {
        d+=(d/100);ans++;
    }
    cout << ans;
    }

Measured memory_bytes: 3652