akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define int long long int
#define pb push_back
// #define M 1000000007
#define inf 10000000000
#define ff first
#define ss second
#define deb(x) cout< #x< " "< x< endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<=n;i++)
#define FORR(a,b,c) for(int a= b;a>=c;a--)
#define fa(arrr) for(auto x:arrr)
#define iPair pair<int, pair<int,int>>
#define sz size()
// #define mp make_pair
#define mxm3(a,b,c) max(a, max(b,c))
#define mi3(a,b,c) min(a, min(b,c))
#define mxn 500005
#define PII pair<int,int>
#define all(v) v.begin(), v.end()
#define endl "\n"
// #define N 1000
#define C 4
#define nfs ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
// Ordered Set Tree
// typedef tree<PII, null_type, less<PII>,
//         rb_tree_tag,
//         tree_order_statistics_node_update>
//         oset;
#define db(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void computeLPSArray(string pat, int M, int* lps);

int dp[3003][3003][2];

int recurr(int *arr, int i, int j, bool turn) {
    if (i > j) return 0;
    if (dp[i][j][turn] != -1) return dp[i][j][turn];

    if (turn == 1) {
        return dp[i][j][turn] = max(arr[i] + recurr(arr, i + 1, j, !turn), arr[j] + recurr(arr, i, j - 1, !turn));
        // return dp[i][j][turn];
    }
    else {
        return dp[i][j][turn] = min(recurr(arr, i + 1, j, !turn), recurr(arr, i, j - 1, !turn));
    }
}

void solve() {
    int n;
    cin >> n;
    int arr[n];
    int sum = 0;
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        sum += arr[i];
    }
    int scrx = recurr(arr, 0, n - 1, 1);
    int scry = sum - scrx;
    cout << scrx - scry << endl;
}


int32_t main()
{


    nfs;
    int t;
    // facto();
    // cin >> t;
    t = 1;
    while (t--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 141440
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ll,ii>

int n;
int arr[200005];
int brr[200005];

int prec[30];

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	
	for (int x=0;x<30;x++) prec[x]=(1<<(x+1))-1;
	
	cin>>n;
	for (int x=0;x<n;x++) cin>>arr[x];
	for (int x=0;x<n;x++) cin>>brr[x];
	
	int ans=0;
	for (int b=28;~b;b--){
		int nums=0;
		for (int x=0;x<n;x++) brr[x]&=prec[b],arr[x]&=prec[b];
		sort(brr,brr+n);
		
		for (int x=0;x<n;x++){
			nums+=lower_bound(brr,brr+n,2*(1<<b)-arr[x])-lower_bound(brr,brr+n,1*(1<<b)-arr[x]);
			nums+=lower_bound(brr,brr+n,4*(1<<b)-arr[x])-lower_bound(brr,brr+n,3*(1<<b)-arr[x]);
		}
		if (nums&1) ans+=(1<<b);
	}
	
	cout<<ans;
}

Measured memory_bytes: 1792
while 1:
    try:s=list(input().split())
    except:break
    a=[]
    for x in s:
        if x in ['+','-','*','/']:
            c,b=str(a.pop()),str(a.pop())
            b+=x+c
            a+=[float(eval(b))]
        else:a+=[float(x)]
    print(a.pop())

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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V)                                                           \
    for (auto v : (V))                                                         \
        cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */
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; }

