akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    ll A[N];
    rep(i, N) cin >> A[i];
    //dp[i][j]:=A[0]〜A[i-1]まででj個まで取るときの最大値(A[i-1]は必ず取る)
    ll dp[N+1][K+1];
    fill(dp[0], dp[N+1], 0);
    //deq[i]の要素x,yについてx<yならばdp[x][j]>dp[y][j]
    deque<ll> deq[K+1];
    rep2(i, 1, N){
        rep(j, K+1){
            while(!deq[j].empty() && deq[j].front() < i-M) deq[j].pop_front();
        }
        dp[i][0] = 0;
        rep2(j, 1, K){
            //j個目をA[i-1]に取る
            if(j > i) dp[i][j] = dp[i][j-1];
            elif(deq[j-1].empty()) dp[i][j] = j*A[i-1];
            else dp[i][j] = dp[deq[j-1].front()][j-1] + j*A[i-1];
        }
        rep(j, K+1){
            while(!deq[j].empty() && dp[deq[j].back()][j] <= dp[i][j]) deq[j].pop_back();
            deq[j].push_back(i);
        }
    }
    ll ans = 0;
    rep(i, N+1){
        //rep(j, K+1) cout << dp[i][j] << ' ';
        //cout << endl; 
        ans = max(ans, dp[i][K]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 236416
#include<cstdio>
#include<iostream>
#include<cctype>
#include<cstring>
#include<string>
using namespace std;

int change(string col, int i, int j) {
    if (i >= j) {
        return 0;
    }
    if (col[i] == 'W') {
        if (col[j] == 'R') {
            return 1 + change(col, i+1, j-1);
        } else {
            return change(col, i, j-1);
        }
    } else {
        if (col[j] == 'R') {
            return change(col, i+1, j);
        } else {
            return change(col, i+1, j-1);
        }
    }
} 

int main() {
    int n, red = 0, whi = 0;
    int col[200000] = {};
    cin >> n;
    for (int i = 0; i < n; i++) {
        char tmp = 'A';
        while (tmp != 'W' && tmp != 'R') {
            scanf("%c", &tmp);
        }
        if (tmp == 'W') {
            col[i] = 1;
            whi++;
        }
    }
    int ans = 0;
    red = n - whi;
    if (red > whi) {
        for (int i = 0; i < whi; i++) {
            if (col[n-i-1] == 0) {
                ans++;
            }
        }
    } else {
        for (int i = 0; i < red; i++) {
            if (col[i] == 1) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4000
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>
#include <stack>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	std::vector<std::vector<int> > g(n);
	rep(i,n-1) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	std::vector<int> col(n);
	auto dfs_color = [&] (auto f, int i, int par, int c) -> void {
		col[i]=c;
		for(auto to:g[i]) {
			if(to==par) continue;
			f(f,to,i,c^1);
		}
	};
	dfs_color(dfs_color,0,-1,0);
	// count the colors
	int colcount[2] = {0};
	rep(i,n) colcount[col[i]]++;
	int modcount[3] = {0};
	std::vector<std::stack<int> > stack(3);
	{
		rep(i,n) {
			modcount[(i+1)%3]++;
			stack[(i+1)%3].emplace(i+1);
		}
	}
	rep(c,2) {
		if(colcount[c]<=modcount[0]) {
			// make 0 all 3;
			std::vector<int> ans(n);
			rep(i,n) {
				if(col[i]==c) {
					ans[i]=stack[0].top();
					stack[0].pop();
				}
			}
			std::stack<int> rest;
			rep(i,3) while(!stack[i].empty()) {
				rest.emplace(stack[i].top());
				stack[i].pop();
			}
			rep(i,n) {
				if(col[i]==(c^1)) {
					ans[i]=rest.top();
					rest.pop();
				}
			}
			rep(i,n) std::cout << ans[i] << ' ';
			std::cout << EL;
			return 0;
		}
	}
	{
		std::vector<int> ans(n);
		rep(i,n) {
			if(col[i]==0) {
				if(!stack[1].empty()) {
					ans[i]=stack[1].top();
					stack[1].pop();
				} else {
					ans[i]=stack[0].top();
					stack[0].pop();
				}
			} else {
				if(!stack[2].empty()) {
					ans[i]=stack[2].top();
					stack[2].pop();
				} else {
					ans[i]=stack[0].top();
					stack[0].pop();
				}
			}
		}
		rep(i,n) std::cout << ans[i] << ' ';
		std::cout << EL;
	}

	return 0;
}


Measured memory_bytes: 18536
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
using namespace std;
const int MAXN=5e5+5;
const int M=MAXN*100;
int n,q,tot;
int a[MAXN];
int T[MAXN],lson[M],rson[M],c[M];

int build(int l, int r){
    int root = tot++;
    c[root] = 0;
    if(l != r){
        int mid = (l+r)>>1;
        lson[root] = build(l,mid);
        rson[root] = build(mid+1,r);
    }
    return root;
}

int update(int root,int pos,int val){
    int newroot=tot++,tmp=newroot;
    c[newroot]=c[root]+val;
    int l=1,r=n;
    while(l<r){
        int mid=(l+r)>>1;
        if(pos<=mid){
            lson[newroot]=tot++;
            rson[newroot]=rson[root];
            newroot=lson[newroot];
            root=lson[root];
            r=mid;
        }else{
            rson[newroot]=tot++;
            lson[newroot]=lson[root];
            newroot=rson[newroot];
            root=rson[root];
            l=mid+1;
        }
        c[newroot]=c[root]+val;
    }
    return tmp;
}

int query(int root,int pos){
    int ret=0;
    int l=1,r=n;
    while(pos<r){
        int mid=(l+r)>>1;
        if(pos<=mid){
            r=mid;
            root=lson[root];
        }else{
            ret+=c[lson[root]];
            root=rson[root];
            l=mid+1;
        }
    }
    return ret+c[root];
}

int main(){
    tot = 0;
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    T[n+1] = build(1, n);
    map<int,int> mp;
    for(int i = n; i >= 1; i--){
        if(mp.find(a[i])==mp.end()){
            T[i] = update(T[i+1], i, 1);
        }else{
            int tmp = update(T[i+1], mp[a[i]], -1);
            T[i] = update(tmp, i, 1);
        }
        mp[a[i]] = i;
    }
    while(q--){
        int l, r; scanf("%d%d", &l, &r);
        printf("%d\n", query(T[l], r));
    }
    return 0;
}


Measured memory_bytes: 253444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int N, X, Y;
int ans[2005] = {0};
int d[2005][2005];
vector<int> dist;

int main(){
    cin >> N >> X >> Y;
    Graph G(N);

    rep(i, N-1) {
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[X-1].push_back(Y-1);
    G[Y-1].push_back(X-1);

    
    rep(i, N)rep(j, N) d[N][N] = 1001001001;

    rep(i, N) {
        dist.assign(N, -1);
        queue<int> q;
        dist[i] = 0;
        q.push(i);
        while(!q.empty()) {
            int v = q.front(); q.pop();

            for (auto nv: G[v]) {
                if (dist[nv] != -1) continue;

                dist[nv] = dist[v] + 1;
                q.push(nv);
            }
        }

        rep(j, N) {
            if (j==i) continue;
            d[min(i, j)][max(i, j)] = dist[j];
        }

    }
    rep(i, N)rep(j, N) {
        if (i >= j) continue;
        if (d[i][j] == 1001001001) continue;
        ans[d[i][j]]++;
    }
    for (int i=1; i<N; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 15488
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;

int main() {
	int n, p[8], q[8], numP = 0, numQ = 0, v[8];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> q[i];
	}
	for (int i = 0; i < n; i++) {
		v[i] = i + 1;
	}
	int count = 0;
	do {
		bool tf1 = true, tf2 = true;
		for (int i = 0; i < n; i++) {
			
			if (v[i] != p[i]) {
				tf1 = false;
			}
			if (v[i] != q[i]) {
				tf2 = false;
			}
		}
		if (tf1) {
			numP = count;
		}
		if (tf2) {
			numQ = count;
		}
		count++;
	} while (next_permutation(v,v+n));
	
	cout << abs(numP - numQ) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0; i < (n); ++i)

int main() {
  ll n, a[100001] = {0};
  cin >> n;
  ll maxA = 0, countSum = 0, maxCountSum = 0;
  ll xCount[100005] = {0};
  REP(i, n) {
    cin >> a[i];
    xCount[a[i]]++;
    if (a[i] - 1 >= 0) xCount[a[i] - 1]++;
    if (a[i] + 1 < 100000) xCount[a[i] + 1]++;
    maxA = max(maxA, a[i]);
  }
  for (int i = 0; i <= maxA; ++i) {
    // countSum = xCount[i - 1] + xCount[i] + xCount[i + 1];
    maxCountSum = max(maxCountSum, xCount[i]);
  }
  cout << maxCountSum << endl;
  return 0;
}

Measured memory_bytes: 1792
n = int(input())
x = list(map(int, input().split()))
m = int(input())
a = list(map(int, input().split()))

for mi in a:
    if x[mi-1] + 1 in x:
        pass
    else :
        x[mi-1] = min(2019, x[mi-1] + 1)

for i in x:
    print(i)


Measured memory_bytes: 5604
/*
C:\Users\jolog\CLionProjects\progcpp
 */
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define int long long

signed main() { //[J][O][L][S][K][E][Y]
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int n, k; cin >> n >> k;
        n %= k;
        cout << min(n, abs(n - k));
        return 0;
}

/*

*/

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

int main()
{
    char c;
    cin >> c;
    if(c == 'a' || c == 'i' || c == 'e' || c == 'u' || c == 'o'){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 



int main(void){
    string s;
    cin>>s;
    int ans = 0;
    int n = s.length();
    for(int i=0;i<n;i++){
        if(s[i]=='1')ans++;
    }
    cout<<2*min(ans,n-ans)<<endl;
    return 0;
}



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

ll power(ll x,ll y){
  if(y==0){
    return 1;
  }else if(y==1){
    return x%MOD;
  }else if(y%2==0){
    return power(x,y/2)*power(x,y/2)%MOD;
  }else{
    return power(x,y-1)*x%MOD;
  }
}

int main(){
  ll N,M,K;cin >> N >> M >> K;
  if(N==1){
    cout << M << endl;
    return 0;
  }
  if(M==1){
    if(K+1==N){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
    return 0;
  }
  if(K+1==N){
    cout << power(M,N)%MOD << endl;
    return 0;
  }
  vector<ll> P(K+1);
  P[0] = 1;
  for(ll l=1;l<=K;l++){
    P[l] = P[l-1] * (M-1)% MOD;
  }
  vector<ll> C(N-1,1);
  C[0] = 1;
  for(ll l=1;l<N-1;l++){
    C[l] = C[l-1]*(N-l)%MOD*power(l,MOD-2)%MOD;
  }
  //cout <<"# " << C[K] << " # " << P[0] << endl; 
  ll sum = 0;
  for(ll l=0;l<=K;l++){
    ll x = C[l];
    //cout << "C[" << l << "] = " << C[l] << endl;
    //cout << "P[" << K-l << "] = " << P[K-l] << endl;
    x = x * P[K-l] % MOD;
    sum = (sum + x)%MOD;
  }
  sum = sum * M % MOD * power(M-1,N-K-1) % MOD;
  cout << sum << endl;
}

Measured memory_bytes: 5800
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f
#define ms(x, y) memset(x, y, sizeof(x))
int n, a[100001], dp[100001];
int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    ms(dp, INF); dp[0] = 0;
    for (int i = 0; i < n; i++){
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(a[i + 1] - a[i]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(a[i + 2] - a[i]));
    }
    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 1024
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
dishes = [a,b,c,d,e]
n = []
ans = 0
for i in range(5):
  if dishes[i]%10==0:
    ans += dishes[i]//10
  else:
    ans += dishes[i]//10+1
    n.append(dishes[i]%10)
if len(n)==0:
  print(ans*10)
else:
  ans = ans*10-10+min(n)
  print(ans)

Measured memory_bytes: 3064
unittest
{
	assert( [ "??2??5" ].parse.expand.solve == 768 );
	assert( [ "?44" ].parse.expand.solve == 1 );
	assert( [ "7?4" ].parse.expand.solve == 0 );
	assert( [ "?6?42???8??2??06243????9??3???7258??5??7???????774????4?1??17???9?5?70???76???" ].parse.expand.solve == 153716888 );
}



import std.conv;
import std.functional;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	const M = 13;
	
	auto dp = new long[ M ][ 1 + s.length ];
	dp[ 0 ][ 0 ] = 1;
	foreach_reverse( i, c; s )
	{
		auto d = s.length.signed - 1 - i.signed;
		if( c != '?' )
		{
			auto n = c - '0';
			auto m = n.mulMod!M( 10.memoize!( powMod!M )( d ) );
			foreach( mb; 0L .. M )
			{
				dp[ d + 1 ][ mb.addMod!M( m ) ] = dp[ d + 1 ][ mb.addMod!M( m ) ].addMod( dp[ d ][ mb ] );
			}
		}
		else
		{
			foreach( n; 0L .. 10L )
			{
				auto m = n.mulMod!M( 10.memoize!( powMod!M )( d ) );
				foreach( mb; 0L .. M )
				{
					dp[ d + 1 ][ mb.addMod!M( m ) ] = dp[ d + 1 ][ mb.addMod!M( m ) ].addMod( dp[ d ][ mb ] );
				}
			}
		}
	}
	return dp[ $ - 1 ][ 5 ];
}

// 足し算
auto addMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( x + y ) % MOD;
}

// 掛け算
auto mulMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y % MOD;
}

// べき乗
auto powMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	auto a = 1L;
	for( ; 0 < y; y >>= 1 )
	{
		if( y & 1 ) a = a * x % MOD;
		x = x ^^ 2 % MOD;
	}
	return a;
}


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

using namespace std;
int main()
{
int n,k,sum;
int i;
vector<int> l(50);
cin>>n;
cin>>k;
for(i=0;i<n;i++)
{
  cin>>l[i];
}
sort(l.begin(),l.end());
reverse(l.begin(),l.end());
sum=0;
for(i=0;i<k;i++)
{
  sum+=l[i];
}
cout<<sum<<endl;
return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>

double arr[1000] = {0};
int main(){
	int n;
	while(1){
		scanf("%d",&n);
		if(n==0)
			break;
		for(int i=1;i<=n;i++){
			scanf("%lf",&arr[i]);
		}
		double sum = 0;
		for(int i=1;i<=n;i++){
			sum += arr[i];
		}
		double sum1 = 0;
		double avg = sum / n;
		for(int i=1;i<=n;i++){
			arr[i] = pow((arr[i]-avg),2);
			sum1 += arr[i];
		}
		double variance = sqrt(sum1/n);
		printf("%.4lf\n",variance );
	}
}


Measured memory_bytes: 2044
#include<iostream>
#include<stack>
#include<vector>
#include<tuple>
using namespace std;
const int N=2e5;
stack<int>FREE;
const int ONE=3;
int p2[60];
vector<tuple<char,int,int,int> >ans;
void pls(int a,int b,int c)
{
	ans.push_back(make_tuple('+',a,b,c));
}
void cmp(int a,int b,int c)
{
	ans.push_back(make_tuple('<',a,b,c));
}
void zero(int a)
{
	cmp(a,a,a);
}
void land(int a,int b,int c)
{
	pls(a,b,c);
	cmp(ONE,c,c);
}
void move(int a,int b)
{
	zero(b);
	pls(a,b,b);
}
void cond_move(int a,int b,int c)
{
	zero(c);
	int d=FREE.top();FREE.pop();
	int e=FREE.top();FREE.pop();
	pls(a,ONE,e);
	for(int i=59;i>=0;i--)
	{
		pls(c,p2[i],d);
		cmp(d,e,d);
		land(b,d,d);
		for(int j=0;j<i;j++)
		{
			pls(d,d,d);
		}
		pls(c,d,c);
	}
	FREE.push(e);
	FREE.push(d);
}
main()
{
	pls(0,1,ONE);
	cmp(2,ONE,ONE);
	p2[0]=ONE;
	for(int i=1;i<60;i++)
	{
		p2[i]=p2[i-1]+1;
		pls(p2[i-1],p2[i-1],p2[i]);
	}
	int p2a[30];
	p2a[0]=p2[59]+1;
	pls(0,p2a[0],p2a[0]);
	for(int i=1;i<30;i++)
	{
		p2a[i]=p2a[i-1]+1;
		pls(p2a[i-1],p2a[i-1],p2a[i]);
	}
	for(int i=p2a[29]+1;i<N;i++)FREE.push(i);
	int cnt=FREE.top();FREE.pop();
	int d=FREE.top();FREE.pop();
	int e=FREE.top();FREE.pop();
	pls(1,ONE,e);
	int f=FREE.top();FREE.pop();
	for(int i=30;i--;)
	{
		pls(cnt,p2[i],d);
		cmp(d,e,d);
		cond_move(p2a[i],d,f);
		pls(2,f,2);
		cond_move(p2[i],d,f);
		pls(cnt,f,cnt);
	}
	cout<<ans.size()<<endl;
	for(tuple<char,int,int,int>p:ans)
	{
		cout<<get<0>(p)<<" "<<get<1>(p)<<" "<<get<2>(p)<<" "<<get<3>(p)<<endl;
	}
}


Measured memory_bytes: 6168
// Problem : K - Stones
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_k?lang=en
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define Ma7moud_7amdy                                                                                                  \
    ios_base::sync_with_stdio(false);                                                                                  \
    cin.tie(NULL);                                                                                                     \
    cout.tie(NULL)
#define Open_Sesame Open()
#define all(v) ((v).begin()), ((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define clr(arr, x) memset(arr, x, sizeof arr)
#define endl "\n"
#define watch(x) cout << #x << " = " << x << endl;
#define RT(x) return cout << (x), 0;
#define Accepted 0
typedef long long ll;
typedef vector<int> vi;
const int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
void Open() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
const int mod = ll(1e9 + 7), N = 2000 + 5;
//“Nobody but you have to believe in your dreams to make them a reality.” ― Germany Kent
int n, a[101], k;
int mem[(int) 1e5+1][2];
bool stones(int rem = k, bool state = 0) {

	if (rem == 0)
		return state;

	int &ret = mem[rem][state];
	if (~ret)
		return ret;
	ret = state;

	for (int i = 0; i < n && a[i] <= rem; i++) {
		if (state)
			ret &= stones(rem - a[i], !state);
		else
			ret |= stones(rem - a[i], !state);
	}
	return ret;
}
int main() {
	Ma7moud_7amdy
	;
	// Open_Sesame;
	clr(mem, -1);
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	cout << (stones() ? "First\n" : "Second");
}


Measured memory_bytes: 12252
/******************************************
*    AUTHOR:         CHIRAG AGARWAL       *
*    INSTITUITION:   BITS PILANI, PILANI  *
******************************************/
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL; 
typedef long double LD;
const int MAX=2e5+5;
int pre[26][MAX];
int dp[MAX];
int mask[MAX];
map<int,int> mp;
string s;

int main() 
{
	memset(dp,-1,sizeof dp);
	cin>>s;

	pre[s[0]-'a'][0]=1;

	for(int i=1;i<s.length();i++)
	{
		for(int j=0;j<26;j++)
		{
			if((s[i]-'a')==j)
			{
				pre[j][i]=pre[j][i-1]+1;
			}
			else
			{
				pre[j][i]=pre[j][i-1];
			}
		}
	}

	for(int i=0;i<s.length();i++)
	{
		int msk=0;
		for(int j=0;j<26;j++)
		{
			if(pre[j][i]%2)
			{
				msk^=(1<<j);
			}
		}
		mask[i+1]=msk;
	}
	dp[s.length()+1]=0;
	for(int i=s.length();i>=1;i--)
	{
		int ans=s.length()-i+1;
		if(mp.find(mask[i-1])!=mp.end())
		{
			ans=min(ans,dp[mp[mask[i-1]]+1]+1);
		}
		for(int j=0;j<26;j++)
		{
			if(mp.find(mask[i-1]^(1<<j))!=mp.end())
			{
				ans=min(ans,1+dp[mp[(mask[i-1]^(1<<j))]+1]);
			}
		}
		ans=min(ans,dp[i+1]+1);
		if(mp.find(mask[i])!=mp.end())
		{
			if(ans<dp[mp[mask[i]]])
			mp[mask[i]]=i;
		}
		else
		{
			mp[mask[i]]=i;
		}
		dp[i]=ans;
///		printf("%d\n",dp[i]);
	}
	printf("%d\n",dp[1]);
	return 0;
}	


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

string s;
ll cnt = 0;

int main(){
  cin >> s;
  REP(i,s.size()){
    if(s[i]=='+') cnt++;
    else cnt--;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    int W, H;
    cin>>W>>H;
    vector<ll> A(W);
    REP(i, W) cin>>A[i];
    vector<ll> B(H);
    REP(i, H) cin>>B[i];
    ll res = 0;
    vector<ll> ca(W+1);
    vector<ll> cb(H+1);
    sort(ALL(A));
    REP(i, W){
        ca[i+1] = ca[i] + A[i];
    }
    REP(i, H){
        cb[i+1] = cb[i] + B[i];
    }
    res += ca[W] + cb[H];
    for(int i=0; i<H; i++){
        ll x = B[i];
        ll n = A.end() - (upper_bound(ALL(A), x)); 
        res += n*x + (ca[W-n]- ca[0]);
        //cout << x << " " << n << " " << res << endl;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
    long long int N,a=0,b=0;
    cin >> N ;
   long long int M[N+1],I[N];
for(long long int i=0; i<N+1;i++){
cin >> M[i];
}
for(long long int i=0; i<N;i++){
cin >> I[i];
}
 
 for(long long int i=0; i<N;i++){
     a=I[i]-M[i];
     if(a<=0){
         b+=I[i];
     }else{
         b+=M[i];
     if(a-M[i+1]<=0){
       b+=a;
        M[i+1]-=a;}else {
            b+=M[i+1];
            M[i+1]=0;
        }
 
     }
    
}
 
 cout << b;
 
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{

  int a[10];
  int b,c,d,e;

  for(b=0;b<10;b++)
    scanf("%d",&a[b]);

  for(b=0;b<10;b++)
    for(c=0;c<b-1;c++)
      if(a[b]>a[c]){
	d=a[b];
	a[b]=a[c];
	a[c]=d;
      }

  for(b=0;b<3;b++)
    printf("%d\n",a[b]);

  return 0;
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

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

int main() {
    ll x, k, d, ans;
    cin >> x >> k >> d;
    x = abs(x);
    if (x / d < k) {
        if ((k - (x - x % d) / d) % 2 == 0)
            ans = x % d;
        else
            ans = d - x % d;
    }
    else {
        ans = x - k * d;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
n, k = map(int, input().split())
arr = [False for i in range(n + 1)]
count = 0
for i in range(k):
    d = int(input())
    darr = list(map(int, input().split()))
    for j in darr:
        arr[j] = True
for i in range(len(arr)):
    if arr[i] == False:
        count+=1
print(count - 1)

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

int gcd(int m,int n){
  if(m%n==0)return n;
  else return gcd(n,m%n);
}
int main(){
  int x,y;
  cin>>x>>y;
  int koutenn=x+1+y+1;

  int tmp=gcd(x,y);
  koutenn=koutenn-tmp-1;
  cout<<koutenn<<endl;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
long long gcd(long long x, long long y) { return (x % y)? gcd(y, x % y): y; };

int main(){
  long long a,b,c;
  cin >> a >> b;
  c = gcd(a,b);
  int cnt=1;
  if(c==1){
    cout << cnt << endl;
    return 0;
  }
  for(int i=2; i <sqrt(c); i++){
    if(c%i==0){
      cnt +=1;
      while(c%i==0){
        c/=i;
      }
    }
  }
  if(c != 1) cnt+=1;
  
  cout << cnt << endl;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    ll n, W; cin >> n >> W;
    ll w[n], v[n];
    rep(i,n) cin >> w[i] >> v[i];

    ll dp[n+1][W+1];
    rep(i,n+1) rep(j,W+1) dp[i][j] = 0;
    
    rep(i,n){
        rep(j,W+1){
            if(j<w[i]) dp[i+1][j] = dp[i][j];
            else{
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
            }
        }
    }
    cout << dp[n][W] << endl;
}

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

using namespace std;

int main()
{
    long long n,k,s=0,t=0,d;
    cin >>n>>k;
    long long arr[n];
    for (int i=0;i<n;i++)
    {
        cin >>arr[i];
        s+=arr[i];
    }
    sort (arr,arr+n);
    if (k==0){
        cout <<s<<"\n";
}
    else if (k>=n){
            cout <<0<<"\n";
    }
    else
    {
        for (int i=(n-1);i>=0;i--)
        {arr[i]=0;
        k--;
        d=n;
            if (k==0)
             break;

        }
        for (int i=0;i<d;i++)
        {
            t+=arr[i];
        }
        cout <<t<<"\n";
    }
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,e;
	cin>>a>>b;
	c=a+b;
	d=a-b;
	e=a*b;
	if(c>=e && c>=d)
		cout<<c<<endl;
	if(e>c && e>=d)
		cout<<e<<endl;
	if(d>e && d>c)
		cout<<d<<endl;
	return 0;
}

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

int main() {
  int A, B;
  int seki;
  cin>>A>>B;
  if(A>9)
    cout<<-1<<endl;
  else if(B>9)
    cout<<-1<<endl;
  else
    cout<<A*B<<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,m;
    std::cin >> n;
    int t[101];
    int sum=0;
    for (int i = 1; i <= n; i++) {
        std::cin >> t[i];
        sum+=t[i];
    }
    std::cin >> m;
    for (int i = 0; i < m; i++) {
        int p,x;
        std::cin >> p >>x;
        std::cout << sum-t[p]+x << std::endl;
    }
}


Measured memory_bytes: 256
s = list(input())
N = len(s)
judge = "balanced"
for i in range(N - 1):
	if s[i] == s[i + 1]:
		print(i + 1, i + 2)
		judge = "unbalanced"
		break

if judge == "balanced":
	for i in range(N - 2):
		if s[i] == s[i + 2]:
			print(i + 1, i + 3)
			judge = "unbalanced"
			break
			
if judge == "balanced":
	print(-1, -1)

Measured memory_bytes: 3956
import java.util.Arrays;
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] nums = new int[n];
		int ans = 0;

		for(int i=0; i<nums.length; i++) {
			nums[i] = sc.nextInt();
		}

		Arrays.sort(nums);
			for(int j=1; j<k+1; j++) {
				ans += nums[nums.length-j];
			}
			System.out.println(ans);
	}
}


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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
if n == 1:
    print('Hello World')
else:
    a = I()
    b = I()
    print(a+b)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
typedef int I;
#define REP(i,n) for(I i=0;i<(I)(n);i++)
I n,dp[1024][100001],v[323456],w[323456],ne;

void dfs(I i){
    I j=i/2;
    if(i>1){
        for(I k=100000;k+1;k--){
            if(dp[j-1][k]or!k){
                if((ne=k+w[i-1])<=100000)dp[i-1][ne]=max(dp[j-1][k]+v[i-1],dp[i-1][ne]);
            }
            dp[i-1][k]=dp[j-1][k];
        }
    }
    if(i*2<=min(1024,n))dfs(i*2);
    if(i*2+1<=min(1024,n))dfs(i*2+1);
}

signed main(){
    cin>>n;REP(i,n)cin>>v[i]>>w[i];
    dp[0][*w]=*v;
    dfs(1);
    REP(i,1024)REP(j,100000)dp[i][j+1]=max(dp[i][j],dp[i][j+1]);
    I q;cin>>q;
    REP(i,q){
        I u,l;cin>>u>>l;
        vector<I> cand;
        while(u>1024){
            cand.push_back(u-1);
            u=u/2;
        }
        I r=cand.size();
        I ans=0;
        REP(j,1<<r){
            I v_sub=0;I w_sub=0;
            REP(k,r){
                if(j>>k&1){
                    v_sub+=v[cand[k]];
                    w_sub+=w[cand[k]];
                }
            }
            if(w_sub<=l)ans=max(ans,dp[u-1][l-w_sub]+v_sub);
        }
        cout<<ans<<endl;
    }
}


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

using namespace std;

const int md = int(1e9) + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
  return (int) ((long long) a * b % md);
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  string s;
  cin >> n >> s;

  vector< vector<int> > dp(n, vector<int>(n + 1));
  dp[0][1] = 1;
  for (int i = 0; i < n - 1; i++) {
    vector<int> sum(n + 1);
    for (int j = 0; j < n; j++) {
      add(sum[j + 1], sum[j]);
      add(sum[j + 1], dp[i][j + 1]);
    }
    for (int j = 1; j <= i + 2; j++) {
      if (s[i] == '<') {
        dp[i + 1][j] = sum[j - 1];
      } else {
        dp[i + 1][j] = sum[n];
        sub(dp[i + 1][j], sum[j - 1]);
      }
    }
  }
  
  int res = 0;
  for (int i = 1; i <= n; i++) {
    add(res, dp[n - 1][i]);
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 35584
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        System.out.println(a+b+c < 22 ? "win" : "bust");
    }
}

Measured memory_bytes: 21844
using System;

public class Test
{
	public static void Main()
	{
		// your code goes here
	string a=Console.ReadLine();
	int ans=0;
	for(int i=0;i<a.Length;i++){
		char top=a[i];
		char at=i%2==0?'g':'p';
		if(at=='g'&&top=='p'){ans--;}
		else if(at=='p'&&top=='g'){ans++;}
	}
	Console.WriteLine(Math.Max(ans,0));
	
	}
}

Measured memory_bytes: 13244
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N, W;
    while(cin >> N >> W){
        vector<int> dp(100*N+1, W+1);
        dp[0] = 0;
        for(int i=0;i<N;i++){
            int v, w; cin >> v >> w;
            for(int j=dp.size()-1;j>=0;j--){
                if(j-v < 0) break;
                dp[j] = min(dp[j], dp[j-v]+w);
            }
        }
        int res = 0;
        for(int i=0;i<dp.size();i++) if(dp[i] <= W) res = i;
        cout << res << endl;
    }
}


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

signed main(){
    int n,k;
    cin >> n >> k;
    vector<int> v1;
    vector<int> v2;
    rep(i,n) {
        int a;
        cin >> a;
        if(a==0) k--;
        if(a<0) v1.push_back(a);
        else v2.push_back(a);
    }
    if(k==0){
        cout << 0 << endl;
        return 0;
    }
    sort(v1.begin(),v1.end(),greater<int>());
    ll ans=1000000000000;

    if(k<=v1.size()) ans=min(ans,abs(v1[k-1]));
    if(k<=v2.size()) ans=min(ans,abs(v2[k-1]));

    rep(i,v1.size()){
        if(k-i-1<=v2.size() && k-i-2>=0) ans=min(ans,abs(v1[i])+v2[k-i-2]*2);
        else continue;
    }
    rep(i,v2.size()){
        if(k-i-1<=v1.size() && k-i-2>=0) ans=min(ans,v2[i]+abs(v1[k-i-2])*2);
        else continue;
    }
    cout << ans << endl;

}

Measured memory_bytes: 1656
import java.util.*;
    public class Main{
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String s = sc.nextLine();
            String t = sc.nextLine();
            int count=0;
            for (int i=1;i <= s.length(); i++) {
                if(!s.substring(i-1,i).equals(t.substring(i-1,i))){
                    count++;
                }
            }
          	System.out.println(count);
        }
    }

Measured memory_bytes: 55144
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
int main(){
string s;cin>>s;
if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;

    if(a <= 8 && b <= 8){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll K;
    cin >> K;
    ll a = 7;
    if(K % 2 == 0){
        cout << -1;
        return 0;
    }
    ll ans = 1;
    rep(i, 100000000){
        if(a % K == 0){
            cout << ans;
            return 0;
        }else{
            a = a*10 + 7;
            a %= K;
            ans++;
        }
    }
    cout << -1;
}


Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main() {
    int day, japa, math, do_japa, do_math, holi = 0, do_day_japa, do_day_math;
    cin >> day >> japa >> math >> do_japa >> do_math;
    if (japa%do_japa == 0) {
        do_day_japa = japa / do_japa;
    }
    else {
        do_day_japa = japa / do_japa + 1;
    }
    if (math%do_math == 0) {
        do_day_math = math / do_math;
    }
    else {
        do_day_math = math / do_math + 1;
    }
    if (do_day_japa > do_day_math) {
        holi = day - do_day_japa;
    }
    else {
        holi = day - do_day_math;
    }
    cout << holi << endl;
    return 0;
}

Measured memory_bytes: 3076
from itertools import product

N = int(input())
B = list(product([1, 0], repeat=N))
L = []
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().split())
        L.append([x, y, i+1])
ans = 0
for b in B:
    for l in L:
        if b[l[2]-1] == 1 and l[1] != b[l[0]-1]:
            break
    else:
        if ans < b.count(1):
            ans = b.count(1)
print(ans)


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

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

int map[51][51];
int w, h;

void oneIsland(int x, int y) {
	for (int i = 0; i < 8; i++) {
		int nextX = x + dx[i];
		int nextY = y + dy[i];
		if ((0 <= nextX && nextX < w)
			&& (0 <= nextY && nextY < h)) {
			if (map[nextY][nextX] == 1) {
				map[nextY][nextX] = 0;
				oneIsland(nextX, nextY);
			}
		}
	}
}

int main() {
	while (1) {
		cin >> w >> h;
		if (w == 0 && h == 0) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> map[i][j];
			}
		}
		
		int count = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (map[i][j] == 1) {
					map[i][j] = 0;
					count++;
					oneIsland(j, i);
				}
			}
		}
		cout << count <<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i,j;
    ll n;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++) cin>>a[i];
    vector<P> b;
    for(i=0;i<n;i++) b.pb(P(a[i],i));
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    VVI w(n+1,VI(n+1,0));
    for(i=0;i<n;i++){
        for(j=0;j<=i+1;j++){
            if(j>=1) chmax(w[j][i+1-j],w[j-1][i+1-j]+b[i].fi*abs(b[i].se-j+1));
            if(j<=i) chmax(w[j][i+1-j],w[j][i-j]+b[i].fi*abs(n-(i+1-j)-b[i].se));
        }
    }
    ll ans=0;
    for(i=0;i<n;i++){
        chmax(ans,w[i][n-i]);
    }
    cout<<ans<<endl;
    

}

Measured memory_bytes: 34612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

struct Date {
  int y;
  int m;
  int d;
};

int maxDate( Date d ){
  if ( d.y % 3 == 0 or d.m % 2 == 1 ) {
	return 20;
  } else {
	return 19;
  }
}

int solve( Date d ) {
  int count = 0;
  while( d.d > 1 ) {
	count++;
	d.d++;
	if ( d.d > maxDate( d ) ) {
	  d.d = 1;
	  d.m++;
	  if ( d.m > 10 ) {
		d.m = 1;
		d.y++;
	  }
	}
  }
  while( d.m > 1 ) {
	count += maxDate( d );
	d.m++;
	if ( d.m > 10 ) {
	  d.m = 1;
	  d.y++;
	}
  }
  while( d.y < 1000 ) {
	if ( d.y % 3 == 0 ) {
	  count += 200;
	} else {
	  count += 195;
	}
	d.y++;
  }
  return count;
}

int main() {
  int n;
  cin >> n;
  for ( int i = 0; i < n; i++ ){
	int y, m, d;
	cin >> y >> m >> d;
	cout << solve( {y, m, d} )  << endl;
  }  
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 13:57:43 2020

@author: shinba
"""
from itertools import combinations

n = int(input())

march = ["M","A","R","C","H"]

data = {}

for s in march:
    data[s] = 0

for i in range(n):
    name = input()
    if name[0] in march:
        data[name[0]] += 1

ans = 0

for i,j,k in combinations(data.values(),3):
    ans += i*j*k

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    bool ok = false;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] == s[i-1]) {
            cout << i << " " << i+1 << endl;
            return 0;
        }
        if (i > 1 && s[i] == s[i-2]) {
            cout << i-1 << " " << i+1 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int a,b,k;
	int num[200];
	int index=0;
	int ans=0;
	
	cin>>a>>b>>k;
	if(b-a+1>=k)
	{
		for(int i=a;i<a+k;i++)
		{
			num[index]=i;
			index++;
		}
		for(int i=b-k+1;i<b+1;i++)
		{
			if(num[index-1]>=i)
			{
				continue;
			}
			num[index]=i;
			index++;
		}

		for(int i=0;i<index;i++)
		{
			cout<<num[i]<<endl;
		}
	}else{
		for(int i=a;i<b+1;i++)
			cout<<i<<endl;
	}
	return 0;
}

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

int main() {
  char c;
  cin >> c;
  
  if( c == 'a' | c == 'e' | c == 'i' | c == 'o' | c == 'u'){
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long N, vector<long long> A){
	ll k = 0;

	rep(i, N) {
		k += A[i];
	}
	// cout << k << endl;
	bool flg = true;
	if (k * 2 % (N * (N + 1)) != 0) flg = false;
	k = k * 2 / (N * (N + 1));
	// cout << k << endl;
	ll cnt = 0;
	
	rep(i, N) {
		ll e =  -1 * (A[(i+1)%N] - A[i%N] - k);
		// cout << i << " " << e << endl;
		if (e < 0 || e % N != 0) {
			flg = false;
			break;
		}
		cnt += e / N;
	}
	if (cnt == k && flg) cout << "YES" << endl; else cout << "NO" << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, A);
	return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
class SegmentTreeRSQ {
private:
    int n;
    vector<LL> node, lazy;

public:
    void init(vector<LL> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);

        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, LL x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

   LL getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        LL vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        LL vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};
int main(){
    CIN(w);CIN(q);
    SegmentTreeRSQ Seg;
    Seg.init(vector<LL>(w,0LL));
    for(int a = 0;a < q;a++){
        CIN(x);CIN(y);CIN(z);
        if(x == 0){
            Seg.add(y-1,y,z);
        }else{
            COUT(Seg.getsum(y-1,z));
        }
        //Seg.show();
    }
    return 0;
}



Measured memory_bytes: 7576
s = gets.chomp.chars

ans_a = ans_b = 0

s.size.times do |i|
  c = s[i].to_i
  ans_a += 1 if i.even? && c == 0 || i.odd? && c == 1
end

s.size.times do |i|
  c = s[i].to_i
  ans_b += 1 if i.even? && c == 1 || i.odd? && c == 0
end

puts ans_a <= ans_b ? ans_a : ans_b


Measured memory_bytes: 6908
import java.util.*

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val op = sc.next()
    val b = sc.nextInt()

    val output = when (op) {
        "+" -> a + b
        "-" -> a - b
        else -> throw IllegalArgumentException()
    }
    println(output)
}

Measured memory_bytes: 31384
import collections

n = int(input())
a = list(map(int, input().split()))

l = []
r = []
for i in range(n):
  l.append(i+a[i])
  r.append(i-a[i])

count = collections.Counter(r)
ans = 0
for i in l:
  ans += count.get(i,0)
      
print(ans)

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	ll ans = 0;
	cin >> s;
	for(auto i:s)
	{
		ans += i-'0';
	}
	if(ans%9 == 0)
		cout <<"Yes\n";
	else
	{
		cout <<"No\n";
	}
	

}


Measured memory_bytes: 3780
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int c =  1;
		for(int i = 0; i < N  - 1; i++){
			c *= (K - 1);
		}
		c = K * c;
		System.out.println(c);
	}
}

Measured memory_bytes: 21844