akhauriyash/Code-Regression huggingface dataset:
// #define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,m; cin >> n >> m;
    cout << (n <= m ? "unsafe" : "safe") << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
const int N=1000005,E=262144;
const int M=998244353;
int n,m,i,j,s,a[N];
char c[N];
bool flag;
int main()
{
	scanf("%d",&n);
	scanf("%s",c);
	--n;
	for(i=0;i<n;++i)
	{
		a[i]=abs(c[i]-c[i+1]);
		if(a[i]==1)
			flag=true;
	}
	if(flag)
	{
		for(i=0;i<n;++i)
		{
			a[i]&=1;
			if(((n-1)&i)==i)
				s^=a[i];
		}
		cout<<s;
	}
	else
	{
		for(i=0;i<n;++i)
			if(((n-1)&i)==i)
				s^=a[i];
		cout<<s;
	}
}


Measured memory_bytes: 5120
#include <iostream>
#include <stack>
#include <cstdio>
using namespace std;


void inputline(char *buf,int linesize){
	cin.getline(buf,linesize);
}

void resolve(char *buf,int maxlength,stack<int> *s){
	int x,y,i=0;
	sscanf((buf+i),"%d",&x);
	s->push(x);
	//cout << x << endl;
	while(*(buf+i)!=' ' && *(buf+i)!='\0' && i<maxlength)
		i++;
	while(*(buf+i)!='\0'){
		i++;
		if(*(buf+i)=='+'){
			y=s->top();
			s->pop();
			x=s->top();
			s->pop();
			s->push(x+y);
		}else if(*(buf+i)=='-'){
			y=s->top();
			s->pop();
			x=s->top();
			s->pop();
			s->push(x-y);
		}else if(*(buf+i)=='*'){
			y=s->top();
			s->pop();
			x=s->top();
			s->pop();
			s->push(x*y);
		}else{
			sscanf((buf+i),"%d",&x);
			s->push(x);
			//cout << x << endl;
		}
		while(*(buf+i)!=' ' && *(buf+i)!='\0' && i<maxlength)
			i++;
	}
}

int printnum(stack<int> *s){
	cout << s->top() << endl;
	s->pop();
	return 0;
}

int main() {
	const int lineSize=1024;
	char inBuff[lineSize];
	stack<int> S;

	inputline(inBuff,lineSize);
	resolve(inBuff,lineSize,&S);
	printnum(&S);

	return 0;
}



Measured memory_bytes: 3180
/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#ifdef LOCAL
#include "debug.h"
#else
#include<bits/stdc++.h>
using namespace std;
#define debug(x...)
#endif
 
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> 
using ordered_set= tree<T, null_type, 
		less<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
template<class T> 		
using ordered_mset= tree<T, null_type, 
		less_equal<T>, 
		rb_tree_tag, tree_order_statistics_node_update> ;
		
*/
 
/*
 
PBDS
-------------------------------------------------
			0 based indexing
-------------------------------------------------			 
1) insert(value)
2) erase(value)
3) order_of_key(value) // Number of items strictly smaller than value
4) *find_by_order(k) : K-th element in a set (counting from zero)
 
*/
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());		

void solve()
{
	string a,b;
	cin>>a>>b;
	
	int n=a.size();
	int m=b.size();
	
	assert(n>=m);
	
	int ans=m+2;
	
	for(int i=0;i+m<=n;i++)
	{
		string c=a.substr(i,m);
		int temp=0;
		for(int j=0;j<m;j++) temp+=(int)(b[j]!=c[j]);
		ans=min(ans,temp);
		debug(c);
	}
	
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int testcase=1;
	//cin>>testcase;
	
	for(int i=1;i<=testcase;i++)
	{
		//cout<<"Case "<<i<<": ";
		solve();
	}
	
	#ifdef LOCAL
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	#endif
	
	
	return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)

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

using namespace std;
using ll=long long;

ll t[4010],p[4010],f[4010];
ll dp[4010][4010],ca[4010][4010],cb[4010][4010];

int deq[4010][4010],head[4010],tail[4010]; 

inline ll sq(ll n){return n*n;}

inline bool check(int base,int i,int j,int k){return (cb[base][j]-cb[base][i])*(ca[base][k]-ca[base][j])<=(cb[base][k]-cb[base][j])*(ca[base][j]-ca[base][i]);}
inline ll func(int base,int idx,ll x){return 1LL*ca[base][idx]*x+cb[base][idx];}