int main() {
    /* code */
    ll A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 2147283647
#define ll long long
using namespace std;
int sum[105],a[7];
void build(int l,int r,int rt)
{
    if(l==r)
        {sum[rt]=a[l];return;}
    ll mid=(l+r)>>1;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
int query(int l,int r,int rt,int i,int j)
{
    if(l>=i&&r<=j)
        return sum[rt];
    ll mid=(l+r)>>1;
    ll ans=0;
    if(i<=mid)ans+=query(l,mid,rt<<1,i,j);
    if(mid<j)ans+=query(mid+1,r,rt<<1|1,i,j);
    return ans;
}
int read(){
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        s=s*10+ch-'0';
        ch=getchar();
    }
    return s*f;
}
int main(){
    char c;
    for(int i=1;i<=6;i++)
        cin>>c,a[i]=c-'0';
    build(1,6,1);
    cout<<query(1,6,1,1,6);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
  int n,i,j,max=1;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    if(i*i<=n&&max<i*i) max=i*i;
    if(i*i>n) break;
  }
  printf("%d\n",max);
  return 0;
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    reverse(h.begin(), h.end());
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        bool flag = true;
        for(int j = i +1; j < n; j++)
        {
            if(h.at(i) < h.at(j)) flag = false;
        }
        if(flag) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		List<int>[] E = new List<int>[N];
		for(int i=0;i<N;i++){
			E[i] = new List<int>();
		}
		for(int i=0;i<N-1;i++){
			E[A[i]].Add(B[i]);
			E[B[i]].Add(A[i]);
		}
		
		int[] parent = new int[N];
		var q = new Queue<int>();
		for(int i=0;i<N;i++) parent[i] = -2;
		parent[0] = -1;
		q.Enqueue(0);
		while(q.Count > 0){
			var now = q.Dequeue();
			foreach(var nxt in E[now]){
				if(nxt == parent[now]) continue;
				parent[nxt] = now;
				q.Enqueue(nxt);
			}
		}
		
		long[] add = new long[N];
		for(int i=0;i<Q;i++){
			add[P[i]] += X[i];
		}
		
		long[] sum = new long[N];
		
		q = new Queue<int>();
		q.Enqueue(0);
		while(q.Count > 0){
			var now = q.Dequeue();
			sum[now] += add[now];
			if(parent[now] != -1){
				sum[now] += sum[parent[now]];
			}
			foreach(var nxt in E[now]){
				if(nxt == parent[now]) continue;
				q.Enqueue(nxt);
			}
		}
		Console.WriteLine(String.Join(" ",sum));
		
		
	}
	int N, Q;
	int[] A, B;
	int[] P;
	long[] X;
	public Sol(){
		var d = ria();
		N = d[0]; Q = d[1];
		A = new int[N-1];
		B = new int[N-1];
		for(int i=0;i<N-1;i++){
			d = ria();
			A[i] = d[0] - 1;
			B[i] = d[1] - 1;
		}
		P = new int[Q];
		X = new long[Q];
		for(int i=0;i<Q;i++){
			d = ria();
			P[i] = d[0] - 1;
			X[i] = d[1];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 60148
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  string a,b;
  cin>>a>>b;
  if(b.substr(0,a.length())==a&&a.length()+1==b.length()){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky....."<<endl;
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(8);
#define sp cout << " "
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';              


typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vpii;
typedef vector<pll > vpll;
long long MOD = (long long) 1e9 + 7LL;

int main()
{
	int i,j,n,m,k;
	string s;
	cin>>s;
	if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])
		cout<<"Bad"<<endl;
	else
		cout<<"Good"<<endl;
}

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

using namespace std;
#define PI 3.1415926535897932384626
#define ll long long
#define ull unsigned long long

#define all(x) x.begin(), x.end()
#define fo(i, n) for (i = 0; i < n; i++)
#define sortall(x) sort(all(x))

#define vi vector<int>
#define vs vector<string>
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, int> pii;
typedef vector<psi> vpsi;
typedef vector<psi> vpci;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
//=======================

const int MOD = 1'000'000'007;
const int N = 2e6 + 13;

//=======================
vi g[N];
int a[N];
int n, m, k;
//=======================

void solve()
{
    cin >> n;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t >= 1000)
    {
        t -= 1000;
    }
    if (t != 0)
    {
        t = abs(t - 1000);
    }
    cout << t << endl;
}

Measured memory_bytes: 50532
s = input()
LetterInS = set(s)
import string
LetterInAlphabets = set(string.ascii_lowercase)
if LetterInAlphabets - LetterInS == set() :
    print("None")
else :
    LetterSurplus = LetterInAlphabets - LetterInS
    ListSurplus = sorted(list(LetterSurplus))
    print(ListSurplus[0])

Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define endl '\n'

int main() {

    fast
    
    int n;cin>>n;
    int c,p;
    p=n%10;
    n=n/10;
    for(int i=0; i<3; ++i){
    	c=n%10;
    	if(p==c){
    		cout<<"Bad";return 0;
    	}
    	p=c;
    	n=n/10;
    }

    cout<<"Good";
    
	    

#ifndef ONLINE_JUDGE
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int N=1e5+5;
char a[10][10];
char test[10][10];
int b[N];
char s[N];
char t[N];
ll f[N];
int used[15];
int cmp1(int a,int b)
{
    return b<a;
}
int h,w,k;
int ans;
void dfs(int now){
    if(now==h+w+1){
        for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++)
            test[i][j]=a[i][j];
        }
        for(int i=1;i<=h+w;i++){
            if(used[i]){
                if(i<=h){
                    for(int j=1;j<=w;j++) test[i][j]='.';
                }
                else{
                    for(int j=1;j<=h;j++) test[j][i-h]='.';
                }
            }
        }
        int sum=0;
        for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++)
            if(test[i][j]=='#') sum++;
        }
        if(sum==k) ans++;
        return ;
    }
    used[now]=1;
    dfs(now+1);
    used[now]=0;
    dfs(now+1);
}
multiset<int> ss;
map<int,int>mp;
int main()
{
    memset(used,0,sizeof(used));
    ans=0;
    cin>>h>>w>>k;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++)
            cin>>a[i][j];
    }
    dfs(1);
    cout<<ans<<endl;
}


Measured memory_bytes: 3632
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>

typedef long long ll;

typedef unsigned int ui;

using namespace std;

