akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-6;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const char nl = '\n';

template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void ckmin(T& a, T b) { a = min(a, b); }
template <class T> void ckmax(T& a, T b) { a = max(a, b); }

// (Integer/Long).bitCount(x)
int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) { cerr << h; if (sizeof...(t)) cerr << ", "; DBG(t...); }

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
void setIO(string s = "") {
	unsyncIO();
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}

// Binary Exponentiation
ll pow(ll b, ll e, ll m = 0LL, ll ans = 1LL) { while (e) { if (e & 1LL) { ans *= b; if (m) ans %= m; } b *= b, e >>= 1LL; if (m) b %= m; } return ans; }



void solve(int tcn) {
	int n;
	cin >> n;
	cout << (n + 999) / 1000 * 1000 - n << nl;
}

int main() {
    setIO();

    int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 3660
def main():
    n,k = tuple([int(t)for t in input().split()])

    if k%2==0:
        t = n//k#kの倍数
        s = n//(k//2)-t#k//2の倍数でkの倍数でない数
        ans = t**3+s**3
        print(ans)
    else:
        ans = (n//k)**3
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define N 300005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int s[N*3];
int lz[N*3];
void update(int node,int l,int r,int b,int e)
{
    if(e<l||r<b)
        return;
    if(b<=l&&r<=e)
    {
        s[node]+=1;
        lz[node]+=1;
        return;
    }
    update(node*2,l,(l+r)/2,b,e);
    update(node*2+1,(l+r)/2+1,r,b,e);
    s[node]=s[node*2]+s[node*2+1];
    return;
}
int query(int node,int l,int r,int x,int carry)
{
    if(x<l||r<x)
        return 0;
    if(x==l&&r==x)
    {
        return s[node]+carry;
    }
    return query(node*2,l,(l+r)/2,x,carry+lz[node])+query(node*2+1,(l+r)/2+1,r,x,carry+lz[node]);
}

main()
{
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    for(auto &u:v)
    {
        cin>>u;
    }
    while(k--)
    {
        memset(s,0,sizeof s);
        memset(lz,0,sizeof lz);
        for(int i=0;i<n;i++)
        {
            update(1,0,n-1,max(0,i-v[i]),min(n-1,i+v[i]));
        }
        fill(v.begin(),v.end(),0);
        bool f=true;
        for(int i=0;i<n;i++)
        {
            v[i]=query(1,0,n-1,i,0);
            if(v[i]!=n)
                f=false;
        }
        if(f)
            break;
    }
    for(int u:v)
        cout<<u<<' ';
}



Measured memory_bytes: 11184
H,N = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
inf = 10**10
f = H+max(A)+1
dp = [[inf]*f for _ in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    dp[i][0] = 0
    for j in range(f):
        dp[i][j] = dp[i-1][j]
        if j-A[i-1]>=0:
            dp[i][j] = min(dp[i][j],dp[i][j-A[i-1]]+B[i-1])
print(min(dp[-1][H:]))

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

const double pi = 3.14159265359;

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

  double a,b,h,m;
  cin >> a >> b >> h >> m;

  double mAngle = 6 * m;
  double hAngle = 30 * h + 0.5 * m;

  double Angle = abs(mAngle - hAngle);
  if(Angle > 180) {
    Angle = 360 - Angle;
  }

  Angle = Angle * pi / 180.0;
  double ans = (a * a) +(b * b) - 2 * a * b * cos(Angle);
  ans = sqrt(ans);
  cout << fixed << setprecision(10) << ans << '\n';
}

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


using namespace std;

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

    int n;
    cin >> n;

    vector<int> sub(n+1, 0);

    for(int i=2; i<=n; i++)
    {
        int boss;
        cin >> boss;
        sub[boss]++;
    }

    for(int i=1; i<=n; i++)
        cout << sub[i] << '\n';

    return 0;
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

ll M = 10000007;

ll divi[10000007];

int main()
{
	ll i,j,k,l,m,n;

	for(i=1;i<(M);i++)
	{
		for(j=i;j<M;j+=i)
		{
			divi[j]++;
		}
	}

	cin >> n;

	k = 0;
	for(i=1;i<=n;i++)
	{
		k += (i*divi[i]);
	}

	cout << k << '\n';

	// cin >> n;


}

Measured memory_bytes: 81756
#include <iostream>

int main()
{
        int p_table[1000000];
        for(int i = 0; i < 1000000; ++i)
                p_table[i] = i;
        p_table[1] = 0;
        for(int i = 2; i < 1000; ++i)
                if(p_table[i] != 0)
                        for(int j = 2; j * i < 1000000; ++j)
                                p_table[i*j] = 0;

        int n, count;
        while(std::cin >> n)
        {
                count = 0;
                for(int i = 0; i <= n; ++i)
                        if(p_table[i] != 0)
                                ++count;
                std::cout << count << std::endl;
        }
        return 0;
}

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

int main(){
    int n;
    cin >> n;
    set<string> s;
    for(int i = 0; i < n; i++){
        string S;
        cin >> S;
        s.insert(S);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19160
#include <stdio.h>
int main(void){
	char a,b;
	scanf("%c %c",&a,&b);
	if(a=='H'){
		printf("%c",b);
	}else{
		if(b=='H'){
			printf("D");
		}else{
			printf("H");
		}
	}
	return 0;
}

Measured memory_bytes: 128
import Control.Applicative
import Data.List
import Data.Char

getInt :: IO Int
getInt = (\a -> read a :: Int) <$> getLine

getIntArray :: IO [Int]
getIntArray = ((map (\a -> read a :: Int)) . words) <$> getLine

getStrArray :: Int -> IO [String]
getStrArray 0 = return [] :: IO [String]
getStrArray n = (:) <$> getLine <*> (getStrArray (n - 1))

main = do
    a <- getInt
    b <- getInt
    c <- getInt
    d <- getInt
    print $ (min a b) + (min c d)


Measured memory_bytes: 508
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <list>
#include <math.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
void printArr(int *a, int len){for(int i=0; i<len; i++){if(i)cout << " ";cout << a[i];}cout << endl;}
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (1ll<<32);
static const int MAX = 100001;

int arr[MAX];

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int h, w, k;
    cin >> h >> w >> k;
    
    vector<vector<int> > vv(h, vector<int>(w));
    int t = 1;
    rep(i, h){
        rep(j, w){
            char c;
            cin >> c;
            if(c == '#'){
                vv[i][j] = t;
                t++;
            }
            else{
                vv[i][j] = 0;
            }
        }
    }
    
    
    
    rep(j, w){
        rep(i, h-1){
            if(vv[i][j] != 0 && vv[i+1][j] == 0){
                vv[i+1][j] = vv[i][j];
            }
        }
    }
    
    
    rep(i, h){
        rep(j, w){
            if(vv[i][j] == 0){
                if(i-1 >=0){
                    vv[i][j] = vv[i-1][j];
                }
            }
        }
    }
    
    for(int i=h-1; i>=0; i--){
        rep(j, w){
            if(vv[i][j] == 0){
                if(i+1 <h){
                    vv[i][j] = vv[i+1][j];
                }
            }
        }
    }
    
    rep(j, w){
        rep(i, h){
            if(vv[i][j] == 0){
                if(j-1 >=0){
                    vv[i][j] = vv[i][j-1];
                }
            }
        }
    }
    
    for(int j=w-1; j>=0; j--){
        rep(i, h){
            if(vv[i][j] == 0){
                if(j+1 <w){
                    vv[i][j] = vv[i][j+1];
                }
            }
        }
    }
    
    
    rep(i, h){
        rep(j, w){
            if(j)cout << " ";
            cout << vv[i][j];
        }
        cout << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll N, W;
    cin >> N >> W;
    vec w(N), v(N);
    loop(i, N) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
    loop(i, N)
    {
        loop(j, W + 1)
        {
            if (j >= w[i])
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            else
                dp[i + 1][j] = dp[i][j];
        }
    }
    putout(dp[N][W]);
    return 0;
}


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

int n, arr[303030];
ll leftsum[303030], rightsum[303030];
ll ans = LLONG_MIN;
priority_queue <int, vector<int>, greater<int>> pq;
priority_queue <int> pq2;
int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= 3 * n; i++)
        scanf("%d", &arr[i]);
    for (int i = 1; i <= n; i++)
    {
        leftsum[n] += arr[i];
        pq.push(arr[i]);
    }
    for (int i = n + 1; i <= 2 * n; i++)
    {
        int x = pq.top();
        if (arr[i] - x > 0)
        {
            leftsum[i] = leftsum[i - 1] + arr[i] - x;
            pq.pop();
            pq.push(arr[i]);
        }
        else
            leftsum[i] = leftsum[i - 1];
    }
    for (int i = 2*n+1; i <= 3*n; i++)
    {
        rightsum[2*n+1] += arr[i];
        pq2.push(arr[i]);
    }
    for (int i = 2 * n; i >= n + 1; i--)
    {
        int x = pq2.top();
        if (arr[i] - x < 0)
        {
            rightsum[i] = rightsum[i + 1] + arr[i] - x;
            pq2.pop();
            pq2.push(arr[i]);
        }
        else
            rightsum[i] = rightsum[i + 1];
    }
    for (int i = n; i <= 2 * n; i++)
        ans = max(ans, leftsum[i] - rightsum[i + 1]);
    printf("%lld", ans);
}

Measured memory_bytes: 5112
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var s = ReadLine();
            var apos = s.Select((c, i) => new { c, i }).First(ci => ci.c == 'A');
            var zpos = s.Select((c, i) => new { c, i }).Last(ci => ci.c == 'Z');
            WriteLine(zpos.i - apos.i + 1);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 15840
X, K, D = map(int, input().split())

if abs(X) - K * D < 0:
    d = abs(X) // D
    if (K - d) % 2 == 0:
        print(abs(abs(X) - d * D))
    else:
        print(abs(abs(X) - (d+1) * D))
else:
    print(abs(X) - K * D)


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

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		while (sc.hasNext()) {
			int N = sc.nextInt();
			int[] T = new int[N];
			for (int i = 0; i < N; ++i) {
				T[i] = sc.nextInt();
			}
			Arrays.sort(T);
			int cur = 0;
			int ans = 0;
			for (int i = 0; i < N; ++i) {
				cur += T[i];
				ans += cur;
			}
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
string s,t;
int s_len, t_len;
int dp[3001][3001];
int lcs(int i, int j){
    if(i>= s_len || j>=t_len ){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
if(s[i]==t[j]){
   return dp[i][j]=1+lcs(i+1, j+1);
}
     int op1=lcs(i+1,j);
     int op2=lcs(i,j+1);
return dp[i][j]=max(op1,op2);
}
string solve(){
    memset(dp,-1,sizeof dp);
    s_len= s.length();
    t_len= t.length();
    string ans;
   int len=lcs(0,0);
       
       // GET LCS
       int i=0, j=0;
       while(len>0){
           if(s[i]==t[j]){
               ans.push_back(s[i]);
               i++;
               j++;
               len--;
           }
           else{
             if(dp[i+1][j] > dp[i][j+1]){
             i++;}
             else{
             j++; 
             }  

           }
       }

return ans;
}

int32_t main() {
      cin>>s>>t;
     // cout<<s<<" "<<t;
    cout<<solve();
    return 0;
}


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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)          \
  sort(x.begin(), x.end()); \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << "(" << #x << ", " << #y << ") = " \
                          << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

// ----------------------------------------------

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

  int n, m, x;
  cin >> n >> m >> x;

  vector<int> v(m);
  rep(i, m) { cin >> v[i]; }

  int a, b;
  a = 0;
  b = 0;

  rep(i, m) {
    if (v[i] < x) {
      a++;
    } else if (v[i] > x) {
      b++;
    }
  }

  cout << min(a, b) << endl;

  return 0;
}

Measured memory_bytes: 256
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#define ll long long
#define str string
#define rtn return
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define db long double
#define MOD 1000000007
#define INF 1e18
#define EPS 1e-15
#define pll pair <ll, ll>
#define vi vector<ll>
#define vpll vector<pll>
#define value_at find_by_order
#define index_of order_of_key
#define fill(a,v) memset(a,v,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define loop1(i, n) for (int i=1;i<=n;++i)
#define loop(i, begin, end) for (__typeof(end) i = (begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif

template<class T> void remin(T &a, T b) {a = min(a, b);}
template<class T> void remax(T &a, T b) {a = max(a, b);}
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define N 100005

vi dp(N, INF);
ll n, W;
ll w[N], v[N];

int main() {
  FAST_IO;
  cin >> n >> W;
  rep(i, n) cin >> w[i] >> v[i];
  dp[0] = 0;
  rep(j, n) {
    for (int i = N-1; i >= v[j]; i--) {
      remin(dp[i], w[j] + dp[i - v[j]]);
    }
  }
  int ans = 0;
  rep(i, N) {
    if (dp[i] <= W) ans = i;
  }
  cout << ans;
  rtn 0;
}


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

using namespace std;

int main()
{
  int N, A, B; cin >> N >> A >> B;

  int ret = 0;
  for (int i = 1; i <= N; ++i) {
    int x = i, sum = 0;
    do {
      sum += x % 10;
    } while ((x /= 10) != 0);

    if (sum >= A and sum <= B) {
      ret += i;
    }
  }

  cout << ret;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	string ans = "Yes";
	if (N & 1)
		ans = "No";
	else {
		rep(i, N / 2) {
			if (S[i] != S[i + N / 2]) {
				ans = "No";
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double calcAngle(double h, double m)
{
    // validate the input
    if (h <0 || m < 0 || h >12 || m > 60)
        printf("Wrong input");

    if (h == 12) h = 0;
    if (m == 60) m = 0;

    // Calculate the angles moved
    // by hour and minute hands
    // with reference to 12:00
    double hour_angle = 0.5 * (h * 60 + m);
    double minute_angle = 6 * m;

    // Find the difference between two angles
    double angle = abs(hour_angle - minute_angle);

    // Return the smaller angle of two possible angles
    angle = min(360 - angle, angle);

    return angle;
}
int main()
{
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double pi=3.1415926535897932384;
    //float dm=6*m;
    //float dh=30*h;
    double diff=calcAngle(h,m);
    printf("%0.21f",sqrt(a*a+b*b-2*a*b*cos(diff*(pi/180))));
    return 0;
}


Measured memory_bytes: 4176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    ll a,b; cin>>a>>b;
    if(a>0){
        cout<<"Positive"<<endl;
    }else if(a==0){
        cout<<"Zero"<<endl;
    }else if(a<0){
        if(b>=0){
            cout<<"Zero"<<endl;
        }else{
            if((b-a)%2==1){
                cout<<"Positive"<<endl;
            }else{
                cout<<"Negative"<<endl;
            }
        }
    }
    
}


Measured memory_bytes: 3676
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int prime[10000010],pr=0;
bool vis[10000010];
int m,s[10000010],last=0,n=0;
int map[210][210],a[210],t1=0,b[210],t2=0,chw[210],match[210],tim=0;
bool findma(int x)
{
	for(int i=1;i<=t2;i++)
	{
		if(chw[i]==tim||!map[x][i]) continue;
		chw[i]=tim;
		if(!match[i]||findma(match[i])) return match[i]=x,true;
	}
	return false;
}
void pre()
{
	memset(vis,true,sizeof(vis));
	vis[1]=false;
	for(int i=2;i<=10000000;i++)
	{
		if(vis[i]) prime[++pr]=i;
		for(int j=1;j<=pr&&prime[j]*i<=10000000;j++)
		{
			vis[prime[j]*i]=false;
			if(i%prime[j]==0) break;
		}
	}
}
int main()
{
	pre();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int c;scanf("%d",&c);
		s[c]=1;
	}
	for(int i=1;i<=1e7+1;i++)
		if(s[i]!=s[i-1])
		{
			//printf("%d\n",i);
			if(i&1) a[++t1]=i;
			else b[++t2]=i;
		}
	for (int i=1;i<=t1;i++)
        for (int j=1;j<=t2;j++)
            if (vis[abs(a[i]-b[j])]) map[i][j]=1;
    int ans=0,tmp=0;
    //printf("ok\n");
    for(int i=1;i<=t1;i++)
    {
    	tim++;
    	if(findma(i)) ans++,tmp++;
	}
	//printf("%d %d %d\n",tmp,t1,t2);
	ans+=(t1-tmp)/2*2+(t2-tmp)/2*2;
    if (t1%2!=tmp%2) ans+=3;
    printf("%d",ans);
}

Measured memory_bytes: 51584
#include <iostream>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int i;
	string ope;
	char now;
	int ans = 0;

	cin >> ope;
	for (i = 0; i < 4; i++) {
		now = ope[i];
		if (now == '+') {
			ans++;
		} else if (now == '-') {
			ans--;
		}
	}

	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <unordered_set>
#include <cassert>
#include <array>
#include <random>
#include <iomanip>
#include <math.h>
#include <stack>
#include <bitset>

using namespace std;

typedef long long ll;

const int INF = 1000000010;
const ll INFLL = 1000000000000000010;
const int LOGN = 16;
const int N = 1000010;
const int K = 101;

mt19937 gen(29);

vector < int > a, b;
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifdef _DEBUG
	freopen("Test.txt", "r", stdin);
#endif
	int n;
	cin >> n;
	int num_a, num_b;
	vector < int > p(n);
	for (int i = 0; i < n; ++i)
		p[i] = i + 1;
	a.resize(n), b.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	int cnt = 0;
	while (true) {
		if (p == a) {
			num_a = cnt;
		}
		if (p == b) {
			num_b = cnt;
		}
		if (next_permutation(p.begin(), p.end())) {
			++cnt;
			continue;
		}
		else {
			break;
		}
	}
	cout << abs(num_a - num_b);
}

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

int n, m;
char arr[1010][1010];
int ans[1010][1010];
bool visited[1010][1010];
queue<pair<int, int>>bfs;

void solve(){
	while (!bfs.empty()){
		pair<int, int> tmp = bfs.front();
		bfs.pop();
		int temp1, temp2;

		temp1 = tmp.first+1;
		temp2 = tmp.second;
		if (temp1 >= 0 && temp2 >= 0 && temp1 < n && temp2 < m && !visited[temp1][temp2]){
			visited[temp1][temp2] = true;
			ans[temp1][temp2] = ans[tmp.first][tmp.second] + 1;
			bfs.push({temp1, temp2});
		}
		temp1 = tmp.first;
		temp2 = tmp.second+1;
		if (temp1 >= 0 && temp2 >= 0 && temp1 < n && temp2 < m && !visited[temp1][temp2]){
			visited[temp1][temp2] = true;
			ans[temp1][temp2] = ans[tmp.first][tmp.second] + 1;
			bfs.push({temp1, temp2});
		}
		temp1 = tmp.first-1;
		temp2 = tmp.second;
		if (temp1 >= 0 && temp2 >= 0 && temp1 < n && temp2 < m && !visited[temp1][temp2]){
			visited[temp1][temp2] = true;
			ans[temp1][temp2] = ans[tmp.first][tmp.second] + 1;
			bfs.push({temp1, temp2});
		}
		temp1 = tmp.first;
		temp2 = tmp.second-1;
		if (temp1 >= 0 && temp2 >= 0 && temp1 < n && temp2 < m && !visited[temp1][temp2]){
			visited[temp1][temp2] = true;
			ans[temp1][temp2] = ans[tmp.first][tmp.second] + 1;
			bfs.push({temp1, temp2});
		}
	}	
}

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

	cin >> n >> m;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> arr[i][j];
			if (arr[i][j] == '#'){
				bfs.push({i, j});
				visited[i][j] = true;
			}
		}
	}

	solve();

	int anss = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			anss = max(anss, ans[i][j]);
		}
	}

	cout << anss << endl;

	return 0;
}

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

