akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 100007

class SegmentTree {
  const static ll inf = (1LL << 31) - 1;
  int n, n0;
  ll data[4*N];

public:
  SegmentTree(int n) {
    n0 = 1;
    while(n0 < n) n0 <<= 1;
    rep(i, 2*n0) data[i] = inf;
  }

  void update(int k, ll x) {
    k += n0-1;
    data[k] = x;
    while(k > 0) {
      k = (k - 1) / 2;
      data[k] = min(data[2*k+1], data[2*k+2]);
    }
  }

  ll query(int l, int r) {
    int l0 = l + n0, r0 = r + n0;
    ll s = inf;
    while(l0 < r0) {
      if(r0 & 1) {
        --r0;
        s = min(s, data[r0-1]);
      }
      if(l0 & 1) {
        s = min(s, data[l0-1]);
        ++l0;
      }
      l0 >>= 1; r0 >>= 1;
    }
    return s;
  }
};

int n, q;

int main() {
  cin >> n >> q;
  SegmentTree st(n);
  rep(i, q) {
    int t, x, y; cin >> t >> x >> y;
    switch(t) {
      case 0:
        st.update(x, y);
        break;
      case 1:
        cout << st.query(x, y+1) << endl;
        break;
    }
  }
  return 0;
}


Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<vector<int>> g(n, vector<int>());
    rep(i, n - 1)
    {
        g[i].emplace_back(i + 1);
        g[i + 1].emplace_back(i);
    }
    g[x].emplace_back(y);
    g[y].emplace_back(x);

    vector<vector<int>> ds(n, vector<int>(n, -1));
    rep(i, n)
    {
        queue<int> q;
        q.push(i);
        ds[i][i] = 0;
        while (q.size())
        {
            int v = q.front();
            q.pop();
            for (int nv : g[v])
            {
                if (ds[i][nv] >= 0)
                    continue;
                ds[i][nv] = ds[i][v] + 1;
                q.push(nv);
            }
        }
    }

    vector<int> d(n);
    rep(i, n) rep(j, n)
    {
        d[ds[i][j]] += 1;
    }

    for (int i = 1; i < n; ++i)
    {
        cout << d[i] / 2 << endl;
    }

    return 0;
}

Measured memory_bytes: 16128
#include<stdio.h>

int N;
int ans=0;

int dfs(long a,int b,int c,int d){
  if(a > N)
    return ans;
  if((b+c+d)==3)
    ans++;
  
  dfs(a*10+3,1,c,d);
  dfs(a*10+5,b,1,d);
  dfs(a*10+7,b,c,1);
}

int main(){
  scanf("%d",&N);
  
  printf("%d\n",dfs(0,0,0,0));
  return 0;
}
    



Measured memory_bytes: 128
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int max_n;
    max_n = 2*a-1;
    if (a+b>2*a-1)
        max_n = a+b;

    if (2*b-1>max_n)
        max_n = 2*b-1;
    cout<<max_n;
    //system("pause");


}


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

using namespace std;

