akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

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;
}

int main()
{
	int N, K;
	cin >> N >> K;
	const ll INF = (int)1e10;
	vector<ll> h(N+K, 0);
	rep(i, N) cin >> h[i];

	vector<ll> dp(N+K, INF);

	dp[0] = 0;
	// ループ
	for (int i = 0; i < N; ++i) {
		for (int j = 1; j <= K; ++j) {
			int fp = i + j;
			chmin(dp[fp], dp[i] + abs(h[i] - h[fp]));
		}
	}

	cout << dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 4768
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10
    sa,sb = input().split()
    m = 10**18
    a = int(sa)
    b = int(float(sb)*m)
    print(a*b//m)

    
main()


Measured memory_bytes: 65424
#include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int n,x;
    cin >> n >> x;
    ll a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    ll cnt=0;
    if(a[0]>x) cnt+=a[0]-x,a[0]-=a[0]-x;
    for(int i=0; i<n-1; i++){
        if(a[i]+a[i+1]>x){
            cnt += a[i]+a[i+1]-x;
            a[i+1]-=a[i]+a[i+1]-x;
        }
    }
    cout << cnt << endl;;;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n,k;
    cin>>n>>k;
    int ans=1;
    rep(i,n){
        if(ans>k) ans+=k;
        else ans*=2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#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;
//using i128 = __int128_t;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
constexpr char ln = '\n';
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
inline int kthbit(long long x, int k) {return (x>>k)&1;}
inline void print() {cout << "\n";}
template<class T>
inline void print(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cout << *itr << " ";
    print();
}
template<class T, class... Args>
inline void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
inline void debug() {cerr << endl;}
template<class T>
inline void debug(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cerr << *itr << " ";
    debug();
}
template<class T, class... Args>
inline void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
#else
#define dump(x) void(0)
inline void debug() {}
template<class T> inline void debug(const vector<T> &v) {}
template<class T, class... Args> inline void debug(const T &x, const Args &... args) {}
#endif
struct Fast_ios {Fast_ios() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);};} fast_ios;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ll dp[1000100][2];

int main() {
    string S; cin >> S;
    int N = S.size();
    reverse(all(S));
    rep(i,N+1) rep(j,2) dp[i][j] = 1e18;
    dp[0][0] = 0;
    rep(i,N) {
        int n = S[i] - '0';
        rep(j,2) {
            rep(k,10) {
                if (k-n-j>=0) chmin(dp[i+1][0],dp[i][j]+k+k-n-j);
                else chmin(dp[i+1][1],dp[i][j]+k+k+10-n-j);
            }
        }
    }
    cout << min(dp[N][0],dp[N][1]+1) << ln;
}


Measured memory_bytes: 19768
#include <iostream>
#include<math.h>
using namespace std;

int main()
{
  int n ;
  cin>> n ;
  long long arr[n] ;
  long long  sum =1 ;
  for (int i=0 ;i<n ;i++)
  {
      cin>> arr[i] ;
      if (arr[i]==0)
      {
          cout << 0 ;
          return 0 ;
      }

  }
  long double log =0 ;
  for (int i=0 ;i<n ;i++)
  {
      log+=log10(arr[i]) ;
  }
  if (log>18.1)
  {


    cout << -1 ;
  return 0 ;
  }
  for (int i=0 ;i<n ;i++)
  {
      sum*=arr[i] ;
  }
  if (sum>1000000000000000000)
    cout << -1 ;
  else
    cout << sum ;
}


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

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = ReadSplit();
            var K = r[0].ToInt();
            var N = r[1].ToInt();
            var r2 = ReadSplit();
            var ar = new List<int>();
            for (int i = 0; i < N; i++)
            {
                ar.Add(r2[i].ToInt());
            }
            var max = (K - ar.Max()) + ar.Min();
            for (int i = 0; i < N; i++)
            {
                if (i + 1 >= N)
                {
                    break;
                }
                var a = ar[i + 1] - ar[i];
                if (max < a)
                {
                    max = a;
                }
            }
            Write(K - max);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
            Read();
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }
}



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

