akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int M, K;
    cin >> M >> K;
    if(K >= (1 << M)){
        cout << -1 << endl;
        return 0;
    }else if(M == 1){
        if(K == 0){
            cout << "0 0 1 1" << endl;
            return 0;
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    deque<int> ans;
    ans.push_back(K);
    for(int i = 0; i < (1 << M); i++){
        if(i == K){
            continue;
        }
        ans.push_front(i);
        ans.push_back(i);
    }
    ans.push_back(K);
    array_output(all(ans));
}

Measured memory_bytes: 4608
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    from collections import Counter
    N = I()
    a = LI()
    c = Counter(a)
    ans=0
    for i in range(0, max(a) + 1):
        candidate = 0
        for j in range(-1, 2):
            if i + j in c:
                candidate += c[i + j]
        ans = max(ans, candidate)
    print(ans)
if __name__ == '__main__':
    main()

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

const int XY_MAX = 100;

signed main() {
	int n;
	cin >> n;
	vector<int> x(n), y(n), h(n);
	tuple<int, int, int> p = make_tuple(-1, -1, -1);

	for (int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] > 0 and get<0>(p) == -1) {
			p = make_tuple(x[i], y[i], h[i]);
		}
	}

	int H;

	for (int cx = 0; cx <= XY_MAX; ++cx) {
		for (int cy = 0; cy <= XY_MAX; ++cy) {
			H = abs(get<0>(p) - cx) + abs(get<1>(p) - cy) + get<2>(p);
			bool flag = true;
			for (int i = 0; i < n; ++i) {
				int expH = abs(x[i] - cx) + abs(y[i] - cy) + h[i];
				if ((h[i] > 0 and expH != H) or (h[i] == 0 and expH < H)) {
					flag = false;
				}
			}
			if (flag) {
				cout << cx << ' ' << cy << ' ' << H << endl;
				return 0;
			}
		}
	}
}

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

int solve1(int &a , int &b , int db , string s){
    for(int i = b; i <= db; i++){
        if(s[i+1] ==  '#' && s[i] == '#'){
            return 0;
        }
        if(s[i-1] == '.' && s[i] == '.' &&  s[i+1] == '.' && i <= db ){
            b = i;
            a = i-1;
            return 1;
        }
    }
    return 0;
}