int main()
{
    string s;
    cin >> s;
    for(char i = 'a'; i <= 'z'; ++i) {
        if(s.find(i) == string::npos) {
            printf("%c\n", i);
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <string.h>
#include <stdio.h>
int main(void){
    char a[201];
    char b[201];
    int shuffle,h,i;
    
    while(1){
        scanf("%s",a);
        if(strcmp(a,"-")==0) break;
        
        strcpy(b,a);
        
        scanf("%d",&shuffle);
        
        for(i=0; i<shuffle; i++){
            scanf("%d",&h);
            strcpy(a,&b[h]);
            strncpy(&a[strlen(a)],b,h);
            strcpy(b,a);
        }
        
        printf("%s\n",a);
    }
    return 0;
}

Measured memory_bytes: 596
#include <set>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> //fixed << setprecision(10)

using namespace std;

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

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

int main(){
	int n;
    cin >> n;
    vi a(n);
    rep(i, n){
        cin >> a[i];
    }

    set<int> s;
    rep(i, n){
        s.insert(a[i]);
    }
    
    if(s.size() == n){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 10496
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

template <unsigned long long mod > class modint{
public:
    ll x;
    constexpr modint(){x = 0;}
    constexpr modint(ll _x) : x((_x < 0 ? ((_x += (LLONG_MAX / mod) * mod) < 0 ? _x + (LLONG_MAX / mod) * mod : _x) : _x)%mod){}
    constexpr modint set_raw(ll _x){
        //_x in [0, mod)
        x = _x;
        return *this;
    }
    constexpr modint operator-(){
        return x == 0 ? 0 : mod - x;
    }
    constexpr modint& operator+=(const modint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr modint operator+(const modint& a) const{
        return modint(*this) += a;
    }
    constexpr modint& operator-=(const modint& a){
        if((x -= a.x) < 0) x += mod;
        return *this;
    }
    constexpr modint operator-(const modint& a) const{
        return modint(*this) -= a;
    }
    constexpr modint& operator*=(const modint& a){
        (x *= a.x)%=mod;
        return *this;
    }
    constexpr modint operator*(const modint& a) const{
        return modint(*this) *= a;
    }
    constexpr modint pow(unsigned long long pw) const{
        modint res(1), comp(*this);
        while(pw){
            if(pw&1) res *= comp;
            comp *= comp;
            pw >>= 1;
        }
        return res;
    }
    //以下、modが素数のときのみ
    constexpr modint inv() const{
        if(x == 2) return (mod + 1) >> 1;
        return modint(*this).pow(mod - 2);
    }
    constexpr modint& operator/=(const modint &a){
        (x *= a.inv().x)%=mod;
        return *this;
    }
    constexpr modint operator/(const modint &a) const{
        return modint(*this) /= a;
    }
};
#define mod2 1000000007
using mint = modint<mod2>;

ostream& operator<<(ostream& os, const mint& a){
    os << a.x;
    return os;
}
using vm = vector<mint>;

int X, Y, Z;
bool ng(int j){
    return (j>>(Z-1))&1 && (j>>(Y+Z-1))&1 && (j>>(X+Y+Z-1))&1;
}

int main() {
    cin>>N>>X>>Y>>Z;
    vector<vm> dp(N + 1, vm(1<<16, 0));
    dp[0][0] = 1;
    rep(i, N){
        rep(j, 1<<16){
            rep(k, 10){
                int nxt = (j<<(k + 1)) + (1 << k);
                if(!ng(nxt)) dp[i+1][nxt & ((1<<16) - 1)] += dp[i][j];
            }
        }
    }
    cout<<mint(10).pow(N) - accumulate(ALL(dp[N]), mint(0))<<endl;
}


Measured memory_bytes: 24904
# D - String Formation
from collections import deque 
S = deque(input())
Q = int(input())
Query = [list(input().split()) for _ in range(Q)]

# 文字列の向き (0: 正, 1: 逆)
rev = 0
for Q in Query:
    if Q[0] == '1':
        if rev == 0:
            rev = 1
        else:
            rev = 0
        continue
    if Q[1] == '1':
        if rev == 0:
            S.appendleft(Q[2])
        else:
            S.append(Q[2])
    else:
        if rev == 0:
            S.append(Q[2])
        else:
            S.appendleft(Q[2])

if rev == 1:
    ans = list(reversed(list(S)))
else:
    ans = list(S)
print(''.join(ans))

Measured memory_bytes: 35932
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  ll A, B;
  cin >> A >> B;
  cout << A * B / gcd(A, B) << endl;
}

Measured memory_bytes: 256
'''     ##     ##  #######  # #  ######
        ##     ##  ##   ##  ###    ##
        ##     ##  ##    #  # #    ##
        #########  #######  # #    ##    '''

import sys
import math
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())

def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end=" \ ")

MODPRIME = int(1e9+7); BABYMODPR = 998244353;

ONLINE_JUDGE = 1
if not ONLINE_JUDGE:
    sys.stdin = open("input.txt","r")  # <<<  Comment this line  >>> #
    sys.stdout = open("output.txt","w")  # <<<  Comment this line  >>> #
    sys.stderr = open("output.txt","w")  # <<<  Comment this line  >>> #

x, n = get_ints()
li = get_list()
li = set(li)
i = 0
ans = -1
while True:
    if x-i not in li:
        ans = x-i
        break
    elif x+i not in li:
        ans = x+i
        break
    i += 1
print(ans)
# for _testcases_ in range(int(input())):

'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS BY ME @luctivud ( UDIT GUPTA )
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
DO NOT PLAGIARISE.
TESTCASES:
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Measured memory_bytes: 62248
#include<stdio.h>

int main()
{
	int n,vote[100]={0},C,open,mem_count;
	int max[2],flag;
	char A[101],mem[101],max_mem[3];
	
	while (1)
	{
		max[0] = max[1] = 0;
		mem_count = 0;
		scanf("%d", &n);
		if (n == 0) break;

		for (int i = 0; i < n;)
		{
			C = getchar();
			if (C < 'A' || 'Z' < C) continue;
			A[i] = C;
			i++;
		}
		A[n] = '\0';
		//過半数を境に判断する
		// 1 過半数超えたら　超えたもの　mem　と　その時の開票数　open+1
		// 2 開票途中で最大の獲得票数　max[0] が
		// 次に多い獲得票数 max[1]　と　残りの票数　n-(open+1) より大きいとき
		for (open = 0; open < n; open++)
		{
			//順番に数えて格納カウント
			if (mem_count)
			{
				int i;
				for (i = 0; i < mem_count; i++)
				{
					flag = 0;
					//既出
					if (A[open] == mem[i])
					{
						vote[i]++;
						flag = 1;
						break;
					}
				}
				//初めて出た
				if (i==mem_count)
				{
					mem[mem_count] = A[open];
					vote[mem_count]=1;
					mem_count++;
				}
				//最大の獲得票数判定
				if (vote[i] > max[1])//二番目より大きい
				{
					if (vote[i] > max[0])//最大より大きい
					{
						max[0] = vote[i];
						max_mem[0] = mem[i];
					}
					else//二番目
					{
						max[1] = vote[i];
						max_mem[1] = mem[i];
					}
				}
			}
			else
			{
				//最初の開票
				mem[0] = A[0];
				vote[0]=1;
				max_mem[0] = mem[0];
				max[0] = 1;
				mem_count++;
			}
			//開票数が過半数超えたら判断開始
			if (open + 1 > n / 2)
			{
				// 2 開票途中で最大の獲得票数　max[0] が
				//次に多い獲得票数 max[1]　と　残りの票数　n-(open+1) の　和　より大きいとき
				if (max[0] > (max[1] + n - (open + 1)))
				{
					printf("%c %d\n", max_mem[0], open + 1);
					flag = 0;
					break;
				}
			}
			flag = 1;
		}
		if(flag) printf("TIE\n");
	}
	
	return 0;
}


Measured memory_bytes: 2036
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int gcd(int a,int b){
  if(b==0) return a;
  return gcd(b,a%b);
}
int main(){
  int N;
  cin>>N;
  VI A(N);
  rep(i,N) cin>>A[i];
  int X=A[0];
  rep(i,N)X=gcd(X,A[i]);
  if(X!=1){
    cout<<"not coprime"<<endl;
    return 0;
  }
  VI PP;
  PP.pb(2);
  rep(i,1000){
    int F=1;
    rep(j,PP.size()){
      if((i+3)%PP[j]==0){
        F=0;
        break;
      }
    }
    if(F) PP.pb(i+3);
  }
  map<int,int> M;
  rep(i,N){
    rep(j,PP.size()){
      if(A[i]%PP[j]==0){
        M[PP[j]]++;
        while(A[i]%PP[j]==0){
          A[i]/=PP[j];
        }
      }
    }
    if(A[i]!=1) M[A[i]]++;
  }
  auto itr=M.begin();
  int ans=0;
  rep(i,M.size()){
    if(itr->second!=1) ans=1;
    itr++;
  }
  
  if(ans) cout<<"setwise coprime"<<endl;
  else cout<<"pairwise coprime"<<endl;
}




Measured memory_bytes: 10716
#include<iostream>
using namespace std;
int main(){
    int H,W; //H=縦  W=横
    
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        
        for(int i = 0; i < H;i++){ //縦
            
            for(int j = 0;j<W; j++){//横
                cout << "#";
                
            }
            cout << endl;
            
        }
        
        cout << endl;
        
        
    }
    
    return 0;
}


Measured memory_bytes: 3072
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = min(x * a + y * b, max(x, y) * 2 * c);
    ll lownum;
    ll highnump;
    if(x > y) {
        lownum = y;
        highnump = a;
    }else {
        lownum = x;
        highnump = b;
    }
    ans = min(ans, lownum * 2 * c + abs(x-y) * highnump);
    cout << ans << endl;
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

ll dp[3002];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  int mod=1e9+7;
  string s;
  cin>>n>>s;
  dp[1]=1;
  rep(i,n-1)
  {
    if(s[i]=='<')
    {
      ll sum=0;
      repi(j,1,i+3)
      {
        sum+=dp[j];
        dp[j]=sum-dp[j];
        dp[j]%=mod;
      }
    }
    else
    {
      for(int j=i+1;j>1;j--)
      {
        dp[j-1]+=dp[j];
        dp[j-1]%=mod;
      }
    }
  }
  ll res=0;
  repi(i,1,n+1)res+=dp[i];
  cout<<res%mod<<endl;

  return 0;

}


Measured memory_bytes: 256
K,N = list(map(int, input().split()))

A = list(map(int, input().split()))

max = 0

for i in range(N):
    if i == N-1:
        if max < K - (A[i]-A[0]):
            max = K - (A[i]-A[0])
    else:
        if max < A[i+1]-A[i]:
            max = A[i+1]-A[i]

print(K-max)

Measured memory_bytes: 26444
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   ll n;
   cin>>n;
   int x=n%10;
   if(x==3)
   {
       cout<<"bon";
   }
   else if(x==0 || x==1 || x==6 || x==8)
   {
       cout<<"pon";
   }
   else
   {
       cout<<"hon";
   }
}


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

