akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
int a, b, c, d;

void solve() {
	cin >> a >> b >> c >> d;
	cout << min(a,b) + min(c, d) << endl;
	return;
}

int main(int args, char* argv[]) {
	solve();
}

Measured memory_bytes: 384
import sys
from collections import deque
from copy import deepcopy
INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())
sys.setrecursionlimit(10 ** 9)


def main():
    H, W = MAP()
    c = [list(INPUT()) for _ in range(H)]

    C = []
    for i in range(H+2):
        tmpc = []
        for j in range(W+2):
            if i == 0 or i == H+1 or j == 0 or j == W+1: tmpc.append(0)
            else: tmpc.append(c[i-1][j-1])
        C.append(tmpc)

    sp = deque()
    for i in range(H+2):
        for j in range(W+2):
            if C[i][j] == ".": sp.append([i, j])
            elif C[i][j] == "#": C[i][j] = 0

    ans = 0
    while sp:
        copy_c = deepcopy(C)
        sy, sx = sp.popleft()
        copy_c[sy][sx] = 0
        d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
        queue = deque([[sy, sx]])

        while queue:
            y, x = queue.popleft()
            for dy, dx in d:
                if copy_c[y+dy][x+dx] == ".":
                    copy_c[y+dy][x+dx] = copy_c[y][x] + 1
                    queue.append([y+dy, x+dx])

        tmp = -1
        for i in range(H+2):
            tmp = max(tmp, max(copy_c[i]))

        ans = max(tmp, ans)

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 57820
N, K = [int(_c) for _c in input().split(" ")]
R, S, P = [int(_c) for _c in input().split(" ")]
T = list(input())

point_dict = {"s": R, "p": S, "r": P}

total = 0
for i in range(len(T)):
    if i - K >= 0:
        if T[i - K] == T[i]:
            T[i] = "done"
            continue
    total += point_dict[T[i]]
print(total)

Measured memory_bytes: 4084
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

void solve(){
    int n, d;
    cin >> n >> d;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> x >> y;
        ans += (ll)x*x + (ll)y*y <= (ll)d*d;
    }
    cout << ans << '\n';
}

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

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

string solve(vector<int>& arr, int k)
{
	int dp[k + 1];
	memset(dp, 0, sizeof dp);
	for(int i = 1; i <= k; i++){
		for(auto move:arr){
			if(move > i)continue;
			if(dp[i-move]  == 0)dp[i] = 1;
		}
	}
	return dp[k] ? "First":"Second";
}

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> arr(n);
	for(int i = 0; i <= n; i++)cin >> arr[i];
	cout << solve(arr, k);
	return 0;
}

Measured memory_bytes: 3996
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <map>

using namespace std;

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

	int N;
	cin >> N;

	map<long long, int> char_map;

	long long result = 0;
	for (int i = 0; i < N; i++)
	{
		long long A;
		cin >> A;

		char_map[A]++;

		result += A;
	}

	int Q;
	cin >> Q;

	for (int i = 0; i < Q; i++)
	{
		long long B, C;
		cin >> B >> C;

		if (char_map.find(B) != char_map.end())
		{
			long long diff = (C - B) * char_map[B];
			result += diff;

			char_map[C] += char_map[B];
			char_map[B] = 0;
		}

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


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

int main()
{
    int n;
    scanf("%d", &n);
    int *a = new int[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d", a + i);
        a[i]--;
    }

    int pos{}, count{};
    bool *done = new bool[n];
    std::fill(done, done + n, false);
    while (true)
    {
        if (pos == 1)
        {
            printf("%d\n", count);
            break;
        }
        else if (done[pos])
        {
            printf("-1\n");
            break;
        }

        count++;
        done[pos] = true;
        pos = a[pos];
    }

    delete[] a;
    delete[] done;

    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}
int n,col = 0;
vector<pii>adj[maxn];
vector<int>ans(maxn);

void dfs(int x,int pe,int p){

	int it = 1;
	for(auto &y:adj[x]){
		if(y.f != p){
			if(pe == it)++it;
			ans[y.se] = it;
			dfs(y.f,it,x);
			col = max(col,it);
			++it;
		}	
	}
}

signed main()
{
    showoff;
    cin >> n;
    FOR(i,1,n){
    	int a,b;
    	cin >> a >> b;
    	adj[a].pb({b,i});
    	adj[b].pb({a,i});
    }
    dfs(1,0,1);
    cout << col << "\n";
    FOR(i,1,n)cout << ans[i] << "\n";
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ... 

Measured memory_bytes: 14208
'use strict'
function main(inp) {
  inp = inp.trim()
  let ans = 0
  for (let i = 0; i < inp.length / 2; i++) {
    if (inp[i] !== inp[inp.length - i - 1]) ans++
  }
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
/*input
3 5
*/
#include <bits/stdc++.h>
using namespace std;
#define TEMPLATE

#ifdef TEMPLATE
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

	#define x first
	#define y second
	#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270L;

	template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
	template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
	template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
	template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }
#endif

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int x, a;
	cin >> x >> a;
	if(x < a)
		printf("0\n");
	else
		printf("10\n");
}

/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* array bounds
*/

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cctype>
#include<iomanip>
#include<iostream>
#include<map>
#include <queue>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define each(e, v) for (auto&& e : v)
#define clamp(v,lo,hi) min(max(v,lo),hi)
#define debug(i) cout<<"point :"<< i << endl;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define all(a) a.begin(),a.end()
typedef long long LL;
typedef vector<int> vint;
typedef vector<long> vl;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef map<string, int> mapstri;
typedef map<int, int> mapii;
typedef std::pair<int, int> pairii;

int main () {
    double A,B;
    cin >> A >> B;
    for (int i = 0; i < 1e5; i++) {
        int a = i * 0.08;
        int b = i * 0.1;
        if (a == A && b == B) {
            out(i)
            return 0;
        }
    }
    out(-1)
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            char[] s = sc.chararr;

            Array.Sort(s);

            if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2])
            {
                wr.wri("Yes");
            }
            else
            {
                wr.wri("No");
            }

        }


    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 13396