int main(){
    string s;
    int n , a , b, da, db;
    cin >> n >> a >> b >> da >> db;
    cin >> s;
    a--; b--; da--; db--;
    if(s[da] == '#' || s[db] == '#'){
        cout << "No\n";
        return 0;
    }
    if(da < b){
        for(int i = a; i <= da; i++){
        if(s[i]=='#' && s[i+1] == '#'){
            cout << "No\n";
            return 0;
        }
        }
        for(int i = b; i <= db; i++){
        if(s[i]=='#' && s[i+1] == '#'){
            cout << "No\n";
            return 0;
        }
        cout << "Yes\n";
        return 0;
    }
    }
    
    for(int i = a; i < b; i++){
        if(s[i]=='#' && s[i+1] == '#'){
            cout << "No\n";
            return 0;
        }
    }
    if(da > db){
        if(solve1(a , b , db , s) == 0){
            cout << "No\n";
            return 0;
        }
        a = b+1;
        for( ; a <= da; a++){
            if(s[a] == '#' && s[a+1] == '#'){
                cout << "No\n";
                return 0;
            }
        }
        cout << "Yes\n";
        return 0;
    }
    for( ; b <= db; b++){
        if(s[b] == '#' && s[b+1]=='#'){
            cout <<"No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 772
#include <stdio.h>
int main(int argc, const char * argv[]) {
    int n, x, i, j, k, count = 0;
    while(1){
        count = 0;
        scanf("%d %d",&n,&x);
        if( n == 0 && x == 0 ){
            break;
        }
        for( i = 1 ; i <= n ; i++ ){
            for( j = i + 1 ; j <= n ; j++ ){
                for( k = j + 1 ; k <= n ; k++ ){
                    if( i + j + k == x ){
                        count++;
                    }
                }
            }
        }
        printf("%d\n",count);
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;
#define MAX 10000
#define NIL -1

struct Node{int p, l, r;};
struct Node T[MAX];

void preorder(int u){
	if(u == NIL){
		return;
	}
	cout << " " << u;
	preorder(T[u].l);
	preorder(T[u].r);
}

void inorder(int u){
	if(u == NIL){
		return;
	}
	inorder(T[u].l);
	cout << " " << u;
	inorder(T[u].r);
}

void postorder(int u){
	if(u == NIL){
		return;
	}
	postorder(T[u].l);
	postorder(T[u].r);
	cout << " " << u;
}

void solve(){
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		T[i].p = NIL;
	}
	int v, l, r;
	for(int i = 0; i < n; ++i){
		cin >> v >> l >> r;
		T[v].l = l;
		T[v].r = r;
		if(l != NIL){
			T[l].p = v;
		}
		if(r != NIL){
			T[r].p = v;
		}
	}
	int root;
	for(int i = 0; i < n; ++i){
		if(T[i].p == NIL){
			root = i;
		}
	}
	cout << "Preorder" << endl;
	preorder(root);
	cout << endl;
	cout << "Inorder" << endl;
	inorder(root);
	cout << endl;
	cout << "Postorder" << endl;
	postorder(root);
	cout << endl;
}

int main(){
	solve();
	return 0;
}



Measured memory_bytes: 3120
n = int(input())
t = str(input())
ans = 0
for i in range(1,len(t)):
    #print(t[:i], t[i:])
    left = list(t[:i])
    right = list(t[i:])
    #print(left,right)
    kyoutuu = set(left) & set(right)
    j = len(list(kyoutuu))
    if ans < j:
        ans = j
print(ans)

Measured memory_bytes: 3060
def main():
    S = input()
    li = []
    li_append = li.append
    is_A = False
    now_state = 0
    for ind,s in enumerate(S):
        if(is_A):
            if(now_state==1):
                now_state = 0
                continue
            else:
                if(s=='A'):
                    li[-1].append(0)
                elif(S[ind:ind+2]=='BC'):
                    li[-1][-1] += 1
                    now_state = 1
                else:
                    is_A = False
        elif(s=='A'):
            is_A = True
            now_state = 0
            li_append([0])
    cnt = 0
    for i in li:
        cnt_b = sum(i)
        for j in i:
            cnt += cnt_b
            cnt_b -= j
            
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 53472
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

int a[150][150];
int main(){
	FIO
	
	int n, m;cin >> n >> m;
	for(int i = 0; i < n; i++){
		int sum = 0;
		for(int j = 0; j < m; j++){
			cin >> a[i][j];
			sum += a[i][j];
		}
		a[i][m] = sum;
	}
	for(int i = 0; i <= m; i++){
		int sum = 0;
		for(int j = 0; j < n; j++){
			sum += a[j][i];
		}
		a[n][i] = sum;
	}
	for(int i = 0; i <= n; i++){
		cout << a[i][0];
		for(int j = 1; j <= m; j++)cout << ' ' << a[i][j];
		cout << '\n';
	}
	return 0;
}



Measured memory_bytes: 3244
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<set>

using namespace std;
set<int> memo;
int main() {
	int c, n, ans = 0;
	cin >> c >> n;
	vector<string> a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n / 2; i++) {
		for (int j = 0; j < n / 2; j++) {
			if (a[i][j] == a[i][n - 1 - j] && a[i][j] == a[n - 1 - i][j] && a[i][j] == a[n - 1 - i][n - 1 - j]);
			else {
				memo.insert(i*n + j);
			}
		}
	}
	if (memo.size() == 0)ans++;
	for (int h = 1; h < c; h++) {
		int d, dx[101], dy[101];
		cin >> d;
		for (int i = 0; i < d; i++) {
			cin >> dx[i] >> dy[i];
			dx[i]--; dy[i]--;
			if (a[dx[i]][dy[i]] == '0')a[dx[i]][dy[i]] = '1';
			else a[dx[i]][dy[i]] = '0';
			if (dx[i] >= n / 2)dx[i] = n - 1 - dx[i];
			if (dy[i] >= n / 2)dy[i] = n - 1 - dy[i];
		}
		for (int i = 0; i < d; i++) {
			if (a[dx[i]][dy[i]] == a[dx[i]][n - 1 - dy[i]] && a[dx[i]][dy[i]] == a[n - 1 - dx[i]][dy[i]] && a[dx[i]][dy[i]] == a[n - 1 - dx[i]][n - 1 - dy[i]]) {
				memo.erase(dx[i] * n + dy[i]);
				memo.erase((n - 1 - dx[i])*n + dy[i]);
				memo.erase(dx[i] * n + n - 1 - dy[i]);
				memo.erase((n - 1 - dx[i])*n + n - 1 - dy[i]);
			}
			else memo.insert(dx[i]*n+dy[i]);
		}
		if (memo.size() == 0)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13260
t1,t2 = map(int,input().split())
c1,c2 = map(int,input().split())
d1,d2 = map(int,input().split())
hosei = 0
if t1*c1>t1*d1:
    a1=c1
    a2=c2
    b1=d1
    b2=d2
else:
    a1,a2,b1,b2=d1,d2,c1,c2
if t1*a1+t2*a2 > t1*b1+t2*b2:
    print(0)
    exit()
elif t1*a1+t2*a2 == t1*b1+t2*b2:
    print("infinity")
else:
    # print((t1*(a1-b1))//(t2*(b2-a2)) + 1,t1*(a1-b1),t2*(b2-a2))
    if t2*(b2-a2) % (t2*(b2-a2)-t1*(a1-b1)) == 0:
        hosei = 1
    print((t2*(b2-a2)) // (t2*(b2-a2)-t1*(a1-b1))*2-1-hosei)
    # print((t2*(a2-b2)))

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#define Max zhi5968
typedef long long ll;
using namespace std;

int main ()
{
	int i;
	double n;
	cin>>n;
	for(i=n;i>=0;i--)
	{
		if((int)sqrt(i)*(int)sqrt(i)==i)
		{
			cout<<i<<endl;
			return 0;
		}
	} 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define MAXN 100001
#define LL long long int 
#define lowbit(x) ((x)&(-(x)))
using namespace std;
int P[MAXN];
int L[MAXN];
int SL[MAXN];
int SR[MAXN];
int R[MAXN];
int sev[MAXN];
int c[MAXN];
int n;
struct SGtree
{
	int l,r,lch,rch;
	int val1,val2;
}rt[MAXN*4];
int totr=0;
inline void push_up(int x)
{
	rt[x].val1=max(rt[rt[x].lch].val1,rt[rt[x].rch].val1); 
	rt[x].val2=min(rt[rt[x].lch].val2,rt[rt[x].rch].val2); 
}
inline void build(int l,int r)
{
	totr++;
	int x=totr;
	rt[x].l=l;
	rt[x].r=r;
	if(l==r)
	{
		rt[x].val1=0;
		rt[x].val2=n+1;
		return ;
	}
	int mid=(l+r)>>1;
	rt[x].lch=totr+1;
	build(l,mid);
	rt[x].rch=totr+1;
	build(mid+1,r); 
	push_up(x); 
}
inline void modify1(int x,int p,int val)
{
	if(p<rt[x].l||rt[x].r<p)return ;
	if(rt[x].l==rt[x].r)
	{
		rt[x].val1=val;
		return ;
	}
	modify1(rt[x].lch,p,val);
	modify1(rt[x].rch,p,val);
	push_up(x);
}

inline void modify2(int x,int p,int val)
{
	if(p<rt[x].l||rt[x].r<p)return ;
	if(rt[x].l==rt[x].r)
	{
		rt[x].val2=val;
		return ;
	}
	modify2(rt[x].lch,p,val);
	modify2(rt[x].rch,p,val);
	push_up(x);
}
inline int search1(int x,int l,int r)
{
	if(r<rt[x].l||rt[x].r<l)return 0;
	if(l<=rt[x].l&&rt[x].r<=r)return rt[x].val1;
	return max(search1(rt[x].lch,l,r),search1(rt[x].rch,l,r));
}
inline int search2(int x,int l,int r)
{
	if(r<rt[x].l||rt[x].r<l)return n+1;
	if(l<=rt[x].l&&rt[x].r<=r)return rt[x].val2;
	return min(search2(rt[x].lch,l,r),search2(rt[x].rch,l,r));
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&P[i]);
		sev[P[i]]=i;
	}
	P[n+1]=n+1;
	build(1,n+1);
	for(int i=1;i<=n;i++)
	{
		L[i]=search1(1,P[i],n);
		SL[i]=search1(1,P[L[i]]+1,n+1);
		SL[i]=max(SL[i],search1(1,P[i],P[L[i]]-1));
		if(L[i]==0)
			SL[i]=0;
		modify1(1,P[i],i);
	}
	for(int i=n;i>=1;i--)
	{
		R[i]=search2(1,P[i],n);
		SR[i]=search2(1,P[R[i]]+1,n+1);
		SR[i]=min(SR[i],search2(1,P[i],P[R[i]]-1));
		if(R[i]==n+1)
			SR[i]=n+1;
		modify2(1,P[i],i);
	}
//	cout<<SR[2]<<endl;
	
	LL ans=0;
	for(int i=1;i<=n;i++)
	{
		int x=sev[i];
		if(L[x]==0&&R[x]==n+1)
			continue;
		
		bool f=0;
		if(L[x]!=0)
		{
			ans+=(LL)i*(L[x]-SL[x]-1);
			ans+=(LL)i*(R[x]-x-1);
			ans+=(LL)(L[x]-SL[x]-1)*(R[x]-x-1)*i;
			ans+=(LL)i;
		}
		if(R[x]!=n+1)
		{
			ans+=(LL)i*(SR[x]-R[x]-1);
			ans+=(LL)i*(x-L[x]-1);
			ans+=(LL)(SR[x]-R[x]-1)*(x-L[x]-1)*i;
			ans+=(LL)i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10368
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	b = readline() |> split |> parseMap
	flg = 0
	ans = Int[]
	for i in 1:n
		if b[i] > i
			flg = 1
			break
		end
	end
	for i in 1:n
		t = length(b)
		for j in 0:t-1
			if b[t-j] == t-j
				t = t-j
				break
			end
		end
		if t == 0
			flg = 1
			break
		else
			push!(ans,t)
			deleteat!(b,t)
		end
	end
	if flg == 1
		println(-1)
	else
		for i in 0:n-1
			println(ans[n-i])
		end
	end
end
main()

Measured memory_bytes: 129276
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()
typedef complex<double> P;
typedef vector<P> VP;
struct L : array<P, 2>{
    L(const P& a, const P& b){ at(0)=a; at(1)=b; }
    L(){}
};
struct C{
    P p;
    double r;
    C(const P& p, const double& r) : p(p), r(r) {}
    C(){}
};

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}
P unit(const P &p){
    return p/abs(p);
}

double distanceLP(const L &l, const P &p) {
    return abs(cross(l[1]-l[0], p-l[0])) /abs(l[1]-l[0]);
}
double distanceSP(const L &s, const P &p) {
    if(dot(s[1]-s[0], p-s[0]) < EPS) return abs(p-s[0]);
    if(dot(s[0]-s[1], p-s[1]) < EPS) return abs(p-s[1]);
    return distanceLP(s, p);
}

int main(){
    while(1){
        double rr;
        int n;
        cin >> rr >> n;
        if(n==0) break;

        VP p(n);
        vector<double> r(n), v(n);
        for(int i=0; i<n; i++){
            int x,y;
            cin >> x >> y >> r[i] >> v[i];
            p[i] = P(x, y);
        }

        int rem = n;
        int ans = 0;
        vector<bool> used(n, false);
        while(rem > 0){
            for(int i=0; i<n; i++){
                if(used[i]) continue;
                if(abs(p[i]) -v[i] < rr +EPS){
                    used[i] = true;
                    rem--;
                    ans++;
                }
                p[i] += -unit(p[i])*v[i];
            }
            int nearest = -1;
            double dist = INF;
            for(int i=0; i<n; i++){
                if(used[i]) continue;
                if(abs(p[i]) < dist){
                    dist = abs(p[i]);
                    nearest = i;
                }
            }
            if(nearest == -1){
                break;
            }
            L ray(unit(p[nearest])*(rr +EPS), 1e6*p[nearest]);
            for(int i=0; i<n; i++){
                if(used[i]) continue;
                if(distanceSP(ray, p[i]) < r[i] +EPS){
                    used[i] = true;
                    rem--;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3276
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<iomanip>


int main(){
	int a, b, h, m;

	double pi= 3.1415926535897932384626;

	std::cin>>a>>b>>h>>m;

	double mDeg= 6*m;
	double hDeg= 30*h + 0.5*m;

	double deg= std::abs(mDeg- hDeg);

	if(deg>180)
		deg= 360-deg;

	double ans= std::sqrt(a*a + b*b - 2*a*b*std::cos(deg*pi/180.0));

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

	return 0;	

}

Measured memory_bytes: 4224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();

        int answer = 0;
        for (int i = a; i <= b; i++)
        {
            string s1 = i.ToString();
            string s2 = string.Join("", s1.Reverse());
            if (s1 == s2)
            {
                answer++;
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll k, a, b;
	cin >> k >> a >> b;
	if(b < a || k <= a){
		cout << (k+1) << endl;
		return 0;
	}

	ll d = k - a;
	ll ans;
	if(d % 2 == 0){
		ans = d / 2 * b - (d / 2 - 1) * a + 1;
	}else{
		ans = (d / 2 + 1) * b - d/2 * a;
	}

	ans = max(ans, k+1);
	cout << ans << endl;
}


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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
int main(){
    int n;
    cin>>n;
    
    vector<int> v(n);
    for(auto &a : v) cin>>a;
    int ren = 0;
    for(int i=0;i<n;++i){
        int count = 0;
        while(i+1<n and v[i] >= v[i+1]){
            count++;i++;
        }
        ren = max(ren,count);
    }
    cout << ren << endl;
    return 0;
}



Measured memory_bytes: 640
#if defined(__GNUC__)
#include <bits/stdc++.h>
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)

int indexDic(vector<int> v);
void digitFix(vector<int> &v, int num);

itn main() {
	std::ios::sync_with_stdio(false);

	int h, n;
  
  cin >> h >> n;
  vector<int> a(n);
  
  REP(i, n){
    cin >> a[i];
  }
  
  int s = ACM(a, 0);
  
  if(s >= h){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
  
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
 
using namespace std;
using ll = long long int;
 
int main(void) {
    int n; cin >> n;
    vector<int> a, b, c;
    a = b = c = vector<int>(n);
    REP(i, n) cin >> a[i] >> b[i] >> c[i];
    vector<vector<int>> dp(3, vector<int>(n + 1));
    dp[0][0] = a[0]; dp[1][0] = b[0]; dp[2][0] = c[0];
    for (int i = 1; i < n; i++) {
        dp[0][i] = a[i] + max(dp[1][i - 1], dp[2][i - 1]);
        dp[1][i] = b[i] + max(dp[2][i - 1], dp[0][i - 1]);
        dp[2][i] = c[i] + max(dp[0][i - 1], dp[1][i - 1]);
    }
    cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1])) << endl;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
  ll X,Y;
  cin>>X>>Y;
  if(Y%2==1)cout<<"No"<<endl;
  else if(2*X<=Y&&Y<=4*X)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include <memory.h>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cctype>
#include <cstring>
#include <climits>
#include <cmath>
#include <vector>
#include <string>
#include <memory>
#include <numeric>
#include <limits>
#include <functional>
#include <tuple>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>

using namespace std;

#define PROFILE_START(i)    clock_t start##i = clock()
#define PROFILE_STOP(i)     fprintf(stderr, "elapsed time (" #i ") = %f\n", double(clock() - start##i) / CLOCKS_PER_SEC)

// https://atcoder.jp/contests/abc149/tasks/abc149_e?fbclid=IwAR0nHOgZ-UygqFHB08BPLs_o3_6r5K2TB_Rd0fV3Ijhcru1aSaIaRQQjo4Y
// E - Handshake

typedef long long           ll;
typedef unsigned long long  ull;

vector<int> A;
vector<ll> S;

// (cnt, sum, min)
tuple<ll, ll, ll> calc(int x) {
    int N = int(A.size());

    ll cnt = 0;
    ll sum = 0;
    ll minX = numeric_limits<ll>::max();

    int j = N - 1;
    for (int i = 0; i < N; i++) {
        while (j >= 0 && (A[i] + A[j]) >= x)
            j--;

        if (j < N - 1) {
            minX = min(minX, 0ll + A[i] + A[j + 1]);
            sum += S[N] - S[j + 1] + 1ll * A[i] * (N - 1 - j);
            cnt += N - 1 - j;
        }
    }

    return make_tuple(cnt, sum, minX);
}

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

    int N;
    ll M;
    cin >> N >> M;

    A.resize(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];

    sort(A.begin(), A.end());
    N = int(A.size());

    S.resize(N + 1);
    for (int i = 0; i < N; i++)
        S[i + 1] = S[i] + A[i];

    int lo = 1, hi = A.back() * 2ll;
    while (lo <= hi) {
        int mid = lo + (hi - lo) / 2;

        auto t = calc(mid);

        if (get<0>(t) >= M)
            lo = mid + 1;
        else
            hi = mid - 1;
    }

    auto t = calc(hi);
    ll ans = get<1>(t) - get<2>(t) * (get<0>(t) - M);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());

    int cnt = 0;
    for(int i=0; i<n-1; ++i){
        if(a[i] == a[i+1])
            ++ cnt;
    }

    int ans = n - (cnt + 1) / 2 * 2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
    char s[5];
    scanf("%s", s);
    for(int i = 0; i < 3; i++){
        if(s[i] == s[i + 1]){
            printf("Bad\n"); 
            return 0;
        }
    }
    printf("Good\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h> 
#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 REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	string s; CI s;
	int k; CI k;
	vector<string> vs;

	if (s.size() == 1) { CO s EN; return 0;}

	int tmp = s.length();

	REP(i, s.length()) {
		FOR(j,1, k) {
			vs.push_back(s.substr(i,j));
		}
	}

	sort(all(vs));
	vs.erase(unique(vs.begin(), vs.end()), vs.end());

	CO vs[k-1] EN;

	return 0;
}

Measured memory_bytes: 1660
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Anirudh Rayabharam
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        MultipleClocks solver = new MultipleClocks();
        solver.solve(1, in, out);
        out.close();
    }

    static class MultipleClocks {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long ans = -1;
            while (n-- > 0) {
                long t = in.nextLong();
                if (ans == -1) ans = t;
                else if (t % ans == 0) ans = t;
                else if (ans % t == 0) {
                } else ans = lcm(ans, t);
            }
            out.println(ans);
        }

        private long lcm(long a, long b) {
            long g = gcd(a, b);
            return (a / g) * b;
        }

        private long gcd(long a, long b) {
            while (b != 0) {
                long t = b;
                b = a % b;
                a = t;
            }
            return a;
        }

    }

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

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 22996
import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {
    val rownum = StdIn.readInt

    var maxv = -2000000000
    var minv = StdIn.readInt

    for (i <- 2 to rownum) {
      val c = StdIn.readInt
      if (maxv < c - minv) maxv = c - minv
      if (c < minv) minv = c
    }

    println(maxv)

  }
}

Measured memory_bytes: 63212
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class dice{
public:
	int a, b, c, d, e, f;
	int g, h, i, j, k, l;
	void east() {
		prep();
		a = j;
		b = h;
		c = g;
		d = l;
		e = k;
		f = i;
	}
	void west() {
		prep();
		a = i;
		b = h;
		c = l;
		d = g;
		e = k;
		f = j;
	}
	void north() {
		prep();
		a = h;
		b = l;
		c = i;
		d = j;
		e = g;
		f = k;
	}
	void south() {
		prep();
		a = k;
		b = g;
		c = i;
		d = j;
		e = l;
		f = h;
	}
private:
	void prep() {
		g = a;
		h = b;
		i = c;
		j = d;
		k = e;
		l = f;
	}
};
int main() {
	dice dice1;
	cin >> dice1.a;
	cin >> dice1.b;
	cin >> dice1.c;
	cin >> dice1.d;
	cin >> dice1.e;
	cin >> dice1.f;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++){
		if (s[i] == 'N'){
			dice1.north();
		}
		else if (s[i] == 'E'){
			dice1.east();
		}
		else if (s[i] == 'W'){
			dice1.west();
		}
		else if (s[i] == 'S'){
			dice1.south();
		}
	}
	cout << dice1.a << endl;
	char c;
	cin >> c;
}

Measured memory_bytes: 3196
import math

N, L = (int(i) for i in input().split())

apple_tastes = [L + i - 1 for i in range(1, N + 1)]
sum_apple_tastes = sum(apple_tastes)
should_eat_apple_index = 0


def sum_up_apple_tastes_without_index(index):
    """sum up apple tastes without index"""
    copy = apple_tastes.copy()
    del copy[index]
    return sum(copy)


def abs_diff_sum_of_apple_tastes(index):
    """diff between sum of all tastes and sum of target """
    return math.fabs(
        sum_up_apple_tastes_without_index(index) -
        sum_apple_tastes
    )


for i, taste in enumerate(apple_tastes):
    current_diff = abs_diff_sum_of_apple_tastes(i)
    acc_diff = abs_diff_sum_of_apple_tastes(should_eat_apple_index)
    if (current_diff < acc_diff):
        should_eat_apple_index = i


result = int(sum_up_apple_tastes_without_index(should_eat_apple_index))
print(result)


Measured memory_bytes: 3064
import math

N,D= map(int,input().split())

X = [list(map(int,input().split())) for _ in range(N)]
ans_p = 0

for i in range(N-1):
    for j in range(i+1,N):
        ans = 0
        for k in range(D):

            ans += (X[i][k] - X[j][k])**2
    
        ans = math.sqrt(ans)
        if(ans%1 == 0):
            ans_p += 1

print(ans_p)

Measured memory_bytes: 38488
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

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


	    int N=gi();
	    Map<Integer, Long> m=new HashMap<Integer, Long>();

        for (int i=1; i<=N; i++) {
        	List<Integer> l=insuB(i);
            for (Integer n : l) {
            	if (m.containsKey(n)) {
            		m.put(n, m.get(n)+1);
            	} else {
            		m.put(n, 1l);
            	}
            }
        }
        
        long ans =1;
        for (Map.Entry<Integer, Long> e : m.entrySet()) {
        	ans*=(e.getValue()+1);
        	ans=ans%1000000007;
        }

        System.out.println(ans);

//        if(ans==0) {
//
//		    System.out.println("Yes");
//        } else {
//        	System.out.println("No");
//
//        }
	}

	public static List<Integer> insuB(int n) {
		List<Integer> l=new ArrayList<Integer>();
		int i=2;
		while(n!=1) {
			if (n%i==0) {
				l.add(i);
				n/=i;
			} else {
				i++;
			}
		}
		return l;
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 36356
import math


def div(x):
    divs = []
    divs_append = divs.append
    for i in range(1, int(math.sqrt(x)) + 1):
        if x % i == 0:
            divs_append(i)
            if i != x // i:
                divs_append(x // i)

    return set(divs)


def is_prime(x):
    if x == 1:
        return False
    for i in range(2, int(math.sqrt(x)) + 1):
        if x % i == 0:
            return False
    return True


A, B = map(int, input().split())
print(len([x for x in div(A) & div(B) if is_prime(x)]) + 1)

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500*a + 100*b + 50*c; // 合計金額
        if (total == X) ++res; // 合計金額が X に一致したら答えをインクリメント
      }
    }
  }
  cout << res << endl;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int x;
  Solver(LL x) : x(x){};

  void solve() {
    for (int i = 0; i <= x / 100; ++i) {
      int r = i * 5;
      if (i * 100 <= x and x <= i * 100 + r) {
        cout << 1 << endl;
        return;
      }
    }
    cout << 0 << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 256
from collections import Counter


def main():
    n = int(input())
    s = (input() for i in range(n))
    d = Counter(s)
    num = d.most_common(1)[0][1]
    ans = sorted(j[0] for j in d.items() if j[1] == num)
    for i in ans:
        print(i)

main()

Measured memory_bytes: 35548
#include <iostream>
using namespace std;
int main()
{
    int n,a[100005],fr[100005],maxx=0;
    cin >> n;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    fr[1]=0;
    for (int i=2;i<=n;i++)
    {
        if (a[i]<=a[i-1]) fr[i]=fr[i-1]+1;
        else fr[i]=0;
    }
    for (int i=1;i<=n;i++)
    {
        maxx=max(fr[i],maxx);
    }
    cout << maxx;
}

Measured memory_bytes: 1024
class RangeMinimumQuery(object):

    def __init__(self, size):
        self.size = 1
        while self.size < size:
            self.size *= 2
        self.data = [float("inf") for _ in xrange(self.size*2+2)]

    def update(self, idx, value):
        k = idx + self.size - 1
        self.data[k] = value
        while k > 0:
            k = (k - 1) / 2
            self.data[k] = min(self.data[k*2+1], self.data[k*2+2])

    def find(self, start, end):
        def query(k, left, right):
            if right <= start or end <= left:
                return float("inf")
            if start <= left and right <= end:
                return self.data[k]
            vl = query(k*2+1, left, (left+right)/2)
            vr = query(k*2+2, (left+right)/2, right)
            return min(vl, vr)
        return query(0, 0, self.size)


def main():
    n, q = map(int, raw_input().split())
    inf = (1 << 31) - 1
    rmq = RangeMinimumQuery(n)
    for _ in xrange(q):
        com, x, y = map(int, raw_input().split())
        if com == 0:
            rmq.update(x, y)
        else:
            v = rmq.find(x, y+1)
            print v if v != float("inf") else inf

if __name__ == "__main__":
    main()

Measured memory_bytes: 13240
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;

            string[] s = Console.ReadLine().Split(' ');

            int A = int.Parse(s[0]);
            int B = int.Parse(s[1]);

            if(A > 12)
            {
                Console.WriteLine(B.ToString());
                return;
            }
            else if(A>5)
            {
                Console.WriteLine((B / 2).ToString());
                return;
            }
            else
            {
                Console.WriteLine("0");
            }


        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    ll ans=1LL<<60;
    for(ll i=-100;i<=100;i++){
        ll tmp=0;
        rep(j,n){
            tmp+=abs(i-a[j])*abs(i-a[j]);
        }
        ans=min(ans,tmp);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, k;
    cin >> n >> k;

    vl h(n);
    rep(i, n) {
        cin >> h[i];
    }

    vl dp(n, INF);  // dp[i] : 足場iにたどりつく最小コスト
    dp[0] = 0;
    rep(i, n) {
        exrep(j, 1, k) {
            if(i+j < n) {
                chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
            }
        }
    }
    
    out(dp[n-1]);
    re0;
}

Measured memory_bytes: 1792
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  ll N,M,X; cin>>N>>M>>X;
  vector<pair<ll,vector<ll>>> mat(N);
  rep(i,N){
    vector<ll> v(M);
    ll a;
    cin>>a;
    rep(j,M) cin>>v[j];
    mat[i] = make_pair(a,v);
  }
  struct Info{
    ll book;
    bool buy;
    ll total;
    bool chk;
  };
  stack<Info> stk;
  ll depth=0;
  vector<ll> b(M);
  ll ans = numeric_limits<ll>::max();
  stk.push({0,false,0,false});
  stk.push({0,true,0,false});
  while(!stk.empty()){
    auto &p = stk.top();
    if(p.buy){
      if(p.chk){
        stk.pop();
        rep(i,M){
          b[i]-=mat[p.book].second[i];
        }
        continue;
      }else{
        p.chk=true;
        p.total += mat[p.book].first;
        bool f=true;
        rep(i,M){
          b[i]+=mat[p.book].second[i];
          f &= b[i] >= X;
        }
        if(f){
          ans = min(ans,p.total);
          continue;
        }
      }
    }else{
      if(p.chk){
        stk.pop();
        continue;
      }else{
        p.chk=true;
      }
    }
    if(p.book >= N-1) continue;
    stk.push({p.book+1,true,p.total,false});
    stk.push({p.book+1,false,p.total,false});
  }
  if(ans == numeric_limits<ll>::max()) ans = -1;
  cout<<ans<<endl;
}

Measured memory_bytes: 3564
object Main {
  def main(args: Array[String]): Unit = {
    val str = scala.io.StdIn.readLine
    var flg = true
    var upper_count = 0

    if(str.head != 'A') flg = false

    for( i <- 1 to str.length - 1) {
      if( str(i).isUpper ) {
        if( i == 1 || i == str.length - 1 || str(i) != 'C') {
          flg = false
        }
        upper_count += 1
      }
    }

    if(upper_count != 1) flg = false


    if(flg) println("AC")
    else    println("WA")

  }
}

Measured memory_bytes: 25416
import heapq,sys
r=sys.stdin.readline
def g(n,E,S,G):
 F=[1e7]*-~n;F[S]=0;H=[(0,S)]
 while H:
  c,u=heapq.heappop(H)
  if u==G:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:F[v]=t;heapq.heappush(H,(t,v))
 return-1
def s(n,k):
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=r();p=map(int,f[2:].split())
  if'0'==f[0]:print(g(n,E,*p))
  else:c,d,e=p;E[c]+=[(e,d)];E[d]+=[(e,c)]
for e in iter(r,'0 0\n'):s(*map(int,e.split()))


Measured memory_bytes: 6308
function main(lines) {
    const input = lines.split(' ').map(Number)
    const A = input[0]
    const B = input[1]
    const C = input[2]
    const X = input[3]
    const Y = input[4]
    
    let output = []
    for(let i=0; i<=Math.pow(10,5);i++){
        let cost = 2*C*i + A*Math.max(X-i,0) + B*Math.max(Y-i,0)
        output.push(cost)
    }
    console.log(output.sort(function(a,b){return a-b;})[0])
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



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

const int N=600;
pair<int,int>a[N];
int b[N*N],n;
void gofail(){cout<<"No\n";exit(0);}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i].first,a[i].second=i,b[a[i].first]=i;
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i){
		int les=a[i].second-1;
		for(int j=1;j<a[i].first&&les;++j)
			if(!b[j])b[j]=a[i].second,--les;
		if(les)gofail();
	}
	for(int i=n;i;--i){
		int les=n-a[i].second;
		for(int j=n*n;j>a[i].first&&les;--j)
			if(!b[j])b[j]=a[i].second,--les;
		if(les)gofail();
	}
	cout<<"Yes\n";
	for(int i=1;i<=n*n;++i)
		cout<<b[i]<<" \n"[i==n*n];
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int n, q;
vector<int> G[200005];
vector<ll> c(200005, 0), ans(200005, 0);

void dfs(int from, int now, ll score){
    score += c[now];
    ans[now] = score;

    for(auto to:G[now]){
        if(to != from){
            dfs(now, to, score);
        }
    }
}


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

    cin >> n >> q;

    for(int i=0; i<n-1; ++i){
        int a,b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for(int i=0; i<q; ++i){
        int p, x; cin >> p >> x;
        c[p] += x;
    }

    // dfs
    dfs(-1, 1, 0);

    for(int i=1; i<=n; ++i){
        if(i > 1) cout << ' ';
        cout << ans[i];
    }
    cout << endl;
    
    return 0;
}



Measured memory_bytes: 25856
n = int(input())
a_list = list(map(int, input().split()))
new_list = [] 

for i in range(0, n):
    if a_list[i] % 2 == 0:
        new_list.append(a_list[i])

if all(elem % 3 == 0 or elem % 5 == 0 for elem in new_list):
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <cstdio>

#include <array>
#include <algorithm>

#include <iostream>

using namespace std;

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

	array<int, 4> N{};

	cin >> N[0] >> N[1] >> N[2] >> N[3];

	for( int i = 0; i < N[0]; i++ )
	{
		int x{};
		cin >> x;
		N[2] = max( N[2], x );
	}

	for( int i = 0; i < N[1]; i++ )
	{
		int y{};
		cin >> y;
		N[3] = min( N[3], y );
	}

	if( N[2] < N[3] )
	{
		cout << "No War" << "\n";
	}
	else
	{
		cout << "War" << "\n";
	}
}


Measured memory_bytes: 256