int main() {

    int X = 0;

    cin >> X;

    if(X<=599){
        cout << 8 << endl;
    }

    else if(X<=799){
        cout << 7 << endl;
    }

    else if(X<=999){
        cout << 6 << endl;
    }

    else if(X<=1199){
        cout << 5 << endl;
    }

    else if (X<=1399){
        cout << 4 << endl;
    }

    else if(X<=1599){
        cout << 3 << endl;
    }

    else if (X<= 1799){
        cout << 2 << endl;
    }

    else if(X<=1999){
        cout << 1 << endl;
    }


}

Measured memory_bytes: 3632
#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>;
using Graph = vector<vector<int>>;

const long long MOD = 1000000007;
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);
  string X;
  cin >> X;
  stack<char> sta;
  for (int i = 0; i < X.size(); i++)
  {
    if (X[i] == 'S')
      sta.push(X[i]);
    else
    {
      if (sta.size() == 0 || (sta.size() > 0 && sta.top() == 'T'))
        sta.push(X[i]);
      else
      {
        sta.pop();
        cerr << "a" << endl;
      }
    }
  }
  cout << sta.size() << endl;
  return 0;
}

Measured memory_bytes: 720
import java.util.*;

public class Main {

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

        String S = sc.next();

        String ans = "Yes";