int main() {
    // your code goes here
    ui n;
    ui  sum = 0;

    cin>>n;

    vector<ui> a(n);

    for(int i = 0 ; i  < n ; i++){
        ui x;
        cin>>x;

        a[i] = x;

        sum ^= x;
    }

    //now each guy xored with the total xor will give me ? that guy?
    for(int i = 0 ; i  < n ; i++){
        ui ans = a[i] ^ sum;

        cout<<ans<<" ";
    }



    return 0;
}


Measured memory_bytes: 4044
def warshall_floyd(N,d):
	for k in range(N):
		for i in range(N):
			for j in range(N):
				d[i][j] = min(d[i][j], d[i][k]+d[k][j])
	return d

H,W = map(int, input().split())
C = []
for i in range(10):
	C.append([int(x) for x in input().split()])
C = warshall_floyd(10,C)
A = []
for i in range(H):
	A.append([int(x) for x in input().split()])

ans = 0
for i in range(H):
	for j in range(W):
		a = A[i][j]
		if a<0:
			continue
		ans += C[a][1]
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#define MN 500000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int n,K,a[MN+5],b[MN+5],head[MN+5],cnt=0,in[MN+5],c[MN+5],d[MN+5];
struct edge{int to,next;}e[MN*4+5];
inline void ins(int f,int t)
{
    if(f<t) swap(f,t);
    f=b[f];t=b[t];++in[t];
    e[++cnt]=(edge){t,head[f]};head[f]=cnt;
}
priority_queue<int> q;set<int> st;
int main()
{
    n=read();K=read();
    for(int i=1;i<=n;++i) b[a[i]=read()]=i;
    for(int i=1;i<n+K;++i)
    {
      //  cout<<i<<"begin\n";
        set<int>::iterator it,it2;
        if(i<=n)
        {
        //    cout<<"Insert"<<a[i]<<endl;
            st.insert(a[i]);
            set<int>::iterator it=st.find(a[i]),it2;
            if(it!=st.begin()) ins(a[i],*(--(it2=it)));
            if((++(it2=it))!=st.end()) ins(a[i],*it2);
        }
        if(i>=K)
        {
          //  cout<<"erase"<<a[i-K+1]<<endl;
            it=st.find(a[i-K+1]);
            if(it!=st.begin()) ins(a[i-K+1],*(--(it2=it)));
            if((++(it2=it))!=st.end()) ins(a[i-K+1],*it2);
            st.erase(it);
        }
    }
    for(int i=1;i<=n;++i) if(!in[i]) q.push(i);
    for(int i=1;i<=n;++i)
    {
        int x=q.top();c[n+1-i]=x;q.pop();
        for(int i=head[x];i;i=e[i].next)
            if(!--in[e[i].to]) q.push(e[i].to);
    }
    for(int i=1;i<=n;++i) d[c[i]]=i;
    for(int i=1;i<=n;++i) printf("%d\n",d[i]);
    return 0;
}


Measured memory_bytes: 54400
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const int mod = 1e9+7;
const double pi = acos(-1);

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  
  double c = abs(6*m-(60*h+m)/2.0);
  double d = min(c,360-c);
  d *= pi;
  d /= 180.0;
  
  double e = sqrt(a*a+b*b-2*a*b*cos(d));
  cout << fixed << setprecision(10) << e << endl;
}

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

void solve(){
	
	int n ,w ;
	cin>>n>>w ;

	ll weight[n] ;
	ll prices[n] ;

	for(int i=0;i<n;i++){

		cin>>weight[i]>>prices[i] ;		

	}

	ll dp[n+1][w+1] ;
	memset(dp,0,sizeof(dp)) ;

	for(int i=0;i<=n;i++){
		for(int j=0;j<=w;j++){

			if(i==0 || j==0)
			{	dp[i][j]=0 ;
				continue ;
			}
			if(j-weight[i-1]>=0)
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight[i-1]]+prices[i-1]) ;
			else
				dp[i][j]=dp[i-1][j] ;

			
		}
	}
	/*
	for(int i=0;i<=n;i++){
		for(int j=0;j<=w;j++){
			cout<<dp[i][j]<<" " ;
		}
		cout<<"\n" ;
	}
	*/

	cout<<dp[n][w] ;
	
}

int main(){

	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}


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

int n;
int x[30];

void A(int t, int p){
	if(t == 0 || p <= x[t-1]){
		x[t] = p;
		for(int i = 0; i <= t; i++){
			if(i != 0) cout << " " << x[i];
			else cout << x[i];
		}
		cout << endl;
	}
	for(int i = p-1; i >= 1; i--){
		x[t] = i;
		if(t != 0) if(x[t-1] < x[t]) continue;
		A(t+1,p-i);
	}
}

int main(){
	while(cin >> n,n){
		A(0,n);
	}
}

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

using namespace std;

