akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int K, S; cin >> K >> S;
    vec v;
    Rep1(i, 0, K){
        Rep1(j, 0, K){
            v.push_back(i+j);
        }
    }
    sort(all(v));
    int res=0;
    Rep1(i, 0, K){
        auto it = lower_bound(all(v), S-i);
        auto it2 = upper_bound(all(v), S-i);
        res += distance(it, it2);
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 38628
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
bool is_not_out_of_range(size_t now, size_t max_num)
{
	return !(now < 0 || max_num <= now);
}
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (2 * b == a + c)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}

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

int a[100];

int main(void){
    int N, cnt;
    cnt = 0;
    
    cin >> N;
    
    for(int i = 0; i < N; i++){
        cin >> a[i];
        
        if(i%2 == 0 && a[i]%2 == 1) cnt++;
    }
    
    cout << cnt << endl;
    
    return 0;
}


Measured memory_bytes: 3616
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 200005
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<pair<ll,ll> >adj[MAX+10];
ll dep[MAX+10];
int main()
{
    fast;
    cin>>n;
    mp.clear();
    FOR(i,n)
    {
        cin>>a;
        mp[a]++;
    }
    v.clear();
    for(auto it=mp.begin();it!=mp.end();it++)
    {
         if(it->ss>=2) vp.p_b(m_p(it->ff,it->ss));
    }
    ll ans=0;
    sort(vp.rbegin(),vp.rend());
    if(vp.size()==0) ans=0;
    else if(vp[0].ss>=4)
    {
        ans=vp[0].ff*vp[0].ff;
    }
    else if(vp.size()>=2)
    {
        ans=vp[0].ff*vp[1].ff;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11264
import java.util.*;


class Main {
	static long sum=0L;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		divise(N);
		System.out.println(sum);
	}

	static void divise(long n) {
		for (int i=1;i<=Math.sqrt(n);i++) {
			if (n%i==0) {
//				if(i-1>n/i) {
//					sum+=i;
//				}
				if (i*i!=n) {
					if(n/i-1>i) {
						sum+=n/i-1;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <climits>

using namespace std;

int main() {
	int n,a;
	int mmax = INT_MIN;
	int mmin = INT_MAX;
	long msum = 0;
	
	cin >> n;
	
	while (n > 0) {
		cin >> a;
		mmax = max(mmax,a);
		mmin = min(mmin,a);
		msum += a;

		n--;
	}
	
	cout << mmin << " " << mmax << " " << msum << endl;
	
}



Measured memory_bytes: 3100
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int arr[] = new int[5];
	int count = 129;
	int number = 0;
	int sum = 0;
		for(int i=0; i<5; i++){
		arr[i] = sc.nextInt();
			if(arr[i]%10!=0 && arr[i]%10<=count%10){
			count = arr[i];
			number = i;
			}
			if(arr[i]%10==0){
			sum = sum + arr[i];
			}
			if(arr[i]%10!=0){
			sum = sum + (arr[i]/10+1)*10;
			}
		}
		if(count!=129){
		sum = sum - (10-arr[number]%10);
		}
	System.out.println(sum);
	}
}
	

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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
// end of Template

ll n,z,w,a[3000];
int main(){

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

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>z>>w;
    for(int i=1;i<=n;i++)cin>>a[i];
    ll ans = abs(w-a[n]);
    if(n>1)ans = max(ans, abs(a[n] - a[n-1]));
    cout<<ans<<newl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using pqin=priority_queue<int>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main()
{
    int n;
    cin>>n;
    vin x(n);
    rep(i,n)cin>>x[i];
    vin phy(101);
    rep2(i,1,101){
        int sum=0;
        rep(j,n){
            sum+=(x[j]-i)*(x[j]-i);
        }
        phy[i]=sum;
    }
    sort(all(phy));
    cout<<phy[1]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 100000007
typedef long long ll;
using namespace std;

int main(){
	int a,b,n;
	cin>>n>>a>>b;
	cout<<min(n*a,b)<<endl;
	return 0;
}


Measured memory_bytes: 256
import Data.Array
import Data.Array.ST
import Control.Monad
import Control.Monad.ST

gen_dp_tbl::Array Int Int ->Int->Array Int Int
gen_dp_tbl ar n = runSTArray $ do
  tbl<-newArray_ (1,n)
  writeArray tbl 1 0
  writeArray tbl 2 (abs (ar!1 - ar!2))
  forM_ [3..n] (\ i -> do
                      v<-readArray tbl (i-1)
                      w<-readArray tbl (i-2)
                      let next = min (v + abs (ar!i - ar!(i-1))) (w + abs (ar!i - ar!(i-2)))
                      writeArray tbl i next)
  return tbl

solver::[Int]->Int->Int
solver ls n = (gen_dp_tbl (listArray (1,n) ls) n)!n

main::IO()
main = do
   n<-(return.read)=<<getLine
   ls<-(return.(map read).words)=<<getLine
   print (solver ls n)

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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int a, b; cin >> a >> b;
	if(a >= b){
		rep(i, a){
			cout << b;
		}
	}
	else{
		rep(i, b){
			cout << a;
		}
	}
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

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

  vector<vector<ll>> dp(N+1,vector<ll>(1000000,INF));
  dp[0][0] = 0;

  rep(i,N) rep(sum_v,100001){
    if (sum_v-v[i]>=0) chmin(dp[i+1][sum_v],dp[i][sum_v-v[i]]+w[i]);
    chmin(dp[i+1][sum_v], dp[i][sum_v]);
  }

  ll ans = 0;
  rep(sum_v,100001){
    if (dp[N][sum_v]<=W) ans = sum_v;
  }

  cout << ans << endl;


 

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 800504
from collections import defaultdict
import copy
x=[]
d=defaultdict(int)
n,a=map(int,input().split())
dp=[[0]*n*51 for _ in range(n)]
for i in input().split():
    x.append(int(i)-a)
for i in x:
    tmp=copy.copy(d)
    for j in tmp:
        d[j+i]+=tmp[j]
    d[i]+=1
ans=d[0]
print(ans)

Measured memory_bytes: 40560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int H, W;
string s[110];
int a[110], b[110];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < H; i++) {
    int all = 1;
    for (int j = 0; j < W; j++) {
      if (s[i][j] == '#') all = 0;
    }
    a[i] = all;
  }
  for (int j = 0; j < W; j++) {
    int all = 1;
    for (int i = 0; i < H; i++) {
      if (s[i][j] == '#') all = 0;
    }
    b[j] = all;
  }
  for (int i = 0; i < H; i++) {
    if (a[i]) continue;
    for (int j = 0; j < W; j++) {
      if (b[j]) continue;
      cout << s[i][j];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			for(int i=0;i<9;i++){
				n -= sc.nextInt();
			}
			System.out.println(n);
		}
	}
}

Measured memory_bytes: 17216
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

int main() {
  char a[4];
  cin >> a;
  if((a[0] == a[1] && a[1] == a[2]) || (a[1] == a[2] && a[2] == a[3])) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;

struct Query {
	int l, r, index;
	bool operator<(const Query&q)const {
		return r < q.r;
	}
};

class Add_Segment_Tree {
	vector<long long int>v;
	long long int ret;
	int num;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = Update(place * 2) + Update(place * 2 + 1);
		return v[place];
	}
public:
	Add_Segment_Tree(int n) {
		n++;
		num = 1;
		while (num < n * 2)num *= 2;
		v.resize(num, 0);
	}
	void Add(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] += num;
		if (!update)return;
		place /= 2;
		while (place) {
			v[place] = v[place * 2] + v[place * 2 + 1];
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int Sum(int a, int b) {
		ret = 0;
		b++;
		for (a += num / 2, b += num / 2; a < b; a >>= 1, b >>= 1) {
			if (a & 1)ret += v[a++];
			if (b & 1)ret += v[--b];
		}
		return ret;
	}
};

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

	cin >> N >> K;
	vector<int>v(N);
	for (auto &i : v)cin >> i;
	vector<Query>query(K);
	for (int i = 0; i < K; i++) {
		cin >> query[i].l >> query[i].r;
		query[i].l--, query[i].r--;
		query[i].index = i;
	}
	sort(query.begin(), query.end());
	Add_Segment_Tree asg(N);
	vector<int>bef(N + 1, -1);
	vector<int>ans(K);
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (bef[v[i]] != -1) {
			asg.Add(bef[v[i]], -1, true);
		}
		asg.Add(i, 1, true);
		bef[v[i]] = i;
		while (cnt < K&&query[cnt].r == i) {
		//	cout << i << " " << cnt << endl;
			ans[query[cnt].index] = asg.Sum(query[cnt].l, query[cnt].r);
		//	cout << "cntup" << endl;
			cnt++;
		}
	//	for (int j = 0; j < N; j++) {
	//		cout << asg.Sum(j, j) << " ";
	//	}
	//	cout << endl;
	//	cout << "cnt " << cnt << endl;
	}
	for (auto i : ans)cout << i << endl;
}

Measured memory_bytes: 23672
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll gcd(ll x,ll y){
    return y?gcd(y,x%y):x;
}

void solve()
{
    ll x,y;cin>>x>>y;
    cout<<x*y/gcd(x,y)<<endl;
}

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



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAx = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAx, min_index = -1;

typedef long long ll;
typedef pair<ll, ll> Pa;

int main() {
    cin >> N;
    int curr = 1;
    int count = 0;
    rep(i, N){
        cin >> A;
        if(curr == A) curr++;
        else count++;
    }
    if(N == count) cout << -1;
    else cout << count;
}


Measured memory_bytes: 256
using System;

namespace noteCsharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] input1 = input.Split(char.Parse(" "));
            int a = int.Parse(input1[0]);
            int b = int.Parse(input1[1]);
            Console.WriteLine(a * b + " " + (a * 2 + b * 2));
        }
    }
}



