akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 200010;

int n;
int w[N];
bool dp[N];
vector<int> g[N];

void dfs(int u) {
  for (int v : g[u])
    if (!w[v]) {
      w[v] = w[u] + 1;
      dfs(v);
    }
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d", &n);
  for (int rep = 1; rep < n; ++rep) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  w[1] = 1;
  dfs(1);
  int u = max_element(w + 1, w + n + 1) - w;
  memset(w, 0, sizeof(w));
  w[u] = 1;
  dfs(u);
  int cent = *max_element(w + 1, w + n + 1);
  dp[0] = false;
  dp[1] = true;
  dp[2] = false;
  for (int i = 3; i <= cent; ++i)
    dp[i] = !dp[i - 1] | !dp[i - 2];
  puts(dp[cent] ? "First" : "Second");

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 18432
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}

ll n, w;
ll weight[110], value[110];

ll dp[110][11010];
int main()
{
	ios_base::sync_with_stdio(false);

	cin >> n >> w;
	rep(i, n) cin >> value[i] >> weight[i];

	rep(i, n) dp[0][i] = 0;

	rep(i, n) {
		rep(j, w+1) {
			if (j >= weight[i]) dp[i + 1][j] = max(dp[i][j - weight[i]] + value[i], dp[i][j]);
			else dp[i + 1][j] = dp[i][j];
		}
	}

	cout << dp[n][w] << endl;
	return 0;
}


Measured memory_bytes: 11360
#include<stdio.h>
 