using namespace std;

struct team {
  int id, cnt;
  int ac[10], wr[10];
  team() { cnt = 0; fill(ac, ac + 10, 0); fill(wr, wr + 10, 0); }
  friend int pena(team t) {
    int res = 0;
    for (int i = 0; i < 10; i++) {
      if (!t.ac[i]) continue;
      res += t.ac[i] + t.wr[i] * 1200;
    }
    return res;
  }
};

bool comp(const team &a, const team &b) {
  if (a.cnt != b.cnt) return a.cnt > b.cnt;
  int pa = pena(a), pb = pena(b);
  if (pa != pb) return pa < pb;
  return a.id < b.id;
}

int main(void) {
  int T, P, R;
  while (cin >> T >> P >> R, T) {
    vector<team> v(T);
    for (int i = 0; i < T; i++) {
      v[i].id = i + 1;
    }

    for (int i = 0; i < R; i++) {
      int t, p, tm;
      string ms;
      cin >> t >> p >> tm >> ms;

      if (ms == "CORRECT") {
        v[t - 1].cnt++;
        v[t - 1].ac[p - 1] = tm;
      } else {
        v[t - 1].wr[p - 1]++;
      }
    }
    sort(v.begin(), v.end(), comp);

    for (int i = 0; i < T; i++) {
      cout << v[i].id << " " << v[i].cnt << " " << pena(v[i]) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3116
#include<iostream>
using namespace std;
int main()
{
  long int a,i,n;
  cin>>n;
  long int max[n]={0};
  for(i=1;i<n;i++)
  {
	cin>>a;
	max[a-1]+=1;
  }
  for(i=0;i<n;i++)
	cout<<max[i]<<"\n";
  return 0;
}

Measured memory_bytes: 5156
#include <iostream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
pair<int, int> pop2(stack<int> &n)
{
    int first = n.top();
    n.pop();
    int second = n.top();
    n.pop();

    return make_pair(first, second);
}
bool is_operator(string s)
{
    if (s == "+" || s == "-" || s == "*")
    {
        return true;
    }
    return false;
}
int main()
{
    string s;
    stack<int> n;

    while (1)
    {
        cin >> s;
        if (cin.eof())
        {
            break;
        }

        if (is_operator(s))
        {
            auto operand = pop2(n);
            char beg = s.front();
            switch (beg)
            {
            case '+':
                n.push(operand.second + operand.first);
                break;
            case '-':
                n.push(operand.second - operand.first);
                break;
            case '*':
                n.push(operand.second * operand.first);
                break;
            }
        }
        else
        {
            n.push(stoi(s));
        }
    }
    cout << n.top() << endl;
}
//enterしてからcntr + Z


Measured memory_bytes: 3168
require 'prime'
n = gets.to_i
count = Prime.prime_division(n).count
a= Prime.prime_division(n)
#puts a[0][1]
def count_up(x)
  y=0
  c=1
  for i in 0..10000000000000000
    if (x-c)<0
      break
    end
    y+=1
    x=x-c
    c+=1

  end
  return y
end

#puts a
sum=0
count.times do |i|
  #puts Math.sqrt(a[i][1]+1).floor
  sum += count_up(a[i][1])
end
puts sum


Measured memory_bytes: 14428
from collections import defaultdict
N = int(input())
dic = defaultdict(list)

for i in range(1,N+1):
  inf = input().split()
  a = int(inf[0])
  b = int(inf[1])
  dic[b] += [a]

keys = list(dic.keys())
keys.sort()
ps = 0

for k in keys:
  ls = dic[k]
  need = sum(ls)
  ps += need
  if ps>k:
    print('No')
    break
else:
  print('Yes')


Measured memory_bytes: 51144
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	string in;
	cin >> in;
	int count = 0;
	int oversea = 0;
	for (int i = 0; i < n; ++i)
	{
		switch (in[i])
		{
		case 'c':
			cout << "No" << endl;
			break;
		case 'a':
			if (count < a + b)
			{
				cout << "Yes" << endl;
				count++;
			}
			else
				cout << "No" << endl;
			break;
		case 'b':
			if (count < a + b && oversea < b)
			{
				cout << "Yes" << endl;
				count++;
			}
			else
				cout << "No" << endl;
			oversea++;
			break;
		default:
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1)
            chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1] << endl;
}

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

int main() {

    std::cout<<std::fixed<<std::setprecision(10);

    int N;
    cin >> N;
    if(N%2==0)
    {
        cout << "0.5" << endl;
    }
    else
    {
        float numer = (N+1.0)/2.0;
        cout << numer/N << 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;
typedef long long ll;

/*
    // TIPS: lower_bound, upper_bound

    lower_bound
        探索したいkey以上のイテレータを返す
    upper_bound
        探索したいkeyより大きいイテレータを返す
*/

int main() {
    int n;
    cin >> n;
    vector<int> L(n);
    rep(i,n) cin >> L[i];
    sort(L.begin(), L.end());
    int ans = 0;
    rep(b, n)rep(a, b){
        int ab = L[a]+L[b];
        // TIPS: lower_bound 添字変換
        int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
        int l = b+1;
        // c = [l, r)
        ans += max(0, r-l);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

let nd=readInts()
let n=nd[0]
let d=nd[1]
var box:[[Int]]=[]

for i in 0..<n{
  let a=readInts()
  box.append([])
  for j in 0..<d{
    box[i].append(a[j])
  }
}

var ans=0

for i in 0..<n-1{
  for j in i+1..<n{
    var sum:Double=0
    for k in 0..<d{
      sum+=Double((box[j][k]-box[i][k])*(box[j][k]-box[i][k]))
    }
    if Double(sqrt(sum))-Double(Int(sqrt(sum)))==0.0 {ans+=1}
  }
}

print(ans)

Measured memory_bytes: 13656
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;
const ll INF=2e18;

ll A,B;
int main(){
    cin>>A>>B;
    ll now=1;
    for(ll i=0;;i++){
      if(now>=B){
        cout<<i;
        return 0;
      }
      now+=A-1;
    }
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
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" ) } ; }
#[allow(unused_macros)]
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 ) * } } ; }
#[allow(unused_macros)]
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 ) * } } ; }

fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
        d: i32,
    }
    let begin = a.max(c);
    let end = b.min(d);
    println!("{}", (end - begin).max(0));
}


Measured memory_bytes: 2160
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

int gcd(int a, int b) {
	return b != 0 ? gcd(b, a%b) : a;
}
lli gcd(lli a, lli b) {
	return b != 0 ? gcd(b, a%b) : a;
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
lli lcm(lli a, lli b) {
	return a * b / gcd(a, b);
}

#define N_MAX 200000
#define D_MAX 32
#define MOD 1000000007

void solv()
{
	int N; scanf("%d", &N);
	int a[N_MAX], b[N_MAX];
	for (int i = 0; i < N; i++) {
		scanf("%d", a + i);
	}
	for (int i = 0; i < N; i++) {
		scanf("%d", b + i);
	}

	int c[N_MAX], d[N_MAX];
	for (int i = 0; i < N; i++) {
		c[i] = a[i]^a[(i + 1) % N];
		d[i] = b[i]^b[(i + 1) % N];
	}

	int fail[N_MAX + 1];
	int j = fail[0] = -1;
	for (int i = 1; i <= N; ++i) {
		while (j >= 0 && d[j] != d[i - 1]) j = fail[j];
		fail[i] = ++j;
	}

	vector<int> dif;
	for (int i = 0, k = 0; i < N * 2 - 1; ++i) {
		while (k >= 0 && d[k] != c[i%N]) k = fail[k];
		if (++k >= N) {
			dif.push_back(i - N + 1);
			k = fail[k];
		}
	}

	for (int i = 0; i < dif.size(); i++) {
		printf("%d %d\n", dif[i], a[dif[i]] ^ b[0]);
	}

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}


Measured memory_bytes: 8308
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
#include<iomanip>
#include<functional>
#include<limits>
#include <unordered_map>
#include <numeric>
#include <array>
#include <queue>
#include <chrono>

using namespace std;
using  ull = unsigned long long int;

#define rep(i,n,m) for(long long int i=n;i<(long long int)(m);i++)
#define INF (1<<29)
#define MD 1000000007

int main() {

	int n, k;
	cin >> n >> k;


	int cnt = 1;

	rep(i, 0, n) {

		if (k < cnt * 2 - cnt)cnt += k;
		else cnt *= 2;
	}

	cout << cnt << endl;

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
    int A, B;
    scanf("%d%d", &A, &B);
    if(A>B && B!=1 || A!=B && A==1){
        printf("Alice");
    }
    else if(A==B) printf("Draw");
    else printf("Bob");
    return 0;
}


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

using namespace std;
using ll = long long;

const int N = 1e6 + 123;

signed main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr);
    ll n;
    cin >> n;
    ll h[N], dp[N];
    for (int i = 1; i <= n; i++) 
        cin >> h[i];
    dp[0] = dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for (int i = 3; i <= n; i++)
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
    cout << dp[n] << "\n";          
    return false;
}