Measured memory_bytes: 15940
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;



ll f(ll w) {
  if(w<0) return 1;
  ll i;
  ll res=0;
  
  for(ll S=0; S<1<<w; S++) {
    vector<ll> v;
    for(i=0; i<w; i++) {
      if(S>>i&1) v.push_back(i);
    }
    
    ll f=1;
    for(i=0; i<(ll)v.size()-1; i++) {
      if(v[i]+1==v[i+1]) f=0;
    }
    
    if(f) res++;
  }
  
  return res;
}

int main(void) {
  ll H, W, K;
  cin >> H >> W >> K;
  ll i, j, k, l;
  ll dp[111][11]={};
  
  dp[0][1]=1;
  for(i=0; i<H; i++) {
    for(j=1; j<=W; j++) {
      
      //left
      if(j==2||j==W) {
        moC(dp[i+1][j-1], +, dp[i][j]*f(W-3)%MOD);
      }else if(2<j && j<W) {
        moC(dp[i+1][j-1], +, dp[i][j]*f(j-3)%MOD*f(W-j-1)%MOD);
      }
      
      //right
      if(j==1||j==W-1) {
        moC(dp[i+1][j+1], +, dp[i][j]*f(W-3)%MOD);
      }else if(1<j && j<W-1) {
        moC(dp[i+1][j+1], +, dp[i][j]*f(j-2)%MOD*f(W-j-2)%MOD);
      }
      
      //down
      if(j==1||j==W) {
        moC(dp[i+1][j], +, dp[i][j]*f(W-2)%MOD);
      }else {
        moC(dp[i+1][j], +, dp[i][j]*f(j-2)%MOD*f(W-j-1)%MOD);
      }
      
      
    }
  }
  
  pt(dp[H][K]);
  
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
const int MOD = 1e9 + 7;
struct segK{//非再帰
    int n;
    long long MIN;
    int size;
    vector<long long> dat;
    segK(int n_){
        n = 1;
        MIN = -1;
        size = n_;
        while(n < n_) n *= 2;
        dat.resize(2 * n);
        for(int i = 1; i < 2 * n; i++) dat[i] = MIN;
    }
    void update(int k, long long a){
        k += n;
        dat[k] = a;
        while(k > 0){
            k >>= 1;
            dat[k] = max(dat[k << 1 | 0], dat[k << 1 | 1]);
        }
    }
    long long query(int l, int r){
        long long res = 0;
        l += n;
        r += n;
        while(r > l){
            if(l & 1) res = max(res, dat[l++]);
            if(r & 1) res = max(res, dat[--r]);
            l >>= 1;
            r >>= 1;
        }
        return res;
    }
    int right_bin(int l, long long v) {
        if(l == size) return l;
        l += n;
        long long zero = -1;
        do {
            while (l % 2 == 0) l >>= 1;
            if (dat[l] >= v) {
                while (l < n) {
                    l = (2 * l);
                    if (dat[l] < v) {
                        zero = max(zero, dat[l]);
                        l++;
                    }
                }
                return l - n;
            }
            zero = max(zero, dat[l]);
            l++;
        } while ((l & -l) != l);
        return size;
    }
    int left_bin(int r, long long v) {
        if(r == 0) return r;
        r += n;
        long long zero = -1;
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (dat[r] <= v) {
                while (r < n) {
                    r = (2 * r + 1);
                    if (dat[r] > v) {
                        zero = max(zero, dat[r]);
                        r--;
                    }
                }
                return r + 1 - n;
            }
            zero = max(zero, dat[r]);
        } while ((r & -r) != r);
        return 0;
    }
};


