akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

void doProblem173B(){
    int N;
    cin >> N;
    string a[100010], s[4] = {"AC", "WA", "TLE", "RE"};
    int count[4] = { 0 };
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i] == "AC"){
            count[0]++;
        }
        else if(a[i] == "WA"){
            count[1]++;
        }
        else if(a[i] == "TLE"){
            count[2]++;
        }
        else{
            count[3]++;
        }
    }
    for(int i = 0; i < 4; i++){
        cout << s[i] << " x " << count[i] << endl;
    }
}

int main(int argc, const char * argv[]) {
    // insert code here...
    doProblem173B();
    return 0;
}

Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  const ll MAX = 1000;
  vector<ll> cnt(MAX + 1, 0);
  REP(i, n) {
    ll l;
    cin >> l;
    cnt[l]++;
  }
  // REP(i, MAX + 1) if (cnt[i] > 0) {
  //   DUMP(i);
  //   DUMP(cnt[i]);
  // }
  // sum[i] = <=i の個数
  vector<ll> sum(MAX + 1, 0);
  REP(i, MAX) { sum[i + 1] = sum[i] + cnt[i + 1]; };
  ll ans = 0;

  FOR(a, 1, MAX + 1) {
    //  a = b > c
    ans += cnt[a] * (cnt[a] - 1) / 2 * (sum[a - 1]);
    // a = b =c
    ans += cnt[a] * (cnt[a] - 1) * (cnt[a] - 2) / 6;
    // a > b > c
    FOR(i, 1, a) if (i - 1 >= a - i) {
      ans += cnt[a] * cnt[i] * (sum[i - 1] - sum[a - i]);
    }
    // a > b = c
    FOR(i, a / 2 + 1, a) { ans += cnt[a] * cnt[i] * (cnt[i] - 1) / 2; }
  }
  cout << ans << endl;
}

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

const int N = 27, N2 = 2097154;

int n, K;
int f[N2];
char s[N2];

inline int next0(int v) {return v & (v + 1) ? ctz(~v) : -1;}
inline int next1(int v) {return v & (v - 1) ? ctz(v) : -1;}
int (*const next[2])(int) = {next0, next1};

int main() {
	int i, j, S, ALL, lo, hi;
	scanf("%d%d", &n, &K), ALL = ~(-2 << n);
	for (i = 0; i <= n; ++i)
		for (scanf("%s", s + (j = 1 << i)); j < 2 << i; ++j) f[j] = s[j] & 1;
	for (i = 0; i < n; ++i)
		for (S = 2 << i; S <= ALL; ++S) {
			lo = S & ~(-1 << i), hi = S >> i, f[1 << i | lo] += f[S];
			if (~(j = next[~hi & 1](hi))) f[hi >> j << i | lo] += f[S];
		}
	for (i = n; i; --i)
		for (j = 0; j < 1 << i; ++j)
			if (f[1 << i | j] >= K) {for (; i; putchar((j >> --i & 1) | 48)); return putchar(10), 0;}
	return 0;
}

Measured memory_bytes: 10496
import math

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

if a ** 2 * b == x:
    print(0.0)
elif a ** 2 * b * 0.5 < x:
    d = a ** 3 / (2 * (a ** 2 * b - x))
    print(90 - math.atan(d) * 180 / math.pi)
else:
    d = 2 * x / (a * b ** 2)
    print(90 - math.atan(d) * 180 / math.pi)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> H >> N;
    vector<int> a(N);
    cin >> a;
    int sum = accumulate(ALL(a), 0);
    if (sum >= H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640
n,m=map(int,input().split())

p = [[int(i) for i in input().split()] for _ in range(m)]

p.append([0,10])

p.sort(key=lambda x:(x[0],x[1]))

A=[]

a=0

for i in range(m):
    if p[i+1][0]==1 and p[i+1][1]==0 and n>1:
        print(-1)
        a=1
        break
    if p[i][0]==p[i+1][0] and not(p[i][1]==p[i+1][1]):
        print(-1)  
        a=1
        break
    elif not(p[i][0]==p[i+1][0]):
        B=p[i+1][0]-p[i][0]
        if B>1:
            for j in range(B-1):
                A.append(0)
        A.append(p[i+1][1])

        
        
if len(A)==n:
    if A[0]==0 and n>1:
        A[0]=1
else:
    for i in range(n-len(A)):
        A.append(0)
    if A[0]==0 and n>1:
        A[0]=1
        

S=''

for i in range(len(A)):
    S=S+str(A[i])

if a==0:
    print(int(S))  

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni(), m = in.ni();
        int x = in.ni();
        String format = "%".concat(String.valueOf(n)).concat("s");
        int[][] a = new int[n][m];
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = in.ni();
            a[i] = in.ni(m);
        }
        int min = inf;
        for (int i = 0; i < (1 << n); i++) {
            char[] s = String.format(format, Integer.toString(i,2)).replace(' ', '0').toCharArray();
            int sum = 0;
            int[] rikai = new int[m];
            for (int j = 0; j < n; j++) {
                if(s[j]=='1'){
                    for (int k = 0; k < m; k++) {
                        rikai[k] += a[j][k];
                    }
                    sum += c[j];
                }
                boolean flag = true;
                for (int k = 0; k < m; k++) {
                    flag &= rikai[k]>=x;
                }
                if(flag) min = Math.min(min, sum);
            }
        }
        out.println(min==inf?-1:min);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 44608