int main(void){
	ll N,T;
	cin >> N >> T;

	vector<tuple<ll,ll,ll>> ary(N);
	rep(i,N){
		ll tt,pp,ff;
		cin >> tt >> pp >> ff;
		ary[i]=make_tuple(ff,tt,pp);
	}

	sort(_all(ary));
	rep(i,N) tie(f[i],t[i],p[i])=ary[i];


	rep(i,1,N+1)rrep(j,T+1,t[i-1]){
		bool ok=true;
		if(j==t[i-1]){
			chmax(dp[i][j],p[i-1]);
		}else if(j>t[i-1]){
			const int base=j-t[i-1];
			if(tail[base]-head[base]==0) ok=false;
			while(tail[base]-head[base]>=2 && func(base,deq[base][head[base]],f[i-1])<= func(base,deq[base][head[base]+1],f[i-1]) ) head[base]++;
			if(ok) chmax(dp[i][j],p[i-1]-sq(f[i-1])+func(base,deq[base][head[base]],f[i-1]));
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}

		if(ok==false) continue;
		const int base=j;
		ca[base][i-1]=2LL*f[i-1],cb[base][i-1]=-sq(f[i-1])+dp[i][j];
		while(tail[base]-head[base]>=2 && check(base,deq[base][tail[base]-2],deq[base][tail[base]-1],i-1)) tail[base]--;
		deq[base][tail[base]++]=i-1;
	}

	ll ans=0LL;
	rep(i,N+1) rep(j,T+1) chmax(ans,dp[i][j]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 367244
N=int(input())
L=[11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381, 1451, 1471, 1481, 1511, 1531, 1571, 1601, 1621, 1721, 1741, 1801, 1811, 1831, 1861, 1871, 1901, 1931, 1951, 2011, 2081, 2111, 2131, 2141, 2161, 2221, 2251, 2281, 2311, 2341, 2351, 2371, 2381, 2411, 2441]
st=""
for i in range(N):
    st+=str(L[i])
    if i!=N-1:
        st+=" "
print(st)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
  
  int A,B,C,D;
   int min = 0;
    int minT = 0;
    int minB = 0;
  scanf("%d%d%d%d",&A,&B,&C,&D);
  
   
      if(A>=B){
        minT = B;
      }else{
        minT = A;
      }
      
      if(C>=D){
        minB = D;
      }else{
        minB = C;
      }
      min = minT+minB;
      
      printf("%d%s",min,"\n");
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n, k; cin>>n>>k;
    vector<ll> h(n+1, 0);
    for(int i=0; i<n; i++) cin>>h[i+1];

    vector<vector<ll>> dp(n+1, vector<ll>(n+1, INF));
    dp[0][0] = 0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=i; j++){
            for(int l=0; l<i; l++){
                chmin(dp[i][j], dp[l][j-1] + max(0LL, h[i] - h[l]));
            }
        }
    }

    ll ans = INF;
    for(int i=0; i<=n; i++){
        chmin(ans, dp[i][n-k]);
    }

    cout << ans << endl;

    return 0;
}

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, k;
string s;

int qp(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1) res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}

int C(int a, int b)
{
	int res = 1;
	for (int i = a; i > a - b; i -- ) res = res * i;
	for (int i = 1; i <= b; i ++ ) res = res / i;
	return res;
}