int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    segK segk(300100);
    for(int i = 0; i < N; i++){
        if(i == 0) segk.update(A[i], 1);
        else{
            int l = max(0, A[i] - K);
            int r = min(300050, A[i] + K);
            int res = segk.query(l, r + 1);
            if(res == -1)segk.update(A[i], 1);
            else segk.update(A[i], res + 1);
        }
    }
    cout << segk.query(0, 300100) << endl;
}


Measured memory_bytes: 12748
N = int(input())
g = [0] * (N+1)
for i in range(N):
    g[i+1] = int(input())

s = 1
cnt = 0
arrive = [0] * (N+1)
while s != 2:
    if arrive[s] == 1:
        print(-1)
        exit()
    arrive[s] = 1
    s = g[s]
    cnt += 1

print(cnt)


Measured memory_bytes: 7748
#include <bits/stdc++.h>
#include<stdlib.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
#define pr pair<ll, ll>
#define prf pair<ld,ld>
#define vct vector<ll>
#define vpt vector<pr>
#define vcf vector<ld>
#define vpf vector<prf>
#define st set<ll>
#define pq priority_queue<ll>
#define mat vector<vector<ll> >
#define all(x) x.begin(),x.end()
#define F(i, n) for(i = 0; i < (1LL*n); i++)
#define Fr(i, n) for(i = n - 1; i >= 0; i--)
 