# input
N = int(input())
A = list(map(int, input().split()))

A = sorted(A, reverse = True)
pair = 0
ans = []

i = 0
while i < N - 1:
    if A[i] == A[i + 1]:
        ans.append(A[i])
        pair += 1
        i += 2
    else:
        i += 1
    if pair == 2:
        print(ans[0] * ans[1])
        break

if pair < 2:
    print(0)

Measured memory_bytes: 14672
#include<bits/stdc++.h>
		#include<unordered_map>	
		#include<unordered_set>
		#define pb emplace_back
		#define rt(v) return cout<<v,0
		#define sz(v) (int)(v.size())
		#define all(a) a.begin(),a.end()
		#define endl '\n'
		#define space " "
		typedef long long ll;
		typedef unsigned long long ull;
		const int N = 10 + 1e5;
		const int mod = 1e9 + 7;
		/*

		███╗   ███╗███████╗███╗   ███╗███████╗    ██╗      ██████╗ ██████╗ ██████╗
		████╗ ████║██╔════╝████╗ ████║██╔════╝    ██║     ██╔═══██╗██╔══██╗██╔══██╗
		██╔████╔██║█████╗  ██╔████╔██║█████╗      ██║     ██║   ██║██████╔╝██║  ██║
		██║╚██╔╝██║██╔══╝  ██║╚██╔╝██║██╔══╝      ██║     ██║   ██║██╔══██╗██║  ██║
		██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║███████╗    ███████╗╚██████╔╝██║  ██║██████╔╝
		╚═╝     ╚═╝╚══════╝╚═╝     ╚═╝╚══════╝    ╚══════╝ ╚═════╝ ╚═╝  ╚═╝╚═════╝

		*/
		//
		int m1[150][150];
		int m2[150][150];
		using namespace std;
		void Ferrari() {
			ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
		}
		
		int main() {
			Ferrari();
			int n, k; cin >> n >> k;
			double sum = 0;
			cout << fixed << setprecision(12);
			for (int i = 1; i <= n; ++i) {
				int j = i;
				int cnt = 0;
				while (j < k)
					j *= 2, ++cnt;
				//ut << cnt << endl;
				double x = (1.0 / n) * (1.0 / (1 << cnt));
				sum += x;

			}
			cout << sum;
			return 0;
		}
		   

	


		/* stuff you should look for
			* keepin sharp mind.
			* int overflow, array bounds.
			* special cases (n=1?), set tle , make sure you understand the proble correctly.
			* don`t stuck in a problem.
			* test the idea on samples.
			*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
#define all(v) v.begin(), v.end()
const int INF = 1<<30;
const long long LINF = 1LL << 60;
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    cin.tie(nullptr) ;
    ios::sync_with_stdio(false) ;

    ll x;
    cin >> x;
    ll b = 1;
    while(1){
        if(b*(b + 1) / 2 >= x){
            cout << b << "\n";
            return 0;
        }
        ++b;
    }
    return 0;
}

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

int main() {
  string s;
  int X,Y;
  cin>>s>>X>>Y;
  s+="T";
  
  int t=0,k=0;
  vector<int> xline;
  vector<int> yline;
  for(int i=0;i<s.size();++i){
    if(s[i]=='F') k++;
    else{
      if(t%2==0) xline.push_back(k);
      else yline.push_back(k);
      int j=i;
      while(i+1<s.size() && s[i+1]=='T') i++;
      if((i-j+1)%2==1) t++;
      k=0;
    }
  }
  /*for(int i=0;i<xline.size();++i) cout<<xline[i]<<" ";
  cout<<endl;
  for(int i=0;i<yline.size();++i) cout<<yline[i]<<" ";
  cout<<endl;*/
  
  bool xdp[8009][16009];
  memset(xdp,0,sizeof(xdp));
  xdp[0][8004]=true;
  xdp[1][xline[0]+8004]=true;
  for(int i=1;i<xline.size();i++){
    for(int x=-8004;x<8005;++x){
      if(xdp[i][x-xline[i]+8004] || xdp[i][x+xline[i]+8004]){
        xdp[i+1][x+8004]=true;
      }
    }
  }
  
  bool ydp[8009][16009];
  memset(ydp,0,sizeof(ydp));
  ydp[0][8004]=true;
  for(int i=0;i<yline.size();i++){
    for(int y=-8004;y<8005;++y){
      if(ydp[i][y-yline[i]+8004] || ydp[i][y+yline[i]+8004]){
        ydp[i+1][y+8004]=true;
      }
    }
  }
  
  if(xdp[xline.size()][X+8004] && ydp[yline.size()][Y+8004]){
    cout<<"Yes"<<endl;
  }
  else cout<<"No"<<endl;
}