int main()
{
    int N;
    cin >> N;
    vector<ll> length(N);
    ll total = 0;
    for (int i = 0; i < N; i++)
    {
        ll a;
        cin >> a;
        length.at(i) = a;
        total += a;
    }
    ll answer = LLONG_MAX;
    ll leftLength = 0;
    ll rightLength = total;
    for (int i = 0; i < N; i++)
    {
        leftLength += length.at(i);
        rightLength -= length.at(i);
        answer = min(answer, abs(leftLength - rightLength));
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
    int N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
		vector<bool> c(N,false);

    ll ans = 0;
    rep(i, N) {
        if (i >= K && T[i] == T[i - K] && !c[i-K]) {
						c[i] = true;
            continue;
        } else if (T[i] == 'r') {
            ans += P;
        } else if (T[i] == 's') {
            ans += R;
        } else if (T[i] == 'p') {
            ans += S;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY (1<<21)

int n,G[100][100];//重みを記録した隣接行列

void dijkstra(){
  int i,minv,u,v;
  int color[100];//訪問状態
  int d[100];//重みが最小の辺の重みを記録
  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }
  
  d[0]=0;
  color[0]=GRAY;
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
     if(minv>d[i] && color[i]!=BLACK){
       u=i;
       minv=d[i];
     }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
     if(color[v]!=BLACK && G[u][v]!=INFTY){
       if(d[v]>d[u]+G[u][v]){
	 d[v]=d[u]+G[u][v];
	 color[v]=GRAY;
       }
     }
    }
  }
 for(i=0;i<n;i++){
   printf("%d %d\n",i,d[i]==INFTY?-1:d[i]);         
 }
}


int main(){
  int i,j,u,k,v,c;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=INFTY;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      G[u][v]=c;
    }
  }
  
  dijkstra();
  return 0;
}




Measured memory_bytes: 2112
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pii = pair<int, int>; // これ以降 pii という型名はpair<int, int> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
   ll r,d,x;
   cin>>r>>d>>x;
   for(int i=0;i<10;i++){
       x=r*x-d;
       cout<<x<<endl;
   }
}

Measured memory_bytes: 256
n, m, x, y= map(int, input().split())
arr_x= list(map(int, input().split()))
arr_y= list(map(int, input().split()))
arr_x.append(x)
arr_y.append(y)
max_x=max(arr_x)
min_y=min(arr_y)
if max_x<min_y:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3060
S = int(input())
if S<3:
    print(0)
    exit()

clear = 0
memory = dict()

def hoge(S):
    clear = 0
    i = 3
    while True:
        if (S-i)==0:
            clear+=1
            break
        elif S-i in memory:
            clear += memory[S-i]
        elif S-i>=3:
            memory[S-i] = hoge(S-i)
            clear += memory[S-i]
        i += 1
    return clear


print(hoge(S)%(10**9+7))


Measured memory_bytes: 9468
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define val first
#define idx second
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;

//Segment Tree
class SegmentTree{
  int n;
  vp node;
public:
  SegmentTree(int n_){
    n=1;
    while(n<n_)n*=2;
    node = vp(2*n, pii(0,0));
  }

  void update_range(int a,int b,pii v,int k=0,int l=0,int r=0){
    if(l>=r)r = n;
    if(r<=a || b<=l)return;
    if(a<=l && r<=b){
      if(node[k]<v)node[k] = v;
      return;
    }
    update_range(a,b,v,2*k+1,l,(l+r)/2);
    update_range(a,b,v,2*k+2,(l+r)/2,r);
  }

  pii is_val(int k){
    k += n-1;
    pii res = node[k];
    while(k>0){
      k = (k-1)/2;
      res = max(res,node[k]);
    }
    return res;
  }
};

void dfs(int v, int d, vi &level, vi &tour, vp &interval,
	 const vector<vi> &tree){
  interval[v].first = tour.size();
  tour.push_back(v);
  level[v] = d;

  for(int child : tree[v]){
    dfs(child, d+1, level, tour, interval, tree);
  }

  tour.push_back(v);
  interval[v].second = tour.size();
}