struct custom_hash{
    static uint64_t splitmix64(uint64_t x){
        x += 0x9e3779b97f4a7c15;x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<long long, long long, custom_hash>
 
void prv(vct v){for (ll i=0;i<v.size();i++)cout<<v[i]<<" ";cout << "\n";}
void prn(ll n){cout<<n<<"\n";}
void prs(string n){cout<<n<<"\n";}
void deb(string s, ll n){cout<<s<<" : "<<n<<"\n";}
void prmt(mat m){for(ll i=0;i<(1LL*m.size());i++)prv(m[i]);}
 
mat getRzMat(ll m,ll n, ll ini=0){mat mt;mt.assign(m,vector<ll>(n,ini));return mt;}
 
ll poww(ll x, ll y, ll m){
    ll res = 1;
    while (y){
        if (y%2 == 0){x = (x * x) % m;y = y / 2;}
        else{res = (res * x) % m;y--;}
    }
    return res;
}
 
vct divsors(ll n){
    vct ans;//ans.push_back(1);
    for(ll i=1;i<=sqrt(n);i++){if(n%i==0){ans.push_back(i);if(i!=(n/i))ans.push_back(n/i);}}
    sort(ans.begin(),ans.end());
    return ans;
}
vct sieve(ll n){
    vct ans(n+1,-1);
    for(ll i=2;i<=n;i++){
        if(ans[i]==-1){
            for(ll j=i;j<=n;j+=i)if(ans[j]==-1)ans[j]=i;
        }
    }
    return ans;
}
mat mt;
ll n, k, m, l, r, x, y, z, ans=0;
ll t, t1, t2;
ll q;
ll i, j;
ll a, b, c, d, w;
ll mod = 1000000007;
ld epi = 0.00000001;
ll cas=0;
void solve(){
    string s,su;
    cin>>s>>su;
    n=s.size();
    m=su.size();
    ll ans=LLONG_MAX;
    for(i=0;i<=(n-m);i++){
        string sk=s.substr(i,m);
        ll cn=0;
        for(j=0;j<m;j++)if(su[j]!=sk[j])cn++;
        ans=min(ans,cn);
    }
    prn(ans);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout<<fixed<<setprecision(10);
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    ll t = 1;
    // cin >> t;
    cas=1;
    while (t--){
        solve();
        cas++;
    }
    return 0;
}
 

Measured memory_bytes: 3684
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    D = I()
    c = LI()
    s = LLIN(D)
    lst = [0] * 26
    for i in range(D):
        print(i % 26 + 1)
        # l = s[i]
        # print(l.index(max(l)) + 1)




if __name__ == '__main__':
    main()

Measured memory_bytes: 78348
#include<bits/stdc++.h>
#define ll long long
#define REP(i,a,n) for(ll i=a;i<(n);i++)
#define RE return
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    int k,a,b;
    cin>>k>>a>>b;
    REP(i,a,b+1)
    if(i%k==0){
    	cout<<"OK";
    	RE 0;
	}
	cout<<"NG";
    RE 0;
}


Measured memory_bytes: 3652
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.array;

void main() {
    int n = readln.chomp.to!int;

    int[] c = new int[](n), s = new int[](n), f = new int[](n);

    for (int i = 0; i < n - 1; ++i) {
        auto l = readln.chomp.split.map!(to!int).array;

        c[i] = l[0];
        s[i] = l[1];
        f[i] = l[2];
    }

    for (int i = 0; i < n - 1; ++i) {
        int ans = s[i];
        for (int j = i; j < n - 1; ++j) {
            ans += c[j];

            if (j == n - 2) {
                break;
            }

            int wait;

            if (ans <= s[j + 1]) {
                ans += (s[j + 1] - ans);
            }
            else {
                if (ans % f[j + 1] != 0) {
                    wait = ((ans + f[j + 1]) / f[j + 1]) * f[j + 1] - ans;
                    ans += wait;
                }
            }
        }

        writeln(ans);
    }
    writeln(0);
    return;
}

Measured memory_bytes: 380
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

ll calc(ll *a, int l, int r){
  if(l > r) return 0;
  return a[r] - a[l-1];
}

int main(){
  int n, k;
  ll a[SIZE];
  ll p[SIZE] = {};
  ll s[SIZE] = {};
  
  scanf("%d%d",&n,&k);

  for(int i=1;i<=n;i++){
    scanf("%lld",a+i);
    if(a[i] > 0) p[i] = a[i];
    s[i] = a[i];
  }

  for(int i=0;i<=n;i++){
    s[i+1] += s[i];
    p[i+1] += p[i];
  }
  
  ll ans = 0;
  
  for(int i=1;i<=n-(k-1);i++){
    ans = max(ans,calc(s,i,i+k-1) + calc(p,1,i-1) + calc(p,i+k,n));
    ans = max(ans,calc(p,1,i-1) + calc(p,i+k,n));
  }

  printf("%lld\n",ans);
  
  return 0;
}


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

int main() {
  int N, cnt, i;
  cnt = 1;
  cin >> N;
  vector<int> mochi(N);
  
  for(i=0; i<N; i++){
    cin >> mochi.at(i);
  }
  
  sort(mochi.begin(),mochi.end(),greater<int>());
  
  for(i=1; i<N; i++){
    if(mochi.at(i-1) > mochi.at(i)){
      cnt++;
    }
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i)
mul = 1

if A.index(0)
    puts '0'
    exit
end

N.times do |i|
    if mul > 10**18 / A[i]
        puts '-1'
        exit
    end
    mul *= A[i]
end
puts mul

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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//------------------------------------------------------------------
class UnionFind{

public:
  int vertexNumber;
  vector<int> parents;

  UnionFind(int n){
    vertexNumber = n;
    parents.assign(n, -1);
  }
  ~UnionFind(){}

  int find(int x){
    if(parents[x]<0){return x;}
    else {return find(parents[x]);}
  }

  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x==y){return;}

    if(parents[x]>parents[y]){
      int tmp = x;
      x = y;
      y = tmp;
    }

    parents[x] += parents[y];
    parents[y] = x;
  }