Measured memory_bytes: 250752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15

 

 
int main(){
	string s;
	cin >> s;
	for(int i= 0; i < (int)s.size(); i++){
		if(i % 2 == 0)
			cout << s[i];
	}
	cout << endl;
	return 0;
}


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

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

using namespace std;

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

	if (a > 2*b)
	{
		cout << a - 2*b;
	}
	else{
		cout << 0;
	}

	return 0;
}

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

signed main() {
	char a; cin >> a;
	if (a == 'A')puts("T");
	else if (a == 'T')puts("A");
	else if (a == 'G')puts("C");
	else puts("G");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long ans = 0;
		ans += (n / (a + b)) * a;
		n %= (a + b);
		if(n >= a) {
			ans += a;
		} else {
			ans += n;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 23380
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    int x = 1;
    REP(i,n){
        if (a[i] == x) x++;
    }
    int ans = -1;
    if (x != 1) ans = n - x + 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

int main(){
    int r, D;
    vector<int> x(11);
    cin >> r >> D >> x[0];
    for(int i = 1; i <= 10; i++){
        x[i] = r * x[i - 1] - D;
    }
    for(int i = 1; i <= 10; i++){
        cout << x[i] << endl;
    }
    return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main()
{
	int N, L;
	cin >> N >> L;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	sort(S.begin(), S.end());
	for (int i = 0; i < N; i++) {
		cout << S[i];
	}
	cout << endl;

}


Measured memory_bytes: 256
r, g, b = map(int,input().split())
soma = 0

if 1 <= r <= 9 and 1 <= g <= 9 and 1 <= b <= 9:
    soma = r*100 + g*10 + b
    if soma%4 == 0:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 2940
import Control.Monad
import Data.List
import Data.Map (Map,(!))
import qualified Data.Map as M
import Data.Set (Set)
import qualified Data.Set as S

type Sushi = (Type,Deli)
type Type = Int
type Deli = Integer
type Score = Integer

main :: IO ()
main = do
  [n,k] <- map read.words <$> getLine :: IO [Int]
  sushis <- replicateM n $ (\[a,b] -> (read a,read b)).words <$> getLine :: IO [Sushi]
  print $ solve n k $ sortBy (\(_,a) (_,b)->compare b a) sushis

solve :: Int -> Int -> [Sushi] -> Score
solve n k sushis = maximum $ go toTake taken removable howRem delisum types
  where
  go :: [Sushi] -> Set Type -> Map Type [Deli] -> [Type] -> Deli -> Integer -> [Score]
  go [] _ _ _ delisum types = [score delisum types]
  go _ _ _ [] delisum types = [score delisum types]
  go ((t,d):toTake) taken removable (r:howRem) delisum types
    | S.notMember t taken = score delisum types
      : go toTake (S.insert t taken) (M.adjust tail r removable)
        howRem (delisum - head (removable!r) + d) (types + 1)
    | otherwise = go toTake taken removable (r:howRem) delisum types
  score :: Deli -> Integer -> Score
  score delisum types = delisum + types*types
  -- Initial Values
  toTake = filter (null.(eats!).fst) remainings
  (delicious,remainings) = splitAt k sushis
  taken = S.empty
  removable = M.filter (\ds -> not (null ds || (null.tail) ds)) eats
  (eats, howRem, types) = foldl folder (noEat, [], 0) delicious
  noEat = M.fromList $ zip [1..n] $ repeat []
  folder :: (Map Type [Deli], [Type], Integer) -> Sushi -> (Map Type [Deli], [Type], Integer)
  folder (eats, howRem, types) (t,d)
    | null (eats!t) = (M.adjust (d:) t eats, howRem, types+1)
    | otherwise     = (M.adjust (d:) t eats, t:howRem, types)
  delisum = sum $ map snd delicious
  

Measured memory_bytes: 118012
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n;
	int a, b, c;
	int cal[100];
	int i, j;
	int tmp;
	int max_cal;
	int sum_cal;
	
	scanf("%d%d%d%d", &n, &a, &b, &c);
	
	for (i = 0; i < n; i++){
		scanf("%d", &cal[i]);
	}
	
	for (i = 0; i < n; i++){
		for (j = 0; j < n - 1; j++){
			if (cal[j] < cal[j + 1]){
				tmp = cal[j];
				cal[j] = cal[j + 1];
				cal[j + 1] = tmp;
			}
		}
	}

	
	sum_cal = c;
	for (i = 0; i < n; i++){
		if (sum_cal / (a + b * i) > (sum_cal + cal[i])  / (a + b * (i + 1))){
			break;
		}
		sum_cal += cal[i];
	}
	
	printf("%d\n", sum_cal / (a + b * i));
	
	return (0);
}

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

int main() {
   
 int A,B,C,D;
  cin>>A>>B>>C>>D;
 
  int i=1;
    while (true){
      
    
    if (C<=0 && A>=0){
      cout<<"Yes"<<endl;
      break;
    }
    
    else if (C>0 && A<=0){
      cout<<"No"<<endl;
      break;
    }
    
    C=C-B;
    A=A-D;
    
      i++;
  }
  
 

       
       

  // ここにプログラムを追記
}


Measured memory_bytes: 3636
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif

struct Graph{
    struct Edge{
        int cost, from, dest;
        Edge(int cost, int dest): cost(cost), from(-1), dest(dest){ }
        Edge(int cost, int from, int dest): cost(cost), from(from), dest(dest){ }
        ostream& operator >> (ostream& out){
            return out << '(' << cost << ':' << from << ' ' << dest << ')';
        }
    };
    struct Node{
        vector<Edge> edges;
    };
    vector<Node> nodes;
    Graph(int num): nodes(num){ }
    void addEdge(int from, int dest, int cost = 1){
        nodes[from].edges.emplace_back(cost, dest);
    }
    void addEdge2(int from, int dest, int cost = 1){
        addEdge(from, dest, cost);
        addEdge(dest, from, cost);
    }
    ll dijkstra2(int start, vector<ll> &lens){
        struct DElem{
            ll cost, dest;
            bool operator < (const DElem& e) const { return cost > e.cost; }
        };
        priority_queue<DElem> pq;
        pq.push({0, start});
        while(pq.size()){
            auto e = pq.top(); pq.pop();
            if(lens[e.dest] <= e.cost){ continue; }
            lens[e.dest] = e.cost;
            for(auto& edge : nodes[e.dest].edges){
                if(lens[edge.dest] > e.cost + edge.cost){
                    pq.push({e.cost + edge.cost, edge.dest});
                }
            }
        }
        return -1;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    Graph g(n);
    for(int i = 0; i < n - 1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        g.addEdge2(a, b, c);
    }
    int q, k;
    cin >> q >> k;
    k--;
    vector<ll> lens(n, MLL);
    g.dijkstra2(k, lens);
    prints(lens);
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        cout << lens[x] + lens[y] << '\n';
    }
}


Measured memory_bytes: 10804
#include<iostream>
#include<cstdio>
using namespace std;
int dp[8001][16001];
int a[8001];
int main()
{
	string s;
	int x,y;
	cin>>s>>x>>y;
	int k=0;
	int w=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='T')
		{
			k++;
			a[k]=w;
			w=0;
		}
		else
		{
			w++;
		}
	}
	k++;
	a[k]=w;
    dp[1][a[1]+8000]=1;
 
    
 
	
	
	for(int i=3;i<=k;i+=2){
		for(int j=0;j<=16000;j++){
			if(j+a[i]<=16000)
				dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
				dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	
	dp[0][8000]=1;
	for(int i=2;i<=k;i+=2){
		for(int j=0;j<=16000;j++){
			if(j+a[i]<=16000)
			dp[i][j]=dp[i-2][j+a[i]];
			if(j-a[i]>=0)
			dp[i][j]=dp[i][j]||dp[i-2][j-a[i]];
		}
	}
	
	int ans;
	if(k%2==0){ 
		ans=dp[k][y+8000]&&dp[k-1][x+8000];
	}
	else{
		ans=dp[k][x+8000]&&dp[k-1][y+8000];
	}
	cout<<(ans==0?"No":"Yes");
	return 0;
}

Measured memory_bytes: 496252
using System;


namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split();
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);

            if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else if (a < b)
            {
                Console.WriteLine("a < b");
            }
            else
            {
                Console.WriteLine("a == b");
            }


        }
    }
}