int main()
{
	cin >> s >> k;
	n = s.size();
	
	int res = 0;
	for (int i = 1; i < n; i ++ )
		if (i >= k)
			res += C(i - 1, k - 1) * qp(9, k);
	
	vector<int> num;
	for (int i = 0; i < n; i ++ ) num.PB(s[i] - '0');
	
	// cout << res << endl;
	
	int last = 0;
	for (int i = 0; i < n; i ++ )
	{
		int x = num[i];
		
		if (x)
		{
			if (i) res += C(n - i - 1, k - last) * qp(9, k - last);
			last ++ ;
			res += (x - 1) * C(n - i - 1, k - last) * qp(9, k - last);
		}
		
		// cout << res << endl;
		
		if (last == k)
		{
			res ++ ;
			break;
		}
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,k=MI()
ans=k*(k-1)**(n-1)
print(ans)

Measured memory_bytes: 3316
#include<stdio.h>
int main()
{
    int N;
    double m;
    scanf("%d",&N);
    if (N%2==0)
        {
        m=N/2;
    printf("%.10lf",m/N);
        }
     else if (N%2!=0)
     {


         m=(N/2)+1;
    printf("%.10lf",m/N);
}
}

Measured memory_bytes: 1724
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

template<class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//--------------------------- Solve ---------------------------//

int d[105][105];

const int INF = 1000000000;

void solve() {
    int H, W; cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; i++) cin >> s[i];

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            d[i][j] = INF;
        }
    }
    
    if (s[0][0] == '#') d[0][0] = 1;
    else d[0][0] = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            // 右へ
            int to_right = INF;
            if (j+1 < W) {
                if (s[i][j] == '.' && s[i][j+1] == '#') to_right = d[i][j] + 1;
                else to_right = d[i][j];
                chmin(d[i][j+1], to_right);
            }
            // 下へ
            int to_under = INF;
            if (i+1 < H) {
                if (s[i][j] == '.' && s[i+1][j] == '#') to_under = d[i][j] + 1;
                else to_under = d[i][j];
                chmin(d[i+1][j], to_under);
            }
        }
    }

    cout << d[H-1][W-1] << '\n';
}

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

    solve();

    return 0;
}

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

int main() {
  double a, b, x, theta;
  cin >> a >> b >> x;

  if (x > a * a * b / 2) {
    theta = atan(2 * (a * a * b - x) / (a * a * a));
  } else {
    theta = atan((a * b * b) / (2 * x));
  }

  double PI = 3.14159265358979;
  theta = theta * 180 / PI;
  cout << fixed << setprecision(10) << theta;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define Max 10000

int main(){
  int i,j,count,n,q,S[Max],T[Max];
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  count=0;

   for(i=0;i<q;i++){
      S[n]=T[i];
      for(j=0;j<=n;j++){
      if(j==n) break;
      else if(S[j]==T[i]){
        count++;
        break;
      }
    }
    }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 644
from collections import deque
import sys

N, u, v = map(int,input().split())
side = [[]for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    side[a-1].append(b-1)
    side[b-1].append(a-1)
node = [[-1,-1,-1]for i in range(N)]
node[v-1] = [0,v-1,-1]
queue = deque([v-1])
leaf = []
while queue:
    q = queue.popleft()
    hoge = 0
    for i in side[q]:
        if node[i][0] == -1:
            node[i][0] = node[q][0]+1
            node[i][1] = q
            queue.append(i)
            hoge += 1
    if hoge == 0:
        node[q][2] = node[q][0]
        leaf.append(q)

leaf.sort(key = lambda x:node[x][0], reverse=True)
for x in leaf:
    while x != v-1:
        if node[node[x][1]][2] < node[x][2]:
            node[node[x][1]][2] = node[x][2]
            x = node[x][1]
        else:
            x = v-1

u -= 1
turn = 0
while 1:
    turn += 1
    if node[node[u][1]][0] > turn:
        u = node[u][1]
    else:
        next = node[u][1]
        node[node[u][1]][2] = 0
        for i in side[u]:
            if node[i][2] > node[next][2]:
                next = i
        u = next
    if node[u][0] < turn:
        break

print(node[u][0])

Measured memory_bytes: 35028
n, k = map(int, input().split())
hlist = []
for _ in range(n):
  hlist.append(int(input()))

shlist = sorted(hlist)
result = 1000000000
for i in range(n-k+1): # 5-3 = 2 = 0,1,2
  sa = abs(shlist[i] - shlist[i+k-1])
  if result > sa:
    result = sa

print(result)

Measured memory_bytes: 8280
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 1 << 29;	// 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策


void solve()
{
	const int MAX_N = 100000, MAX_M = 100000;
	int N, M;
	int L[MAX_M + 1], R[MAX_M + 1];
	cin >> N >> M;
	FOR(i, 0, M) {
		cin >> L[i] >> R[i];
	}

	int L_max = 1;
	int R_min = N;
	FOR(i, 0, M) {
		if (L[i] > L_max) {
			L_max = L[i];
		}
		if (R[i] < R_min) {
			R_min = R[i];
		}
	}
	int ans = R_min - L_max + 1;
	if (ans < 0) ans = 0;

	/*
	int ANS[MAX_N];
	FOR(i, 0, N) {
		ANS[i] = 1;
	}
	FOR(i, 0, M) {
		for (int j = 0; j < L[i]; j++) {
			ANS[j] = 0;
		}
		for (int j = R[i] + 1; j < N; j++) {
			ANS[j] = 0;
		}
	}

	int ans = 0;
	FOR(i, 0, N) {
		if (ANS[i] == 1) {
			ans++;
		}
	}
	*/

	cout << ans << endl;
}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<set<ll>> vsll;
typedef set<pair<ll, ll>> spll;
typedef vector<spll> vspll;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }
#define round(x, y) ((2 * x + y) / (2 * y))
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))
 
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
template <typename T = ll>
vector<T> ga(ll n, bool oneIndexed = false) {
    vector<T> a = vector<T>(n + oneIndexed);
 
    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }
 
    return move(a);
}
 