        if(S.length() % 2 == 1){
            ans = "No";
        } else {
            for(int i=0;i < S.length()/2;i+=2){
                if(!S.substring(i,i+2).equals("hi")){
                  ans = "No";
                }
            }
        }
        System.out.println(ans);

    }

}









Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main(){
  int n;
  cin>>n;
  vector<ll> a(n),b(n),c(n);
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++) cin>>b[i];
  for(int i=0;i<n;i++) cin>>c[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  sort(c.begin(),c.end());
  ull ans=0;
  decltype(a)::iterator ita;
  decltype(c)::iterator itc;
  for(int i=0;i<n;i++){
    ita=lower_bound(a.begin(),a.end(),b[i]);
    itc=upper_bound(c.begin(),c.end(),b[i]);
    //cout<<(ita-a.begin())<<" "<<(itc-c.begin())<<endl;
    ans+=(ita-a.begin())*(n-(itc-c.begin()));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2560
from heapq import heappush, heappop, heapify

N = int(input())
A = list(map(int, input().split()))
B = [-a for a in A[:: -1]]

L = [0] * (N * 3)
que = A[:N]
heapify(que)
now = sum(A[:N])
for mid in range(N, N * 2 + 1):
    L[mid] = now
    a = A[mid]
    if a > que[0]:
        now -= heappop(que)
        heappush(que, a)
        now += a

R = [0] * (N * 3)
que = B[:N]
heapify(que)
now = sum(B[:N])
for mid in range(N, N * 2 + 1):
    R[mid] = now
    a = B[mid]
    if a > que[0]:
        now -= heappop(que)
        heappush(que, a)
        now += a

R = R[:: -1]

ans = -10**18
for mid in range(N, N * 2 + 1):
    x = L[mid] + R[mid - 1]
    ans = max(ans, x)

print(ans)

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

signed main() {
  int N, K; cin >> N >> K;
  vector<int> A(N);
  int max = 0;
  rep(i, N) {
    cin >> A[i];
    chmax(max, A[i]);
  }

  int lh = 0, rh = max; 
  while(lh != rh -1){
    int mid = (lh +rh)/2;
    int buf = 0;
    rep(i, N) {
      buf += ((A[i] - 1)/mid);
      if(buf > K) break;
    }
    if(buf <= K) rh = mid;
    else lh = mid;
    PRINT(buf)
    PRINT(mid)
  }
  cout << rh << endl;
}

Measured memory_bytes: 4764
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var s = Console.ReadLine();
        if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi")
        {
            Console.WriteLine("Yes");
            return;
        }

        Console.WriteLine("No");
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n; cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  sort(a, a + n);
  cout << a[n / 2] - a[n / 2 - 1] << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    ll x,y;
    cin >> x >> y;
    ll A = abs(abs(x)-abs(y));
    ll B = 0;
    if(( x>0 && y>0 )||( x<0 && y<0 )){
        if((x>0 && abs(x) > abs(y)) || (x<0 && abs(x) < abs(y)))B = 2;
    }else{
        B=1;
        if((x<0 && y==0) || (x==0 && y>0))B = 0;
    }
    cout << (A+B) << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define inf 9e18
#define pii pair<int,int>
#define fastio ios_base::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
using namespace std;
vector<pair<int,int> > v;

int n,W;
int dp[102][100005];
int solve(int i,int w){
    if(i==n)
        return 0;
    if(dp[i][w]!=-1)
        return dp[i][w];
    int ans = 0;
    if(v[i].ff<=w)
        ans = v[i].ss + solve(i+1,w-v[i].ff);
    ans = max(ans,solve(i+1,w));
    return dp[i][w]=ans;
}
int32_t main()
{
    
    fastio
   
    cin>>n>>W;
    for(int i=0;i<n;i++){
        pii p;
        cin>>p.ff>>p.ss;
        v.pb(p);
    }
    // ans = max(v[i] + dp[i+1][W-w[i]],dp[i+1][W]);
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,W);

    return 0;
}

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

int main(void) {
	string T;

	cin >> T;

	if (T == "ABC") {
		cout << "ARC";
	}
	else {
		cout << "ABC";
	}




	


	return 0;
}

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

struct Card {
    int idx, num;
    bool operator<(const Card &c) const {
        return num == c.num ? idx < c.idx : num > c.num;
    }
};
struct Count {
    int cnt, num;
    bool operator<(const Count &c) const {
        return num == c.num ? cnt < c.cnt : num < c.num;
    }
};

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

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

    priority_queue<Card> que;
    for (int i = 0; i < N; i++) {
        Card c;
        c.idx = i;
        cin >> c.num;
        que.push(c);
    }

    priority_queue<Count> cntq;
    for (int i = 0; i < M; i++) {
        Count c;
        cin >> c.cnt >> c.num;
        cntq.push(c);
    }

    int64_t S = 0;
    for (int i = 0; i < N; i++) {
        Count cn;
        if (!cntq.empty()) {
            cn = cntq.top();
            cntq.pop();
        } else {
            cn.num = 0;
            cn.cnt = 1;
        }
        Card cd = que.top();
        que.pop();

        if (cn.num > cd.num) {
            S += cn.num;
            cn.cnt--;
        } else {
            S += cd.num;
        }
        if (cn.cnt > 0) cntq.push(cn);
    }
    cout << S << endl;

    return 0;
}