Measured memory_bytes: 5300
while True:
    H = int(input())
    if H == 0:  break

    score = 0
    game = [[None] * 5 for _ in range(H)]
    for i in reversed(range(H)):
        game[i] = [int(x) for x in input().split()]

    try_again = True
    while(try_again):
        # スコアを加算
        try_again = False
        for i in range(H):
            for j in range(3):
                if game[i][j] == None:  continue
                if game[i][j] == game[i][j + 1] == game[i][j + 2]:
                    try_again = True
                    num = game[i][j]
                    game[i][j] = game[i][j + 1] = game[i][j + 2] = None
                    score += 3 * num
                    for k in range(j + 3, 5):
                        if game[i][k] != num: break
                        game[i][k] = None
                        score += num
                    break

        # 石を落とす
        for i in range(1, H):
            for j in range(5):
                k = i
                while k > 0 and game[k - 1][j] == None:
                    k -= 1
                game[k][j], game[i][j] = game[i][j], game[k][j]

    print(score)


Measured memory_bytes: 5632
#include <stdio.h>

int min(int a, int b) {
	return (a > b) ? b : a;
}

int main(void) {
	int n, k, x[100] = { 0 };
	int sum = 0, def;

	scanf("%d", &n);
	scanf("%d", &k);
	for (int i = 0; i < n; i++) scanf("%d", &x[i]);

	for (int i = 0; i < n; i++) {
		def = min(x[i], k - x[i]);
		sum += def * 2;
	}

	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 128
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}
/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>s;
		if(s=="ABC")
			s="ARC";
		else s="ABC";
		
		cout<<s;

		
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3644
import java.io.*;
import java.util.*;