template <typename T, typename A>
void pa(vector<T, A> const &a, ll begin = 0, ll end = -1) {
    if (end == -1)
        end = sz(a) - 1;
    for (ll i = begin; i <= end; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
}
 
void solve() {
    ll n,k;
    cin >>n>>k;
    v data(n);
    data=ga(n);
    sort(all(data));
    ll sum=0;
    for(ll i=0;i<n-k;i++)
    {
        sum+=data[i];
    }
    cout << sum <<"\n";

}
 
int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // freopen("file", "r", stdin);
    // freopen("file", "w", stdout);

    solve();
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include<string>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn=1e5+4;
struct p{
	int v;
	int num;
};
bool cmp(p x,p y){
	return x.num>y.num;
}
p appr[2][maxn];
int main(){
    int n;
    while(cin>>n){
    	int i,j;
    	for(i=1;i<=maxn;i++){
    		appr[0][i].num=appr[1][i].num=0;
    		appr[0][i].v=appr[1][i].v=i;
		}
    	for(i=1;i<=n;i++){
    		int t;
    		scanf("%d",&t);
    		appr[i%2][t].num++;
		}
		sort(appr[0]+1,appr[0]+maxn,cmp);
		sort(appr[1]+1,appr[1]+maxn,cmp);
		int ans=0;
		if(appr[0][1].v!=appr[1][1].v){
			ans=n-appr[0][1].num-appr[1][1].num;
		}
		else{
			if(appr[0][1].num+appr[1][2].num>appr[1][1].num+appr[0][2].num)
				ans=n-(appr[0][1].num+appr[1][2].num);
			else
				ans=n-(appr[1][1].num+appr[0][2].num);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb       push_back
#define mp       make_pair
#define mod      1000000007
#define pi       acos(-1.0)
#define test     int t;cin>>t;while(t--)
typedef long long ll;
using namespace std;
int a[28],b[28];

int main()
{      
     ios::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
  
      int n;
      cin>>n;
      vector<pair<int,int>>v;
      int x,y;
      for(int i=0;i<n;i++)
      {
         cin>>x>>y;
         v.push_back(make_pair(x,y));
      }
      for(int i=0;i<n-2;i++)
      {
          if(v[i].first==v[i].second)
          {
             if((v[i+1].first==v[i+1].second)&&(v[i+2].first==v[i+2].second))
             {
                cout<<"Yes"<<endl;
                return 0;
             }
          }

      }

      cout<<"No"<<endl;

      return 0;
      
 }       

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
int check(int x) 
{
	 for(register int i=0;i<n-1;i++) 
	 {
	 	if((a[n+i]>x&&a[n+i+1]>x)||(a[n-i]>x&&a[n-i-1]>x)) return 0;
	 	else if((a[n+i]<=x&&a[n+i+1]<=x)||(a[n-i]<=x&&a[n-i-1]<=x)) return 1;
	 }
	 return a[1]<=x;
}
int main() 
{
	scanf("%d",&n);
	for(register int i=1;i<=2*n-1;i++)
	{
		scanf("%d",&a[i]);
	}
	int ans=0;
	int l=0,r=2*n-1;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid))
		{
			r=mid-1;
			ans=mid;
		}
		else 
		{
			l=mid+1;
		}
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 1024
a,b=map(int,input().split())

sum = 0

if a == 1:
  sum = sum + 300000
elif a == 2 :
  sum = sum + 200000
elif a == 3 :
  sum = sum + 100000
  
if b == 1:
  sum = sum + 300000
elif b == 2 :
  sum = sum + 200000
elif b == 3 :
  sum = sum + 100000
  
if a == 1 and b == 1:
  print(1000000)
else:
  print(sum)

Measured memory_bytes: 3064
use std::fs;
use std::io::{stdin, Read};
struct UnionFind {
    parents: Vec<usize>,
}
impl UnionFind {
    pub fn new(n: usize) -> Self {
        let par = (0..n).collect();
        UnionFind { parents: par }
    }
    pub fn root(&mut self, x: usize) -> usize {
        if self.parents[x] == x {
            return x;
        }
        let par = self.parents[x];
        self.parents[x] = self.root(par);
        self.parents[x]
    }
    pub fn union(&mut self, x: usize, y: usize) {
        let rx = self.root(x);
        let ry = self.root(y);
        if rx == ry {
            return;
        }
        self.parents[rx] = ry;
    }
    pub fn is_same(&mut self, x: usize, y: usize) -> bool {
        let rx = self.root(x);
        let ry = self.root(y);
        rx == ry
    }
}

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, m): (usize, usize) = parse!(it, 2);
    let p: Vec<usize> = parse!(it, n);
    let mut uf = UnionFind::new(n);
    for _ in 0..m {
        let (x, y): (usize, usize) = parse!(it, 2);
        uf.union(x - 1, y - 1);
    }
    let mut ret = 0;
    for i in 0..n {
        if uf.root(p[i] - 1) == uf.root(i) {
            ret += 1;
        }
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 8444
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

typedef long long ll;

int main(void)
{
    long long x;
    cin >> x;

    /*
    REP(i, 1000)
    {
        long long a, b;
        a = 1;
        b = 1;
        REP(j, 5)
        {
            a *= i;
            b *= i - 1;
        }
        if (a - b > 1e9)
        {
            cout << i << " " << a - b;
            break;
        }
    }
    */
    REP(i, 125)
    {
        rep(j, -125, 125)
        {
            long long tmp = pow(i, 5) - pow(j, 5);
            if (tmp == x)
            {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3940
s = input()
n = len(s)-1
h = ["2" , "4" , "5" , "7" , "9"]
p  = ["0" , "1" , "6" , "8"]
if s[n] in h:
    print("hon")
elif s[n] in p:
    print("pon")
elif s[n] == "3":
    print("bon")


Measured memory_bytes: 9040
n, m = gets.split.map(&:to_i)
d = []
h = []
n.times{ d << gets.to_i }
m.times{ h << gets.to_i }
dp = Array.new(2){ Array.new(m, 1<<31) }
table = Array.new(n){ Array.new(m) }
n.times do |i|
  m.times do |j|
    table[i][j] = d[i] * h[j]
  end
end
m.times{ |i| dp[0][i] = table[0][i] }
(0...n-1).each do |j|
  (j..m-n+j+1).each do |k|
    (k+1..m-n+j+1).each do |i|
      dp[j%2^1][i] = [dp[j%2^1][i], dp[j%2][k] + table[j+1][i]].min
    end
  end
  dp[j%2].fill(1<<31)
end
p dp[n%2^1][n-1..-1].min

Measured memory_bytes: 15084
#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>
#include<random>
#include<ctime>
using namespace std;

const long long int mod=998244353;
const long long int INF=99999999999999999;

long long int n,m,sum[3300]={},sum2[3300]={},res=0,d[100005];
string str;
int main() {
	cout << fixed << setprecision(10);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>d[i];
        sum[d[i]]++;
        sum2[d[i]]++;
    }
    for(int i=1;i<=1002;i++){
        sum[i+1]+=sum[i];
    }
    for(int i=1002;i>=0;i--){
        sum2[i]+=sum2[i+1];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            long long int tmp=n;
            if(d[i]+d[j]<=1000){
                tmp-=sum2[d[i]+d[j]];
            }
                tmp-=sum[abs(d[i]-d[j])];
            if(abs(d[i]-d[j])<d[i]&&d[i]<d[i]+d[j]){tmp--;}
            if(abs(d[i]-d[j])<d[j]&&d[j]<d[i]+d[j]){tmp--;}
            res+=tmp;
            //cout<<sum2[d[i]+d[j]]<<" "<<sum[abs(d[i]-d[j])+1]<<" "<<tmp<<endl;
        }

    }
    cout<<res/3;
} 


Measured memory_bytes: 256
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn main()
{
    let mut n:usize;
    input!(n);
    let mut flag=true;
    while n>0{
        if n%10==9{
            flag=false;
        }
        n/= 10;
    }
    if flag{
        println!("No")
    }else{
        println!("Yes");
    }
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int a;
	cin >> a;
	int ans = 0; int b = a;
	ans += a;
	b *= a;
	ans += b;
	b *= a;
	ans += b;
	cout << ans;
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long int
#define forr(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define oo 100000000000000000
using namespace std;

set<int> g[200200];
vector<bool> vis;

int dfs(int node, int par){
    int cnt = 1;
    vis[node] = 1;
    for(auto &i: g[node]){
        if(!vis[i] && i!=par){
            cnt+= dfs(i,node);
        }
    }
    return cnt;
}

void _sol(){
    int n,m; cin >> n >> m;
    vis.assign(n+1,0);
    forr(i,m){
        int u,v; cin >> u >> v;
        g[u].insert(v); g[v].insert(u);
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(!vis[i]) ans = max(ans , dfs(i,-1));
    }
    cout << ans;

}


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


Measured memory_bytes: 44312
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll R,G,B,N;
  cin>>R>>G>>B>>N;
  ll ans=0;
  for(int i=0;i<=3000;i++){
    for(int j=0;j<=3000;j++){
      ll num=N-R*i-G*j;
      if(num>=0&&num%B==0)ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*
import kotlin.*

import java.io.InputStream
import java.lang.NumberFormatException
import java.lang.StringBuilder


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = FastScanner()
        val x = sc.nextLong()
        val y = sc.nextLong()

        // 0,0となって終わり 無い
        // 1,0となって終わり 前 0,2
        // 1,1で終わり 前 0,3

        // 差が2以上 操作で差を2未満にできる
        // 差が2未満 どんな操作しても差は2以上

        // 最適なプレイ
        // 差が2以上 -> 差が2未満になるように操作
        // 2未満 負け確定

        println(if (Math.abs(x - y) >= 2) "Alice" else "Brown")
    }
}


class FastScanner {
    companion object {
        val input: InputStream = System.`in`
        val buffer = ByteArray(1024) { 0 }
        fun isPrintableChar(c: Int): Boolean = c in 33..126
    }

    var ptr = 0
    var buflen = 0
    private fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = input.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }

    private fun readByte(): Int = if (hasNextByte()) buffer[ptr++].toInt() else -1

    private fun skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr].toInt())) ptr++
    }

    fun hasNext(): Boolean {
        skipUnprintable()
        return hasNextByte()
    }

    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b)
            b = readByte()
        }
        return sb.toString()
    }

    fun nextInt(): Int {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var b = readByte()
        // '-' = 45
        val minus = b == 45
        if (minus) {
            b = readByte()
        }

        // '0' = 48 '9' = 57
        if (b !in 48..57) {
            throw NumberFormatException()
        }

        while (true) {
            if (b in 48..57) {
                n *= 10
                n += b - 48
            } else if (b == -1 || !isPrintableChar(b)) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun nextDouble(): Double = next().toDouble()
}


Measured memory_bytes: 29356
package main

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

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	fa := float64(a)
	fanswer := math.Abs(fa)
	return int(fanswer)
}

