akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

ll h, w;
vector<ll> dx = { -1, 0, 1, 0 };
vector<ll> dy = { 0, -1, 0, 1 };


bool isInField(ll x, ll y) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

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

    int h, a;
    cin >> h >> a;

    int cnt = 0;

    while (h > 0) {
        h -= a;
        cnt++;
    }

    cout << cnt << "\n";
    vector<int> dx = { 0,1,0,-1 };
    vector<int> dy = { 1,0,-1,0 };

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a=0,b=0;
  cin>>n;
  for (int i = 0; i < n; ++i)
  {
    string s,t;
    cin>>s>>t;
    if(s==t) ++a,++b;
    else if(s>t) a+=3;
    else b+=3;
  }
  cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
#include <string>
using namespace std;

typedef long long int ll;

int main(){
    ll A, B;
    cin >> A >> B;
    string sa, sb;
    sa = to_string(A);
    sb = to_string(B);
    if(sa.size()>1 || sb.size()>1){
        cout << -1;
        }
    else cout << A*B;
}

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

int main() {
    int A, B, C, X, total;
    cin >> A >> B >> C >> X;
    int res = 0;
    for (int i_a=0; i_a<=A; i_a++) {
        for (int i_b=0; i_b<=B; i_b++) {
            for (int i_c=0; i_c<=C; i_c++) {
                total = 500*i_a + 100*i_b + 50*i_c;
                if (total == X) res++;
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#define NIL -1
#define LEN 26
using namespace std;
int pre[100],in[100],cnt=0,q = 0;

int infinda(int c){
    int i = 0;
    while(in[i]!=c)
        i++;
    return i;
}
void print(int u)
{
    if(q++)putchar(' ');
    printf("%d",u);
}
void reconstruction(int l,int r){
    if(l>=r)return;
    int c = pre[cnt++];
    int m = infinda(c);
    reconstruction(l,m);
    reconstruction(m+1,r);
    print(in[m]);
}

int main()
{
    int n,i;
    cin >> n;

    for(i = 0;i < n;i++){
        scanf("%d",&pre[i]);
    }
    for(i = 0;i < n;i++){
        scanf("%d",&in[i]);
    }
    reconstruction(0,n);
    putchar('\n');
    return 0;
}



Measured memory_bytes: 3204
#include<stdio.h>

int main(void){

	int a,b,c,d,n,count;
	while(scanf("%d",&n)!=EOF){
		count=0;
	for(a=0;a<10;a++){
		for(b=0;b<10;b++){
			for(c=0;c<10;c++){
				for(d=0;d<10;d++){
					if((a+b+c+d)==n){count++;}
				}
			}
		}
	}
	printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define mxn 1000010
#define db double
#define LL long long
#define ldb long double
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
#define x1 faqx1
#define y1 faqy1
#define x2 faqx2
#define y2 faqy2
using namespace std;
const int inf=1e9;
LL n,sl,fh,ans;
LL rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	n=rd();ans=n-1;
	for(LL i=2;i*i<=n;++i)
		if(n%i==0)
			ans=min(ans,i+n/i-2);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define ar array
#define N 100005
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//list of functions: set.insert(val), *(set.find_by_order(order-1)), set.order_of_key(val)

using namespace __gnu_pbds;
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    string s;
    cin>>s;
    int n = s.length();
    int val = 0;
    for(int i=0;i<n;i++){
        val = (val+s[i]-'0')%9;
    }
    if(val){
        cout<<"No\n";
    }
    else{
        cout<<"Yes\n";
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

#define int ll

int32_t main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	int n, a, b;cin >> n >> a >> b;
	if(b%2 == a%2){
		cout << (b-a)/2 << "\n";
		return 0;
	}
	cout << (b-a)/2  + min(a, n-b + 1) << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,ans{};
    cin>>n;
    for(ll d{1};d*d<=n;++d){
        ans+=d*d+d*((n/d)*(n/d+1)-d*(d+1));
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define r(i,n) for(auto i=0;i<n;i++)
#define s(c) static_cast<int>((c).size())

struct Node{
	int key;
	Node *l;
	Node *r;
	Node *p;
};
Node *nil = new Node{INT_MAX};

Node* get(Node *node, int i){
	stack<bool> s;
	do{
		s.push(i%2 ? true : false);
	}while((i/=2) != 0);
	s.pop();

	Node *x = node;
	while(!s.empty()){
		x = s.top() ? x->r : x->l;
		s.pop();
	}
	return x;
}

int main(){
	int m;
	cin >> m;

	Node *root = new Node{INT_MAX, nil, nil, nil};
	int i, key;
	for(i = 1; i <= m; i++){
		cin >> key;
		if(i == 1){
			root->key = key;
			continue;
		}

		Node *x = get(root, i/2);

		Node *node = new Node{key, nil, nil, x};
		if(i%2){
			x->r = node;
		}else{
			x->l = node;
		}
	}

	for(i = 1; i <= m; i++){
		Node *node = get(root, i);
		printf("node %d: key = %d, ", i, node->key);
		if(node->p != nil)
			printf("parent key = %d, ", node->p->key);
		if(node->l != nil)
			printf("left key = %d, ", node->l->key);
		if(node->r != nil)
			printf("right key = %d, ", node->r->key);
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 3236
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
#include <stdio.h>
#include <sstream>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const ll mod = 1e9 + 7;
const ll inf = 1<<29;
const long double pi = 3.14159265358979323846;

// ****************************************CODE***************************************//

int main() {
    _upgrade;

    int n,k;
    cin >> n >> k;

    vector<double> p(n);
    vector<double> sum(n+1);
    sum[0] = 0;

    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        p[i] = (1+tmp)/2.0;
        sum[i+1] = sum[i] + p[i];
    }

    double ans = 0.0;
    for(int i = k; i <= n; i++){
        double temp;

        temp = sum[i] - sum[i-k];
        ans = max(ans, temp);
    }

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

    return 0;
}

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

int main(){
  int n;
  cin >>n;
  int sum = 0;
  int N = n;
  while(n>0){
    sum += n%10;
    n /= 10;
  }
  if(N%10 == 0)cout << 10 << endl;
  else cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
};

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;

  if (s[2] == s[3] && s[4] == s[5])
    cout << "Yes" << en;
  else
    cout << "No" << en;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.*;

public class Main {
	public static int setCal(int d){
		int pos = 0;
		int i = d;
		while(i <600){
			pos+= i * i * d;
			i+=d;
		}
		return pos;
	}
	public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	while(scan.hasNext()){
		int output = setCal(scan.nextInt());
		System.out.println(output);
	}
	

	
}

}



Measured memory_bytes: 26152
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 
 
void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}
 
double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}
 
ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}
 
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
 
vec modncrlistp,modncrlistm;
 
ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}
 
ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}
 
ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
 
ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}
 
ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  startupcpp();
  ll i,j,N,M,ans=0;
  cin>>N>>M;
  if(N<M)swap(N,M);
  if(N-M>1){
    cout<<0<<endl;
    return 0;
  }
  vec v(N+1);
  v[0]=1;
  rep1(i,N+1){
    v[i]=v[i-1]*i%mod;
  }
  ans=v[N]*v[M]%mod;
  if(N==M){
    ans=ans*2%mod;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
	int n;
	string s1,s2;
	int p1=0,p2=0;
	cin>>n;
	for(int i=0;i<n;i++){
	cin>>s1>>s2;
	if(s1==s2){
		p1++;
		p2++;
	}
	else if(s1>s2) p1+=3;
	else if(s1<s2) p2+=3;
	}
	cout<<p1<<" "<<p2<<endl;
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> segs(n);
  for (int i = 0; i < n; i++) {
    int x, l;
    cin >> x >> l;
    segs[i].second = x - l;
    segs[i].first = x + l;
  }
  sort(segs.begin(), segs.end());
  for (int i = 0; i < n; i++) {
    swap(segs[i].first, segs[i].second);
  }
  int ans = 0;
  int L = (int) -1 * (2e9 + 20);
  for (int i = 0; i < n; i++) {
    if (segs[i].first >= L) {
      ++ans;
      L = segs[i].second;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
/**
 *    author:   K.R.Surrya  
 *    created:  30/04/2020 08:41:44
**/
#include<bits/stdc++.h>
#define vi vector<int>
#define vii vector<vector<int> >
#define vpi vector<pair<int,int> >
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pb push_back
using namespace std; 

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)  { return ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a,Args... args)
{
    cerr << *it << " = " << a <<endl;
    err(++it,args...);   //args is going to end.
}

void solve() {
    int N,K;
    cin >> N >> K;
    long long ret=0;
    for(int elements=K;elements<=N+1;++elements) { //Why changing from int to long long is changing the answer ?
        long long lo=(0+((long long)elements-1))*(long long)elements/2;   //sum of A.P. sequence;
        long long hi=(N-((long long)elements-1)+N)*(long long)elements/2; //sum of last elements term of the sequence;
        (ret+=(hi-lo+1))%=1000000007;
    }
    cout << ret << '\n';
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

     //freopen("input.txt", "r", stdin);
     //freopen("output.txt", "w", stdout);

     auto start = chrono::high_resolution_clock::now();
     solve();
     auto end = chrono::high_resolution_clock::now();

     cerr << " Execution time : " << chrono::duration_cast<chrono::milliseconds>(end-start).count()<<"ms"<<endl;

   
    return 0;
}


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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0);
#define eb(x) emplace_back(x)
#define mp(a,b) make_pair(a,b)
#define sz(a) int((a).size())
#define mod 1000000007
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


void seethis(vector<ll>vect)
{
    for(ll x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / __gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}



int main()
{
	FASTIO;
	string s;
	 cin>>s;
	 sort(s.begin(),s.end());

	 if(s[0]==s[1] && s[1]!=s[2] && s[2]==s[3])
        cout<<"Yes";
     else
        cout<<"No";

	return 0;
}













Measured memory_bytes: 256
n=int(input())
h=list(map(int, input().split()))  
ans=[]
count=0
if n==1:
    print(0)
    exit()
    
for i in range(1,n):
    if h[i]-h[i-1]<=0:
        count+=1
    else:
        ans.append(count)
        count=0
ans.append(count)
        
print(max(ans))
        

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

using namespace std;
//long long mod = 1000000000+7;

  long long  pow(long long  a, long long  b, long long mod)
 {
        stack<int>k;
        int j = 2048;
        int l = 1;
       int an = 1;
        while(b){
            if(b>=j){
                k.push(j);
                b-=j;
            }
            j/=2;
        }
        while(!k.empty()){
            if(k.top()==l){
                an = (an*a)%mod;
                k.pop();
            }
            a = (a*a)%mod;
            l*=2;
        }

        return an;
 }
long long an = 0;



 int main(){
   ios_base::sync_with_stdio(0);cin.tie(NULL);
         //freopen("task.in","r",stdin);
     //freopen("palindrome.out","w",stdout);
      int n,k;
      cin>>n>>k;
      int x[n];
      int dp[n];
      cin>>x[0]>>x[1];
      dp[1] = abs(x[0]-x[1]);
      dp[0] = 0;
        for(int i = 2;i<n;++i){
            cin>>x[i];
            dp[i] = abs(x[i]-x[i-1])+dp[i-1];

            for(int j = i-1,s=0;s<k-1&&j>0;++s,--j){
            dp[i] = min(abs(x[i]-x[j-1])+dp[j-1],dp[i]);
            }
           // cout<<dp[i]<<endl;
        }
        cout<<dp[n-1]<<endl;

    return 0;
 }


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	int n,x,count;
	while(true){
		scanf("%d %d",&n,&x);
		if(n == 0 && x == 0) break;
		count = 0;
		for(int min = 1; min < x/3 && min <= n-2;min++){
			for(int middle = min+1;middle < x - (min+middle) && middle <= n-1; middle++){
				if(x-(min+middle) <= n) count++;
			}
		}
		printf("%d\n",count);
	}

}



Measured memory_bytes: 2700
input()
a=[]
for i in input().split():
	a.append(int(i))

maxp = 0
minp = 10000000000000
maxval=0
c=0
for i in range(len(a)):
	if a[i]<minp:
		minp=a[i]
	val=a[i]-minp
	if val>maxval:
		maxval=val
		c=1
	elif val==maxval:
		c+=1

print(c)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<ll>v(n);
    for(ll i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    ll ans=0;
    for(ll i=0;i<n;i++){
        for(ll j=i+1;j<n;j++){
            for(ll k=j+1;k<n;k++){
                if(v[i]==v[j] || v[j]==v[k] || v[k]==v[i])continue;
                if(v[i]+v[j]>v[k]){
                    //cout<<i<<" "<<j<<" "<<k<<endl;
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3660
#include <stdio.h>

int n,k=10000, A[2000001], B[2000001];

void CountingSort(){
  int i, j, C[2000001];
  for(i=0; i<=k; i++)
    C[i] = 0;

  for(j=0; j<n; j++)
    C[A[j+1]]++;

  for(i=1; i<=k; i++)
    C[i]=C[i]+C[i-1];

  for(j=n; j>=1; j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
}

int main(){
  int i;

  scanf("%d",&n);
  for(i=0; i<n; i++)
    scanf("%d",&A[i+1]);

  CountingSort();

  for(i=1; i<n; i++)
    printf("%d ",B[i]);
  printf("%d\n",B[i]);

  return 0;
}
  
    



Measured memory_bytes: 17404
n = int(input())
a = input().split()

r = ''
if len(a) % 2 == 0:
    for i in range(len(a) - 1, 0, -2):
        r += a[i] + ' '
    for i in range(0, len(a), 2):
        r += a[i] + ' '
else:
    for i in range(len(a) - 1, -1, -2):
        r += a[i] + ' '
    for i in range(1, len(a), 2):
        r += a[i] + ' '
print(r[:-1])


Measured memory_bytes: 25764
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=1e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n;
vector<int>E[N];
#define pb push_back
void input()
{
	int x;
	n=read<int>();
	For(i,2,n)x=read<int>(),E[x].pb(i);
}
int dp[N];
int a[N],top;
void DP(int u)
{
	for(int v:E[u])DP(v);
	top=0;
	for(int v:E[u])a[++top]=dp[v];
	if(top)
	{
		sort(a+1,a+top+1);
		For(i,2,top)if(a[i]<=a[i-1])a[i]=a[i-1]+1;
		dp[u]=a[top]+1;
	}
	//cerr<<u<<' '<<dp[u]<<endl;
}
void work()
{
	DP(1);
	write(dp[1],'\n');
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 10752
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	long long ans = n - 1;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ans = min(ans, i - 1 + n / i - 1);
		}
	}

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


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double

struct datas{
  ll sumd;
  set<int> ts;
};
ll max(ll a,ll b){
  if(a<b){
    return b;
    
  }else{
    return a;
  }
}
ll gcd(int a,int b){//最大公約数
  if (a%b==0){
		return(b);
    }
	else{
		return(gcd(b,a%b));
    }
}
int main(void){
  int a,b;
  cin>>a>>b;
  vi ans(3,0);
  ans[a-1]++;
  ans[b-1]++;
  rep(i,3){
    if(ans[i]==0){
      cout<<i+1<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  ll N;
  cin >> N;
  vll A(N), B(N), C(N);
  for(int i = 0; i < N; i++) cin >> A.at(i);
  for(int i = 0; i < N; i++) cin >> B.at(i);
  for(int i = 0; i < N; i++) cin >> C.at(i);
  ll result = 0;
  ll a, b, c;
  sort(ALL(A)); sort(ALL(B)); sort(ALL(C));
  for(int i = 0; i < N; i++){
    b = B.at(i);
    ll anum = lower_bound(ALL(A), b) - A.begin();
    ll cnum = C.end() - upper_bound(ALL(C), B.at(i));
    result += anum * cnum;
  }
  cout << result << endl;
}


Measured memory_bytes: 2688
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>

#define MOD 1000000007

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

int main(void)
{
	string S; cin >> S;
	set<char> spell;
	bool flag = true;
	rep(i, 0, S.length()) {
		if (spell.find(S[i]) != spell.end()) {
			flag = false;
			break;
		}
		else spell.insert(S[i]);
	}
	cout << (flag ? "yes" : "no") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i =(b)-1;i>=(a);--i)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
typedef vector<int> vi;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 10;
ll a[maxn];
ll q = 1e18;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll r = 1;
	int n;
	cin >> n;
	rep(i,0,n)cin >> a[i];
	sort(a,a+n);
	if(a[0] == 0){cout << '0';return 0;}
	rep(i,0,n){
	//	cout << r << '\n';
		if(q / a[i] >= r)
			r*=a[i];
		else{
			cout << "-1";
			return 0;
		}	
	}
	cout << r;
	return 0;
}


Measured memory_bytes: 4440
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const ll INF = 1e10;
const double eps = 1e-6;
const ll MOD = 1000000007;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int main() {
	ll N, M;
	cin >> N >> M;
	UnionFind uf(N);
	//vector<T> q(M);
	vector<vector<T>> q(N);
	for (int i = 0;i < M;i++) {
		ll L, R, D;
		cin >> L >> R >> D;
		L--; R--;
		q[L].push_back(T(L, R, D));
		q[R].push_back(T(L, R, D));
		uf.unionSet(L, R);
	}
	vector<int> visited(N, 0);
	set<int> todo;
	vector<ll> iti(N, -1);
	for (int i = 0;i < N;i++) {
		iti[uf.root(i)] = 0;
		todo.insert(uf.root(i));
		visited[uf.root(i)] = true;
	}
	bool ok = true;
	while (!todo.empty()) {
		ll now = *todo.begin();
		todo.erase(todo.begin());
		for (int i = 0;i < q[now].size();i++) {
			ll l, r, d;
			tie(l, r, d) = q[now][i];
			if (iti[l] == -1 && r == now)
				iti[l] = iti[r] - d;
			else if (iti[r] == -1 && l == now)
				iti[r] = iti[l] + d;
			else if(iti[r] - iti[l] != d)
				ok = false;
			if (!visited[l])
				todo.insert(l);
			if (!visited[r])
				todo.insert(r);
			visited[l] = true;
			visited[r] = true;
		}
	}
	if (ok)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 22192
N = int(input())
S = str(input())
count = S.count('R')*S.count('G')*S.count('B')
for i in range(N):
  for l in range(N):
    j = i + l
    k = j + l
    if k >= N:
      break
    if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
      count -= 1

print(count)

Measured memory_bytes: 9200
//arc097_d.cpp
//Sat Aug 25 14:03:48 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int par[100000],treerank[100000];

int find(int x){
	if (par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if (x==y) return;
	if (treerank[x] < treerank[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if (treerank[x] == treerank[y]) treerank[x]++;
	}
}

int main(){
	int n,m;
	cin >> n >> m;

	int p[n+1];
	p[0] = 0;
	for (int i=1;i<n+1;i++){
		cin >> p[i];
	}

	for (int i=0;i<n+1;i++){
		par[i] = i;
		treerank[i] = 0;
	}

	for (int i=0;i<m;i++){
		int x,y;
		cin >> x >> y;
		unite(x,y);
//		cout << par[x] << "&" << par[y] << endl;;
	}

	int ans = 0;
	for (int i=1;i<n+1;i++){
//		cout << par[i] << " ";
		if (find(par[i]) == find(par[p[i]])){
			ans++;
		}
	}
//	printf("\n");
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <iostream>

using namespace std;



int main()
{
    int a,b,c;
    while(cin>>a>>b>>c)
    {
        int ans=(a-c)/(b+c);
        cout<<ans<<endl;
    }
    return 0;
}


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

const int MAX_M = 100008;

int N;
int M;
int L[MAX_M];
int R[MAX_M];

int main() {
  int l = 0;
  int r = 1000000;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i];
    l = max(l, L[i]);
    r = min(r, R[i]);
  }
  int ans = r - l + 1;
  
  if (ans > 0) cout << ans << endl;
  else cout << 0 << endl;
}


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

int main(){
  int N;
  string S,T;
  cin>>N;
  cin>>S>>T;
  for(int i=0;i<2*N;i++){
    if(i%2==0) cout<<S[i/2];
    else cout<<T[(i-1)/2];
  }
return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
N, M = map(int, input().split())
a = defaultdict(list)
b = defaultdict(int)
for i in range(M):
    li = list(input().split())
    li[0] = int(li[0])
    a[li[0]].append(li[1])
    if li[1] == 'AC':
        b[li[0]] = 1
ac = len(b)
wa = 0
for i in range(1, N+1):
    if b[i] == 1:
        for x in a[i]:
            if x == 'AC':
                break
            wa += 1
            
print(ac, wa)

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

#define fi first
#define se second
#define pb push_back
#define endl '\n'

#define FOR(i,a,b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef long double ld;

void solve();

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

#define int ll

const int N = 1e5 + 2;
int pa[N],sz[N];

void make_set(int x) {
    pa[x] = x;
    sz[x] = 1;
}

int find_set(int x) {
    if(pa[x] == x) {
        return x;
    }
    return pa[x] = find_set(pa[x]);
}

void union_set(int a,int b) {
    a = find_set(a);
    b = find_set(b);
    if(a != b) {
        if(sz[a] < sz[b])
            swap(a,b);
        sz[a] += sz[b];
        pa[b] = a;
    }
}

void solve() {
        int n;
        cin >> n;
        std::vector<pair<int,int > > a,b;
        FOR(i,0,n) {
                int x,y;
                cin >> x >> y;
                a.pb({x,i});
                b.pb({y,i});
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        FOR(i,0,N) make_set(i);
        std::vector<pair <int, pair <int,int > > > v;
        FOR(i, 1, int(a.size())) {
                v.pb({a[i].fi - a[i-1].fi, {a[i].se,a[i-1].se}});
        }
        FOR(i, 1, int(b.size())) {
                v.pb({b[i].fi - b[i-1].fi, {b[i].se,b[i-1].se}});
        }
        sort(v.begin(), v.end());
        ll ans = 0;
        for(auto i:v) {
                if(find_set(i.se.fi) != find_set(i.se.se)) {
                        union_set(i.se.fi,i.se.se);
                        ans += i.fi;
                }
        }
        cout << ans << endl;
}

Measured memory_bytes: 14560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		StringBuilder sb = new StringBuilder(in.next());
		int num = in.nextInt();

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

			String command = in.next();

			if(command.equals("print")){

				int first_num = in.nextInt();
				int second_num = in.nextInt();

				System.out.println(sb.substring(first_num, second_num + 1));

			}else if(command.equals("reverse")){

				int first_num = in.nextInt();
				int second_num = in.nextInt();

				String reverse_word = sb.substring(first_num, second_num + 1);

				StringBuilder reverse_sb = new StringBuilder(reverse_word);

				reverse_word = reverse_sb.reverse().toString();

				sb = sb.replace(first_num, second_num+1, reverse_word);

			}else if(command.equals("replace")){

				int first_num = in.nextInt();
				int second_num = in.nextInt();
				String str = in.next();

				sb.replace(first_num, second_num + 1, str);

			}
		}
	}
}

Measured memory_bytes: 29156
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 1000000000;
const ll M = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

int main() {
    int N, K;
    scanf("%d %d", &N, &K);
    vector<int> h;
    rep(i, N) {
        int j;
        scanf("%d", &j);
        h.pb(j);
    }
    /* ====================================== */
    sor(h);
    int min = 1000000001;
    rep(i, N - K + 1) {
        int a = h[K + i - 1] - h[i];
        if (min > a) {
            min = a;
        }
    }

    cout << min;
    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 892
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    graph = []
    for i in range(N):
        graph.append(int(A[i] - 1))

    
    new = [True] * N
    num = 0
    visited = []
    while True:
        new[num] = False
        visited.append(num)
        num = graph[num]
        if not new[num]: #bool型なので
            visited.append(num)
            break
    v = visited.index(visited[-1])
    l = len(visited)
    kurikaeshi = l - v - 1
    if K + 1 <= l:
        print(visited[K] + 1)
    else:
        amari = (K + 1 - v) % kurikaeshi
        if amari == 0:
            amari = kurikaeshi
        print(visited[v + amari - 1] + 1)

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 33400
#include <iostream>

int main(){
    int N,A,B,C,D;
    std::cin>>N>>A>>B>>C>>D;
    
    int X=N/A;
    if(N%A!=0) X++;
    int Y=N/C;
    if(N%C!=0) Y++;  

    X=X*B;
    Y=Y*D;
    if(X<=Y) std::cout<<X<<"\n";
    else std::cout<<Y<<"\n";

    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1e9 + 7;

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int bisect_right(int x,int a[],int left,int right){
    int mid;
    right++;
    while (left < right) {
        mid = (left + right) / 2;
        if (a[mid] <= x) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    return left;
}

int main(void){
    int N;int len = 0;
    scanf("%d", &N); 
    int *array  = (int *)malloc(10E5+10 * sizeof(int));
    for (int i = 0; i < N; i++) {
        int x; scanf("%d", &x); x *= -1;
        int index  = bisect_right(x,array,0,len -1);
        if (index == len) {
            array[len] = x;
            len++;
        } else {
            array[index] = x;
        }
    }    
    printf("%d\n",len);
    free(array);
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a*b;
        int length = 2*a+2*b;
        System.out.println(area + " " + length);
    }
}


Measured memory_bytes: 26148
// https://atcoder.jp/contests/agc012/tasks/agc012_a
// A - AtCoder Group Contest
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 標準入力から改行かスペースまで読み取り、数字として返す
int get_num() {
    // 10文字+区切り文字までしか受け付けられない
    char s[11];
    int i, n;
    // scanf()の直後は改行が入力に残っているので、
    // 最初の改行は読み飛ばす
    do {
        s[0] = getchar();
    } while (s[0] == '\0' || s[0] == '\n');
    for (i = 1; i < sizeof(s); i++) {
        s[i] = getchar();
        if (s[i] == ' ' || s[i] == '\n') {
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}


// intバブルソート
void sort(int a[], int num) {
    int i, j, b;
    for (i = 0; i < num-1; i++) {
        for (j = 0; j < num-i-1; j++) {
            if (a[j] > a[j+1]) {
                b = a[j];
                a[j] = a[j+1];
                a[j+1] = b;
            }
        }
    }
}

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void) {
    int a[300000];
    int n;
    long sum = 0;
    n = get_num();
    //n = 100000;

    for (int i = 0; i < 3 * n; i++) {
        //a[i] = 1000000000;
        a[i] = get_num();
    }

//    sort_q(a, n*3);
    qsort(a, n*3, sizeof(int), compare_int);
    
    for (int i = 0; i < n; i++) {
        sum += a[n*3-1 - (i*2+1)];
    }
    
    printf("%ld", sum);
    
    return 0;
}


Measured memory_bytes: 2556
#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>;

int main() {

  int N;
  cin >> N ;

  bool ans = false;
  rep(i,9){
    rep(j,9){
      if (N == (i+1)*(j+1)){
        ans = true;
        break;
      }
    }
  }  

  if (ans){
    cout << "Yes" << endl;
  }
  else {
   cout << "No" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
n=int(input())
abc=[[0,0,0]]
for i in range(n):
  labc=list(map(int,input().split()))
  abc.append(labc)

dp=[[0]*3 for i in range(n+1)]

for i in range(n):
  for j in range(3):
    if j==0:
      dp[i+1][j]=max(dp[i][1],dp[i][2])+abc[i+1][j]

    elif j==1:
      dp[i+1][j]=max(dp[i][0],dp[i][2])+abc[i+1][j]

    else:
      dp[i+1][j]=max(dp[i][1],dp[i][0])+abc[i+1][j]

print(max(dp[n]))
#print(dp)

Measured memory_bytes: 47324
#include <bits/stdc++.h>
using  namespace std;
#define ll    long long int
#define pai     pair<int,int>
#define vi      vector<int>
#define vd      vector<double>
#define mpi     map<int,int>
#define mps     map<string,int>
#define sti     stack<int>
#define stc     stack<char>
#define sei     set<int>
#define ses     set<string>
#define multii  multiset<int>

 int main()
{
  /*#ifndef ONLINE_JUDGE
  freopen("tin.txt","r",stdin);
  freopen("tout.txt","w",stdout);
  #endif*/
  ll t;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      cout<<i<<"x"<<j<<"="<<i*j<<endl;
    }
  }

}







Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <deque>
#include <algorithm>
using namespace std;

int main(){
	string s;
	int q;
	cin >> s >> q;
	deque<char> dq(s.begin(), s.end());
	int r = 1;
	for(int i = 0; i < q; ++i){
		int t;
		cin >> t;
		if(t == 1){ r = 3 - r; }
		else{
			int f;
			char c;
			cin >> f >> c;
			if(f == r){ dq.push_front(c); }
			else{ dq.push_back(c); }
		}
	}
	s.assign(dq.begin(), dq.end());
	if(r == 2){ reverse(s.begin(), s.end()); }
	cout << s << endl;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define N 1000005
#define ll long long
#define debug(a) cout<<#a<<": ";for(auto i:a)cout<<i<<" ";cout<<'\n';
#define trace(a) cout<<#a<<": "<<a<<"\n"
#define int ll
int a[N];
int ps[N];
signed main() {
	ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
	int i,j,k,l,m,n,t;
	cin >> n;
	for(int i = 0;i < n;i++) {
		cin >> a[i];
		a[i] -= (i+1);
		// cout << a[i] << endl;
	}
	sort(a,a+n);
	ps[0] = a[0];
	for(i = 1;i < n;i++) {
		ps[i] = ps[i-1] + a[i];
	}
	int ans = 1e18;
	for(i = 0;i < n;i++) {
		int b = a[i];
		ans = min(ans,(i+1)*b - ps[i] + ps[n-1]-ps[i] - (n-1-i)*b);
		// trace(ans);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
using pii = pair<int, int>;
using vi = vector<int>;
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
int di[] = {0, 0, -1, 1, -1, 1, -1, 1}; //右、左、マイナス、プラス
int dj[] = {1, -1, 0, 0, -1, 1, 1, -1};
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
//manip
template<class T> bool chmax(T &a, T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, T &b) {if (a > b) {a = b; return 1;} return 0;}
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power(T a, T b)
{return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0






int main() {
    //cast caution
    //look constraints always
    cin.tie(0); ios::sync_with_stdio(false);
    
    
    
    
    
    
    
    int n, m;
    while (cin >> n >> m && n) {
        int a[n];
        rep(i, n) cin >> a[i];
        int ans = 0;
        rep(i, n) {
            int tmp = a[i];
            rep(j, n) {
                
                if (i == j) continue;
                
                if (tmp + a[j] >  m) continue;
                ans = max(ans, tmp + a[j]);
            }
        }
        if (ans == 0) cout << "NONE" << endl;
        else cout << ans << endl;
    }
    
    
    
    
    
    
    
}
//cast caution





Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const double pi = 3.141592653589793;



int main(){
    ll H, W, D;
    cin>>H>>W>>D;
    vector<vector<ll>> A(H, vector<ll>(W));
    map<ll, pair<ll, ll>> M;
    rep(i, H){
        rep(j, W){
            cin>>A[i][j];
            A[i][j]--;
            M[A[i][j]]=make_pair(i, j);
        }
    }
    vector<ll> Dist(H*W);
    rep(i, H*W){
        if(i-D<0){
            Dist[i]=0;
        }
        else{
            Dist[i]=Dist[i-D]+abs(M[i].first-M[i-D].first)+abs(M[i].second-M[i-D].second);
        }
      	//cout<<Dist[i]<<endl;
    }
    ll Q;
    cin>>Q;
    vector<ll> L(Q), R(Q);
    rep(i, Q){
        cin>>L[i]>>R[i];
        cout<<Dist[R[i]-1]-Dist[L[i]-1]<<endl;
    }
	
}

Measured memory_bytes: 9856
#include<iostream>

void swap(int *x, int*y)
{
	int temp=0;

	temp = *x;

	*x = *y;

	*y = temp;
}

int main()
{
	int a=0, b=0, c=0, d=0;

	while(std::cin >> a >> b)
	{	
		c=a;

		d=b;//最小公倍数の計算のため保存

		if(a<b)
		{
			swap(&a,&b);
		}

		while(a%b!=0)
		{
			a = a%b;

			swap(&a,&b);

		}

		std::cout << b << ' ' << c/b*d << '\n';
	}
}

Measured memory_bytes: 1160
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = input()
    n = n.replace('1', '#').replace('9', '1').replace('#', '9')
    print(n)



if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import numpy as np
N=int(input())
a=list(map(int,input().split()))

a=np.array(a)
min_s = 10**29
for i in range(201):
    s=np.sum((a-np.ones(N)*(i-100))**2)
    min_s = min(int(s),min_s)
print(min_s)

Measured memory_bytes: 12484