  int size(int x){return -parents[find(x)];}

  bool is_same(int x, int y){return find(x) == find(y);}

  int count_roots(){
    int ct=0;
    for(int i=0; i<vertexNumber; i++){
      if(parents[i]<0){ct++;}
    }
    return ct;
  }
};

int main(void){
  ll n, m;
  cin >> n >> m;
  vec a(m), b(m);
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  UnionFind uf(n);

  vecll ans;
  ll tmp=n*(n-1)/2;
  rep(i,m){
    ans.push_back(tmp);
    if(uf.is_same(a[m-i-1], b[m-i-1])) continue;
    ll n1 = uf.size(a[m-i-1]);
    ll n2 = uf.size(b[m-i-1]);
    tmp -= n1*n2;
    uf.unite(a[m-i-1], b[m-i-1]);
  }

  rep(i,m){
    prt(ans[m-i-1]);
  }

}


Measured memory_bytes: 5500
#include <iostream>

using namespace std;

int main(void)
{
	int n;
	int a[200010];
	int exor = 0;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		exor ^= a[i];
	}

	for (int i = 0; i < n; i++)
	{
		cout << (exor^a[i]) << " ";
	}

	return 0;
}

Measured memory_bytes: 4288
use proconio::{fastout, input};

use rand::prelude::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::time::SystemTime;