template <class T> void mini(T &l, T r) {l = min(l, r);}
template <class T> void maxi(T &l, T r) {l = max(l, r);}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(bool a) {
  return a ? "T" : "F";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = long long;
using ld = long double;

const int N = 110;

int n;
int A[3][N];
int f[3][N];

void run() {
  cin >> n;
  for (int i = 1; i <= 2; ++i) {
    for (int j = 1; j <= n; ++j) {
      cin >> A[i][j];
    }
  }
  f[1][1] = A[1][1];
  for (int i = 1; i <= 2; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (i == 1 && j == 1) continue;
      if (i - 1 >= 1) maxi(f[i][j], f[i - 1][j] + A[i][j]);
      if (j - 1 >= 1) maxi(f[i][j], f[i][j - 1] + A[i][j]); 
    }
  }
  cout << f[2][n] << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
  string S;
  ll w;
  cin >> S >> w;
  rep(i,(S.size()+w-1)/w){
    cout << S[i*w];
  }
  cout << endl;
}


Measured memory_bytes: 256
a,b,c = gets.chomp.split(""),gets.chomp.split(""),gets.chomp.split("");second = "a"

loop{
if (eval("#{second}.size") == 0) then
  puts second.upcase
  break
else
  old_next = second
  eval("second = #{old_next}[0]")
  eval("#{old_next}.delete_at(0)")
end
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define inf 1e18
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

         ll n;
         cin>>n;
         n= n + (n*n) + (n*n*n);
         cout<<n<<"\n";

}


Measured memory_bytes: 3648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = Console.ReadLine().Split();
            if (r[0].CompareTo(r[1]) == 0)
            {
                Console.WriteLine("=");
            }
            else if (r[0].CompareTo(r[1]) < 0)
            {
                Console.WriteLine("<");

            }
            else
            {
                Console.WriteLine(">");

            }
        }

    }
}

Measured memory_bytes: 13280
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  ll x[100],y[100];
  cin >> n;
  rep(i,0,n)cin >> d[i];
  cin >> m;
  rep(i,0,m)cin >> x[i] >> y[i];
  rep(i,0,m){
    ll ans = 0;
    rep(j,0,n){
      if(x[i]-1 == j)ans += y[i];
      else ans += d[j];
    }
    print(ans);
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
	int n, m;
	int ver[31];
	scanf("%d", &n);
	scanf("%d", &m);
	for (int i = 0; i < n; i++) {
		ver[i] = i + 1;
	}
	for (int i = 0; i < m; i++) {
		int x, y;
		scanf("%d,%d", &x, &y);
		swap(ver[x-1], ver[y-1]);
	}
	for (int i = 0; i < n; i++) {
		printf("%d\n", ver[i]);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cmath>

int cnt[2000];

int main()
{
	int n, x, y;
	scanf("%d%d%d", &n, &x, &y);
	--x, --y;
	for (int i = 0; i < n - 1; ++i)
	{
		for (int j = i + 1; j < n; ++j)
		{
			int dist;
			if (i < x)
			{
				if (j <= x)
				{
					dist = j - i;
				}
				else if (j >= y)
				{
					dist = (x - i) + 1 + (j - y);
				}
				else
				{
					dist = std::min(j - i, (x - i) + 1 + (y - j));
				}
			}
			else if (i <= y)
			{
				dist = std::min(j - i, (i - x) + 1 + std::abs(j - y));
			}
			else
			{
				dist = j - i;
			}
			cnt[dist]++;
		}
	}
	for (int k = 1; k < n; ++k)
	{
		printf("%d\n", cnt[k]);
	}
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    char a[110];
    char b[110];
    scanf("%s %s",a,b);
    int c = strcmp(a,b);
    if(strlen(a)>strlen(b))
        printf("GREATER");
    else if(strlen(a)<strlen(b))
        printf("LESS\n");
    else{
    if(c<0)
        puts("LESS");
    else if(c>0)
        puts("GREATER");
    else
        puts("EQUAL");
    }
return 0;
}


Measured memory_bytes: 128
#include<cctype>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define REP(a,b,c) for(int a=b;a<=c;++a)
#define RREP(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
using namespace std;

template<class T> inline
void read(T &x) {
	x=0; char c=getchar(); while(!isdigit(c)) c=getchar();
	while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
}

char s[100005];
int x[100005];
int n,flag;

inline int ch(int a) {return a>=n?a-n:a;}

inline void solve() {
	REP(i,2,n-1) {
		x[i]=s[i-1]=='o'?0:1;
		x[i]=(x[i]+x[i-1]+x[i-2])&1;
	} 
	int a=(s[0]=='o'?0:1);
	a=(x[n-1]+x[0]+a)&1;
	if(a!=x[1]) return;
	a=(s[n-1]=='o'?0:1);
	a=(x[n-1]+x[n-2]+a)&1;
	if(a!=x[0]) return;
	flag=1;
	REP(i,0,n-1) printf("%c",x[i]?'W':'S');
}

int main() {
	read(n); scanf("%s",s); flag=0;
	for(x[0]=0;x[0]<2;++x[0]) {
		for(x[1]=0;x[1]<2;++x[1]) {
			solve(); if(flag) break;
		} if(flag) break;
	} if(!flag) printf("-1\n");
	return 0;
}

Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main(){
    int a;
    int b;
    int c;
    int x;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    int result = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if((500 * i) + (100 * j) + (50 * k) == x){
                    result++;
                }
            }
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 256
import java.util.*;

/**
 * B
 */
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        Queue<String> name_array = new ArrayDeque<String>();
        Queue<Integer> time_array = new ArrayDeque<Integer>();

        int n = sc.nextInt();
        int q = sc.nextInt();
        
        int sum_time = 0;

        for (int i = 0; i < n; i++) {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        }

        sc.close();

        while (name_array.peek() != null) {

            String str = name_array.remove();
            int tmp = time_array.remove();

            if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            }

        }
    }
}