class Heap
    attr_reader :size
    def initialize(n)
        @heap = Array.new(n)
        @size = 0
    end

    def push(x)
        i = @size
        @size += 1
        while i > 0
            t = (i-1)>>1
            break if @heap[t] <= x
            @heap[i] = @heap[t]
            i = t
        end
        @heap[i] = x
    end

    def pop
        @size -= 1
        x = @heap[@size]
        i = 0
        a = (i<<1)+1
        while a < @size
            if a+1 < @size && @heap[a+1] < @heap[a]
                a += 1
            end
            break if @heap[a] >= x
            @heap[i] = @heap[a]
            i = a
            a = (i<<1)+1
        end
        @heap[i] = x
    end

    def top
        @heap[0]
    end
end

INF = 1<<30
INF2 = 1<<60
mask = INF-1
mask2 = INF2-1

N, Q = gets.split.map(&:to_i)
events = []
N.times do |i|
    s, t, x = gets.split.map(&:to_i)
    next if t-x <= 0
    events.push(((s-x)<<60) + (x<<30) + t-x)
end
events.sort!
events.push(1<<90)

pt = 0
heap = Heap.new(N+1)
heap.push((1<<60) + mask)
Ans = Array.new(Q)
Q.times do |i|
    d = gets.to_i
    d2 = (d+1)<<60
    while events[pt] < d2
        heap.push(events[pt] & mask2)
        pt += 1
    end
    heap.pop while (heap.top & mask) <= d
    ans = heap.top >> 30
    Ans[i] = (ans == INF ? -1 : ans)
end
puts Ans

Measured memory_bytes: 22492
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int n,k,x,y,res[1005][1005]={},cou=0,tmp=0;
long long int tmpx,tmpy;


int main() {
    const long long int mod = 1000000007,INF=99999999999999;
	map<long long int, long long int>mp;
    string str;
	cout << fixed << setprecision(10);
    cin>>str>>k;
    for(int i=0;i<str.length();i++){
        if(str[i]=='a'){continue;}
        else if('a'+26-str[i]<=k){
            
            k-='a'+26-str[i];
            str[i]='a';
            
            
        }else{
            continue;
        }
    }
    k%=26;
    if(k>0){
        str[str.length()-1]=str[str.length()-1]+k;
    }
    cout<<str;
} 


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fatafat ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define MOD ((long long)(1e9)+7)
#define excl(i,a,b) for(int i=a;i<b;i++)
#define incl(i,a,b) for(int i=a;i<=b;i++)
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define PII pair<int,int>

using namespace std;

int binexp(int a,int b)
{
    if(b)
    {
        if(b%2)
            return a*binexp(a*a,b/2);
        return binexp(a*a,b/2);
    }
    return 1;
}