#[fastout]

fn calc_score(d: usize, c: &Vec<i64>, s: &Vec<[i64; 27]>, t: &Vec<usize>) -> i64 {
    let mut res = 0;
    let mut last: [usize; 26 + 1] = [0; 26 + 1];
    for day in 1..=d {
        let now_contest = t[day];
        res += s[day][now_contest];
        last[now_contest] = day;
        for contest in 1..=26 {
            res -= c[contest] * (day - last[contest]) as i64;
        }
    }
    res
}

fn get_time(time: SystemTime) -> f64 {
    time.elapsed().unwrap().as_secs_f64()
}

fn main() {
    let time = SystemTime::now();
    let mut rand = rand_pcg::Pcg64Mcg::new(890482);

    // input
    input! {
        d: usize,
        _c: [i64; 26],
        _s: [[i64; 26]; d],
    }

    let mut c = vec![0];
    c.extend(_c.iter());

    let mut s = vec![[0; 26 + 1]; d + 1];
    for day in 1..=d {
        for contest in 1..=26 {
            s[day][contest] = _s[day - 1][contest - 1]
        }
    }

    let mut t = vec![1; d + 1];

    // process
    let mut score = calc_score(d, &c, &s, &t);
    while get_time(time) < 1.90 {
        for _ in 1..=1000 {
            let day = rand.gen_range(1, d + 1);
            let contest = rand.gen_range(1, 26 + 1);

            let tmp = t[day];
            t[day] = contest;
            let next_score = calc_score(d, &c, &s, &t);
            if (next_score > score) {
                score = next_score;
            } else {
                t[day] = tmp;
            }
        }
    }

    for i in 1..=d {
        println!("{}", t[i]);
    }
}