Measured memory_bytes: 6656
from collections import Counter

n = int(input())
a = Counter([int(x) for x in input().split()])

tmp = 0
for x, y in sorted(list(a.items()), key=lambda x: x[0], reverse=True):
    if tmp != 0 and y >= 2:
        print(tmp * x)
        break
    if y >= 4:
        print(x**2)
        break
    if y >= 2:
        tmp = x
else:
    print(0)


Measured memory_bytes: 22428
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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







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

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    
    sort(a.begin(), a.end(), greater<ll>());
    ll g = a[0], idx = 0;
    REP(i, n){
        ll t = gcd(g, a[i]);
        if(g > t){
            g = t;
            idx = i;
        }
    }
    g = a[0];
    ll gg = a[1];
    REP(i, n){
        if(i > 0){
            gg = gcd(gg, a[i]);
        }
        if(i == idx) continue;
        g = min(g, gcd(g, a[i]));
    }
    cout << max(g, gg) << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	ll m; cin>>m;
	vector<vector<ll>> l(n);
	REP(i,m){
		ll a,b;
		cin>>a>>b;
		a--;b--;
		l[a].push_back(b);
		l[b].push_back(a);
	}
	deque<pair<ll,ll>> q;
	vector<ll> ans(n,-2);
	q.push_back(pair<ll,ll>(0,0));
	while(q.size()!=0){
		ll now=q.front().first;
		ll old=q.front().second;
		q.pop_front();

		ans[now]=old;
		
		//cout<<now<<":";
		//cout << "q: "; REP(i,(signed)q.size()) cout<<q[i].first<<" "; cout << endl; //----------cout----------//


		for(auto &i:l[now]){
			if(i==old)continue;
			if(ans[i]!=-2)continue;
			q.push_back(pair<ll,ll> (i,now));
			ans[i]=-1;
		}
	}
	cout<<"Yes"<<endl;
	FOR(i,1,n){
		cout<<ans[i]+1<<endl;
	}
	return 0;
}
/*
10 10
1 2
2 4
4 7
2 5
5 8
5 9
1 3
3 6
6 10
3 5
*/