// DeleteElement returns a *NEW* slice, that have the same and minimum length and capacity.
// DeleteElement makes a new slice by using easy slice literal.
func DeleteElement(s []int, i int) []int {
	if i < 0 || len(s) <= i {
		panic(errors.New("[index error]"))
	}
	// appendのみの実装
	n := make([]int, 0, len(s)-1)
	n = append(n, s[:i]...)
	n = append(n, s[i+1:]...)
	return n
}

// Concat returns a *NEW* slice, that have the same and minimum length and capacity.
func Concat(s, t []rune) []rune {
	n := make([]rune, 0, len(s)+len(t))
	n = append(n, s...)
	n = append(n, t...)
	return n
}

// sort package (snippets)
//sort.Sort(sort.IntSlice(s))
//sort.Sort(sort.Reverse(sort.IntSlice(s)))
//sort.Sort(sort.Float64Slice(s))
//sort.Sort(sort.StringSlice(s))

// copy function
//a = []int{0, 1, 2}
//b = make([]int, len(a))
//copy(b, a)

/*******************************************************************/

var n int

func main() {
	tmp := NextIntsLine()
	n = tmp[0]
	q := int(math.Pow(float64(n), 0.5))
	answer := 100
	for i := 1; i <= q; i++ {
		if n%i != 0 {
			continue
		}
		a := i
		b := n / i
		adigit := getDigit(a)
		bdigit := getDigit(b)
		f := Max(adigit, bdigit)
		if f < answer {
			answer = f
		}
	}
	if answer == 100 {
		answer = 1
	}
	fmt.Println(answer)
}