Measured memory_bytes: 73540
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <unistd.h>
#include <bits/stdc++.h>

#define pii pair<int,int>
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;


typedef long long ll;
static const ll INF = 1000000000000000000LL;
static const ll MOD = 1000000007;

//桁dp 
// Nからの 1のくらいに下がっていく?

//dp[n][100]: n桁目で、0が100個

int main()
{
    string s;
    cin >> s;
    int K;
    cin >> K;

    
    //long long dp[ 102 ][ 2 ][ 2 ][102];
    long long dp[ 102 ][ 2 ][102];
    fill( ( long long * )dp, ( long long * )dp + sizeof( dp ) / sizeof( long long ), 0 );
    //dp[桁][smaller][leading_zero][0でない数]
    //leading_zero 0以外を入れたときに trueになる?
    //0でない数字だった

    dp[0][0][0] = 1;

    for(int i = 0; i < s.size(); ++i)
    {
        int D = s[i] - '0';

        for(int j = 0; j < 2; ++j)
        {
            for(int k = 0; k <= i; ++k)
            {
                //未満フラグ
                for(int d = 0; d <= (j ? 9 : D); ++d)
                {
                    if(d == 0)
                    {
                        dp[i+1][j || (d < D)][k] += dp[i][j][k];
                    }
                    else
                    {
                        dp[i+1][j || (d < D)][k+1] += dp[i][j][k];
                    }
                }
            }
        }
    }

    int N = s.size();

    ll res = dp[N][0][K] + dp[N][1][K];
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const int maxN = 1e6 + 55;

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

    int a, b, c;

    cin >> a >> b >> c;

    swap(a, b);
    swap(a, c);

    cout << a << ' ' << b << ' ' << c << '\n';

    return 0;
}


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

namespace ALDS1_9_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int H = int.Parse(Console.ReadLine());

            int[] heapNodes = Console.ReadLine()
                                     .Split(' ')
                                     .Select(s => int.Parse(s))
                                     .ToArray();

            for (int i = 2 * H - 1; i >= 0; i--)
            {
                Program.MaxHeapfy(heapNodes, i);
            }
            foreach (int i in heapNodes)
            {
                Console.Write(" {0}", i);
            }
            Console.WriteLine();
            //Console.ReadLine();
        }

        private static void MaxHeapfy(int[] heapNodes, int index)
        {
            int maxKeyIndx = index;
            if ((index + 1) * 2 - 1 < heapNodes.Length && heapNodes[maxKeyIndx] < heapNodes[(index + 1) * 2 - 1])
            {
                maxKeyIndx = (index + 1) * 2 - 1;
            }
            if ((index + 1) * 2 < heapNodes.Length && heapNodes[maxKeyIndx] < heapNodes[(index + 1) * 2])
            {
                maxKeyIndx = (index + 1) * 2;
            }
            if (maxKeyIndx != index)
            {
                int tmp = heapNodes[index];
                heapNodes[index] = heapNodes[maxKeyIndx];
                heapNodes[maxKeyIndx] = tmp;
                Program.MaxHeapfy(heapNodes, maxKeyIndx);
            }
        }


    }
}



Measured memory_bytes: 53504
import java.util.*;
public class Main {
    
    public static long fbn(long b, long n){
        if(n<b)
            return n;
        else
            return fbn(b,n/b) + n % b;
    }
    
    public static void main(String[] args) throws InterruptedException{
            Scanner sc = new Scanner(System.in);
            String s = sc.nextLine();
            System.out.println(s.substring(0,4) + " " +s.substring(4));
    }
}

Measured memory_bytes: 8916
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	vector<int> a(3);
	int i = 0;
	while (i < 3) {
		cin >> a[i];
		i++;
	}
	sort(a.begin(), a.end());
	int x = abs(a[0] - a[1]);
	int y = abs(a[1] - a[2]);

	cout << x + y << endl;

	return 0;
}

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