int main(void){
  
  int hp1,hp2,atk1,atk2;
  scanf("%d %d %d %d",&hp1,&atk1,&hp2,&atk2);
  int cnt=0;
  
  while(hp1>0 && hp2>0){
    if(cnt%2==0){
      hp2-=atk1;
    }else{
      hp1-=atk2;
    }
    cnt++;
  }
  
  if(hp1<=0){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll n;
  V a;

  ll sum = 0;
  ll n_neg = 0;
  ll min_abs = 1000000000;

  ll res;

  cin >> n;

  for(ll i=0; i<n; i++) {
    ll t;
    cin >> t;
    a.push_back(t);
  }

  for(ll i=0; i<n; i++) {
    if(a[i] < 0) {
      sum -= a[i];
      n_neg++;
    } else {
      sum += a[i];
    }

    if(min_abs > abs(a[i])) {
      min_abs = abs(a[i]);
    }
  }

  if(n_neg % 2) {
    res = sum - min_abs * 2;
  } else {
    res = sum;
  }

  cout << res << endl;

  return 0;
}


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

int main() {
  int N, cnt=0, M=0;
  cin >> N;
  int a[N], b[N]={1};
  for(int i=0; i<N; i++) {
    cin >> a[i];
  }
  for(int i=0; i<N*100; i++) {
    M=a[M]-1;
    cnt++;
    if(M==1) {
      cout << cnt << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 1024
D, N = map(int, input().split())

def chk(n):
    result = 0
    while  n % 100 == 0:
        n = int(n/100)
        result += 1
    return result

ans = 1
cnt = 0
while True:
    d = chk(ans)
    if d == D:
        cnt += 1
    if d == D and cnt == N:
        break
    ans += 1

print(ans)

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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define ALL(x) (x).begin(), (x).end()

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

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    ll a, b, x;
    cin >> a >> b >> x;

    ll ans = b/x - a/x;
    if(a%x == 0) {
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    k, a, b = map(int, input().split())

    if b - a < 2 or k - a < 1:
        print(k + 1)
    else:
        k -= a - 1
        q, k = divmod(k, 2)
        res = a + q * (b - a) + k
        print(res)


if __name__ == '__main__':
    resolve()


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

int h,m,s,h2,m2,s2;

void res(int &h,int &m,int &s,int &h2,int &m2,int &s2){
  int sa;
  sa = (h2 * 3600 + m2 * 60 + s2) - (h * 3600 + m * 60 + s);
  h = sa / 3600;
  m = (sa - h * 3600) / 60;
  s = sa - h * 3600 - m * 60;
}

int main(){
  for(int i = 0; i < 3; i++){
    cin >> h >> m >> s;
    cin >> h2 >> m2 >> s2;
    res(h,m,s,h2,m2,s2);
    cout << h << " " << m << " " << s << endl;
  }

  return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = (int)1e9 + 7;
const int INF = (int)100100100;

int main() {
    ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int h[N];
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
    bool can=true;
    for(int i=N-1;i>0;i--){
        if(h[i-1]-h[i]>=2)can=false;
        else if(h[i-1]-h[i]==1)h[i-1]--;
    }
    if(can)cout << "Yes";
    else cout << "No";


}

/*



 */



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

int main(){
  int p,q,r;
  cin>>p>>q>>r;
  int ans=p+q;
  ans=min(ans,q+r);
  ans=min(ans,r+p);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;
LL f[200005], rf[200005];
LL pw(LL a, LL b){
	LL res = 1;
	while(b){
		if(b%2) res = (res*a)%mod;
		a = (a*a)%mod;
		b/=2;
	}
	return res;
}
LL ncr(int a, int b){
	return f[a]*rf[b]%mod*rf[a-b]%mod;
}
map<int, int> dp;
map<int, int>::iterator its;
int main(){
	f[0] = 1;
	for(int i=1;i<=200000;i++) f[i] = (f[i-1]*i)%mod;
	for(int i=0;i<=200000;i++) rf[i] = pw(f[i], mod-2);
	int n, m;
	scanf("%d%d", &n, &m);
	int nm = m;
	for(int i=2;i*i<=nm;i++){
		int cnt = 0;
		while(m%i == 0) m/=i, cnt++;
		dp[i] += cnt;
	}
	if(m != 1) dp[m]++;
	LL ans = 1;
	for(its = dp.begin();its != dp.end();its++){
		int dv = its->first;
		int cnt = its->second;
		ans = (ans * ncr(cnt+n-1, cnt))%mod;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

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

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

    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    vector<int> dp;
    for(int aa : a){
        auto it=lower_bound(dp.rbegin(),dp.rend(),aa);
        if(it==dp.rbegin()) dp.push_back(aa);
        else{
            it--;
            *it=aa;
        }
    }
    cout<<dp.size();

    return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back

using namespace std;

const int N=1e5+5;

int n,U,V,dis[N],DIS[N],p[N];

vector<int>adj[N];

void dfs(int x,int par)
{
    p[x]=par;
    for (auto X:adj[x])
    {
        if (X!=par)
        {
            dis[X]=1+dis[x];
            dfs(X,x);
        }
    }
}

void BFS(int s)
{
    DIS[s]=0;
    queue<int>q;
    q.push(s);
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        for (auto X:adj[x])
        {
            if (DIS[X]==-1&&DIS[x]+1<=dis[X])
            {
                DIS[X]=1+DIS[x];
                q.push(X);
            }
        }
    }
}

int main()
{
    memset(DIS,-1,sizeof DIS);
    cin >> n >> U >> V;
    for (int i=0;i<n-1;i++)
    {
        int u,v;cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(V,0);
    BFS(U);
    int mx=0;
    for (int i=1;i<=n;i++)
    {
        if (DIS[i]!=-1&&DIS[p[i]]!=-1)mx=max(mx,dis[p[i]]);
    }
    cout << mx << endl;
}


Measured memory_bytes: 10752
using System;

namespace Application
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            var x = s.Substring(0, n / 2);
            var y = s.Substring(n / 2);

            if (x == y)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11092
//shrinking

#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

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

    int ans=1e9;





    for(char test='a';test<='z';++test){
        int max_interval=0;
        int cnt_interval=0;
        for(auto &x:S){
            if(x==test){
                cnt_interval=0;
            }else{
                cnt_interval++;
            }

            max_interval=max(max_interval,cnt_interval);
        }
        ans=min(ans,max_interval);
    }



    cout<<ans<<endl;

}





Measured memory_bytes: 256
#include <iomanip>
#include <string>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
	long long int a, b, c = 1;
	cin >> a >> b;
	for (int i = 0; i < a; i++) {
		c = min(c * 2, c + b);
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
def solve():
    readline = sys.stdin.readline
    write = sys.stdout.write
    N, M, *V = map(int, readline().split())
    G = [[] for i in range(N)]
    for i in range(M):
        u, v = map(int, readline().split())
        G[u-1].append(v-1)
    def matmul(A, B):
        C = [[0]*N for i in range(N)]
        for i in range(N):
            for j in range(N):
                C[i][j] = +(sum(A[i][k] & B[k][j] for k in range(N)) > 0)
        return C

    def fast_pow(X, k):
        R = [[0]*N for i in range(N)]
        for i in range(N):
            R[i][i] = 1
        while k:
            if k & 1:
                R = matmul(R, X)
            X = matmul(X, X)
            k >>= 1
        return R
    V.sort()
    prv = 0
    ES = [[0]*N for i in range(N)]
    for v in range(N):
        for w in G[v]:
            ES[v][w] = 1
    EE = []
    ds = []
    rgs = []
    for i, k in enumerate(V):
        d = [0]*N
        rg = [[] for i in range(N)]
        ek = fast_pow(ES, k)
        EE.append(ek)
        for v in range(N):
            ts = ek[v]
            for w in range(N):
                if ts[w]:
                    d[v] += 1
                    rg[w].append(v)
        ds.append(d)
        rgs.append(rg)
    D = [0]*N
    for i in range(3):
        d = ds[i]
        for v in range(N):
            if d[v]:
                D[v] += 1
    U = [-1]*N
    U[N-1] = 0
    que = deque([N-1])
    while que:
        v = que.popleft()
        u = U[v]
        for i, rg in enumerate(rgs):
            d = ds[i]
            for w in rg[v]:
                if d[w] == 0:
                    continue
                d[w] = 0
                D[w] -= 1
                if D[w] == 0:
                    if U[w] == -1:
                        U[w] = u+1
                        que.append(w)
    write("%d\n" % U[0] if U[0] != -1 else "IMPOSSIBLE\n")
solve()


Measured memory_bytes: 6196
# usr/bin/python
# coding: utf-8
################################################################################
# List of Top 3 Hills
#There is a data which provides heights (in meter) of mountains. The data is only for ten mountains.
#
#Write a program which prints heights of the top three mountains in descending order.
#
################################################################################

if __name__ == "__main__":
    hight_of_mount  = [0]*10
    for i in range(0, 10):
        hight_of_mount[i]  = int(input())

    hight_of_mount.sort(reverse=True)

    for i in range(0, 3):
        print(hight_of_mount[i])
    exit(0)
  

Measured memory_bytes: 5604
#include<iostream>
using namespace std;
int main(){
	int a[4][14] = {};
	int n;
	char mark;
	int number;
	cin >> n;
	
	for (int i = 0; i < n; i++){
		cin >> mark >> number;
		if (mark == 'S') a[0][number] = 1;
		if (mark == 'H') a[1][number] = 1;
		if (mark == 'C') a[2][number] = 1;
		if (mark == 'D') a[3][number] = 1;
	}
	for (int b =0; b <4; b++){
		for (int c = 1; c < 14;c++){
			if (a[b][c] != 1)
			{
				if (b == 0){ cout << 'S'; }
				else
					if (b == 1){cout << 'H';
				}
					else if (b == 2){ cout << 'C'; }
					else if (b == 3){ cout <<'D'; }
				cout<< ' ' << c << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    deque<int> d;
    rep(i,n) {
        int a;
        cin >> a;
        if(i%2 == 0) d.pb(a);
        else d.push_front(a);
    }
    if(n%2 == 0) {
        rep(i,n) {
            cout << d.front() << " ";
            d.pop_front();
        }
    } else {
        rep(i,n) {
            cout << d.back() << " ";
            d.pop_back();
        }
    }
    cout << endl;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main(){
    #define int long long
    int n;
    cin >> n;
    int const N = 1e5+ 1e3;
    vector <int> x(n), y(n), visx(N), visy(N);
    vector < vector <int > > gx(N), gy(N);
    for(int i = 0; i < n; ++i){
        cin >> x[i] >> y[i];
        gx[x[i]].push_back(y[i]);
        gy[y[i]].push_back(x[i]);
    }

    vector <int> visiX, visiY;
    function<void(int, int)> dfs = [&](int v, int opt){
        if(opt == 0){
            visx[v] = 1;
            visiX.push_back(v);
            for(int dy : gx[v]){
                if(!visy[dy])dfs(dy, opt^1);
            }
        }
        else {
            visy[v] = 1;
            visiY.push_back(v);
            for(int dx : gy[v]){
                if(!visx[dx])dfs(dx, opt^1);
            }
        }
    };
    int ans = 0;
    for(int i = 0; i < N; ++i){
        if(!visx[i]){
            dfs(i, 0);
            int u = visiX.size()*visiY.size();
            int t = 0;
            for(int r : visiX){
                t += gx[r].size();
            }
            u -= t;
            ans += u;
            // if(visiX.size() > 0  && visiY.size() > 0){
            //     cerr <<"asd\n";
            //     for(int x : visiX){
            //         cerr << x << ' ';
            //     }
            //     cerr << '\n';
            //     for(int Y : visiY){
            //         cerr << Y << ' ';
            //     }
            //     cerr << '\n';
            //     cerr << t << '\n';
            //     cerr <<"tra\n";
            // }
            
            visiX.clear();
            visiY.clear();


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

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


int main()
{
    string s;

    cin>>s;

    if(s=="SUN") cout<<7<<endl;
    if(s=="MON") cout<<6<<endl;
    if(s=="TUE") cout<<5<<endl;
    if(s=="WED") cout<<4<<endl;
    if(s=="THU") cout<<3<<endl;
    if(s=="FRI") cout<<2<<endl;
    if(s=="SAT") cout<<1<<endl;
    return 0;
}


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

#define PB          push_back
#define PF          push_front
#define MP          make_pair
#define FI          first
#define SE          second
#define SIZE( A )   int( ( A ).size( ) )
#define ALL( A )    ( A ).begin( ), ( A ).end( )
#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )

using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lf;
typedef pair< int, int >    pii;
typedef pair< ll, ll >      pll;
typedef vector< bool >      vb;
typedef vector< lf >        vd;
typedef vector< ll >        vll;
typedef vector< int >       vi;
typedef vector< pii >       vpii;

const int MAXN = int( 1e5 )+10;
const int MOD  = int( 360 );
const int oo   = INT_MAX;

int tc, n, m;
vi graph[ MAXN ];

int seen[ MAXN ];
vi path;

void dfs1( int p, int u ) {
  seen[ u ] = tc;
  for( auto& v : graph[ u ] ) {
    if( v == p || seen[ v ] == tc ) {
      continue;
    }
    dfs1( u, v );
    break;
  }
  path.PB( u );
}

void dfs2( int p, int u ) {
  seen[ u ] = tc;
  path.PB( u );
  for( auto& v : graph[ u ] ) {
    if( v == p || seen[ v ] == tc ) {
      continue;
    }
    dfs2( u, v );
    break;
  }

}

int main( ) {

  #ifdef LOCAL
    freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
  #else
    //freopen( "attack.in", "r", stdin );
    //freopen( "attack.out", "w", stdout );
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );
  #endif

  for( tc = 1; cin >> n >> m; ++tc ) {
    for( int i = 0; i < n; ++i ) {
      graph[ i ].clear( );
    }
    for( int i = 0; i < m; ++i ) {
      int u, v; cin >> u >> v; --u; --v;
      graph[ u ].PB( v );
      graph[ v ].PB( u );
    }
    path.clear( );
    dfs1( -1, 0 );
    for( auto& v : graph[ 0 ] ) {
      if( seen[ v ] != tc ) {
        path.pop_back( );
        dfs2( -1, 0 );
        break;
      }
    }
    cout << SIZE( path ) << '\n';
    for( int i = 0; i < SIZE( path ); ++i ) {
      cout << path[ i ]+1 << " \n"[i+1==SIZE(path)];
    }
  }

  return 0;
}


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

int main(){
	int n;
	cin >> n;
	map<int,int> mp;
	rep(i,n) {
		int input; 
		cin >> input;
		mp[input]++;
	}
	vector<pair<int,int>> pr(mp.size());
	int i=0;
	for(auto a:mp){
		auto now = make_pair(a.first,a.second);
		pr[i]=now;
		i++;
	}
	sort(pr.begin(),pr.end(),greater<pair<int,int>>());
	ll edge1=-1,edge2=-1;
	rep(i,pr.size()){
		if(pr[i].second>=4){
			if(edge1==-1) edge1=pr[i].first;
			if(edge2==-1) edge2=pr[i].first;
		}
		else if(pr[i].second>=2){
			if(edge1==-1) edge1=pr[i].first;
			else if(edge2==-1) edge2=pr[i].first;
		}
		if(edge1!=-1&&edge2!=-1)
			break;
	}
	if(edge1==-1||edge2==-1) cout << 0 << endl;
	else cout << edge1*edge2 << endl;
	return 0;
}


Measured memory_bytes: 5760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ACprac
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int nm = int.Parse(str);
            int wnm = 0;

            for(int i = 0; i < str.Length; i++)
            {
                wnm = wnm + int.Parse(str.Substring(i, 1));
            }

            if(nm%wnm == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11092
using System;

namespace D___Digits_Parade
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var N = new int[S.Length];
            for (int i = 0; i < S.Length; i++) N[i] = S[i] == '?' ? -1 : int.Parse(S[i].ToString());
            var MOD = 1000000007;
            var DP = new long[13, S.Length + 1];
            DP[0, 0] = 1;

            for (int i = 0; i < N.Length; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (N[i] != -1 && N[i] != j) continue;
                    for (int k = 0; k < 13; k++)
                    {
                        DP[(10 * k + j) % 13, i + 1] += DP[k, i];
                        DP[(10 * k + j) % 13, i + 1] %= MOD;
                    }
                }
            }
            Console.WriteLine(DP[5, S.Length]);
        }
    }
}


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

int arr[5],k;
bool can=true;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	for(int i=0;i<5;i++){
		cin>>arr[i];
	}
	cin>>k;
	for(int i=0;i<5;i++){
		for(int j=i+1;j<5;j++){
			if(abs(arr[i]-arr[j])>k){
				can=false;
				break;
			}
		}
		if(!can)
			break;
	}
	if(can)
		cout<<"Yay!";
	else
		cout<<":(";
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

//function to sort and print array using selection
int SelectionSort (int arr[], int n)
{
    int i, j, mini, count=0, temp;
    for (i=0; i<n-1; i++){
    	mini = i;
        for (j = i; j<n; j++){
        	if (arr[j]<arr[mini]){
				mini = j;
        	}
    	}
    	//swap
    	if (mini!=i){
    		temp = arr[i];
        	arr[i] = arr[mini];
        	arr[mini] = temp;
        	count++;
    	}	
    }
    return count;
}

//test sort
int main()
{
    int i, n, swap;
    
    scanf("%d", &n);
    
    int a[n];
    
    for(i=0; i<n; i++)
        scanf("%d", &a[i]);
    
    swap = SelectionSort(a,n);
    
    for(i=0; i<n; i++){
    	printf("%d", a[i]);
    	if(i<n-1)
    		printf(" ");
    	else 
    		printf("\n");
    }
    
    printf("%d\n",swap);
    
    return 0;
}





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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
/*
 * Be careful of overflow
 * Array bounds
 * Assert a!=0 when performing x/a
 * Check base condition for recursion
 * Iterator -> O(1), Element -> O(log n) while using erase
 * 1LL<<x when x>32
 * Be sure of what you are going to code (exception dp)
 * Don't try fancy tricks during contest
 * You can always make a bad round to a good enough round
 */ 

vector<int> adj[200009];
bool vis[200009];
int cnt;

void dfs(int v)
{
	vis[v]=1;
	cnt++;
	for(auto u:adj[v]) if(!vis[u]) dfs(u);
}

void solve()
{
	int n,m,i;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	int ans=0;
	for(i=1;i<=n;i++)
	if(!vis[i])
	{
		cnt=0;
		dfs(i);
		ans=max(ans,cnt);
	}
	cout<<ans<<'\n';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


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

template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};

using namespace std;

int A[100001];
int main(){
    int s,l,r;
    cin>>s;
    while(s--){
       cin>>l>>r;
       for(int i=l;i<=r;i++)
             A[i]=1;
    }
    int sum=0;
    for(int i=0;i<100001;i++)
         sum+=A[i];
   cout<<sum;
    return 0;
}


Measured memory_bytes: 640
def main():
    x, y = map(int, input().split())
    if x <= y:
        if x == 0 or y == 0:
            print(y-x)
        elif 0 < x and 0 < y:
            print(y-x)
        elif x < 0 and y < 0:
            print(y-x)
        else:
            if -x <= y:
                print(y-(-x)+1)
            else:
                print((-x)-y+1)
    else:
        if x == 0 or y == 0:
            print(x-y+1)
        elif 0 < x and 0 < y:
            print(x-y+2)
        elif x < 0 and y < 0:
            print(min(x-y+2, (-y)-x+1))
        else:
            if x <= -y:
                print((-y)-x+1)
            else:
                print(y-(-x)+1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

/* 文字から数値に変換 */
int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

/* 文字列から数値へ変換して key を生成する */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); /* 文字列を数値に変換 */
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) % M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); /* 文字列を数値に変換 */
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str);
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16076
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long

using namespace std;
ll zerobp( int n , ll weight , vector<ll>& w , vector<ll>& v , ll vcnt){
  vector<ll> dp( 1e5 + 1 , INT_MAX );
  //cout << INT_MAX << endl;
  dp[0] = 0;
  for( int i = 1 ; i <= n ; i++ ){
    for( int j = vcnt; j >= 0 ; j-- ){
      if( j >= v[i] ){
          dp[j] = min( dp[j] , dp[j - v[i] ] + w[i] ) ;
        }
    }
   // cout << v[i] << endl;

//    for( int j = 0 ; j <= vcnt ; j++ ){
//      //cout << dp[j] << " " ;
//      printf("(%d,%lld)  ",j,dp[j]);
//    }
//    cout << endl ; 
  }
  int ret = -1;
  for( int i = vcnt ; i >= 0 ; i-- ){
    if( dp[i] <=  weight ){
      return i;
    }
  }
  return -1;
}

int main(){
  ll N,W;
  cin >> N >> W;//N <= 100 , W <= 1e5
  vector<ll> w(N+ 1);
  vector<ll> v(N + 1);
  ll vcnt = 0;
  for( int i = 1 ; i <= N ; i++ ){
    int wi,vi;
    cin >> wi >> vi ;
    w[i] = wi;//wi <= 1e9
    v[i] = vi;//vi <= 1e3
    vcnt += v[i];
  }
  ll ret = zerobp( N , W , w , v , vcnt);

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int count=0;
    for (int i=2;i<=n;i+=2) {
        for (int j=1;j<=n;j+=2) {
            count++;
        }
    }
    cout<<count<<endl;
}


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

int main(){
	int x,y;
	cin>>x>>y;
	if ((y - 2*x) >= 0 && (y-2*x)%2 == 0){
		int a = (y - 2*x)/2;
		int b = (x - a);
		if (b >= 0){
			cout<<"Yes";
		}
		else{
			cout<<"No";
		}
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3644
def factorization(N):
    factoring={}
    num=N
    for i in range(2,int(N**.5)+1):
        if num%i==0:
            count=0
            while num%i==0:
                count+=1
                num//=i
            factoring[i]=count
    if num!=1:
        factoring[num]=1
    return factoring

N=int(input())
prime=factorization(N)
count=0
for num in prime:
    e=1
    while prime[num]>=e:
        count+=1
        prime[num]-=e
        e+=1
print(count)

Measured memory_bytes: 9364
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
ll n, m, k;
pair<ll, ll> a[200010];
vector<ll> vt;
vector<pair<ll, ll>> vt1;
vector<ll> vt2;
int main()
{
	scanf("%lld %lld %lld", &n, &m, &k);
	for (int i = 0; i < n; i++) {
		scanf("%lld %lld", &a[i].first, &a[i].second);
		vt.push_back(a[i].first);
		vt.push_back(a[i].first + 2 * m);
	}
	sort(a, a + n);
	sort(vt.begin(), vt.end());
	vt.erase(unique(vt.begin(), vt.end()), vt.end());
	int idx = 0;
	for (int i = 0; i < vt.size(); i++) {
		ll value = 0;
		if (a[idx].first == vt[i]&&idx<n) {
			value = a[idx].second;
			idx++;
		}
		vt1.push_back({ vt[i],value });
		vt2.push_back(0);
	}
	ll sum = 0;
	ll ans = 0;
	for (int i = 0; i < vt1.size(); i++) {
		vt1[i].second += sum;
		if (vt1[i].second > 0) {
			ll howman = 0;
			howman += vt1[i].second / k;
			if (vt1[i].second % k)
				howman++;
			sum -= k * howman;
			ans += howman;
			int nextidx = lower_bound(vt.begin(), vt.end(), vt[i]+2*m) - vt.begin();
			if(nextidx!=vt1.size())
				vt2[nextidx] += k * howman;
		}
		sum += vt2[i];
	}
	printf("%lld", ans);
}


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

int main(){
  int N, M;
  cin >> N >> M;
  vector<string> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
   vector<string> B(M);
  for(int i = 0; i < M; i++){
    cin >> B[i];
  }
  
  for(int i = 0; i <= N-M; i++){
    for(int j = 0; j <= N-M; j++){
      int  I = i;
      while(I < i+M){
        if(A[I].substr(j, M) != B[I-i]){
              break;
         };
        I++;
        if(I == M+i){
              cout << "Yes" << endl;
              return 0;
        }
      }            
    }
  }
  
  cout << "No" << endl;
  return 0;
}
  


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

int MAX = 0;

int main(){
    //入力
    int d=365;
    vector<int> c;
    int all_c=0;
    int tmp;
    rep(i,26){
        cin>>tmp;
        c.push_back(tmp);
        all_c+=tmp;
    }
    int max_s;
    int ans = 1;
    rep(i,d){
        max_s = MAX;
        rep(j,26){
            cin>>tmp;
            if(tmp>max_s){
                max_s=tmp;
                ans = j+1;
            }
        }
        cout<<ans<<endl;
    }

   return 0;

}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define MOD 998244353
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace __gnu_pbds; 
using namespace std;

ll valueOfIndex(ordered_set&s , ll i){ return *(s.find_by_order(i)); }
ll indexOfValue(ordered_set&s , ll x){ return s.order_of_key(x); }
ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { //a%=p; b%=p; 
return (a*b + p)%p;} // __int128
ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
    ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}

ll inv(ll x){return power(x,MOD-2);}

ll fac[300010],finv[300010];

void f_pre(){
	fac[0]=1; finv[0]=1;
	for(ll i=1;i<=300000;i++){
		fac[i] = (i*fac[i-1])%MOD;
		finv[i] = inv(fac[i]);
	}
}

ll ncr(ll n,ll r){
    return mul(fac[n] , mul(finv[r] , finv[n-r]));
}




void __sol(){
    
    ll n,m,k; cin >> n >> m >> k;
    ll ans = 0;
    if(m==1){
        if(k==n-1) cout << 1;
        else cout << 0;
        return;
    }
    for(ll i=0;i<=k;i++){
        ll block = n - i;
        ll way = m;
        way = mul(way , power(m-1,block-1,MOD));
      //  cout << way << "\n";
        way = mul(way , ncr(n-1,i));
        ans = add(ans , way);
    }
    cout << ans;
    
    return;
}


int main(){
    f_pre();
    fastio
    ll tc=1; //cin >> tc;
    while(tc--) __sol();
    return 0;
}

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

int main(void){
    long long int n,m,d;
    cin >> n >> m >> d;
    
    if(d==0){
        cout << setprecision(8) << (long double)(m-1)/n;
    }else{
        cout << setprecision(8) <<  2.0*(long double)(n-d)*(m-1)/(long double)(n*n);
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd (ll a, ll b) {
	if (a > b) return gcd(b, a);
	if (a == 0) return b;
	return gcd(b % a, a);
}

int main () {
	ll a, b;
	cin >> a >> b;
	ll g = gcd(a, b);
	ll ans = 1;
	for (ll i = 2; i * i <= g; i++) {
		if (g % i != 0) continue;
		ans++;
		while (g % i == 0) g /= i;
	}
	if (g != 1) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,a,b) for(long long int i=a;i<b;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long int ll;
int main(){
    fast
    int n;cin>>n;
    long double k=1,val;
    int f=0;
    f(i,0,n){
        cin>>val;
        if(val==0){
            f=1;
            break;
        }
        k=k*val;
    }
    if(f)cout<<0;
    else if(k>1000000000000000000)cout<<-1;
    else{
        cout<<long(k);
    }
    return 0;
}

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

int main(){
  long long N=0 ;
  cin>>N;
  long long temp=0;
  long long ans=1e16;
  for (int i=1;i<sqrt(N)+1;i++){
    if(i*(N/i)==N){
      temp=i+(N/i)-2;
      ans=min(ans,temp);
    }
  }
  cout<<ans<<endl;
  return 0;
}

      

Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << '\n';}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

Vec cost = {LINF, 2, 5, 5, 4, 5, 6, 3, 7, 6};

bool cmp(string s, string t){
	if(s.size() == t.size()) return s > t;
	return s.size() > t.size();
}

int main(void){
	ll n, m;
	cin >> n >> m;
	Vec a(m);
	rep(i, m) cin >> a[i];
	sort(all(a));
	reverse(all(a));

	VecS dp(n+1, "");
	for(ll i : a){
		ll c = cost[i];
		repn(j, n){
			if(j >= c && (j == c || dp[j-c].size())){
				string s = dp[j-c];
				s += '0'+i;
				if(cmp(s, dp[j])) dp[j] = s;
			}
		}
	}
	co(dp[n]);

	return 0;
}


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

using namespace std;

int main() {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, a, b;
    cin >> n >> a >> b;

    bool f = 1;
    for(int i = 0; i < 1000; ++i) {
        if(f) {
            if(b - a > 1) {
                a++;
            } else if(a > 1) {
                a--;
            } else {
                cout << "Borys";
                return 0;
            }
        } else {
            if(b - a > 1) {
                b--;
            } else if(b < n) {
                b++;
            } else {
                cout << "Alice";
                return 0;
            }
        }
        f ^= 1;
    }

    if(a == 1) {
        cout << "Borys";
    } else {
        cout << "Alice";
    }

    return 0;
}

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

using namespace std;

int main() {
  int m, d;
  cin >> m >> d;
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    for (int j = 22; j <= d; ++j) {
      int tmp = j;
      int d1 = tmp % 10;
      tmp /= 10;
      int d2 = tmp % 10;
      if (d1 * d2 == i && d1 >= 2 && d2 >= 2) {
	ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <bitset>
#include <random>
#include <regex>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,f,n) for(int i=f;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(10)
#define int int_fast64_t
using pii = pair<int,int>;
using Graph = vector<vector<pii> >;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;

int n;
vector<int> h, dp;

int rec(int k){
    if(~dp[k]) return (dp[k]);
    int ret = INF;
    for(int i = 1; k - i >= 1 && i <= 2; ++i){
        chmin(ret, abs(h[k] - h[k-i]) + rec(k - i));
    }
    return (dp[k] = ret);
}

signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    cin >> n;

    h.resize(n+1);
    dp.resize(n+1, -1);

    reps(i,1,n){
        cin >> h[i];
    } 

    dp[1] = 0;

    cout << rec(n) << '\n';

    return 0;
}  

Measured memory_bytes: 11004
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(1, n+1):
    x = str(i)
    d[(int(x[0]), int(x[-1]))] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += d[(i, j)] * d[(j, i)]
print(ans)

Measured memory_bytes: 3572
import copy


def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                cnt += 1
    return cnt


n, k = map(int, input().split())
a = list(map(int, input().split()))
b = copy.deepcopy(a)
tmp = [0] * n
initial = bubble_sort(a)
ans = initial
for i in range(n):
    cnt = 0
    for j in b:
        if b[i] > j:
            cnt += 1
    tmp[i] = cnt
d = sum(tmp)
ans = k * (2 * initial + d * (k - 1)) // 2
print(ans % (10 ** 9 + 7))


Measured memory_bytes: 3700
import math
n=int(input())
xs=list(map(float,input().split()))
ys=list(map(float,input().split()))
ds=[ abs(x - y) for (x,y) in zip(xs,ys) ]
print('{0:.6f}'.format(sum(ds)))
print('{0:.6f}'.format((sum(map(lambda x: x*x,ds)))**0.5))
print('{0:.6f}'.format((sum(map(lambda x: x*x*x,ds)))**(1./3.)))
print('{0:.6f}'.format(max(ds)))

Measured memory_bytes: 7856
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define m_p make_pair
#define sz(x) (int)x.size()
#define out(x) cerr<<#x<<" = "<<x<<" "
#define outln(x) cerr<<#x<<" = "<<x<<endl
#define outarr(x,l,r) cerr<<#x"["<<l<<"-"<<r<<"] = "; for (int _i=l;_i<=r;++_i) cerr<<x[_i]<<" ";cerr<<endl;
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
#define gc() getchar()
//char buf[1<<23],*p1=buf,*p2=buf;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <class T> void read(T &x)
{
    x=0; char c=gc(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=gc();
    while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=gc();
    if (flag) x=-x;
}
template <class T> T _max(T a,T b){return a>b ? a : b;}
template <class T> T _min(T a,T b){return a<b ? a : b;}
template <class T> bool checkmax(T &a,T b){return b>a ? a=b,1 : 0;}
template <class T> bool checkmin(T &a,T b){return b<a ? a=b,1 : 0;}
const int N=200005;
int n,m,v,p;
int a[N],sum[N];
void init()
{
    read(n); read(m); read(v); read(p);
    for (int i=1;i<=n;++i)
    {
    	read(a[i]);
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for (int i=1;i<=n;++i)
	{
		sum[i]=sum[i-1]+a[i];
	}
}

bool check(int x)
{
	if (a[x]+m<a[p]) return 0;
	return m*v<=(p-1)*m+(n-x+1)*m-(sum[x-1]-sum[p-1])+(x-p)*(a[x]+m);
}

void solve()
{
	int l=p,r=n,mid,best=p;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (check(mid))
		{
			best=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	printf("%lld\n",best);
}

#undef int
int main()
{
	init();
	solve();
    return 0;
}

Measured memory_bytes: 5264
<?php
# 標準入力を取得するClass
class Scanner {
  private $arr = [];
  private $count = 0;
  private $point = 0;
  # 文字列を取得する
  public function next() {
    if ($this->point >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->point = 0;
    }
    $result = $this->arr[$this->point];
    $this->point++;
    return $result;
  }

  # 次の値があるか取得（boolean）
  public function isNext() {
    return $this->point < $this->count;
  }

  # Intに変換する
  public function nextInt() {
    return (int) $this->next();
  }

  # Doubleに変換する
  public function nextDouble() {
    return (double) $this->next();
  }
}

# 標準出力
class Out {
  public static function println($str = "") {
    echo $str . PHP_EOL;
  }
}


$scan = new Scanner();
$n = $scan->nextInt();

if ($n <= 999) {
  Out::println('ABC');
} else {
  Out::println('ABD');
}

 ?>


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
//m.emplace(x,0).fi->se++;

vector<vector<ll>> G(200005);//隣接リスト(添え字は始点、値は終点)
vector<ll>t(200005);//訪問したかどうか
vector<ll>cnt(200005,0);
void dfs(ll k,ll num){
  t[k]=1;
  num+=cnt[k];
  cnt[k]=num;
  for(ll i=0;i<G[k].size();i++){
    if(t[G[k][i]]==0){
      dfs(G[k][i],num); 
    }
  }
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n,q;cin>>n>>q; 
  for(ll i=0;i<n-1;i++){
    ll p,q;
    cin>>p>>q;
    G[p-1].push_back(q-1);
    G[q-1].push_back(p-1);
  }
  vector<ll>x(q),y(q);
  rep(i,0,q)cin>>x[i]>>y[i];
  rep(i,0,q)cnt[x[i]-1]+=y[i];
  dfs(0,0);
  debug(cnt,n);
  return 0;
}

Measured memory_bytes: 27392
#include <iostream>
#include <cmath>

using namespace std;

int distance(int a, int b);

int main()
{
	int a, b, c, d;

	cin >> a >> b >> c >> d;

	if (distance(c, a) <= d || (distance(a, b) <= d && distance(c, b) <= d)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}

int distance(int a, int b)
{
	return fabs(a - b);
}


Measured memory_bytes: 256