public class Main {
	void run() {
		int n = in.nextInt();
		boolean[][] a = new boolean[n][n];
		int[] row = new int[n];
		int[] col = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			String s = in.next();
			for (int j = 0; j < n; j++) {
				if (s.charAt(j) == '#') {
					a[i][j] = true;
					row[i]++;
					col[j]++;
					sum++;
				}
			}
		}
		if (sum == 0) {
			out.println(-1);
			return;
		}
		int full = -1;
		for (int i = 0; i < n; i++) {
			if (row[i] == n) {
				full = i;
			}
		}
		if (full != -1) {
			int ans = 0;
			for (int j = 0; j < n; j++) {
				if (col[j] < n) {
					ans++;
				}
			}
			out.println(ans);
			return;
		}
		int ans = 3 * n;
		for (int r = 0; r < n; r++) {
			int cur = 0;
			boolean[] b = a[r];
			if (col[r] == 0) {
				cur = 1;
			}
			for (int j = 0; j < n; j++) {
				if (b[j]) {
					continue;
				}
				cur++;
			}
			for (int j = 0; j < n; j++) {
				if (b[j] && col[j] == n) {
					continue;
				}
				cur++;
			}
			ans = Math.min(ans, cur);
		}
		System.out.println(ans);
	}

	static MyScanner in;
	static PrintWriter out;

	public static void main(String[] args) throws IOException {
		boolean stdStreams = true;
		String fileName = Main.class.getSimpleName().replaceFirst("_.*", "").toLowerCase();
		String inputFileName = fileName + ".in";
		String outputFileName = fileName + ".out";
		
		Locale.setDefault(Locale.US);
		BufferedReader br;
		if (stdStreams) {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			br = new BufferedReader(new FileReader(inputFileName));
			out = new PrintWriter(outputFileName);
		}
		in = new MyScanner(br);
		int tests = 1;//in.nextInt();
		for (int test = 0; test < tests; test++) {
			new Main().run();
		}
		br.close();
		out.close();
	}
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		MyScanner(BufferedReader br) {
			this.br = br;
		}
		
		void findToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		
		String next() {
			findToken();
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 24632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

string MINUSINF = "-";
long long match[10] = {2,5,5,4,5,6,3,7,6};
string dp[11000];

void chmax(string &a, string b){
    if(a == MINUSINF) a=b;
    else if(a.size() < b.size()) a=b;
    else if(a.size()==b.size()){
        if(a<b) a=b;
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> a(101,0);
    REP(i,3){
        int b;cin>>b;
        a[b]++;
    }
    int ans=0;
    REP(i,101) if(a[i]>0) ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#pragma GCC optimize(3)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<bitset>
#include<deque>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define ri register int
#define il inline
#define fi first
#define se second
#define mp make_pair
#define pi pair<int,int>
#define mem0(x) memset((x),0,sizeof (x))
#define mem1(x) memset((x),0x3f,sizeof (x))
il char gc() {
	static const int BS = 1 << 22;
	static unsigned char buf[BS], *st, *ed;
	if (st == ed) ed = buf + fread(st = buf, 1, BS, stdin);
	return st == ed ? EOF : *st++;
}
#define gc getchar
template<class T>void in(T &x) {
	x = 0;
	bool f = 0;
	char c = gc();
	while (c < '0' || c > '9') {
		if (c == '-') f = 1;
		c = gc();
	}
	while ('0' <= c && c <= '9') {
		x = (x << 3) + (x << 1) + (c ^ 48);
		c = gc();
	}
	if (f) x = -x;
}
#undef gc
#define pb push_back
#define N 100010
#define M N
int v[M], u[M], nx[M];
int cnt, head[N];
il void add(int uu, int vv) {
	u[++cnt] = uu, v[cnt] = vv, nx[cnt] = head[uu];
	head[uu] = cnt;
}
int n, m;
ll k;
double pos[N];
double de[N];
double ans[N];
int num[N], ys[N];
int cur;
int bel[N], rk[N];
vector<int>hv[N];
void dfs(int x, int k) {
	bel[x] = k;
	hv[k].pb(x);
	rk[x] = hv[k].size() - 1;
	for (ri i = head[x]; i; i = nx[i])
		if (!bel[v[i]]) dfs(v[i], k);
}
signed main() {
#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
#endif
	in(n);
	for (ri i = 1; i <= n; ++i) {
		scanf("%lf", &pos[i]);
		de[i] = pos[i] - pos[i - 1];
		num[i] = i;
	}
	in(m), in(k);
	for (ri i = 1, t; i <= m; ++i) {
		in(t);
		swap(num[t], num[t + 1]);
	}
	for (ri i = 1; i <= n; ++i) ys[num[i]] = i;
	for (ri i = 1; i <= n; ++i)
		add(i, ys[i]);
	for (ri i = 1; i <= n; ++i)
		if (!bel[i]) {
			++cur;
			dfs(i, cur);
		}
	for (ri i = 1, t; i <= n; ++i) {
		t = hv[bel[i]][(k + rk[i]) % (ll)hv[bel[i]].size()];
		ans[t] = de[i];
	}
	double tmp = 0.0;
	for (ri i = 1; i <= n; ++i) {
		tmp += ans[i];
		printf("%.9f\n", tmp);
	}
	return 0;
}

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

int main0() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
	int N, K;
	cin >> N >> K;
	long long arr[100001]={};
	int num, qty;
	long long count = 0;
	for (long long i=0; i<N; i++){
		cin >> num >> qty;
		arr[num]+=qty;
	}
	for (int i=1; i<100001; i++){
		count += arr[i];
		if (count >= K){
			cout << i << endl;
			return 0;
		}
	}
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n , k;
    cin >> n >> k;
    long long arr[100001] = {};
    for (long long i = 0 ; i < n ; i++){
        int num , qty;
        cin >> num >> qty;
        arr[num] += qty;
    }
    long long count = 0;
    for (long long i = 0 ; i < 100001 ; i++ ){
       count += arr[i];
       if( count >= k ){
         cout << i;
         return 0;
       }
    }
}



Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std ;

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	cin >> N;
	if (N > 999)
	{
		cout << "ABD" << endl;
	}
	else
	{
		cout << "ABC" << endl;
	}

	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    int Xor = 0;
    REP(i,n) {
        cin >> a[i];
        Xor ^= a[i];
    }
    bool ans = Xor==0;
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        Map<Integer, Integer> A = new HashMap<>();
        Map<Integer, Integer> cache = new HashMap<>();
        for (int i = 0; i < N; i++) {
            A.put(i + 1, scanner.nextInt());
        }

        long ans = 0;
        for (int i = 1; i < N + 1; i++) {
            int L = A.get(i) - i;
            ans += cache.getOrDefault(L, 0);

            int R = -i - A.get(i);
            cache.put(R, cache.getOrDefault(R, 0) + 1);
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 73968
//tokenakatta

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

int main() {
    int N; cin >> N;
    vector<int> x(N, 0);
    vector<int> y(N, 0);
    rep(i, N) cin >> x.at(i) >> y.at(i);
    vector<vector<double>> len(N, vector<double>(N, 0.0));

    for(int i=0; i<N; i++){
        for(int j=i; j<N; j++) {            
            len.at(i).at(j) = pow((x.at(i) - x.at(j))*(x.at(i) - x.at(j)) + (y.at(i)-y.at(j)) * (y.at(i)-y.at(j)), 0.5);
        }
    }

    double sum = 0;
    
    rep(i, N){
        rep(j,N){
            sum += len.at(i).at(j);
        }
    }

    sum = sum * 2 / N;

    cout << fixed << setprecision(10) << sum << endl;

}


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

//２点 P1(x1, y1), P2(x2, y2) の距離を求めるプログラム
int main(){
    double x1, y1, x2, y2, distance;

    cin >> x1 >> y1 >> x2 >> y2;

    distance = sqrt(pow(x2 - x1, 2.0) + pow(y2 - y1, 2.0));

    cout << fixed << distance << endl;
    return 0;
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
ll exp(ll a, ll b){
  if(b==0)return 1;
  if(a==1||a==0)return a;
  if(b%2==0){
    int t =exp(a,b/2);
    return t*t%big;
  }
  else return exp(a,b-1)*a%big;
}

int main(){
    int n;cin >> n;
    int ans;cin >> ans;
    rep(i,n-1){
        int k;cin >> k;
        ans=__gcd(ans,k);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace DPL1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = scan;
            var n = a[0];
            var dp = Enumerable.Repeat(int.MaxValue, n + 1).ToArray();
            dp[0] = 0;
            var c = scan;

            foreach (var t in c)
            {
                for (int i = t; i <= n; i++)
                {
                    dp[i] = Math.Min(dp[i], dp[i - t] + 1);
                }
            }

            Console.WriteLine(dp[n]);
            
        }

        static int[] scan
        {
            get { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
        }
    }
}

Measured memory_bytes: 10268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		String s = in.next();
		System.out.print(process(s));
		in.close();
	}

	public static String process(String s) {
		if (null == s || s.length() == 0) {
			return s;
		}

		char[] A = s.toCharArray();
		int N = A.length;
		if (N == 1) {
			A[0] = A[0] == '?' ? 'D' : A[0];
		} else {
			for (int i = 0; i < N; i++) {

				if (A[i] != '?') {
					continue;
				}

				if (i == 0) {
					A[i] = A[i + 1] == 'P' ? 'D' : 'P';
				} else if (i == N - 1) {
					A[i] = 'D';
				} else {
					if (A[i - 1] == 'P') {
						A[i] = 'D';
					} else if (A[i + 1] == '?' || A[i + 1] == 'D') {
						A[i] = 'P';
					} else {
						A[i] = 'D';
					}
				}
			}
		}
		return new String(A);
	}

}


Measured memory_bytes: 41168
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;

signed main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    bool beg,end;
    if(s[0]=='0')beg=true;
    else beg=false;
    if(s[s.size()-1]=='0')end=true;
    else end=false;
    vector<P> h;
    int memo;
    if(s[0]=='1')memo=0;
    for(int i=1;i<s.size();i++){
        if(s[i]=='0'&&s[i-1]=='1')h.push_back(make_pair(memo, i-1));
        if(s[i]=='1'&&s[i-1]=='0')memo=i;
    }
    if(s[s.size()-1]=='1')h.push_back(make_pair(memo, s.size()-1));
    int stand=h.size()-1+beg+end;
    if(stand<=k){
        cout<<s.size()<<endl;
    }else{
        vector<P> st;
        for(int i=0;i<h.size()-1;i++){
            st.push_back(make_pair(h[i].first, h[i+1].second));
        }
        if(beg)st.push_back(make_pair(0, h[0].second));
        if(end)st.push_back(make_pair(h[h.size()-1].first, s.size()-1));
        sort(st.begin(),st.end());
        int ma=0;
        for(int i=0;i<=st.size()-k;i++){
            if(st[i+k-1].second-st[i].first+1>=ma){
                ma=st[i+k-1].second-st[i].first+1;
            }
        }
        cout<<ma<<endl;
    }
    return 0;
}


Measured memory_bytes: 2676
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] input = sc.nextLine().toCharArray();
		int count = 0;
		String tmp = "";
		String before = "";
		for (char c : input) {
			tmp = tmp + c;
			if (!tmp.equals(before)) {
				count++;
				before = tmp;
				tmp = "";
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 41272
n = int(input())
shogens = []

for i in range(n):
    a = int(input())
    shogens.append([])

    for j in range(a):
        x, y = map(int, input().split())
        x -= 1
        shogens[-1].append((x, y))


def is_honest(i, j):
    return (i >> j) % 2 == 0


def honest_cnt(i):
    ans = 0
    for j in range(n):
        ans += is_honest(i, j)

    return ans


ans = 0
for i in range(1 << n):
    ok = True
    for j in range(n):
        if not is_honest(i, j):
            continue
        for x, y in shogens[j]:
            if y == 0 and is_honest(i, x):
                ok = False
            if y == 1 and not is_honest(i, x):
                ok = False

    if ok:
        ans = max(ans, honest_cnt(i))


print(ans)


Measured memory_bytes: 3064
import heapq

n, k = map(int, input().split())

h = []
for _ in range(n):
    heapq.heappush(h, int(input()))

q = [heapq.heappop(h) for _ in range(k-1)]

ans = 1e9
for i in range(len(h)):
    p = i % (k-1)
    s = q[p]
    e = heapq.heappop(h)
    q[p] = e
    ans = min(ans, e - s)

print(ans)

Measured memory_bytes: 7496
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define ll long long
using namespace std;

const int N = 2001;

int n;
ll dp[N][N];
vector<pair<int, int>> a;

// returns max after filling in [l, r]
ll go(int idx, int l, int r) {
    if (idx == n)
        return 0;
    ll &ret = dp[l][r];
    if (ret != -1)
        return ret;
    ret = go(idx + 1, l + 1, r) + a[idx].first * abs(l - a[idx].second);
    ret = max(ret, go(idx + 1, l, r - 1) + a[idx].first * abs(r - a[idx].second));
    return ret;
}

void solve() {
    cin >> n;
    a.assign(n, {0, 0});
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.rbegin(), a.rend());
    cout << go(0, 0, n - 1) << endl;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t = 1;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 34544
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] A = new int[N + 1];
            for (int i = 1; i <= N; i++) {
                A[i] = sc.nextInt();
            }

            int c1 = 0, c2 = 0, c3 = 0;
            for (int a : A) {
                if (a == 1) {
                    c1++;
                } else if (a == 2) {
                    c2++;
                } else if (a == 3) {
                    c3++;
                }
            }

            double[][][] dp = new double[c1 + c2 + c3 + 1][c2 + c3 + 1][c3 + 1];

            double ans = solve(N, dp, c1, c2, c3);

            System.out.println(ans);
        }
    }

    static double solve(int N, double[][][] dp, int c1, int c2, int c3) {
        if (dp[c1][c2][c3] != 0) {
            return dp[c1][c2][c3];
        }

        int c = c1 + c2 + c3;

        if (c == 0) {
            return 0;
        }

        dp[c1][c2][c3] = (double) N / c;

        if (c1 > 0) {
            dp[c1][c2][c3] += solve(N, dp, c1 - 1, c2, c3) * c1 / c;
        }

        if (c2 > 0) {
            dp[c1][c2][c3] += solve(N, dp, c1 + 1, c2 - 1, c3) * c2 / c;
        }

        if (c3 > 0) {
            dp[c1][c2][c3] += solve(N, dp, c1, c2 + 1, c3 - 1) * c3 / c;
        }

        return dp[c1][c2][c3];
    }

}