int main () {
  int a, b;
  cin >> a >> b;
  cout << (b % a == 0 ? (a+b) : (b-a)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <cstdio>
#include <stdio.h>
using namespace std;
int main(){
	double x1,y1,x2,y2,xq,yq,x,y,xm,ym;
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&xq,&yq) != EOF){
		double a=x2-x1,b=y2-y1,c=y1-yq,d=yq-y2;
		if(x1 != x2){
			xm = (xq*a*a-x1*b*d-x2*b*c)/(a*a+b*b);
			ym = b*(xm-x1)/a+y1;
			x = 2*xm-xq;
			y = 2*ym-yq;
		}else{
			x = 2*x1-xq;
			y = yq;			
		}
		printf("%.6lf %.6lf\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	ll r=0,g=0,b=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R')
			r++;
		if(s[i]=='G')
			g++;
		if(s[i]=='B')
			b++;
	}
	ll ans=r*g*b;
	for(int i=0;i<n;i++)
	{
		for(int j=1;i+j+j<n;j++)
		{
			if((s[i]^s[i+j]^s[i+j+j])==('R'^'G'^'B'))ans--;
		}
	}
	// int ck='R'^'G'^'B';
	// cout<<('R'^'G'^'B')<<" "<<ck<<endl;
	cout<<ans<<endl;

}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]
xy = [[int(x) for x in input().split()] for _ in range(m)]

status = [[0, 1] for _ in range(n + 1)]
status[1] = [1, 1] # 赤？、個数

for i in range(m):
    x, y = xy[i]
    if status[x][0] == 1:
        if status[x][1] > 1:
            status[x][1] -= 1
        else:
            status[x] = [0, 0]
        status[y][0] = 1
        status[y][1] += 1
    else:
        status[x][1] -= 1
        status[y][1] += 1

ans = 0

for i in status[1:]:
    if i[0] == 1:
        ans += 1

print(ans)


    


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