Measured memory_bytes: 2548
#include<bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	bool dt[1000000];
	rep(i,1000000)dt[i]=true;
	dt[0]=dt[1]=false;
	loop(i,2,1000000){
		for(int j=2;i*j<1000000;j++){
			dt[i*j]=false;
		}
	}
	long long a,ans;
	int d,n;
	while(1){
		cin>>a>>d>>n;
		if(a==0 && d==0 && n==0)break;
		long long cnt=0;
		for(long long i=0;i<1000000;i++){
			long long alt=a+d*i;
			if(dt[alt])cnt++;
			if(cnt==n){
				ans=alt;
				break;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std; 
long long ans,n,a,b,i;
int main ()
{
    cin>>n;
    for(i=sqrt(n);i>=1;i--)
    {
    	if(n%i==0) 
		break;
	}
	b=n/i;
	while(b>0)
	{
		b=b/10;
		ans++;
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n;
    cin >> n;
    vector<int>p(n);
    vector<bool>ok(n,true);
    rep(i,n){
        cin >> p[i];
        if(i+1==p[i])ok[i] = false;
    }
    int ans = 0;
    rep(i,n){
        if(!ok[i]){
            swap(p[i],p[i+1]);
            ans++;
            ok[i+1] = !(p[i+1]==i+2);
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a>b){
    cout<<"a > b"<<endl;
  }else if(a<b){
    cout<<"a < b"<<endl;
  }else if(a==b){
    cout<<"a == b"<<endl;
  }

}

Measured memory_bytes: 1156
#!/usr/bin/env python
from collections import deque

def main():
    N, K = map(int, input().split())
    ps = map(int, input().split())

    dq = deque()
    maxnum = None
    total = None

    for idx, p in enumerate(ps):
        dq.append(p)

        if len(dq) == K:
            total = sum(dq)
            maxnum = total

        if len(dq) > K:
            popnum = dq.popleft()
            total -= popnum
            total += dq[-1]
            if total > maxnum:
                maxnum = total

    exp = (maxnum + K) / 2.0
    print(exp)


if __name__ == '__main__':
    main()


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

int main(void){
    int w, h, x, y, r;
    scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
    bool isInside = x - r >= 0 && y - r >= 0 && x + r <= w && y + r <= h; 
    cout << (isInside ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3220
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()

A=[[R,"r","s"],[S,"s","p"],[P,"p","r"]]
A.sort()

rec=[0]*N
for i in range(N):
  if T[i]==A[0][2]:
    if i<K:
      rec[i]=A[0][1]
    elif rec[i-K] !=A[0][1]:
      rec[i]=A[0][1]
for i in range(N):
  if T[i]==A[1][2]:
    if i<K:
      rec[i]=A[1][1]
    elif rec[i-K] !=A[1][1]:
      rec[i]=A[1][1]
for i in range(N):
  if T[i]==A[2][2]:
    if i<K:
      rec[i]=A[2][1]
    elif rec[i-K] !=A[2][1]:
      rec[i]=A[2][1]


x=0
for i in range(N):
  if rec[i]=="r":
    x+=R
  elif rec[i]=="s":
    x+=S
  elif rec[i]=="p":
    x+=P
print(x)

Measured memory_bytes: 44788
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
//これは、頭が悪く競プロが世界で一番できないHIR180が
//IOI2014日本代表になるまでのN日間の記録である。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000LL
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
#define SIZE 131072
class segtree
{
public:
	ll seg[SIZE*2];
	ll lazy[SIZE*2];
	void lazy_evaluate(int k)
	{
		lazy[k*2+2]+=lazy[k];
		lazy[k*2+1]+=lazy[k];
		seg[k*2+2]+=lazy[k];
		seg[k*2+1]+=lazy[k];
		lazy[k]=0;
	}
	ll update(int beg,int end,int idx,int lb,int ub,ll num)
	{
		if(lazy[idx] && lb!=ub)
		{
			lazy_evaluate(idx);
		}
		if(ub<beg||end<lb)
		{
			return seg[idx];
		}
		if(beg<=lb&&ub<=end)
		{
			lazy[idx]+=num;
			seg[idx]+=num;
			return seg[idx];
		}
		return seg[idx]=max(update(beg,end,idx*2+1,lb,(lb+ub)/2,num),update(beg,end,idx*2+2,(lb+ub)/2+1,ub,num));
	}
	ll query(int beg,int end,int idx,int lb,int ub)
	{
		if(lazy[idx] && lb!=ub)
		{
			lazy_evaluate(idx);
		}
		if(ub<beg||end<lb)
		{
			return -INF;
		}
		if(beg<=lb&&ub<=end)
		{
			return seg[idx];
		}
		return max(query(beg,end,idx*2+1,lb,(lb+ub)/2),query(beg,end,idx*2+2,(lb+ub)/2+1,ub));
	}
}seg;
int main()
{
	srand((unsigned int)time(NULL));
	int n; ll maxv; scanf("%d %lld",&n,&maxv);
	seg.update(0,SIZE-1,0,0,SIZE-1,maxv);
	priority_queue<P>bestfloor;
	ll ret=0;
	for(int i=1;i<n;i++)
	{
		ll gen,pl; scanf("%lld%lld",&gen,&pl);
		bestfloor.push(mp(pl,i));
		while(!bestfloor.empty()&&seg.query(i+1,i+1,0,0,SIZE-1)<=gen)
		{
			P p=bestfloor.top();
			ll got=p.f;
			int id=p.s;
			//how many times can we use recovery without overflowing
			ll x=(maxv-seg.query(id,i+1,0,0,SIZE-1))/got;
			//how many times must we use recovery
			ll y=(1-seg.query(i+1,i+1,0,0,SIZE-1)+gen+got-1)/got;
			if(x>=y)
			{
				//we use best recovery
				ret+=y;
				seg.update(id,SIZE-1,0,0,SIZE-1,y*got);
			}
			else
			{
				//we stop using this recovery
				ret+=x;
				bestfloor.pop();
				bestfloor.push(mp(((maxv-seg.query(id,i+1,0,0,SIZE-1))%got),id));
				seg.update(id,SIZE-1,0,0,SIZE-1,x*got);
			}
		}
		seg.update(i+1,SIZE-1,0,0,SIZE-1,-1*gen);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 6452
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int row = Integer.parseInt(input[0]);
        int col = Integer.parseInt(input[1]);
        int sumOfRow;
        int[] sumOfCol = new int[col + 1];
        String line;
        int i, j, num;
        for (i = 0; i < col + 1; i++) {
            sumOfCol[i] = 0;
        }
        for (i = 0; i < row; i++) {
            line = br.readLine();
            input = line.split(" ");

            sumOfRow = 0;

            for (j = 0; j < col; j++) {
                num = Integer.parseInt(input[j]);
                sumOfRow += num;
                sumOfCol[j] += num;
            }

            sumOfCol[col] += sumOfRow;

            System.out.println(line + " " + sumOfRow);

        }
        line = "";
        for (i = 0; i < col + 1; i++) {
            line += sumOfCol[i];
            if (i == col) break;
            line += " ";
        }
        System.out.println(line);
    }
}

Measured memory_bytes: 28504
#include<bits/stdc++.h>
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf 
#define itn int
using namespace std;
const int N=1e6;
const long long mod=1e9+7;
const int oo=0x7fffffff;
const int sup=0x80000000;
typedef long long ll;
typedef unsigned long long ull;
template <typename it>
string to_str(it n){string s="";while(n)s+=n%10+'0',n/=10;reverse(s.begin(),s.end());return s;}
template <typename it>int o(it a){cout<<a<<endl;return 0;}
int P,Q,R;
int main(){
	cin>>P>>Q>>R;
	int ans=min(P+R,Q+R);
	ans=min(ans,min(R+P,Q+P));
	ans=min(ans,min(P+Q,R+Q));
	o(ans);	
}


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

using namespace std;

int main()
{

	int a = 1, b = 0, c = 0, d = 0, e = 0, maxy = 0, max = 0, ans = 1,count=0;

	int yoko = 0, tate = 0;
	std::string output, output2, output3, input = {};
	bool okada = false;
	int array[10000];
	

	cin >> b;
	if (b == 1) {
      cout <<"Hello World" << endl;
	}
	else {
		cin >> c >> d;
		cout << c + d << endl;
	}
	
}







Measured memory_bytes: 764
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	string s;
	cin >> n >> s;
	int r, b;
	r = b = 0;

	REP(i, n){
		if (s[i] == 'R') r++;
		else b++;
	}
	if (r > b) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Foods Loved by Everyone
            var line = ReadLine();
            int n = line[0];
            int m = line[1];

            var menus = new int[m];

            for(int i = 0; i < n; i++)
            {
                var lovedFoods = ReadLine().Skip(1);

                foreach(var food in lovedFoods)
                {
                    menus[food - 1]++;
                }
            }

            int count = 0;

            foreach(var menu in menus)
            {
                if (menu == n)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine().TrimEnd();
            var array = line.Split(' ');
            var numbers = new List<int>();

            foreach (var s in array)
            {
                int num = int.Parse(s);
                numbers.Add(num);
            }

            return numbers;
        }
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {
  
  static String kaiten(String str) {
    String newStr = "";
    newStr += str.charAt(str.length() - 1);
    for(int i = 0; i < str.length() - 1; i++) {
      newStr += str.charAt(i);
    }
    return newStr;
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    String mohan = sc.next();
    for(int i = 0; i < str.length(); i++) {
      if(str.equals(mohan)) {
        System.out.println("Yes");
        return;
      }else {
        str = kaiten(str);
      }
    }
    System.out.println("No");
  }

}


Measured memory_bytes: 25428
# coding : UTF-8
import bisect
N,M = map(int,input().split())

PM_list = [ input() for _ in range(M) ]
PM_list = [ list(map(int,_.split(" "))) for _ in PM_list]
PM_dict = {}

for i in PM_list:
    if i[0] in PM_dict:
        PM_dict[i[0]].append(i[1])
    else:
        PM_dict[i[0]] = [i[1]]

for j in PM_dict:
    PM_dict[j].sort()

for k in PM_list:
    print("{}{}".format(str(k[0]).zfill(6),str(bisect.bisect_left(PM_dict[k[0]],k[1])+1).zfill(6)))

Measured memory_bytes: 42260
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
#define ll long long
#define MOD 1000000007
#define EPS 1e-9
/*
	E - Knapsack 2
	Slight changes from the previous one
*/

const ll INF=1e18L+5;

int main(){
	ll n,W; cin>>n>>W;
    vector<ll> v(n),w(n);
	for(ll i=0;i<n;i++){
		cin>>w[i]>>v[i];
	}
	ll sval=0;
	for(ll i=0;i<n;i++){
		sval+=v[i];
	}
	vector<ll> dp(sval+1,INF);
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=sval-v[i];j>=0;j--){
			dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
		}
	}
	ll ans=0;
	for(ll i=0;i<=sval;i++){
		//cout<<i<<" "<<dp[i]<<endl;
		if(dp[i]<=W){
			//cout<<i<<endl;
			ans=max(ans,i);
		}
	}
	cout<<ans;
	return 0;
}




Measured memory_bytes: 1024
package main

import (
    "fmt"
)

func main() {
    var a, b int
    fmt.Scan(&a, &b)

    var sum = 0
    for i := 0; i < 2; i++ {
        if a > b {
            sum += a
            a--
        } else {
            sum += b
            b--
        }
    }

    fmt.Println(sum)
}


Measured memory_bytes: 512
n = input()
s = raw_input().strip()

pre = [[0 for i in xrange(3)] for j in xrange(n + 1)]

for i in xrange(n):
    for j in xrange(3): pre[i + 1][j] = pre[i][j]

    if s[i] == 'R': pre[i + 1][0] += 1
    elif s[i] == 'G': pre[i + 1][1] += 1
    else: pre[i + 1][2] += 1

collist = ['R', 'G', 'B']

ans = 0
for j in xrange(1, n):
    for k in xrange(j + 1, n):
        if s[j] == s[k]: continue
        
        it = 2
        if 'R' not in (s[j], s[k]): it = 0
        elif 'G' not in (s[j], s[k]): it = 1

        ans += pre[j][it]

        i = j + j - k

        if i >= 0:
            if s[i] == collist[it]: ans -= 1

print ans
            
        


Measured memory_bytes: 73660
#!/usr/bin/env python3
# vim: set fileencoding=utf-8

# pylint: disable=unused-import, invalid-name, missing-docstring, bad-continuation


"""Module docstring
"""

import functools
import heapq
import logging
import math
import random
import string
import sys
from argparse import ArgumentParser
from collections import defaultdict
from copy import deepcopy


def solve(values, nb, max_jump_size):
    max_jump_size = min(nb, max_jump_size)
    cost_to = [0] * nb
    for i in range(1, nb):
        cost_to[i] = min(
            cost_to[i - k] + abs(values[i] - values[i - k])
            for k in range(1, max_jump_size + 1)
            if i - k >= 0
        )
    return cost_to[nb - 1]


def do_job():
    "Do the work"
    LOG.debug("Start working")
    # first line is number of test cases
    N, K = map(int, input().split())
    values = list(map(int, input().split()))
    result = solve(values, N, K)
    print(result)


def print_output(testcase, result) -> None:
    "Formats and print result"
    if result is None:
        result = "IMPOSSIBLE"
    print("Case #{}: {}".format(testcase + 1, result))


def configure_log(log_file=None) -> None:
    "Configure the log output"
    log_formatter = logging.Formatter(
        "%(asctime)s - %(filename)s:%(lineno)d - " "%(levelname)s - %(message)s"
    )
    if log_file:
        handler = logging.FileHandler(filename=log_file)
    else:
        handler = logging.StreamHandler(sys.stdout)
    handler.setFormatter(log_formatter)
    LOG.addHandler(handler)


LOG = None
# for interactive call: do not add multiple times the handler
if not LOG:
    LOG = logging.getLogger("template")
    configure_log()


def main(argv=None):
    "Program wrapper."
    if argv is None:
        argv = sys.argv[1:]
    parser = ArgumentParser()
    parser.add_argument(
        "-v",
        "--verbose",
        dest="verbose",
        action="store_true",
        default=False,
        help="run as verbose mode",
    )
    args = parser.parse_args(argv)
    if args.verbose:
        LOG.setLevel(logging.DEBUG)
    do_job()
    return 0


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    sys.exit(main())


Measured memory_bytes: 104668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i< (n); ++i)
const long long INF = 1LL<<58;

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){ if(a>b) a = b; }
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

// 最大公約数を求める GCD
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


// 素因数分解 pair
vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            ++num;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 210000;
const int MOD = 1000000007;

//  二項係数の計算nCk セット
//  https://drken1215.hatenablog.com/entry/2018/06/08/210000
//  使い方としては、最初に一度前処理として COMinit() をしておけば、あとは COM(n, k) 関数を呼べばよい
//  前処理 COMinit(): O(n)
//　クエリ処理 COM(n, k): O(1)
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


/*

 *
 * */

int main() {

    int N, K;
    cin >> N >> K;

    int d[K];
    vector<int> A(N+1, 0);

    rep(i, K){
        cin >> d[i];
        rep(j,d[i]){
            int tmp;
            cin >> tmp;
            A[tmp]++;
        }
    }

    int ans=0;
    for (int i = 1; i <= N; ++i) {
        if(A[i]==0){
            ans++;
        }
    }

    cout << ans << endl;
}

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

#define TC int T;cin>>T;for(int tc=1;tc<=T;++tc)

using ll=long long;
constexpr ll mod=1000000007;

ll dp[10001][100][2];
string k;
int d;

ll getWays(int i, int j, bool lim){
    if(i>=k.size())return j==0;
    if(dp[i][j][lim]!=-1) return dp[i][j][lim];
    int max_dig = 9;
    if(lim) max_dig = k[i]-'0';
    ll ways=0;
    for(int k=0;k<=max_dig;++k){
        ways=(ways+getWays(i+1,(j+d-k)%d,lim&&(k==max_dig)))%mod;
    }
    dp[i][j][lim]=ways;
    return ways;
}

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

    cin>>k>>d;
    memset(dp,(ll)-1,sizeof(dp));
    ll ans = (getWays(0,0,true)+mod-1)%mod;
    cout<<ans<<endl;
    
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int l = s.length();
    int ans = 0;
    
    for (int i = 1; i < l; i++) {
        if (((l - i) % 2) != 0) {
            continue;
        }
        
        string cs = s.substr(0, l - i);
        string ls = cs.substr(0, (l - i) / 2);
        string rs = cs.substr((l - i) / 2);
        
        if (ls == rs) {
            ans = l - i;
            break;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back

#define debug(x) cerr << #x << " = " << x << " "

int main()
{
  int n; scanf("%d", &n);
  vector<int> all(n);
  for (auto & e : all) scanf("%d", &e);
  vector<deque<int> > v(2);
  for (int i = 0; i < all.size(); ++i)
    v[i%2].pb(all[i]);
  sort(all.begin(), all.end());
  for (auto &ve : v)
    sort(ve.begin(), ve.end());
  vector<int> buf(2, 0);
  for (int i = 0, flag; i < all.size(); ++i)
    if (!v[flag = (i&1)].empty() && v[flag].front() == all[i])
      v[flag].pop_front();
    else
      {
        assert(!v[!flag].empty() && v[!flag].front() == all[i]);
        ++buf[flag];
        v[!flag].pop_front();
      }
  assert(buf[0] == buf[1]);
  printf("%d\n", buf[0]);

}



Measured memory_bytes: 1024
// https://atcoder.jp/contests/arc059/tasks/arc059_a
#include <bits/stdc++.h>
using namespace std;

int ar[111];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    int n;cin>>n;
    for(int i=0;i<n;i++) cin>>ar[i];
    int ans = INT_MAX;
    for(int i=-100;i<=100;i++) {
        int sum=0;
        for(int j=0;j<n;j++) {
            int d = ar[j]-i;
            d *= d;
            sum += d;
        }
        ans = min(ans, sum);
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3636