int modexp(int a,int b,int m)
{
    if(b)
    {
        if(b%2)
            return (a*modexp((a*a)%m,b/2,m))%m;
        return modexp((a*a)%m,b/2,m);
    }
    return 1;
}

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

int euclidgcd,euclidx,euclidy;

void exteuclid(int a,int b)
{
    if(b==0)
    {
        euclidgcd=a;
        euclidx=1;
        euclidy=0;
    }
    else
    {
        exteuclid(b,a%b);
        int temp=euclidx;
        euclidx=euclidy;
        euclidy=temp-euclidy*(a/b);
    }
}

int modinv(int a,int m)
{
    exteuclid(a,m);
    return (euclidx%m + m)%m;
}

int pmodinv(int a,int m)
{
    return modexp(a,m-2,m);
}

bool checkprime(int a)
{
    for(int i=2;i*i<=a;i++)
        if(a%i==0)
            return false;
    return true;
}

vector<bool> seive(int n)
{
    vector<bool> ret(n+1,true);
    ret[0]=ret[1]=false;
    for(int i=2;i*i<=n;i++)
        if(ret[i])
            for(int j=i*i;j<=n;j+=i)
                ret[j]=false;
    return ret;
}

vector<bool> seivelims(int l,int r)
{
    vector<bool> ret(r-l+1,true);
    for(int i=2;i*i<=r;i++)
    {
        for(int j=max(i*i,((l+i-1)/i)*i);j<=r;j+=i)
        {
            ret[j-l]=false;
        }
    }
    return ret;
}

vector<int> rootnfact(int n)
{
    vector<int> ret;
    for(long i=2;i*i<=n;i++)
        while(n%i==0)
        {
            ret.push_back(i);
            n/=i;
        }
    if(n!=1)
        ret.push_back(n);
    return ret;
}

vector<int> prelognfact(int n)
{
    vector<int> minprime(n+1,0);
    minprime[0]=minprime[1]=0;
    for(int i=2;i*i<=n;i++)
    {
        if(minprime[i]==0)
        {
            for(int j=i*i;j<=n;j+=i)
            {
                if(minprime[j]==0)
                    minprime[j]=i;
            }
        }
    }
    for(int i=2;i<=n;i++)
        if(minprime[i]==0)
            minprime[i]=i;
    return minprime;
}

vector<int> lognfact(int n,vector<int> minprime)
{
    vector<int> ret;
    while(n!=1)
    {
        ret.push_back(minprime[n]);
        n/=minprime[n];
    }
    return ret;
}

int temp,temp1,temp2;

signed main()
{
    fatafat;
    string s;
    cin>>s;
    if((s[5]-'0')==0 && (s[6]-'0')<=4)
        cout<<"Heisei";
    else
        cout<<"TBD";
}

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	VI v(3);
	REP(i,3) cin >> v[i];
	SORT(v);

	int ans = v[2]*10+v[1]+v[0];
	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    char a;
    cin >> a;
    if(isupper(a)) cout << "A" << endl;
    else cout << "a" << endl;

}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
const int MOD=1e9+7;
const int INF=1e18;


signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    //freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int d,t,s;cin>>d>>t>>s;
    if(d<=t*s){
        cout<<"Yes";
    }else cout<<"No";
}

Measured memory_bytes: 3632
a,b,c,x,y=map(int,input().split())
#A,Bをそれぞれ買う
cand1=a*x+b*y
#すべてABピザでそろえる
cand2=2*c*max(x,y)
#A,Bのうち必要枚数が少ないほうをすべてABピザで作る
cand3=2*c*x+b*(y-x) if x<y else 2*c*y+a*(x-y)
print(min(cand1,cand2,cand3))

Measured memory_bytes: 3060
def insert_sort(A,n,g):
	cnt = 0
	for i in range(g,n):
		key = A[i]
		j = i - g
		while j >= 0 and A[j] > key:
			A[j+g] = A[j]
			j -= g
			cnt+=1
		A[j+g] = key
	return cnt