int main(){
  int n,q,v;
  char qtype;

  while(scanf("%d%d",&n,&q),n){
    vector<vi> tree(n,vi());

    rep(i,n-1){
      scanf("%d",&v); v--;
      tree[v].push_back(i+1);
    }

    vi level(n,0), tour;
    vp interval(n);
    dfs(0,0,level,tour,interval,tree);

    SegmentTree st(tour.size());
    st.update_range(0,2*n,pii(0,0));

    long long ans = 0;
    rep(i,q){
      cin >> qtype >> v; v--;
      if(qtype == 'M'){
	st.update_range(interval[v].first, interval[v].second, pii(level[v], v));
      }else{
	ans += st.is_val(interval[v].first).second + 1;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 21408
main = do
  n <- readLn
  inps <- mapM (const (fmap (map read . words) getLine)) [1..n]
  mapM_ (print . solve) inps


solve :: [Int] -> Int
solve [a,b] =
  (max 0 (2*(m-2))) - sa - sb + count m a b 0 + count m b a 1
  where
    m  = floor (sqrt (fromIntegral(a*b-1)))
    sa = if a < m-1 then 1 else 0
    sb = if b < m-1 then 1 else 0
    count x s t f
      | x <= 0    = 0
      | x < m-1   = 0
      | x == s    = count (x-1) s t 0
      | length[() |i<-[f..5], x*(m+i) < a*b, m+i/=t] >= 1 = 1 + count (x-1) s t 0
      | otherwise = count (x-1) s t 0

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

using namespace std;

typedef long long LL;

const int N = 100010;

int cnt[N];

int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++)
        cnt[s[i] - 'a']++;

    for(int i = 0; i < 26; i++)
        if(cnt[i] > 1)
        {
            puts("no");
            return 0;
        }

    puts("yes");

    return 0;
}


Measured memory_bytes: 384
S = input()
n = len(S)

# Sのi番目を最後尾として、j文字をとったときの最大のK
dp = [[0, 0, 0] for _ in range(n)]
dp[0][1] = 1
dp[0][2] = -(10**18)
dp[1][1] = 1

# i: 0-indexted
for i in range(1, n):
    # print(f"i: {i}")
    if S[i-1] == S[i]:
        dp[i][1] = dp[i-1][2]+1
    else:
        dp[i][1] = max(
            dp[i-1][1]+1,
            dp[i-1][2]+1
        )
    end = i+1
    if S[max(0, end-4):max(0, end-2)] == S[max(0, end-2):end]:
        dp[i][2] = dp[i-2][1]+1
    else:
        dp[i][2] = max(
            dp[i-2][1]+1,
            dp[i-2][2]+1
        )
    # for dp_i in dp:
    #     print(dp_i)

print(max(dp[n-1]))


Measured memory_bytes: 36404
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m,a,b,t;
    ll sum1=0,sum2=0,sumt=0;
    cin>>n>>m>>a>>b;
    t=a*b/__gcd(a,b);
    sum1=m/a-(n-1)/a;
    sum2=m/b-(n-1)/b;
    sumt=m/t-(n-1)/t;
    cout<<(m-n+1)-(sum1+sum2-sumt)<<endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readInteger()
    val aList = readIntegerList().sorted()
    val bList = readIntegerList().sorted()
    val cList = readIntegerList().sorted()

    var ans = 0L
    for (i in bList) {
        val aCount = lowerBound(aList, i)
        val cCount = cList.size - lowerBound(cList, i + 1)

        ans += aCount.toLong() * cCount
    }

    println(ans)
}

fun lowerBound(aList: List<Int>, i: Int): Int {
    var left = -1
    var right = aList.size
    while (right - left > 1) {
        var center = (right + left) / 2
        if (i <= aList[center])  {
            right = center
        } else {
            left = center
        }
    }

    return right
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 100108
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range(1,len(p)-1):
    s=[p[i-1],p[i],p[i+1]]
    s.remove(min(s))
    s.remove(max(s))
    if s[0]==p[i]:
        count+=1
print(count)

Measured memory_bytes: 3064
S = list(input())
T = list(input())
dp = [[float('inf')]*(len(T)+1) for _ in range(len(S)+1)]
dp[0][0] = 0

for i in range(len(S)):
  dp[i+1][0] = i+1
for j in range(len(T)):
  dp[0][j+1] = j+1
for i in range(len(S)):
  a = S[i]
  for j in range(len(T)):
    b = T[j]
    dp[i+1][j+1] = min(dp[i+1][j]+1, dp[i][j+1]+1, dp[i][j]+(a != b))

print(dp[len(S)][len(T)])


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

if((S.at(0)=='R')&&S.at(1)=='R'&&S.at(2)=='R')
{
    cout << 3<< endl;
    return 0;
}

if((S.at(0)=='R')&&S.at(2)=='R')
{
    cout << 1<< endl;
    return 0;
}

int count=0;
for(int i=0; i<3; i++)
{
    if(S.at(i)=='R')
    {
        count++;
    }
}
cout << count << endl;
}

Measured memory_bytes: 3624
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	s := sc.Text()
	sl := strings.Split(s, " ")
	k, _ := strconv.Atoi(sl[0])
	x, _ := strconv.Atoi(sl[1])

	min := x - k + 1
	if min < -1000000 {
		min = -1000000
	}
	max := x + k - 1
	if 1000000 < max {
		max = 1000000
	}

	for i := min; i <= max; i++ {
		fmt.Print(i, " ")
	}
}


Measured memory_bytes: 640
/*
Author: Babin Dutta
*/

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,n) for(int i=0;i<n;i++)
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define inf 1e18
#define mm 998244353
#define pp pair<int,int>
#define vector<int> vi
#define vector<int> vll
#define ft first
#define se second

ll power(ll x, ll y, ll p)
{
    ll res = 1;  
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }
    return res;
}
ll modInverse(ll A,ll M)
{
    return power(A,M-2,M);
}