Measured memory_bytes: 13540
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
        int ans=0;
        rep(i,n){
            int rize,syaro,tiya,tino;
            cin>>rize>>syaro>>tiya>>tino;
            tiya+=rize+syaro;
            if(tiya<=60&&tino<=2)
                ans+=600;
            else if(tiya<=80&&tino<=5)
                ans+=800;
            else if(tiya<=100&&tino<=10)
                ans+=1000;
            else if(tiya<=120&&tino<=15)
                ans+=1200;
            else if(tiya<=140&&tino<=20)
                ans+=1400;
            else if(tiya<=160&&tino<=25)
                ans+=1600;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 2996
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    long n = scan!long;
    long s = scan!long;

    long infty = n + 999;
    long ans = infty;
    for(long b = 2; b * b <= n; b ++) if(digsum(n, b) == s) ans.lowerTo(b), log("ans:", ans);

    long[] ds = (n - s).divisors;
    foreach(d; ds) if(digsum(n, d + 1) == s) ans.lowerTo(d + 1), log("ans:", ans);

    if(n == s) ans.lowerTo(n + 1);

    if(ans >= infty) "-1".writeln;
    else ans.writeln;
}

long digsum(long n, long b){
    long ans;
    log("n:", n, "b:", b);
    while(n > 0){
        ans += n % b;
        n /= b;
    }
    log("sum:", ans);
    return ans;
}