def shell_sort(A,n):
	cnt = 0
	g = []
	tmp = 1
	while tmp <= -(-n//3):
		g.append(tmp)
		tmp = tmp*3 + 1
	g.reverse()
	m = len(g)
	print(m)
	print(*g)
	for i in range(m):
		cnt += insert_sort(A,n,g[i])
	print(cnt)

if __name__ == '__main__':
	n = int(input())
	A = []
	for i in range(n):
		A.append(int(input()))
	shell_sort(A,n)
	for i in A:
		print(i)


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

const int N = 1e5+3;
char s[N], t[N];
int sp[N], tp[N];
int main()
{
    int q, a, b, c,d;
    scanf("%s%s%d",s+1,t+1,&q);
    for(int i=1; s[i]; ++i)
        sp[i] = sp[i-1]+s[i]-'A'+1;
    for(int i=1; t[i]; ++i)
        tp[i] = tp[i-1]+t[i]-'A'+1;
    while(q--)
    {
        scanf("%d%d%d%d",&a,&b,&c,&d);
        if((sp[b]-sp[a-1])%3 == (tp[d]-tp[c-1])%3)
            puts("YES");
        else
            puts("NO");
    }
    return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);


  int N; cin >> N;
  int A; cin >> A;
  cout<<N*N-A<<endl;


  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL mod = 10000;
LL N, K, A[112], B[112];
std::map<LL, LL>list;
LL memo[112][4][4];

LL dp(LL d, LL b2, LL b1)
{
	if (memo[d][b2][b1] != -1) { return memo[d][b2][b1]; }
	if (d == N + 1) { return memo[d][b2][b1] = 1; }
	if (list[d] > 0)
	{
		if (!(b2 == b1 && b1 == list[d])) { return memo[d][b2][b1] = dp(d + 1, b1, list[d]) % mod; }
		else { return memo[d][b2][b1] = 0; }
	}
	else
	{
		LL res = 0;
		for (int i = 1; i <= 3; ++i)
		{
			if (!(b2 == b1 && b1 == i)) { res += dp(d + 1, b1, i) % mod; }
			res %= mod;
		}
		return memo[d][b2][b1] = res;
	}
}

int main()
{
	memset(memo, -1, sizeof(memo));
	in >> N >> K;
	rep(i, N) { in >> A[i] >> B[i]; }
	rep(i, N) { list[A[i]] = B[i]; }
	out << dp(1, 0, 0) << std::endl;
	return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define me(a,x) memset(a,x,sizeof(a))
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);
#define sc scanf
#define itn int
#define STR clock_t startTime = clock();
#define END clock_t endTime = clock();cout << double(endTime - startTime) / CLOCKS_PER_SEC *1000<< "ms" << endl;
using namespace std;
const int N=2e5+5;
const long long mod=1e9+7;
const long long mod2=998244353;
const int oo=0x7fffffff;
const int sup=0x80000000;
typedef long long ll;
typedef unsigned long long ull;
template <typename it>void db(it *begin,it *end){while(begin!=end)cout<<(*begin++)<<" ";puts("");}
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;}
inline ll mul_64(ll x,ll y,ll c){return (x*y-(ll)((long double)x/c*y)*c+c)%c;}
inline ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=a*a%c)if(b&1)ans=ans*a%c;return ans;}
inline void exgcd(ll a,ll b,ll &x,ll &y){if(!b)x=1,y=0;else exgcd(b,a%b,y,x),y-=x*(a/b);}
int a[N],n;
int lpos[N],rpos[N];
int pos[N];
int main(){
   // IN
    cin>>n;
    for(int i=1;i<=n;i++)sc("%d",&a[i]),pos[a[i]]=i;
    deque<int>q,p;
    q.push_back(a[1]);lpos[a[1]]=0;
    for(int i=2;i<=n;i++){
        while(!q.empty()&&q.back()<a[i])q.pop_back();
        if(q.empty())lpos[a[i]]=0;
        else {
            int x=q.back();
            lpos[a[i]]=pos[x];
        }
        q.push_back(a[i]);
    }
    p.push_back(a[n]);rpos[a[n]]=n+1;
    for(int i=n-1;i>=1;i--){
        while(!p.empty()&&p.back()<a[i])p.pop_back();
        if(p.empty())rpos[a[i]]=n+1;
        else {
            int x=p.back();
            rpos[a[i]]=pos[x];
        }
        p.push_back(a[i]);
    }
    ll ans=0;
    for(int i=1;i<n;i++){
        int l=lpos[i],r=rpos[i];
        if(i==1){
            if(l==0)ans+=1;
            else if(r==n+1)ans+=1;
            else ans+=2;
            continue;
        }
        int ql=0,qr=n+1;
        for(int j=l-1;j>=1;j--)if(a[j]>i){ql=j;break;}
        for(int j=r+1;j<=n;j++)if(a[j]>i){qr=j;break;}
        if(l==0){
            ans+=1LL*i*(pos[i]-l)*(qr-r);
        }else if(r==n+1){
            ans+=1LL*i*(r-pos[i])*(l-ql);
        }else{
            ans+=1LL*i*(r-pos[i])*(l-ql);
            ans+=1LL*i*(pos[i]-l)*(qr-r);
        }
    }
    o(ans);
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl
class UnionFind{
public:
	vector<int> par;
	//0-indexed
	UnionFind(int n){
    	init(n);
	}
	void init(int n = 1) {
		par.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i;
	}
	int root(int x = 1){
		if(par[x]==x)return x;
		else{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x = 1,int y = 1){
		x = root(x);
		y = root(y);
		if(x==y)return;
		else par[x] = y;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N ,M ,ans = 0;
	cin >> N >> M;
	vector<ll> a(M),b(M);
	FOR(i,0,M)cin>>a[i]>>b[i];
	FOR(i,0,M){
		UnionFind uf(N+1);
		FOR(j,0,M){
			if(j!=i)uf.unite(a[j],b[j]);
		}
		if(uf.root(a[i])!=uf.root(b[i]))ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        int[] b = new int[m];
        int[] c = new int[m];
        List<Pair> list = new ArrayList<>();
        for(int i=0; i<m; i++) {
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
            list.add(new Pair(b[i], c[i]));
        }
        Arrays.sort(a);
        Collections.sort(list);

        int index = 0;

        A: for(Pair p: list) {
            for(int i=0; i<p.b; i++) {
                if(p.c > a[index]) {
                    a[index] = p.c;
                }
                index++;
                if(index >= n) break A;
            }
        }

        long res = 0;
        for(int i=0; i<n; i++) {
            res += a[i];
        }

        System.out.println(res);


    }

    static class Pair implements Comparable<Pair> {
        int b, c;
        Pair(int b, int c) {
            this.b = b;
            this.c = c;
        }

        @Override public int compareTo(Pair o) {
            return o.c - c;
        }
    }

}


Measured memory_bytes: 93852
// https://atcoder.jp/contests/abc162/tasks/abc162_b

#include <iostream>
using namespace std;

int main(){
	long long int n, n3, n5, n15;
	cin >> n;
	n3 = n/3;
	n5 = n/5;
	n15 = n/15;
	cout << ((n*(n+1))>>1) - 3*((n3*(n3+1))>>1) - 5*((n5*(n5+1))>>1) + 15*((n15*(n15+1))>>1) << endl;
	return 0;
}

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

int main()
{
  double a, b, x;
  cin >> a >> b >> x;
  if (x / a <= (a * b / 2))
    cout << fixed << setprecision(10) << 90 - atan((2 * x) / (a * b * b)) * (180 / M_PI) << endl;
  else
    cout << fixed << setprecision(10) << atan((2 * (b - x / (a * a))) / a) * (180 / M_PI) << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
	int H,W,i,j,sum=0,ans=0;
	for(;;){
		cin>>H>>W;
		if(H==0 && W==0)break;
		for(i=1;i<=H;i++){
			for(j=1;j<=W;j++){
				sum=j+i;
				ans=sum/2*2;

			if(ans==sum){
				cout<<"#";
				}else{
					cout<<".";
				}
			
			}
			cout<<endl;

		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3088
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt(),k = sc.nextInt();
    int ans = 0;
    for(int i = 0;i<n;i++){
      int x = sc.nextInt();
      if(Math.abs(k-x) < x){
        x = Math.abs(k-x);
      }
      ans += x;
    }
    System.out.println(ans * 2);
  }
}


Measured memory_bytes: 21332
#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 main()
{
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  int MAX = A.at(0) + (K - A.at(N-1));
  REP(i,N-1){
    MAX = max(MAX,(A.at(i+1)-A.at(i)));
  }
  cout << K - MAX << endl;
}

Measured memory_bytes: 1024
import sys

N = int(input())
ls = list(map(int, input().split()))
k = len(ls)
p = [ i for i in ls if (i%4) == 0]
j = [ i for i in ls if (i%4) != 0]
r = [ i for i in j if (i%2) == 0]

if(len(p) >= int(k/2)):
    print('Yes')
elif (len(p) >= (len(j) - len(r))):
    print('Yes')
else:
    print('No')

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int x;
  string s;
  cin >> s;
  map<int, int> p;
  p[0] = -1;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      q;
  q.emplace(0, 0);
  for (int i = 1; i <= n; i++) {
    if (s[i] == '1') continue;
    while (!q.empty() && q.top().second < i - m) {
      q.pop();
    }
    if (q.empty()) continue;
    p[i] = q.top().second;
    q.emplace(q.top().first + 1, i);
  }
  if (!p.count(n)) {
    cout << "-1\n";
  } else {
    vector<int> res;
    int x = n;
    while (p[x] != -1) {
      res.push_back(x - p[x]);
      x = p[x];
    }
    reverse(res.begin(), res.end());
    for (auto& v : res) cout << v << " ";
    cout << '\n';
  }
  return 0;
}

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

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

dic = {}

for i in X:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

lis = [0] * M
rem = [0] * M

for i in dic:

    lis[i % M] += dic[i]
    rem[i % M] += dic[i] // 2 * 2

#print (lis,rem)

ans = 0
for i in range((M-1) // 2):

    i += 1

    if lis[i] >= lis[-1*i]:
        ans += lis[-1*i] * 2 + min(rem[i] , (lis[i]-lis[-1*i]) // 2 * 2)

    else:
        ans += lis[i] * 2 + min(rem[-1*i] , (lis[-1*i] - lis[i]) // 2 * 2)

ans += lis[0] // 2 * 2

if M % 2 == 0:
    ans += lis[M//2] // 2 * 2
    

print (ans // 2)


Measured memory_bytes: 61676
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		bool h=false;
		int co=0;
		rep(i,n){
			int a;cin>>a;
			if(a>=2)h=true;
			if(a>=1)co++;
		}
		if(h)cout<<co+1<<endl;
		else cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 1160
# 空あり
# input: 0 or 1

# 入力
S = input()

result=[]
for i in range(len(S)):
    if S[i]=="0":
        result.append("0")
    elif S[i]=="1":
        result.append("1")
    elif S[i]=="B":
        if result != []:
            result.pop()
        
print("".join(result))



Measured memory_bytes: 38384
n = STDIN.gets.to_i
t, a = STDIN.gets.split(" ").map(&:to_i)
hs = STDIN.gets.split(" ").map(&:to_i)

ni = 0
nd = 10000
for i in 0...n
  ti = t - hs[i] * 0.006
  diff = (ti - a).abs

  if diff < nd
    ni = i
    nd = diff
  end
end

puts (ni+1)


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

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL 
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for(int I = A; I < B; I++)
#define RFOR(I, A, B) for(int I = A; I >= B; I--)

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

int h, w, n, xi, yi;
string s, t;

bool deubom = false;

void build(string &s, string &t ){
	int xu = xi, xd = xi, yl = yi, yr = yi;
	char c;
	FOR(i,0,n){
		c = s[i];
		if(c == 'U'){
			xu--;
			if(xu <= 0)  deubom = true;
		} 
		if(c == 'L'){
			yl--;
			if(yl <= 0) deubom = true;
		} 
		if(c == 'R'){
			yr++;
			if(yr > w) deubom = true;
		} 
		if(c == 'D'){
			xd++;
			if(xd > h) deubom = true;
		}
		c = t[i];
		if(c == 'U'){
			xd--;
			if(xd <= 0) xd++;
		} 
		if(c == 'L'){
			yr--;
			if(yr <= 0) yr++;
		} 
		if(c == 'R'){
			yl++;
			if(yl > w) yl--;
		} 
		if(c == 'D'){
			xu++;
			if(xu > h) xu--;
		}
	}
}

int main(){
	scanf("%d%d%d", &h, &w, &n);
	scanf("%d%d", &xi, &yi);
	cin >> s >> t;

	build(s, t);

	string ans;
	if(deubom){
		ans = "NO\n";
	} else {
		ans = "YES\n";
	}
	cout << ans;

	return 0;
}

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

int main()
{
	int r,r_c;
	cin >> r;

	switch(r_c = r/ 100){
	case(4):
	case(5):
		cout << 8;
		break;
	case(6):
	case(7):
		cout << 7;
		break;
	case(8):
	case(9):
		cout << 6;
		break;
	case(10):
	case(11):
		cout << 5;
		break;
	case(12):
	case(13):
		cout << 4;
		break;
	case(14):
	case(15):
		cout << 3;
		break;
	case(16):
	case(17):
		cout << 2;
		break;
	case(18):
	case(19):
		cout << 1;
		break;
	default:
		break;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1<<30);
 
int main() {
  double t,x;
  cin >> t >> x;
  cout << t/x << endl;
}

Measured memory_bytes: 3780
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    use std::collections::HashMap;
    let mut map: HashMap<usize, Vec<usize>> = HashMap::new();
    for _ in 0..N {
        let v: usize = read();
        let entry = map.entry(v).or_insert(vec![]);
        entry.push(v);
    }
    let mut ans = 0;
    for (key, value) in map {
        use std::cmp::Ordering;
        match key.cmp(&value.len()) {
            Ordering::Equal => continue,
            Ordering::Less => ans += value.len() - key,
            Ordering::Greater => ans += value.len(),
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 16016
import java.util.*;
import java.io.*;

//atcoder need change class name to Main
//E - Knapsack 2
//stand dp 
//this time Weight is to big, can not use it as lenght of dp
//loop from right to left

//https://atcoder.jp/contests/dp/tasks/dp_c

public class Main {
    static StringTokenizer st;
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

 
    public static void main(String[] args) throws IOException {
  
        int N = nextInt(); 
        int W = nextInt(); 
 
        //no need calc sum, use max 100* 1000
        int maxValue = 100000;
        long[] dp = new long[maxValue+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;

        for (int i=1; i<=N;  i++) {
            int w = nextInt();
            int v = nextInt();
            for (int j=maxValue; j>=v; j--) {// from right to left
                //from right to left,  make usue only use 1
                //this can be use limit item
                //use count array 
                dp[j] = Math.min(dp[j], dp[j-v] + w); 
            }
        }

        for (int i = maxValue; i>=0; i--){
            if (dp[i] <=W) {
                System.out.println(i);
                return;
            }
        }
    }
    

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  cin >> n;
  int ans = 1;
  while(ans <= n){
    ans *= 2;
  }
  cout << ans/2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i));
        pro/=(i+1);
    }
    return pro;
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,b,c;
    cin>>a>>b>>c;
    ll x=min(a,c);
    c=c-x;
  	a=a-x;
    ll y=min(c,b);
    c=c-y;
  	b=b-y;
    ll ans=2*y+x+b;
    if(c>=1) ans++;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
//#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	int out=-1;
	rep(i,n)rep(j,i){
		int t=in[i]*in[j];
		string s=to_string(t);
		bool h=true;
		rep(k,s.size()-1)if(s[k]+1!=s[k+1])h=false;
		if(h)out=max(out,t);
	}
	cout<<out<<endl;
}

Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
#define int long
main(){
  int n,k,h=0;
  string s;
  cin>>n>>k>>s;
  for(int i=0;i<n;++i){
    if(s[i]=='L'&&0<i&&s[i-1]=='L')h++;
    if(s[i]=='R'&&i<n-1&&s[i+1]=='R')h++;
  }
  cout<<min(h+k*2,n-1);
}

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

int dp[100005][3];
int main(){
    int data[100005][3];
    int N;cin>>N;
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++)cin>>data[i][j];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            dp[i+1][j]=+data[i][j]+max(dp[i][(j+1)%3],dp[i][(j+2)%3]);
        }
    }
    sort(dp[N],dp[N]+3);
    cout<<dp[N][2]<<endl;

    return 0;
}

Measured memory_bytes: 2560
N = int(input())
h_list = [int(number) for number in input().split(' ')]

counter = 0

while True:
	flag=False
	keep=False
  
	for i, h in enumerate(h_list):
		if h>=1:
			keep=True
			h_list[i] -= 1
			flag=True
			if (i+1)==N:
				counter += 1
		elif h==0:
			if flag:
				counter += 1
				flag=False
		else:
			raise ValueError()
      
	if not keep: break
    
print(counter) 

Measured memory_bytes: 3064
//前置き
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

typedef  long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//偶数 ->　true :: 奇数　-> false
bool EVEN(ll a);

//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main(){
    // ========================================================
    string s;
    cin >> s;
    if(s == "Sunny")    cout << "Cloudy";
    if(s == "Cloudy")  cout << "Rainy";
    if(s == "Rainy")  cout << "Sunny"; 
    cout << endl;
}

//偶数 ->　true :: 奇数　-> false
bool EVEN(ll a){
    return a%2;
}

//最大公約数
ll gcd(ll a, ll b) {  
    if (!b)  
        return a;  
    return gcd(b, a%b);  
}

//最小公倍数
ll lcm(ll a, ll b) {  
    return a*b/gcd(a,b);  
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define asort(x) sort((x).begin(), (x).end())
#define rsort(x) sort((x).rbegin(), (x).rend())
using namespace std;
int frog(int a[], int n)
{
    int dp[n+5];
    dp[1]=0,dp[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i] = min(abs(a[i]-a[i-1]) + dp[i-1], abs(a[i]-a[i-2]) + dp[i-2]);
    }
    return dp[n];
}
int main()
{
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int ans = frog(a,n);
    cout<<ans<<"\n";

}

Measured memory_bytes: 4344
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define MEMSET(a, n, x) REP(i, n) a[i]=x;
#define ARRIN(a, n) REP(i, n) cin>>a[i];
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n;
  cin>>n;
  int ans=1, w;
  FOR(i, 2, sqrt(n)+1){
    w=i;
    while(w*i<=n)w*=i;
    ans=max(ans, w);
  }
  ECHO(ans);

  return 0;
}


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

using ll = long long int;

int n;
string str;

//map<pair<string, string>, ll> cnt;

unordered_map<string, ll> cnt;

ll ans;

int main(void){
  scanf("%d", &n);
  cin >> str;

  for (int i = 0; i < (1 << n); ++i) {
    string s1, s2;
    for (int j = 0; j < n; ++j) {
      if (i & (1 << j)) s1.push_back(str[j]);
      else s2.push_back(str[j]);
    }
    cnt[(s1 + "_" + s2)] += 1;
  }

  reverse(str.begin(), str.end());


  for (int i = 0; i < (1 << n); ++i) {
    string s1, s2;
    for (int j = 0; j < n; ++j) {
      if (i & (1 << j)) s1.push_back(str[j]);
      else s2.push_back(str[j]);
    }
    ans += cnt[(s1 + "_" + s2)];
  }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 70900
#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 ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
    string s;
    cin >> s;
    
    ll ans = 0, cur = 0;
    
    REP(i, s.size()) {
        if (s[i] == 'A') ++cur;
        else if (s.substr(i, 2) == "BC") { ans += cur; ++i; }
        else cur = 0;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
const int INF = 1001001001;

int main()
{
    int n,alice=0,bob=0;
    in n;
    vector<int> a(n);
    rep(i,n)in a[i];
    sort(a.begin(),a.end(),greater<int>());
    for(int i=0;i<n;i++)
    {
        if(i%2==1)bob+=a[i];
        else alice+=a[i];
    }
    cout<<alice-bob<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long luythua (long long n,long long x)
{
    if (x==0) return 1;
    if (x==1) return n;
    else
    {
        long long tam=luythua(n,x/2)%1000000007;
        if(x % 2 == 0)
            return ((tam*tam))%1000000007;
        else
            return (((tam*tam)%1000000007)* n)%1000000007;
    }
}

int main()
{
    long long n,x;
    cin>>n>>x;
    cout<<luythua(n,x)%1000000007;
    cout<<'\n';
}
    


Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll dp[3030][3030];
ll sum[3030];

int main(){
  int n;
  cin>>n;
  ll a[n+1]={};
  for(int i=1;i<=n;i++){
    cin>>a[i];
    sum[i]=sum[i-1]+a[i];
  }

  for(int i=1;i<=n;i++){
    dp[i][i]=a[i];
  }

  for(int len=1;len<n;len++){
    for(int l=1;l+len<=n;l++){
      int r=l+len;
      dp[l][r]=max(a[l]+sum[r]-sum[l]-dp[l+1][r],a[r]+sum[r-1]-sum[l-1]-dp[l][r-1]);
    }
  }

  cout<<dp[1][n]-(sum[n]-dp[1][n])<<endl;



  return 0;
}


Measured memory_bytes: 71936
import java.io.*;
import java.io.ObjectInputStream.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = (long)1e9+7;
	//final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		slove(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void slove(String[] args) throws Exception{
		char[] s = nextString().toCharArray();
		int K = nextInt();

		for(int i=0;i<s.length;i++) {
			int dist = (26-(s[i]-'a'))%26;
			if(K-dist>=0) {
				K-=dist;
				s[i]='a';
			}
		}
		s[s.length-1]=(char)('a'+((s[s.length-1]-'a'+K)%26));

		pw.println(s);
	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}



Measured memory_bytes: 28624