Measured memory_bytes: 2396
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    long long ans=0;
    int a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        if(b[i]>a[i]){
            ans+=(b[i]-a[i])/2;
        }
        else ans+=(b[i]-a[i]);
    }
    if(ans>=0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 384
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim D As Integer = NextInt()
        Dim X As Integer = NextInt()

        For i As Integer = 0 To N - 1
            Dim A As Integer = NextInt()
            X += 1 + (D - 1) \ A
        Next

        WriteLine(X)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
import math

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

if math.fabs(N-M)>1:
    print(0)
elif N==M:
    print((math.factorial(N)*math.factorial(M)*2)%(10**9+7))
else:
    print((math.factorial(N)*math.factorial(M))%(10**9+7))


Measured memory_bytes: 5188
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main() {
    int n, k; cin >> n >> k;
    vi p(n); rep(i, n) cin >> p[i];
    sort(all(p));
    
    ll tot = 0;
    rep(i, k){
        tot += p[i];
    }
    
    cout << tot << endl;
    
    return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    double a, b;
    double xa, xb;
    int ans = -1;
	cin>>a>>b;
    for (int i = 1000; i > 0; i--){
        if ((int)(i*0.08) == a){
            if ((int)(i*0.1) == b){
                ans = i;
            }
        }
    }
	cout<<ans<<endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<P>a(n);
  rep(i,0,n){
    cin>>a[i].fi;
    a[i].se=i;
  }
  sort(ALLR(a));
  auto dp=vec(n+1,n+1,0LL);
  rep(i,0,n){
    rep(j,0,i+1){
      ll l=j,r=i-j;
      chmax(dp[l+1][r],dp[l][r]+a[i].fi*abs(a[i].se-l));
      chmax(dp[l][r+1],dp[l][r]+a[i].fi*abs(a[i].se-(n-r-1)));
    }
  }
  //debug(dp,n+1,n+1);
  rep(i,0,n+1)chmax(res,dp[i][n-i]);
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 34588
#16D8101014F 久留米 竜之介 Kurume Ryunosuke 2018/5/9 python3
import collections 
List=collections.deque()
n=int(input())
for i in range(n):
	command=input().split()
	if command[0] == 'insert':
		List.appendleft(command[1])		
	elif command[0] == 'delete':
		try:
			List.remove(command[1])
		except:
			pass
	elif command[0] == 'deleteFirst':
		List.popleft()	
	elif command[0] == 'deleteLast':
		List.pop()
		
print(*List)



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

ans=[]
for i in range(k):
    if a+i not in ans and a+i<=b:
        ans.append(a+i)

for j in range(k):
    if b-j not in ans and b-j>=a:
        ans.append(b-j)

ans.sort()
for num in ans:
    print(num)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int x,y,z;
  cin>>x>>y>>z;
  int sum;
  if(x+y<y+z) sum=x+y;
  else sum=y+z;
  if(sum>x+z) sum=x+z;
  
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
//
// Created by yoshihito.hotta on 2018/06/10.
//

#include <iostream>
#include <algorithm>

using namespace std;

void printtable(int *a, int n) {
    for (int k = 0; k < n; k++) {
        if(k) {
            cout << " ";
        }

        cout << a[k];
    }
    cout << endl;
}
int main() {
    int n;
    int *a;

    cin >> n;
    a = new int[n];

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    printtable(a, n);
    for (int i = 1; i < n; i++) {
        int v = a[i];
        int j = i - 1;
        while (a[j] > v && j >= 0) {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        printtable(a, n);
    }

    return 0;
}




Measured memory_bytes: 3092
n=int(input())
string=[input() for i in range(n)]

base_ab=0
last_a=0
first_b=0
all_ba=0
for s in string:
    base_ab+=s.count("AB")
    if s[-1]=="A":
        last_a+=1
    if s[0]=="B":
        first_b+=1
    if s[0]=="B" and s[-1]=="A":
        all_ba+=1
if last_a-all_ba==0 and first_b-all_ba==0 and all_ba>0:
    print(base_ab+min(last_a,first_b)-1)
else:    
    print(base_ab+min(last_a,first_b))


Measured memory_bytes: 3700
N,M,K = map(int, input().split())
AList = list(map(int, input().split()))
BList = list(map(int, input().split()))

a = [0]
b = [0]

for i in range(N):
  a.append(a[i] + AList[i])
for j in range(M):
  b.append(b[j] + BList[j])

ans = 0
j = M

for i in range(N+1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -=1
  ans = max(ans, i+j)
  
print(ans)

Measured memory_bytes: 47492
#include <iostream>
#include <algorithm>
using namespace std;
 
int main()
{
  	int n, a, b;
  	cin >> n >> a >> b;
  	if(n == 1) {
      cout << "Hello World" << endl;
    }else if(n == 2){
      cout << a + b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
/*AtCoder Beginner Contest 108 (๑•﹏•๑｀)*/

int main(){
    integer N,K;
    SCLLD2(N,K);

    integer ans1 = 0;
    ans1 = (N/K)*(N/K)*(N/K);

    integer ans2 = 0;
    if (K % 2 == 0){
        FORq(i,0,N){
            integer r = K/2;
            integer nvalue = K*i + r;
            if (nvalue > N) break;
            ans2++;
        }
    }
    integer ans3 = ans2 * ans2 * ans2;

    PRINTLLD(ans1+ans3);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		UnionFind tree = new UnionFind(N);
		for(int i=0; i<M; i++) {
			int X = in.nextInt()-1;
			int Y = in.nextInt()-1;
			int Z = in.nextInt();
			tree.unit(X, Y);
		}
		System.out.println(tree.countRoots());
	}
	
	class UnionFind{
		int[] parent;
		int[] depth;
		
		public UnionFind(int eNum){
			parent = new int[eNum];
			depth = new int[eNum];
			for(int i=0;i<eNum;i++){
				parent[i] = i;
			}
		}
		
		public int getRoot(int x){
			if(parent[x]==x) return x;
			return parent[x] = getRoot(parent[x]); // press
		}
		
		public void unit(int x,int y){
			x = getRoot(x);
			y = getRoot(y);
			if(x==y) return;
			if(depth[x]<depth[y]){
				parent[x] = y;
			}else{
				parent[y] = x;
				if(depth[x]==depth[y]) depth[x]++;
			}
		}
		
		public boolean same(int x,int y){
			return getRoot(x)==getRoot(y);
		}
		
		public int countRoots() {
			int count = 0;
			for(int i=0; i<parent.length; i++) {
				if(parent[i] == i) count ++;
			}
			return count;
		}
	}

	public static void main(String[] args) {
		new Main().solve();
	}
}

Measured memory_bytes: 93964
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int H, W;
        public int[,] M;
        public int[] DX = new int[] { 1, 0, -1, 0, 1, 1, -1, -1 };
        public int[] DY = new int[] { 0, 1, 0, -1, 1, -1, 1, -1};
        public int ret;

        public void Run()
        {
            while (true)
            {
                {
                    var line = Input.ReadIntArray();
                    W = line[0];
                    H = line[1];
                }
                if (W == 0 && H == 0) return;

                M = new int[H, W];
                for (int y = 0; y < H; y++)
                {
                    var line = Input.ReadIntArray();
                    for (int x = 0; x < W; x++)
                        M[y, x] = line[x];
                }

                DFSRun();
                Console.WriteLine(ret);
            }
        }

        public void DFSRun()
        {
            ret = 0;
            for (int y = 0; y < H; y++)
            for (int x = 0; x < W; x++)
            {
                if (M[y, x] == 1)
                {
                    DFS(y, x);
                    ret++;
                }
            }
        }

        public void DFS(int y, int x)
        {
            if (M[y, x] == 0) return;
            M[y, x] = 0;
            for (int i = 0; i < DY.Length; i++)
            {
                int yy = y + DY[i];
                int xx = x + DX[i];
                if (0 <= yy && yy < H && 0 <= xx && xx < W)
                    DFS(yy, xx);
            }
        }

    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}


Measured memory_bytes: 14404