func getDigit(a int) int {
	i := 1
	for {
		a /= 10
		if a == 0 {
			break
		}
		i++
	}
	return i
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll mod(ll a,ll b)
{
    return max(a,b)-min(b,a);
}
ll dp[1000000];
ll h[1000000];
ll jum(ll n)
{
    if(n==1)return 0;
    if(dp[n]!=1000000000000000)
        return dp[n];
    if(n==2)
    {
        dp[n]=mod(h[n],h[n-1]);
        return dp[n];
    }
    if(dp[n-1]==1000000000000000)
        dp[n-1]=jum(n-1);
    if(dp[n-2]==1000000000000000)
        dp[n-2]=jum(n-2);
    dp[n]=min(dp[n],min(dp[n-1]+mod(h[n],h[n-1]),dp[n-2]+mod(h[n],h[n-2])));
    return dp[n];
}
int main() {
    ll n;
    cin>>n;
    for(ll i=0;i<=n;i++)
        dp[i]=1000000000000000;
    for(ll i=1;i<=n;i++)
        cin>>h[i];
    cout<<jum(n)<<endl;
	return 0;
}

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

using namespace std;

int main()
{
	int n=0;

	while(cin >> n && n)
	{
		int num[500000]={};
		int count=0;

		for(int i=n+1;i<=2*n;i++)num[i]=1;
		for(int i=2;i<=sqrt(2*n);i++)
		{
			for(int j=1;j*i<=2*n;j++)
				num[i*j]=0;
		}
		for(int i=n+1;i<=2*n;i++)if(num[i])count++;
		cout<< count << endl;
	}

    return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
ll x[200005];
ll rui[200005];
ll X;
int main(){
	scanf("%d%lld",&n,&X);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x[i]);
		rui[i] = rui[i-1]+x[i];
	}
	ll ans = 1e19;;
	for(int i=1;i<=n;i++){
		ll base = X*1LL*(n+i);
		int c = 0;
		for(int j=1;j<=n;j+=i){
			int beg = j, en = j+i-1;
			en = min(en,n);
			en = n+1-en; beg = n+1-beg;
			if(c == 0){
				base += 5LL*(rui[beg]-rui[en-1]);
			}
			else{
				base += 1LL*(3+2*c)*(rui[beg]-rui[en-1]);
			}
			c++;
		}
		ans = min(ans,base);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<int, int>
#define mpi make_pair
#define F first
#define S second
#define pb push_back
#define INF 1e15

const int nax = 200005;

int arr[nax];
int hgt[nax];
ll mod = 1e9+7;
ll t[4*nax];

void update(int v , int tl , int tr , int pos, ll val)
{
    if(tl == tr)
    {   
        t[v] = val;
        return;
    }

    int mid = (tl+tr)/2;

    if(pos > mid)update(2*v+1 , mid+1 , tr, pos , val);
    else update(2*v , tl , mid , pos , val);

    t[v] = max(t[2*v] , t[2*v+1]);
}

ll query(int v , int tl , int tr , int l , int r)
{
    if(l >r)return INT_MIN;

    if(tl==l && r==tr)
        return t[v];

    int mid = (tl +tr)/2;

    return max(query(2*v , tl , mid  , l , min(mid,r)) , query(2*v+1,mid+1 , tr  , max(mid+1 , l) , r));
}


int main()
{   
    fastio
    
    int n;
    cin>>n;

    for(int i = 0 ;i<n;i++)cin>>hgt[i];
    for(int j =0;j<n;j++)cin>>arr[j];

    for(int i = 0 ;i<n;i++)
    {   
        
        ll curr = query(1 , 0 , n-1 , 0 , hgt[i]-2);
        if(curr < 0)curr =0;

        // cout<<curr<<endl;
        curr += arr[i];
        update(1 , 0 ,n-1 , hgt[i]-1 , curr);
        // cout<<hgt[i]<<" "<<arr[i]<<endl;
        
    }

   

    ll ans = query(1 , 0 , n-1 , 0 , n-1);

    cout<<ans<<endl;
    
    
    return 0;
} 


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

length = float("inf")
for i in range(N - K + 1):
  r = i + K - 1
  l = i
  li = min(abs(x[r]) + abs(x[r] - x[l]), abs(x[l]) + abs(x[r] - x[l]))
  if li < length:
    length = li

print(length)

Measured memory_bytes: 15020
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int a[105];
int main(){
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    sort(a,a+3);
    printf("%d\n",a[0]+a[1]);
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
query_pairs = []
prefs = {}
for i in range(M):
    p, y = map(int, input().split())
    query_pairs.append([p, y])
    if p in prefs:
        prefs[p].append(y)
    else:
        prefs[p] = [y]

prefs_with_year_order = {}
for pref, years in prefs.items():
    years.sort()
    prefs_with_year_order[pref] = {}
    for i in range(len(years)):
        prefs_with_year_order[pref][years[i]] = i + 1 

for p, y in query_pairs:
    pref_part = "{0:06d}".format(p)
    order_part = "{0:06d}".format(prefs_with_year_order[p][y])
    print(pref_part + order_part)

Measured memory_bytes: 72504
S=int(input())
p=10**9+7
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

N = 2*(10 ** 3)+2  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
if S<3:
    print(0)
elif S==3:
    print(1)
else:
    s=0
    for x in range(1,S//3+1):
        s=s%p+cmb((S-2*x-1),(x-1),p)
    print(s%p)

Measured memory_bytes: 9304
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int N, A, B, used[100], rings[100], G[100][199];

int rec(int pos)
{
	int ret = 1; used[pos] = 1;

	for(int i = 0; i < rings[pos]; i++)
	{
		int r = G[pos][i];
		
		if(!used[r])
		{
			ret = max(ret, rec(r) + 1);
		}
	}

	used[pos] = 0;

	return ret;
}

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

	while(true)
	{
		scanf("%d", &N);
 
		if(N == 0) { break; }

		memset(used, 0, sizeof(used));
		memset(rings, 0, sizeof(rings));

		for(int i = 0; i < N; i++)
		{
			scanf("%d", &A); A--;
			scanf("%d", &B); B--;

			G[A][rings[A]] = B; rings[A]++;
			G[B][rings[B]] = A; rings[B]++;
		}

		int nodes = 0;

		for(int i = 0; i < 100; i++)
		{
			if(rings[i])
			{
				nodes++;
			}
		}

		int ret = 0;

		for(int i = 0; i < 100; i++)
		{
			ret = max(ret, rec(i));

 			if(ret == nodes) break;
		}
 
		printf("%d\n", ret);
	}

	return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  ll w,h,x,y;
  cin >> w >> h >> x >> y;
  cout << w*h/2.0 << ' ';
  if(2*x == w and 2*y == h) cout << 1;
  else cout << 0;
  return 0;
}


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

int main() {
	cin.tie(nullptr); ios::sync_with_stdio(false);
	string a, b;
	cin >> a >> b;
	bool ans = equal(begin(a), end(a), rbegin(b), rend(b));
	cout << (ans ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mem(a,x) memset(a,x,sizeof(a))
#define nl "\n"
#define fout(x) fixed<<setprecision(x)
#define one(x) __builtin_popcountll(x)
#define F first
#define S second
#define or_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(), order_of_key()

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << fout(10)<<x;}
void __print(double x) {cerr << fout(10)<<x;}
void __print(long double x) {cerr << fout(10)<<x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int mod=1e9+7;
const double eps=1e-9;
const double PI=acos(-1.0);

ll qpow(ll n,ll k){ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1)ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}


// ****************************************************



int main()
{
    int n;
    cin>>n;
    double ans=2*PI*n;
    printf("%.8f\n", ans);
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define FORN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define FORR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

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

	ll ans = LINF, sum = 0, b = 0, c = 0, sign = 1;
	rep(i, n){
		sum += a[i];
		if(sum/sign <= 0){
			b += 1-sum/sign;
			sum = sign;
		}
		sign *= -1;
	}
	ans = min(ans, b);
	sum = 0, sign = -1;
	rep(i, n){
		sum += a[i];
		if(sum/sign <= 0){
			c += 1-sum/sign;
			sum = sign;
		}
		sign *= -1;
	}
	ans = min(ans, c);
	co(ans);

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n;
signed main(){
    cin>>n;
    n--;
    int ans=(1+n)*n/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256