/// 約数の集合
/// 1とその数自身も含む、正の約数の集合。
/// 例 divisors(48) = [1, 2, 3, 4, 6, 8, 12, 16, 24, 48]
/// O(√N)
long[] divisors(long a){
	long[] res, res2;
	for(long d = 1; d * d <= a; d ++){
		if(a % d == 0) res ~= d, res2 ~=  a / d;
	}
	foreach_reverse(d; res2) if(res[$ - 1] < d) res ~= d;
	return res;
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
void solveA();
void solveB();
void solveC();
void solveD();
long long func(int,long long);
  
int main() {
  solveD();
}

void solveA(){
  int d;
  cin >> d ;
  string s = "Christmas";

  for(int i = 0; i<25-d; i++){
    s += " EVE";
  }
 
  cout << s <<  endl;
}

void solveB(){
  int n;
  cin >> n ;
  int a[n];

  for(int i = 0; i<n; i++){
    cin >> a[i];
  }
  sort(a,a+n);
  a[n-1] = a[n-1]/2;
    
    int ans = 0;
  for(int i = 0; i<n; i++){
    ans += a[i];
  }
 
  cout << ans <<  endl;
}

void solveC(){
  int n,k;
  cin >> n >> k;
  k--;
  int a[n];

  for(int i = 0; i<n; i++){
    cin >> a[i];
  }
  sort(a,a+n);
    
  int ans = INT_MAX;
  for(int i = 0; i<n-k; i++){
    int dif = a[i+k] - a[i];
    if (dif<ans) ans = dif;
  } 
  cout << ans <<  endl;
}

long long a[55],p[55];

void solveD(){
  int n;
  long long k;
  cin >> n >> k;
  a[0] = 1;
  p[0] = 1;
  
  for(int i = 1; i<=n; i++){
    a[i] = a[i-1]*2 + 3;
    p[i] = p[i-1]*2 + 1;
  }
  long long ans = func(n,k);
  cout << ans <<  endl;
}

long long func(int n, long long k){
  if (n==0) {
    if (k<=0) return 0;
    else return 1;
  }
  else if (k<=a[n-1] + 1) return func(n-1,k-1);
  else return 1 + p[n-1] + func (n-1,k-2-a[n-1]);
}


Measured memory_bytes: 256