void solve(){
	double a, b, c, d; cin>>a>>b>>c>>d;
	double h = 30 * c;
	double m = 6 * d;
	h += d/2;
	double ale = abs(h-m);
	ale = min(ale, 360-ale);
	double ans = a*a + b*b;
	double pi = 2 * acos(0.0);
	ans -= (2*a*b*cos((pi/180)*ale));
	ans = sqrt(ans);
	cout << fixed << setprecision(20) << ans << endl;
}

int main(){
	#ifdef JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
	boost;
	int t=1; //cin>>t;
	for(int i=1;i<=t;i++) solve();
	return 0;
}


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

int main() {
  int a, b, m;
  cin >> a >> b >> m;
  int mina=100000, minb=100000;
  vector<int> A(a), B(b);
  for (int i=0; i<a; i++) {
    int num; cin >> num;
    A[i]=num;
    mina=min(mina, num);
  }
  for (int i=0; i<b; i++) {
    int num; cin >> num;
    B[i]=num;
    minb=min(minb, num);
  }
  long long ans=mina+minb;
  for (int i=0; i<m; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--; y--;
    long long sum=A[x]+B[y]-c;
    ans=min(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, c;
  cin >> a >> b >> c;
  set<int> st;
  st.insert(a);
  st.insert(b);
  st.insert(c);
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 3560
#!/usr/bin/env python3
X = input()
sub = 0
tmp = 0
s, t, = 0, 0
for c in X:
    if c == 'S':
        s += 1
    else:
        t += 1
        if s > 0:
            s -= 1
            t -= 1
print(s + t)


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

using namespace std;

int main()
{
    int a, b; //a:500,b:100,c:50

    cin >> a >> b;

    int max = -10000000;
    if (max < a + b)
        max = a + b;
    if (max < a - b)
        max = a - b;
    if (max < a * b)
        max = a * b;
    cout << max << endl;

    return 0;
}

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

typedef long long ll;

int cnt1[30], cnt2[30];

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt",  "w", stdout);
    #endif
    string s, t;

    cin>>s>>t;
    int n = s.size();

    for(int i = 0; i < n; i++){
        cnt1[s[i]-'a']++;
        cnt2[t[i]-'a']++;
    }    

    sort(cnt1, cnt1 + 26);
    sort(cnt2, cnt2 + 26);

    for(int i = 0; i < 26; i++){
        if(cnt1[i] != cnt2[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;

    return 0;
}

Measured memory_bytes: 916
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String rexp = "^A?KIHA?BA?RA?$";
    if (s.matches(rexp)) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define deb(x) cout<<#x<<" " <<x<<"\n";
#define pi 3.1415926535897932384626433832795
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define cr7 ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))
#define forr(i, n) for(ll i = 0;i < n; ++i)
#define trav(a,x) for(auto a=x.begin();a!=x.end();a++)
#define test ll testcase; cin>>testcase; while(testcase--)
#define time printf("\n\nTime taken: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC)
int main()
{
	//clock_t tStart = clock();
	cr7
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ll h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	ll hr = (h2 - h1) * 60;
	ll min = (m2 - m1);
	ll tt = hr + min;
	ll rem = tt - k;
	cout << rem << "\n";
	return 0;
}


Measured memory_bytes: 3632
import numpy as np

MOD=998244353
N=int(input())
A=np.array(sorted([int(input()) for _ in range(N)]))

TOTAL=pow(3,N,MOD)
ASum=np.sum(A)

# dp=[[0 for _ in range(ASum+1)] for _ in range(2)]
dp=np.zeros((2,ASum+1),dtype=np.int64)
dp[0][0] = 2
dp[0][A[0]] = 1

# dpOther=[[0 for _ in range(ASum+1)] for _ in range(2)]
dpOther=np.zeros((2,ASum+1),dtype=np.int64)
dpOther[0][0] = 1
dpOther[0][A[0]] = 1

prev=0
current=1
curMax=A[0]
# for n in range(1,N):
for n, a in enumerate(A):
	if n==0:
		continue
	# curMax += a
	current = n % 2
	prev = (n+1) % 2
	# for e in range(curMax+1):
	dp[current,:] = dp[prev,:]*2 % MOD
	dp[current,a:] += dp[prev,:-a] % MOD

	if ASum %2 == 0:
		dpOther[current,:] = dpOther[prev,:] % MOD
		dpOther[current,a:] += dpOther[prev,:-a] % MOD

sumStart = 0
plus = 0

if ASum % 2 == 0:
	# 合計が偶数
	sumStart=ASum//2
	plus = (dpOther[current][ASum//2]*3) % MOD
else:
	# 合計が奇数の場合、ceil
	sumStart=ASum//2+1

exceptCnt=0
for s in range(sumStart,ASum+1):
	exceptCnt = (exceptCnt + dp[current][s]*3) % MOD

exceptCnt -= plus

print((TOTAL - exceptCnt) % MOD )



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

int main() {
    int n;
    cin>>n;
    int arr[n][3];
    for(int j=0;j<n;j++)
    {
        for(int i=0;i<3;i++)
        cin>>arr[j][i];
    }
    int dp[n][3];
    for(int j=0;j<n;j++)
    {
        for(int i=0;i<3;i++)
        {
            if(j==0)
            dp[j][i]=arr[j][i];
            else
            {
              if(i==0)
              dp[j][0]=arr[j][0]+max(dp[j-1][1],dp[j-1][2]);
              else if(i==1)
              dp[j][1]=arr[j][1]+max(dp[j-1][0],dp[j-1][2]);
              else dp[j][2]=arr[j][2]+max(dp[j-1][1],dp[j-1][0]);
            }
        }
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
	using namespace std;
	
	typedef long long ll;
	#define pi 3.14159265 
	#define EPS 1e-8
	
	#define mod 1000000007
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
	#define endl "\n"

	const ll INF=(ll)3e17;
	
	ll memo[2005][2005];
	vector<pair<ll,ll> > v;
	ll dp(ll idx,ll l,ll r)
	{
		if(l>r)
			return 0;
		if(memo[l][r]!=-1)
			return memo[l][r];
			
		ll ans=max(dp(idx+1,l+1,r)+ v[idx].fi*(abs(l-v[idx].se)),dp(idx+1,l,r-1)+v[idx].fi*(abs(r-v[idx].se)));
		return memo[l][r]=ans;
	}
	
	
	int main()
	{
		 ios_base::sync_with_stdio(false);
		 cin.tie(NULL);
		 
		ll n;
		cin>>n;
		
		v=vector<pair<ll,ll> >(n);
		for(ll i=0;i<n;i++)
		{
			cin>>v[i].fi;
			v[i].se=i;
		}
		sort(v.begin(),v.end());
		reverse(v.begin(),v.end());
		memset(memo,-1,sizeof(memo));
		cout<<dp(0,0,n-1);
	}


Measured memory_bytes: 35152
//code written by a living bruh moment
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Random;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        int m = in.nextInt();
        int x = in.nextInt()+1;
        int y = in.nextInt();
        int[] xa = new int[n];
        int[] ya = new int[m];
        for(int i = 0; i<n; i++){
            xa[i] = in.nextInt();
        }
        for(int i = 0; i<m; i++){
            ya[i] = in.nextInt();
        }
        Arrays.sort(xa);
        boolean check = true;
        Arrays.sort(ya);
        if(xa[n-1]<ya[0]){
            while(x<=y){
                if(xa[n-1] < x && x <= ya[0]){
                    out.println("No War");
                    check = false;
                    break;
                }
                ++x;
            }
            if(check){
                out.println("War");
            }
        }
        else{
            out.println("War");
        }
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong()
        {
            return Long.parseLong(next());
        }
        public double nextDouble()
        {
            return Double.parseDouble(next());
        }
        public String nextLine()
        {
            try
            {
                return reader.readLine();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return null;
        }
        public boolean hasNext()
        {
            String next=null;
            try
            {
                next=reader.readLine();
            }
            catch(Exception e)
            {
            }
            if(next==null)
            {
                return false;
            }
            tokenizer=new StringTokenizer(next);
            return true;
        }
    }
}

Measured memory_bytes: 33116
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int a,b,c;
  int ans=0;
  cin >> a >> b >> c;
  vector<int> d(3);
  d[0]=a;
  d[1]=b;
  d[2]=c;
  sort(d.begin(),d.end());
  ans=d[0]+d[1];
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

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

bool isLower(char c){
    if(c - 'a' < 26){
        return true;
    }else{
        return false;
    }
}

int main() {
    string S;
    cin >> S;
    ll size = S.size();

    if(S[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }
    ll count = 0;
    for(ll i=2;i<size-1;i++){
        if(S[i] == 'C'){
            count++;
        }
    }
    if(count != 1){
        cout << "WA" << endl;
        return 0;
    }

    count=0;
    rep(i,size){
        if('A'<=S[i] && S[i]<='Z'){
            count++;
        }
    }
    if(count == 2){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
    }



}



Measured memory_bytes: 3624
//#define DEB1 //input from input.txt
//#define NDEBUG
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>
#include <cassert>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
// closed interval, inverse repeat
#define CIREP(i,start,fin) for(int i=(start);i>=(fin);i--)
#define CREP(i,start,fin) for(int i=(start);i<=(fin);i++)
#define RNG(i,start,fin) for(int i=(start);i<(fin);i++)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back
#define SZ(x) (int)(x).size()

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;
const LL LINF = 1001002003004005006ll;
/* 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,SZ(v))i>>v[j];return i;}

template<typename T>string join(const vector<T>&v)
{stringstream s;REP(i,SZ(v))s<<' '<<v[i];return s.str().substr(1);}

template<typename T>inline ostream& operator<<(ostream&o,const vector<T>&v)
{if(SZ(v))o<<join(v);return o;}
*/

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;
}




/*
constant values
*/

//const int dx[] = {1,0,-1,0};
//const int dy[] = {0,1,0,-1};
//const int MX = 31001;

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9


// Main program
void solve(){
    string S;
    cin >> S;
    cerr << S << endl;
    if(S=="SUN") cout << 7 << endl;
    if(S=="SAT") cout << 1 << endl;
    if(S=="FRI") cout << 2 << endl;
    if(S=="THU") cout << 3 << endl;
    if(S=="WED") cout << 4 << endl;
    if(S=="TUE") cout << 5 << endl;
    if(S=="MON") cout << 6 << endl;
    

    return;
}



// ----------------------------------------------
int main(){

#ifdef DEB1
    cout << "DEBUG MODE"  << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf()); //for debug
#endif

    int T=1; 

    for (int i = 0; i < T; ++i) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e18;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);

  loop(i, 1, n + 1) cin >> a[i];
  rep(i, n) a[i + 1] += a[i];
  vector<int> b;

  loop(i, 1, n + 1) loop(j, i, n + 1) b.push_back(a[j] - a[i - 1]);

  int ans = 0;
  for (int t = 40; t >= 0; t--) {
    int cnt = 0;
    for (auto x : b) {
      if (((ans | (1LL << t)) & x) == (ans | (1LL << t))) cnt++;
      if (k <= cnt) ans |= (1LL << t);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6388
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    long long A;
    long long B;
    cin >> A >> B;
    
    /*
    long long ans = A;
    for (int i = 0; i < B-A; i++) {
        ans = ans^(A+i+1);
    }
    cout << ans;
    */
    long long x;
    long long y;
    long long ans = 0;
    //f(0,B) = f(0,A-1)^f(A,B)
    //   x   =    y  ^  z
    //y^x = z
    if(A != 0) {
        if ((A-1)%4 == 0) {
            y = A-1;
        }else if ((A-1)%4 == 1 || (A-1) == 0) {
            y = 1;
        } else if ((A-1)%4 == 2){
            y = A;
        } else {
            y = 0;
        }
    }else{
        y = 0;
    }
    
    if(B != 0) {
        if (B%4 == 0) {
            x = B;
        }else if (B%4 == 1 || B == 0) {
            x = 1;
        } else if (B%4 == 2){
            x = B+1;
        } else {
            x = 0;
        }
    }else{
        x = 0;
    }
    
    ans = x ^ y;
    
    cout << ans << endl;
    
    return 0;
}

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

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

    int dx, dy;
    dx = x2 - x1;
    dy = y2 - y1;

    int x3, x4, y3, y4;

    x3 = x2 - dy;
    y3 = y2 + dx;
    x4 = x1 - dy;
    y4 = y1 + dx;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

bool C(long long A, long long B, long long x){
    long long mx = 0;
    long long mid = x / 2;
    for(long long y=mid-100; y<=mid+100; y++){
        if(y<1 || y>x) continue;
        long long a = y;
        long long b = x-y+1;
        if(a >= A) a++;
        if(b >= B) b++;
        mx = max(mx, a*b);
    }
    return mx < A*B;
}

long long solve(long long A, long long B){
    long long ub = A + B;
    long long lb = 0;
    while(ub - lb > 1){
        long long mid = (ub-lb)/2+lb;
        if(C(A, B, mid)) lb = mid;
        else ub = mid;
    }
    return lb;
}

int main(){
    int Q;
    cin >> Q;
    for(int i=0; i<Q; i++){
        long long A, B;
        cin >> A >> B;
        cout << solve(A, B) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{
    public void slove()
    {
        var inputs = Console.ReadLine().Split();
        int n = int.Parse(inputs[0]);
        int m = int.Parse(inputs[1]);
        var nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] match = new int[] { 0,2,5,5,4,5,6,3,7,6}.Select((x, i) => nums.Contains(i) ? x : int.MaxValue).ToArray();
        BigInteger[] dp = new BigInteger[n + 1];
        foreach(var item in match.Select((x, i) => new {i, x}).Reverse())
        {
            foreach(int i in Enumerable.Range(0, Math.Max(0, n + 1 - item.x)))
            {
                if(i != 0 && dp[i] == 0)
                    continue;
                var temp = dp[i] * 10 + item.i;
                if(dp[i + item.x] < temp)
                    dp[i + item.x] = temp;
            }
        }
        System.Console.WriteLine(dp[n]);
    }
    
    static void Main(string[] args)
    {
        new Program().slove();
    }
}


Measured memory_bytes: 36076
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
int main(){
    int n;
    cin >>n;
    int h[100000+7];
    int dp[100000+7];
    for(int i=0;i<n+1;i++){
        dp[i]=1000000000;
    }
    dp[0]=0;
 
    for(int i=0;i<n;i++){
        cin >>h[i];
    
    }
    dp[1]=dp[0]+abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

int main(){
    int k;
    long answer;
    queue<long> lunlun;
    cin >> k;
    rep2(i, 1, 10){
        lunlun.push(i);
    }
    rep(i, k){
        answer = lunlun.front();
        lunlun.pop();
        if(answer%10==0){
            lunlun.push(answer*10);
            lunlun.push(answer*10+1);
        }else{
            if(answer%10==9){
                lunlun.push(answer*10+8);
                lunlun.push(answer*10+9);
            }else{
                lunlun.push(answer*10 + answer%10 - 1);
                lunlun.push(answer*10 + answer%10);
                lunlun.push(answer*10 + answer%10 + 1);
            }
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <atcoder/segtree>
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using namespace atcoder;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int
int ma(int l, int r) { return max(l, r); }
int uni() { return 0; }
void solve(long long N, long long K, std::vector<long long> A) {
  segtree<int, ma, uni> seg(3e5 + 20);
  rep(i, N) {
    int ans = 0;
    int l = A[i] - K, r = A[i] + K + 1;
    if (l < 0)
      l = 0;
    if (r > 3e5 + 10)
      r = 3e5 + 10;
    chmax(ans, seg.prod(l, r));

    seg.set(A[i], ans + 1);
  }
  cout << seg.all_prod() << endl;
}

signed main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 16220
N, M = [int(i) for i in input().strip().split()]
H = {str(i+1): int(j) for i, j in enumerate(input().strip().split())}
out = {str(i+1): 0 for i in range(N)}
for _ in range(M):
  h = input().strip().split()
  out[h[0]] += 1
  out[h[1]] += 1
  
  if H[h[0]] > H[h[1]] and out[h[0]]==1:
    out[h[0]] = 0
  if H[h[0]] < H[h[1]] and out[h[1]]==1:
    out[h[1]] = 0
print(len([k for k, v in out.items() if v==0]))

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> x(n);
	for (int i = 0; i < n; i++)
		cin >> x[i];
	int min_d =10e9, d;
	for (int i = 0; i < n - k + 1; i++) {
		if (x[i] <= 0 && x[k - 1 + i] <= 0)
			d = -x[i];
		else if (x[i] >= 0 && x[k - 1 + i] >= 0)
			d = x[k - 1 + i];
		else
			d = min(abs(x[i]), x[k - 1 + i]) * 2 + max(abs(x[i]), x[k - 1 + i]);
		if (min_d > d)
			min_d = d;
	}
	cout << min_d << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

const string yey = "Yay!";
const string sad = ":(";

struct perm {
private:
	int sz;
	vector<ll> p, invp;
public:
	perm(int n) {
		sz = n + 1;
		p.resize(sz), invp.resize(sz);
		p[0] = 1;
		rep1(i, sz - 1) {
			p[i] = p[i - 1] * i%mod;
		}
		invp[sz - 1] = 1;
		ll cop = mod - 2, x = p[sz - 1];
		while (cop) {
			if (cop % 2)invp[sz - 1] = invp[sz - 1] * x%mod;
			cop >>= 1; x = x * x % mod;
		}
		per(i, sz - 1) {
			invp[i] = invp[i + 1] * (i + 1) % mod;
		}
	}
	ll comb(ll x, ll y) {
		if (x < y || y < 0)return 0;
		ll ret = p[x];
		(ret *= invp[y]) %= mod;
		(ret *= invp[x - y]) %= mod;
		return ret;
	}
	ll combP(ll x, ll y) {
		if (x < y || y < 0)return 0;
		return p[x] * invp[x - y] % mod;
	}
	ll query(int n) {
		ll ret = 0;
		rep1(i, n) {
			ret += p[i];
			if (ret >= mod)ret -= mod;
		}
		return ret;
	}
	ll call(int n) {
		return p[n];
	}
};
perm p(1 << 21);
ll mod_pow(ll x, ll n=mod-2) {
	ll ret = 1;
	while (n) {
		if (n % 2)ret = ret * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return ret;
}

struct BIT {
private:
	vector<ll> node; int n;
public:
	BIT(int n_) {
		n = n_; node.resize(n, 0);
	}
	//0-indexed
	void add(int a, ll w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	//[0,a)
	ll sum(int a) {
		ll ret = 0;
		for (int i = a - 1; i >= 0; i = (i&(i + 1)) - 1)ret += node[i];
		return ret%mod;
	}
	//[a,b)
	ll sum(int a, int b) {
		return sum(b) - sum(a);
	}
};

void solve() {
	int n, h, d; cin >> n >> h >> d;
	ll s = p.query(n);
	BIT b(h + 1);
	ll sta = p.call(n) % mod;
	b.add(0, sta);
	ll ans = 0;
	rep1(i, h) {
		ll z = b.sum(max(i - d,0), i);
		z = (z%mod + mod) % mod;
		//cout << i << " " << z << endl;
		b.add(i, z*s%mod);
		if (i == h)ans = z;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(9);
	//init();
	//while (cin >> n>>m>>l,n)solve();
	solve();
	//stop
	return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vector<int> arr(n), arr2(n);
  for (int i = 0; i < n; i++) {
    if (i % 2 == 1) {
      arr[i] = a[n - (i / 2) - 1];
    } else {
      arr[i] = a[i / 2];
    }
  }
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      arr2[i] = a[n - (i / 2) - 1];
    } else {
      arr2[i] = a[i / 2];
    }
  }
  ll ans = 0, ans2 = 0;
  for (int i = 1; i < n - 1; i++) {
    ans += abs(arr[i - 1] - arr[i]);
  }
  if (abs(arr[0] - arr[n - 1]) > abs(arr[n - 2] - arr[n - 1])) {
    ans += abs(arr[0] - arr[n - 1]);
  } else {
    ans += abs(arr[n - 2] - arr[n - 1]);
  }
  for (int i = 1; i < n - 1; i++) {
    ans2 += abs(arr2[i - 1] - arr2[i]);
  }
  if (abs(arr2[0] - arr2[n - 1]) > abs(arr2[n - 2] - arr2[n - 1])) {
    ans2 += abs(arr2[0] - arr2[n - 1]);
  } else {
    ans2 += abs(arr2[n - 2] - arr2[n - 1]);
  }
  cout << max(ans, ans2) << endl;
  return 0;
}

Measured memory_bytes: 1792
import bisect
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
sa = set(A)
sb = set(B)
MOD = 10**9+7

if len(sa) != N or len(sb) != M:
    print(0)
    exit()

ans = 1
for n in range(N*M, 0, -1):
    if n in sa and n in sb: continue
    if n in sa:
        vacant = M - bisect.bisect(B,n)
    elif n in sb:
        vacant = N - bisect.bisect(A,n)
    else:
        i = N - bisect.bisect(A,n)
        j = M - bisect.bisect(B,n)
        vacant = i*j - (N*M-n)
        if vacant <= 0:
            print(0)
            exit()
    ans *= vacant
    ans %= MOD

print(ans)

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

int main(void){
    char str[1001],c[8],p[1002];
    int i,j,q,a,b;

    scanf("%s",str);
    scanf("%d",&q);
    
    for(i=0;i<q;i++){
        scanf("%s",c);
        if(!strcmp(c,"print")){
            scanf("%d %d",&a,&b);
            for(j=a;j<=b;j++) putchar(str[j]);
            putchar('\n');
        }
        else if(!strcmp(c,"reverse")){
            scanf("%d %d",&a,&b);
            for(j=0;j<=(b-a)/2;j++){
                char tmp=str[a+j];
                str[a+j]=str[b-j];
                str[b-j]=tmp;
            }
        }
        else{
            scanf("%d %d %s",&a,&b,p);
            for(j=a;j<=b;j++) str[j]=p[j-a];
        }
        getchar();
    }

    return 0;
}

Measured memory_bytes: 572
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
         
        int S = stdIn.nextInt();
         
        int h = S / 3600;
        S = S - h*3600;
         
        int m = S / 60;
        S = S - m*60;
         
        System.out.println(h+ ":" + m + ":" + S);
    }
}




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

string s;

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

    string s;
    cin >> s;

    int iwa = 0;
    for(int i = a;i <= c;i++){
        if(s[i] == '#'){
            iwa++;
            if(iwa == 2){
                cout << "No" << endl;
                return 0;
            }
        }else{
            iwa = 0;
        }
    }

    iwa == 0;
    for(int i = b;i <= d;i++){
        if(s[i] == '#'){
            iwa++;
            if(iwa == 2){
                cout << "No" << endl;
                return 0;
            }
        }else{
            iwa = 0;
        }
    }

    if(c < d){
        cout << "Yes" << endl;
        return 0;
    }

    for(int i = b;i <= d;i++){
        if(s[i] != '#'){
            if(s[i-1] == '.' && s[i+1] == '.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

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



Measured memory_bytes: 640