Measured memory_bytes: 305108
from sys import stdin
n = int(input())
a = list(map(int, stdin.readline().split()))
b = list(map(int, stdin.readline().split()))
c = list(map(int, stdin.readline().split()))
ans = sum(b)
for i in range (n-1):
    if a[i]+1 == a[i+1]:
        t = a[i]-1
        ans +=c[t]
print(ans)


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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)


#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    ll w ,a , b;

    cin >> w >> a >> b;



    ll x1 = a ,x2 = a+w;

    ll y1 = b , y2 = b+w;

    if(x1<=b && b<=x2)
    {
        cout << 0 << endl;
    }
    else if(x2<b)
    {

        //cout << "asd" << endl;

        cout << y1 - x2 << endl;
    }
    else
    {
        cout << x1-y2 << endl;
    }





    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e9+7;
int main(){
	ll n,k;
	cin >> n >> k;
	ll m=(((k+1)*k)/2)%N;
	ll p =((k*(k-1))/2)%N;
	ll a[n];
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	ll cnt = 0;
	for(int i=0;i<n;i++){
		ll sum=0;
		ll ans=0;
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j])sum++;} 
		sum%=N;
		cnt+=(sum*(m%N))%N;
		for(int j=i-1;j>=0;j--){
			if(a[i]>a[j])ans++;
		}
		ans%=N;
		cnt+=(ans*(p%N))%N;
	}
	cout << cnt%N << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=998244353;
int n,i,a[100005];
long long s=1;
int gcd(int x,int y)
{
	if(y==0)
		return x;
	return gcd(y,x%y);
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(i=1;i<=n;i++)
		s=s*gcd(a[i],i-1)%M;
	cout<<s;
}


Measured memory_bytes: 640