int main() {
  int n,k,q;
  cin>>n>>k>>q;
  vector<int>s(n,0);
  rep(i,q){
    int a;
    cin>>a;
    a--;
    s[a]++;
  }

  rep(i,n){
    if (s[i]>(q-k)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }



}


Measured memory_bytes: 1024
import java.util.Scanner;

class Main{

	Main(){
		Scanner scan = new Scanner(System.in);	
		int[] w = new int[10];
		int[] k = new int[10];
		w=this.init(w);
		k=this.init(k);	
		int[] ans1;
		int[] ans2;
		
		for(int i=0;i<10;i++){
			w[i]=scan.nextInt();
		}
		for(int i=0;i<10;i++){
			k[i]=scan.nextInt();
		}
		
		ans1=this.sort(w);
		ans2=this.sort(k);
		
		

		System.out.print(ans1[0]+ans1[1]+ans1[2]+" ");
		System.out.println(ans2[0]+ans2[1]+ans2[2]);
	}

	int[] init(int[] w){
		for(int i=0;i<w.length;i++){
			w[i]=0;
		}	
		return w;
	}

	int[] sort(int[] array){
		int[] sArray = new int[3];
		init(sArray);
		for(int i=0;i<array.length;i++){
			if(array[i]>sArray[2]){
				if(array[i]>sArray[1]){
					if(array[i]>sArray[0]){
						sArray[2]=sArray[1];
						sArray[1]=sArray[0];
						sArray[0]=array[i];
						
						continue;
					}
					sArray[2]=sArray[1];	
					sArray[1]=array[i];
					continue;
				}
				sArray[2]=array[i];
				continue;
			}

			

		}

		return sArray;
	}

	public static void main(String[] args){
		Main a = new Main();
	}


}

Measured memory_bytes: 17180
import math

a, b, x = map(int, input().split())

p = ((x*2)/(a**2)) - b

if p == 0:
    print(45)
    exit()

if p > 0:
    radian = math.atan2(a, b-p)
    print(90-math.degrees(radian))
else:
    p = 2*x/(a*b)
    radian = math.atan2(b, p)
    print(math.degrees(radian))


Measured memory_bytes: 38356
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;

vi eratosthenes_sieve(int n){
	vi res(n+1);
	if(n<2) return res;
	res[2]=1;
	for(int i=3;i<=n;i+=2){
		if(i*i<=n && !res[i]) for(int j=i+i+i;j<=n;j+=i+i) res[j]=1;
		res[i]=!res[i];
	}
	return res;
}
vi prime_list(const vi& isprime){
	vi res;if(isprime.size()<=2)return res;
	res.push_back(2);
	for(unsigned int i=3;i<isprime.size();i+=2)
		if(isprime[i])res.push_back(i);
	return res;
}
vi prime_list(int n){
	return prime_list(eratosthenes_sieve(n));
}

int n;

main(){
vi pl = prime_list(1100000);
	while(cin >> n){
		cout << upper_bound(ALL(pl), n) - pl.begin() << endl;
	}
	return 0;
}

Measured memory_bytes: 5892
#include<bits/stdc++.h>
using namespace std;
pair<int,int> st[500010];
int f[500010],mx[500010];
map<int,int> mp;
int tp,ans;
const double pi=acos(-1);
void update(int s,int w){while (s<=tp) {mx[s]=max(mx[s],w);s+=s&(-s);}}
int getmax(int s){int ans=0;while (s) {ans=max(ans,mx[s]);s-=s&(-s);}return ans;}
int main()
{//freopen("in.txt","r",stdin);
	int x1,y1,x2,y2;scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	bool rev=false;
	if ((x1<=x2)&&(y1<=y2)) {}
	else if ((x1>=x2)&&(y1>=y2)) {swap(x1,x2);swap(y1,y2);}
	else
	{
		rev=true;
		x1=-x1;x2=-x2;
		if ((x1>=x2)&&(y1>=y2)) {swap(x1,x2);swap(y1,y2);}
	}
	if (!((x1<=x2)&&(y1<=y2))) assert(0);
	int n,top=0;scanf("%d",&n);
	while (n--)
	{
		int px,py;scanf("%d%d",&px,&py);if (rev) px=-px;
		if ((px>=x1)&&(px<=x2)&&(py>=y1)&&(py<=y2)) st[++top]=make_pair(px,py);
	}
	sort(st+1,st+top+1);cerr<<top<<endl;//cerr<<st[1].first<<' '<<st[1].second<<endl<<st[2].first<<' '<<st[2].second<<endl;
	for (int i=1;i<=top;i++) mp[st[i].second]=0;
	for (map<int,int>::iterator it=mp.begin();it!=mp.end();it++) it->second=++tp;
	for (int i=1;i<=top;i++)
	{
		int p=mp[st[i].second];
		f[i]=getmax(p-1)+1;
		ans=max(ans,f[i]);
		update(p,f[i]);
	}
	cerr<<ans<<' '<<min(x2-x1,y2-y1)<<endl;
	if (ans>min(x2-x1,y2-y1)) printf("%.10lf\n",(double)(x2-x1+y2-y1)*100-(double)(ans-1)*(20-5*pi)+(10*pi-20));
	else printf("%.10lf\n",(double)(x2-x1+y2-y1)*100-(double)ans*(20-5*pi));
}

Measured memory_bytes: 14592
N,M=map(int,input().split())
S=[]
for i in range(N):
    A,B=map(int,input().split())
    S.append([A,B])

S.sort()
m=0
while M>0:
    for i in range(N):
        if S[i][1]<=M:
            m+=S[i][0]*S[i][1]
            M-=S[i][1]
        else:
            m+=S[i][0]*M
            M=0
            break

print(m)



    



Measured memory_bytes: 20056
#include <bits/stdc++.h>
#define pb push_back
#define sc second
#define fr first
#define mk make_pair
#define ll long long
#define ii pair<int,int>
#define mp make_pair
#define scn(x) scanf("%d",&x)
typedef long long intt;
using namespace std;
intt tree[200004*4];
intt h[200004];
intt a[200004];
intt dp[200004];
void update(int node, int start, int endd, int idx, intt val)
{
    if(start == endd)
    {

        tree[node]=val;
    }
    else
    {
        int mid = (start + endd) / 2;
        if(start <= idx and idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update(2*node, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update(2*node+1, mid+1, endd, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node]=max(tree[2*node],tree[2*node+1]);
    }
}
intt query(int node, int start, int endd, int l, int r)
{
    if(r < start or endd < l)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if(l <= start and endd <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    intt mid = (start + endd) / 2;
    intt p1 = query(2*node, start, mid, l, r);
    intt p2 = query(2*node+1, mid+1, endd, l, r);
    return max(p1,p2);
}

int main()
{
    int n;
    cin>>n;
    int i;
    for(i=0;i<n;i++)
        cin>>h[i];
    for(i=0;i<n;i++)
        cin>>a[i];
     intt mx=0;
    for(i=0;i<n;i++)
    {
        dp[i]=max(dp[i],a[i]+query(1,0,n,0,h[i]-1));
        update(1,0,n,h[i],dp[i]);
        mx=max(mx,dp[i]);
    }
    cout<<mx<<endl;



    return 0;
}


Measured memory_bytes: 10496
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		int min = 100000;
		for (int i = 0; i < N; i++) {
			int ant = 0;
			int post = 0;
			for (int j = 0; j <= i; j++) {
				ant += list.get(j);
			}
			for (int j = i + 1; j < N; j++) {
				post += list.get(j);
			}
			if (min > Math.abs(ant - post)) {
				min = Math.abs(ant - post);
			}
		}
		System.out.println(min);
	}

}


Measured memory_bytes: 36148
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

typedef pair<pii, int> P;
int H, W;
string maps[50];
int dis[50][50];

int main() {
	cin >> H >> W;
	REP(i, H) cin >> maps[i];
	
	queue<P> que;
	fill(dis[0], dis[H], INF);
	dis[0][0] = 0;
	que.push(P(pii(0,0),0));
	
	while (!que.empty()) {
		P cur = que.front(); que.pop();
		int nx = cur.fi.se, ny = cur.fi.fi, nd = cur.se;
		if (dis[ny][nx] < nd) continue;
		
		int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
		REP(i, 4) {
			int x = nx + dx[i], y = ny + dy[i];
			if (x < 0 || x >= W || y < 0 || y >= H) continue;
			if (maps[y][x] == '#' || dis[y][x] <= nd + 1) continue;
			dis[y][x] = nd + 1;
			que.push(P(pii(y,x),nd + 1));
		}
	}
	
	int ans = 0;
	REP(i, H) ans += count(ALL(maps[i]), '.');
	if (dis[H-1][W-1] == INF) ans = -1;
	else ans -= dis[H-1][W-1] + 1;
	
	cout << ans << endl;
	
	return 0;
}


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

typedef long long ll;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < vl > vvl;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll;
typedef vector < pii > vpii;
typedef vector < vpll > vvpll;
typedef vector < vpii > vvpii;

#define pb push_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x,y) make_pair((x), (y))
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)



ll solve(){
    
    ll n; cin >> n;
    ll sum = 0;
    if(n % 2 == 0){
        int cnt = 0;
        while(n % 2 == 0){
            cnt++;
            n /= 2;
        }
        ll candidate = (ll)sqrt(2 * cnt);
        if(candidate * (candidate + 1) > 2 * cnt)
            candidate--;
        sum += candidate;
        candidate++;
        if(candidate * (candidate + 1) <= 2 * cnt)
            sum++;
    }
    for(ll i = 3; i * i <= n; i += 2){
        if(n % i == 0){
            int cnt = 0;
            while(n % i == 0){
                cnt++;
                n /= i;
            }
            ll candidate = (ll)sqrt(2 * cnt);
            if(candidate * (candidate + 1) > 2 * cnt)
                candidate--;
            sum += candidate;
            candidate++;
            if(candidate * (candidate + 1) <= 2 * cnt)
                sum++;
        }
    }
    if(n > 2)
        sum++;
    return sum;
}


int main(){
	boost;
	int t = 1;
// 	cin >> t;
	
	while(t--){
		cout << solve() << '\n';
	}
	
	return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,a,b;
	cin>>n>>a>>b;
	ll x=n/(a+b);
	ll y=n%(a+b);
	cout<<x*a+min(a,y)<<"\n";
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

MOD = 10 ** 9 + 7
n, k = map(int, raw_input().split())

def fact(N):
    if N <= 1:
        return 1
    return fact(N - 1) * N

def pow(N):
    ret = 1
    for i in range(n):
        ret *= N
        ret %= MOD
    return ret

C = 0
for i in range(k - 1, 0, -1):
    num = fact(k) / fact(i) / fact(k - i) * pow(i)
    if (i - k) % 2 == 1:
        num *= -1
    C += num
print (pow(k) + C) % MOD


Measured memory_bytes: 5816
#include<stdio.h>
#include<string.h>
int main()
{
	int n,m,i,j,c,x=0;
	char s[111][11],t[111][11];
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%s",s[i]);
	scanf("%d",&m);
	for(i=0;i<m;i++)
		scanf("%s",t[i]);

	for(i=0;i<n;i++){
		c=0;
		for(j=0;j<n;j++)
			if(strcmp(s[i],s[j])==0)
				c++;
		for(j=0;j<m;j++)
			if(strcmp(s[i],t[j])==0)
				c--;
		x=(c>x)?c:x;
	}
	printf("%d",x);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<math.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
//小さい順
int compareInt(const void* a, const void* b){int aNum = *(int*)a;int bNum = *(int*)b;return aNum - bNum;}

long long _gcd(long long a,long long b){
    long long c;
    while(b!=0){c=a%b;a=b;b=c;}
    return a;
    
}
long long _lcm(long long a,long long b){long long c=_gcd(a,b);a/=c;return a*b;}

int main(){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    int la,lb;
    if(a>=b){
        la=b;
    }else{
        la=a;
    }
    if(c>=d){
        lb=d;
    }else{
        lb=c;
    }
    printf("%d",la+lb);
}




Measured memory_bytes: 128
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	multiset<int> s;
	int n; cin >> n;
	while (n--)
	{
		int a; cin >> a;
		auto it = s.lower_bound(a);
		if (it == s.begin())s.insert(a);
		else
		{
			--it;
			s.erase(it);
			s.insert(a);
		}
	}
	cout << s.size() << endl;
}

Measured memory_bytes: 4992