akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;


signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n;
    int k;
    int h[100010];
    long long dp[100010];
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> h[i];
        dp[i] = 0;
    }
    for(int i=1;i<n;i++){
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        for(int j=2;j<=min(i,k);j++){
            dp[i] = min(dp[i],dp[i-j] + abs(h[i] - h[i-j]));
        }
        /*
        if(i >= 2){
            dp[i] = min(dp[i],dp[i-2] + abs(h[i] - h[i-2]));
        }
        */
    }
    cout << dp[n-1] << "\n";
    return 0;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; std::cin >> N;
  int count = 0;
  int num = 1;
  for (int i = 0; i < N; ++i) {
    int a; std::cin >> a;
    if (num == a) ++num;
    else          ++count;
  }

  if (count == N) std::cout << -1 << std::endl;
  else            std::cout << count << std::endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // not prime num
            return false;
        }
    }
    // prime num
    return true;
}

struct edge{
    int cost, to;

    edge(int in_cost, int in_to){
        cost=in_cost;
        to=in_to;
    }
    bool operator<(const edge &a) const
    {
        return cost > a.cost;
    }
};

int N=0;
bool isJudge(int monster, vector<int>a){
    ll moster_size=a[monster];

    for(int i=0; i<N; i++){
        if(i==monster)continue;

        if(2*moster_size>=a[i]){
            moster_size+=a[i];
        }else{
            // 吸収不可能なモンスターが見つかった場合
            // これ以上吸収不可能
            return false;
        }
    }

    return true;
}


int main() {
    cin >> N;
    vector<int>A(N);

    rep(i,N){
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    int lb=-1, ub=N;
    while(ub-lb>1){
        int mid=(lb+ub)/2;
        if(isJudge(mid, A)){
            ub=mid;
        }else{
            lb=mid;
        }
    }
    cout << N-ub << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<cstdlib>
#include<typeinfo>
#include<sstream>
#include<list>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int stringInt(string a)
{
	return atoi(a.c_str());
}
string intString(int a)
{
	stringstream ss;
	ss<<a;
	return ss.str();
}

int main() {
	int n;cin>>n;
	vector<double> X,Y;
	X.push_back(0.0);
	X.push_back(100.0);
	Y.push_back(0.0);
	Y.push_back(0.0);
	double kaku=1.0/3.0*3.14159;
	for(int i=0;i<n;i++)
	{
		int e=X.size();
		vector<double> o,O;
		o.push_back(X[0]);
		O.push_back(Y[0]);
		for(int l=1;l<e;l++)
		{

			double a,b,c;//x
			double A,B,C;//y
			a=(2.0*X[l-1]+1.0*X[l])/3.0;
			c=(1.0*X[l-1]+X[l]*2.0)/3.0;
			A=(2.0*Y[l-1]+1.0*Y[l])/3.0;
			C=(1.0*Y[l-1]+Y[l]*2.0)/3.0;
			b=(c-a)*cos(kaku)-(C-A)*sin(kaku)+a;
			B=(c-a)*sin(kaku)+(C-A)*cos(kaku)+A;

			o.push_back(a);
			o.push_back(b);
			o.push_back(c);
			o.push_back(X[l]);
			O.push_back(A);
			O.push_back(B);
			O.push_back(C);
			O.push_back(Y[l]);
		}
		X=o;Y=O;
	}
	for(int i=0;i<X.size();i++)
	{
		printf("%.8f %.8f\n",X[i],Y[i]);

	}

}

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

const int N = 3005;
const int mod = 1e9 + 7;

void add(int &x,int y) {
	x += y; if (x >= mod) x -= mod;
}

int n;
char s[N];
int f[N][N];

int main() {
	scanf("%d %s", &n, s + 1);
	f[1][1] = 1;
	for (int i = 1; i <= n - 1; ++i) {
		if (s[i] == '<') {
			int now = 0;
			for (int j = 1; j <= i + 1; ++j) {
				f[i + 1][j] = now;
				add(now, f[i][j]);
			}
		} else {
			int now = 0;
			for (int j = i + 1; j > 0; --j) {
				add(now, f[i][j]);
				f[i + 1][j] = now;
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		add(ans, f[n][i]);
	}
	printf("%d\n", ans);
}

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

using namespace std;

int main()
{
    int x;
    string s = "No";

    cin >> x;

    while(x > 0)
    {
        int y = x % 10;
        x /= 10;

        if(y == 7)
            s = "Yes";
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
int ara[100005];

int main()
{
	int prob,sub,n,i,pen=0,ans=0;
	char ch[3];
	scanf("%d %d",&prob,&sub);
	for(i=0;i<sub;i++){
		scanf("%d %s",&n,&ch);
		if(0==strcmp(ch, "WA") && ara[n]!=-1){
			ara[n]++;
		}
		else if(0==strcmp(ch, "AC") && ara[n]!=-1){
			ans++;
			pen=pen+ara[n];
			ara[n]=-1;
		}
	}
		printf("%d %d\n",ans,pen);

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  string S;
  cin >> S;
  int n = S.length();

  vector<int> dp(13);
  dp[0] = 1;
  
  REP(i, n) {
    vector<int> dp_nxt(13);
    int c;
    if (S[i] == '?') c = -1;
    else c = S[i] - '0';

    REP(j, 10) {
      if (c != -1 && c != j) continue;
      REP(ki, 13) {
        (dp_nxt[(ki * 10 + j) % 13] += dp[ki]) %= MOD;
      }
    }
    dp = dp_nxt;
  }

  cout << dp[5] << endl;
  return 0;
}


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

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    struct S
    {
        public int X, Y;
    }

    class Program
    {
        private int N, M, Q;
        private int[] p, q;

        private long[,] Sum;

        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            M = sc.NextInt();
            Q = sc.NextInt();
            Sum = new long[N + 1, N + 1];
            p = new int[Q];
            q = new int[Q];
            for (int i = 0; i < M; i++)
            {
                int l = sc.NextInt();
                int r = sc.NextInt();
                Sum[l, r]++;
            }

            for (int i = 0; i < Q; i++)
            {
                p[i] = sc.NextInt();
                q[i] = sc.NextInt();
            }
        }

        public void Solve()
        {
            Scan();
            for (int i = 1; i <= N; i++)
            {
                long line = 0;
                for (int j = 1; j <= N; j++)
                {
                    line += Sum[i, j];
                    Sum[i, j] = Sum[i - 1, j] + line;
                }
            }
            var sb = new StringBuilder();
            for (int i = 0; i < Q; i++)
            {
                int pp = p[i];
                int qq = q[i];
                long a = Sum[qq, qq];
                long b = Sum[pp - 1, qq];
                long c = Sum[qq, pp - 1];
                long d = Sum[pp - 1, pp - 1];
                sb.AppendLine((a - b - c + d).ToString());

            }
            Console.Write(sb.ToString());
        }

        static void Main() => new Program().Solve();
    }
}

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

int main() {
    int n, k, s;
    cin >> n >> k >> s;
    vector<int> ans(n);
    if (s == 1e9) {
        for (int i = 0; i < n; ++i) cout << (i < k ? s : 1) << " ";
    } else {
        for (int j = 0; j < n; ++j) cout << (j < k ? s : s + 1) << " ";
    }
}


Measured memory_bytes: 1664
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val a = in.readLine()
    val b = in.readLine()

    System.out.println(
      (Set("1","2","3") - a - b).mkString("")
    )
  }
}


Measured memory_bytes: 27468
from collections import defaultdict, deque
import sys

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def main():
    N = int(input())
    H = [int(a) for a in input().split()]
    # H = [
    #     int(input())
    #     for _ in range(N)
    # ]
    # A = [int(a) for a in input().split()]

    m = MAX
    for hi in reversed(H):
        if hi > m + 1:
            print("No")
            return
        m = min(hi, m)
    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 14908
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	vector<int> n(3); for (int i = 0; i < 3; i++) cin >> n[i];
	sort(n.rbegin(), n.rend());
	cout << 10 * n[0] + n[1] + n[2] << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll a,b,c;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> a >> b >> c;
    if( a+b+c>=22 ){
        cout << "bust";
    }else{
        cout << "win";
    }

    return 0;
}


Measured memory_bytes: 256
// う　し　た　ぷ　に　き　あ　く　ん　笑
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

int h, w, k;
vector<string> c;

int paint(int hh, int ww) {
    int blacks = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (hh & 1 << i) continue;
            if (ww & 1 << j) continue;

            if (c[i][j] == '#') blacks++;
        }
    }

    return blacks;
}

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

    cin >> h >> w >> k;
    c.resize(h);
    for (int i = 0; i < h; i++) {
        cin >> c[i];
    }

    int ans = 0;

    for (int hh = 0; hh < (1 << h); hh++) {
        for (int ww = 0; ww < (1 << w); ww++) {
            const int blacks = paint(hh, ww);

            if (blacks == k) ans++;
        }
    }

    cout << ans << endl;
}


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

#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 2e5 + 10;

int a[N];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	for (int i=0; i<n; i++){ cin >> a[i]; a[i] -= i+1;}

	sort(a, a + n);
	int x = a[n/2];

	ll ans = 0;
	for (int i=0; i<n; i++)
		ans += abs(a[i] - x);
	cout << ans << endl;

}


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

using namespace std;

int main()
{	
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	int ans = INT_MAX;
	for (int i = 0; i <= 100000; i++)
	{
		ans = min(ans, i * 2 * c + max(0, x - i) * a + max(0, y - i) * b);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 1e9+7
#define N 1000010
#define MAX_V 400010
#define vec vector<int>
#define ALL(c) (c).begin(),(c).end()

int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
using namespace std;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        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<ll,int,custom_hash>
struct pair_hash
{
    template<class T1,class T2>
    size_t operator() (const pair<T1,T2> &p)const{
        return hash<T1>()(p.first)^hash<T2>()(p.second);
    }
};


main(){
    int n;
    cin>>n;
    string s;cin>>s;
    int k[100],q;
    cin>>q;
    rep(i,q){
        cin>>k[i];
    }
    vec c;
    rep(i,q){
        ll ans=0;
        int t=k[i];
        ll dp[3]={};
        ll m=0;
        rep(j,t){
            if(s[j]=='D'){
                dp[0]++;
            }
            if(s[j]=='M'){dp[1]+=dp[0];m++;}
            if(s[j]=='C')ans+=dp[1];
        }
        rep(j,n-t){
            if(s[j]=='D'){
                dp[1]-=m;
                dp[0]--;
            }
            if(s[j]=='M')m--;
            if(s[j+t]=='C'){
                ans+=dp[1];
            }
            if(s[j+t]=='D'){
                dp[0]++;
            }
            if(s[j+t]=='M'){
                m++;
                dp[1]+=dp[0];
            }
        }
        printf("%lld\n",ans);
    }
    return 0;

}




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

long long count_n(const vector<long long> vec, long long n)
{
    long long ret = 0;
    for (long long i = 0; i < vec.size() - 1; i++)
    {
        long long l = i + 1;
        long long r = vec.size() - 1;
        if (vec[i] < 0)
        {
            if (vec[i] * vec[l] < n)
            {
                continue;
            }
            if (vec[i] * vec[r] >= n)
            {
                ret += vec.size() - l;
                continue;
            }
            while (r - l > 1)
            {
                long long c = (l + r) / 2;
                if (vec[i] * vec[c] >= n)
                {
                    l = c;
                }
                else
                {
                    r = c;
                }
            }
            ret += l - i;
        }
        else if (vec[i] > 0)
        {
            if (vec[i] * vec[r] < n)
            {
                continue;
            }
            if (vec[i] * vec[l] >= n)
            {
                ret += vec.size() - l;
                continue;
            }
            while (r - l > 1)
            {
                long long c = (l + r) / 2;
                if (vec[i] * vec[c] >= n)
                {
                    r = c;
                }
                else
                {
                    l = c;
                }
            }
            ret += vec.size() - r;
        }
        else
        {
            if (n <= 0)
            {
                ret += vec.size() - i - 1;
            }
        }
    }
    return ret;
}

int main()
{
    long long N, K;
    cin >> N >> K;

    vector<long long> A(N);
    for (long long &a : A)
    {
        cin >> a;
    }
    sort(A.begin(), A.end());

    long long l = -1e18;
    l -= 5;
    long long r = 1e18;
    r += 5;
    while (r - l > 1)
    {
        long long c = l + (r - l) / 2;
        if (count_n(A, c) >= N * (N - 1) / 2 - K + 1)
        {
            l = c;
        }
        else
        {
            r = c;
        }
    }
    cout << l << endl;
}


Measured memory_bytes: 3428
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i = s; i < t ; ++i)
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define UNIQ(a) a.erase(unique(ALL(a)),a.end())
#define debug(a) cerr<<#a":="<<a<<endl;
#define SZ(a) (int)a.size()
using LL = long long; template<class T> using V = vector <T>; template <class T> using VV = V<V<T>>;


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

	int N; cin >> N;
	V<int>h(N);
	FOR(i, 0, N) {
		cin >> h[i];
	}
	// iに対するl,rを決定する
	V<int>st(N+1);
	int tpos = 0;
	V<LL>R(N + 1), L(N + 1);
	FOR(i, 0, N) {
		while (tpos && h[st[tpos - 1]] >= h[i]) {
			tpos--;
		}
		if (tpos) {
			L[i] = st[tpos - 1] + 1;
		}
		else {
			L[i] = 0;
		}
		st[tpos++] = i;
	}
	tpos = 0;
	for (int i = N - 1; i >= 0; i--){
		while (tpos && h[st[tpos - 1]] >= h[i]) {
			tpos--;
		}
		if (tpos) {
			R[i] = st[tpos - 1] ;
		}
		else {
			R[i] = N;
		}
		st[tpos++] = i;
	}
	LL ans = 0;
	FOR(i, 0, N) {
		ans = max(ans, h[i] * (R[i] - L[i]));
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 5212
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
using namespace std;
int h,w,sx,sy,zx,zy,ans=INT_MAX;
char mp[1010][1010];
bool pan[1010][1010];
int jx[5]= {0,1,-1,0,0},jy[5]= {0,0,0,1,-1};
struct dua {
	int x,y,m;
	bool operator < (const dua &x) const {
		return x.m<m;
	}
};
priority_queue<dua> q;
void bfs(int x,int y) {
	q.push((dua){x,y,0});
	while(!q.empty()) {
		int dx=q.top().x,dy=q.top().y,dis=q.top().m;
		q.pop();
		if(pan[dx][dy])
			continue;
		if(dis>=ans)
		    continue;
		pan[dx][dy]=1;
		for(int i=1; i<=4; i++) {
			int nx=dx+jx[i],ny=dy+jy[i];
			if(nx<1||ny<1||nx>h||ny>w||pan[nx][ny]||mp[nx][ny]=='#')
				continue;
			if(nx==zx&&ny==zy) {
				ans=min(ans,dis);
				continue;
			}
			q.push((dua){nx,ny,dis});
		}
		for(int nx=dx-2; nx<=dx+2; nx++)
			for(int ny=dy-2; ny<=dy+2;ny++) {
				if(nx<1||ny<1||nx>h||ny>w||pan[nx][ny]||mp[nx][ny]=='#')
					continue;
				if(nx==zx&&ny==zy) {
					ans=min(ans,dis+1);
					continue;
				}
				q.push((dua){nx,ny,dis+1});
			}
	}
}
signed main() {
	scanf("%d %d %d %d %d %d",&h,&w,&sx,&sy,&zx,&zy);
	for(int i=1; i<=h; i++)
		for(int j=1; j<=w; j++)
			cin>>mp[i][j];
	bfs(sx,sy);
	printf("%d\n",ans==INT_MAX?-1:ans);
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int n, a;
    cin >> n >> a;
    cout << n * n - a;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // AGC034B - ABC
  string s; cin >> s;
  int n = s.size();
  
  string ss = ""; // 新しく文字列を作っていく
  int t = 0;
  while(t < n){
    if(s[t] == 'A') ss += "A";
    if(s[t] == 'C') ss += "X";
    if(s[t] == 'B'){
      if(t == n-1){
        ss += "X";
      }else{
        if(s[t+1] == 'C'){
          ss += ".";
          t++;
        }else{
          ss += "X";
        }
      }
    }
    t++;
  }

  ll ans = 0, cnt = 0;
  int nn = ss.size();
  for(int i = nn-1; i >= 0; i--){
    if(ss[i] == '.') cnt++;
    if(ss[i] == 'A') ans += cnt;
    if(ss[i] == 'X') cnt = 0;
  }

  cout << ans << endl;
}

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

int sc[26],tc[26];
int main(){
    int n;
    string s,t;
    cin>>n>>s>>t;

    for(int i=0;i<n;i++){
        sc[s[i]-'a']++;
        tc[t[i]-'a']++;
    }


    sort(sc,sc+26);
    sort(tc,tc+26);

    int ans=0;
    for(int i=25;i>=0;i--){
        ans+=max(0,tc[i]-sc[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1404
#include<stdio.h>
int main(void){
    int a,b,c,x;
    while(1){
        scanf("%d %d %d",&a,&b,&c);
        if(a>b){
            x=a; a=b; b=x;
        }else if(b>c){
            x=b; b=c; c=x;
        }else if(a>b){
            x=a; a=b; b=x;
        }else{
            break;
        }
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s; cin >> s;
    int n = s.size();

    string tmp, tmp2;
    tmp.push_back(s[0]);
    int cnt = 0;
    for (int i = 1; i < n; i++) {
        tmp2.push_back(s[i]);
        if (tmp != tmp2) {
            cnt++;
            tmp = tmp2;
            tmp2.clear();
        }
    }

    cout << cnt + 1 << '\n';
    return 0;
}


Measured memory_bytes: 720
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var S = Read();
            var cnt = new Dictionary<char, int>();
            for (char c = 'a'; c <= 'z'; c++) cnt.Add(c, 0);
            for (int i = 0; i < N; i++) cnt[S[i]]++;
            int mod = (int)Math.Pow(10, 9) + 7;
            var ans = 1L;
            foreach(var c in cnt)
            {
                if (c.Value > 0)
                {
                    ans *= (c.Value + 1);
                    ans %= mod;
                }
            }
            ans--;

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13500
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

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

  ll b=0;
  for(int i=0;i<n;i++)b+=a[i+1];
  b/=2;
  ll c=b;
  for(int i=1;2*i<=n;i++)b-=a[2*i];
  for(int i=1;2*i+1<=n;i++)c-=a[2*i+1];
  cout << 2*b << endl;
  cout << 2*c << endl;


  for(int i=3;i<n+1;i++){
    if(i%2==1){
      b+=a[i-1];
      b-=a[i-2];
      cout << 2*b << endl;
    }
    else{
      c+=a[i-1];
      c-=a[i-2];
      cout << 2*c << endl;
    }
  }

}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
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());
    string ans;
    for(int i = 0; i < N; i++) {
        ans += S[i];
    }
    cout << ans << endl;
}


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

#[fastout]
fn main() {
    input!{
        tmp: String,
    }
    let st = tmp.chars().collect::<Vec<char>>();
    for i in 0..1 << 3 {
	let mut ret: i32 = st[0] as i32 - '0' as i32;
	let mut vec = Vec::new();
	for j in 0..3 {
	    if (1 << j) & i == 0 {
		ret += st[j+1] as i32 - '0' as i32;
		vec.push('+');
	    } else {
		ret -= st[j+1] as i32 - '0' as i32;
		vec.push('-');
	    }
	}
	if ret == 7 {
	    for i in 0..3 {
		print!("{}{}", st[i], vec[i]);
	    }
	    println!("{}=7", st[3]);
	    break;
	}
    }
		
		
}


Measured memory_bytes: 2124
#include <iostream>
#include <utility>
#include <cstring>
using namespace std;
#define MOD 1000000007

int n, m, s[2010], t[2010];
long dp[2010][2010], sum[2010][2010];

int main(){
	cin >> n >> m;
	for (int i = 0; i < n; ++i) cin >> s[i];
	for (int i = 0; i < m; ++i) cin >> t[i];
	dp[0][0] = (s[0] == t[0]);
	sum[0][0] = dp[0][0];
	for (int i = 1; i < n; ++i){
		dp[i][0] = (s[i] == t[0]);
		sum[i][0] = sum[i-1][0] + dp[i][0];
	}
	for (int j = 1; j < m; ++j){
		dp[0][j] = (s[0] == t[j]);
		sum[0][j] = sum[0][j-1] + dp[0][j];
	}
	for (int i = 1; i < n; ++i){
		for (int j = 1; j < m; ++j){
			dp[i][j] = (s[i] == t[j]) ? (sum[i-1][j-1] + 1) : 0;
			sum[i][j] = (((sum[i-1][j] + sum[i][j-1]) % MOD - sum[i-1][j-1] + MOD) % MOD + dp[i][j]) % MOD;
		}
	}
	cout << (sum[n-1][m-1] + 1);
}

Measured memory_bytes: 63232
//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    public static class Task {

        public boolean check(int a, boolean[] forbid) {
            for (char c: Integer.toString(a).toCharArray()) {
                if (forbid[c - '0']) return false;
            }
            return true;
        }

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int k = sc.nextInt();
            boolean[] forbid = new boolean[10];
            for(int i = 0; i < k; i++) forbid[sc.nextInt()] = true;
            for (int i = n; i <= 99999; i++) {
                if (check(i, forbid)) {
                    pw.println(i);
                    return;
                }
            }
        }
    }

    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("input"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("input"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

Measured memory_bytes: 27732
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(lli i=(lli)a;i<=(lli)b;i++)
#define endl "\n"
#define mp make_pair
#define X first
#define Y second
#define inf 1e18
#define mod 1000000007
#define pb push_back
#define pi 3.14159265359
#define gc getchar
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()
// #define lli int
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pli;
typedef vector<pii> vii;
typedef pair<lli,lli> pll;
typedef vector<lli> vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
lli A[200009],B[200009];
int main()
{
	lli n,m,a,b;
	cin>>n>>m;
	FOR(i,1,m)
	{
		cin>>a>>b;
		if(a==1) A[b]=1;
		if(b==1) A[a]=1;
		if(a==n) B[b]=1;
		if(b==n) B[a]=1;
	}
	FOR(i,2,n-1)
	if(A[i] & B[i])
	{
		cout<<"POSSIBLE";return 0;
	}
	cout<<"IMPOSSIBLE";
}

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

int main() {
	long long N, K;
	cin >> N >> K;
	double ans = 0;

	if (N > K) ans += (double)(N - K);
	for (long long i = 1; i <= min(N, K); i++)
	{
		int logk = ceil(log2((double)K / i));
		ans += (double)pow(0.5, logk);
	}

	printf("%.12lf\n", ans / N);
	// cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define sum(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class CBoxesAndCandies {
public:
  static void solve(istream &cin, ostream &cout) {
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int ans = 0;
    if (a[0] > x) {
      ans += a[0] - x;
      a[0] = x;
    }
    rep(i, N - 1) {
      if (a[i + 1] + a[i] > x) {
        ans += a[i + 1] + a[i] - x;
        a[i + 1] = x - a[i];
      }
    }
    cout << ans << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  CBoxesAndCandies solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int ctoi(char c) {
	switch (c)
	{
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default:
		cout << "ERR_ctoi" << endl;
		return -1;
	}
}
int main() {
	
	char b;
	cin >> b;
	if (b == 'A')PRI('T');
	if (b == 'T')PRI('A');
	if (b == 'G')PRI('C');
	if (b == 'C')PRI('G');
	return 0;
}

Measured memory_bytes: 3524
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    A = [format(a, "b")[::-1] for a in A]
    a_sum = [int()]*60

    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "1":
                a_sum[i] += 1

    a_sum = [a_s_*(2**i)%MOD for i, a_s_ in zip(range(60), a_sum)]
    a_acc_sum = [_ for _ in a_sum]

    for x in range(1,60):
        a_acc_sum[x] = a_acc_sum[x-1] + a_acc_sum[x] 
    
    ans = 0
    for a in A:
        for i, r_a in enumerate(a):
            if r_a == "0":
                ans += a_sum[i]
        
        ans += a_acc_sum[59] - a_acc_sum[i]
        ans %= MOD

    print(ans%MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 179712
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] bingo = new int[9];
        int[][] card = {{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}};
        boolean ok = false;
        for(int i = 0;i < 9;i++){
            bingo[i] = sc.nextInt();
        }

        int n = sc.nextInt();

        for(int i = 0;i < n;i++){
            int b = sc.nextInt();
            for(int j = 0;j < 9;j++){
                if(b == bingo[j])
                    bingo[j] = 0;
            }
        }

        for(int i = 0;i < 8;i++){
            if(bingo[card[i][0]] + bingo[card[i][1]] + bingo[card[i][2]] == 0)
                ok = true;
        }
        System.out.println(ok ? "Yes" : "No");


    }
}

Measured memory_bytes: 22612
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
tree<int,int,greater<int>,rb_tree_tag,tree_order_statistics_node_update> map_t;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define sz(x) (int)x.size()
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define REV(x) reverse(x.begin(),x.end())
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

void print(string s,map<string,int> m) {
    if(m.find(s)==m.end())
        cout << s << " x " << 0 << "\n";
    else
        cout << s << " x " << m[s] << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    map<string,int> m;
    string s;
    F0R(i,n) {
        cin >> s;
        m[s]++;
    }
    print("AC",m);
    print("WA",m);
    print("TLE",m);
    print("RE",m);

    return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main() {
	int flag = 0;
	string s;
	cin >> s;
	if (s[0] != 'A') {
		flag = 1;
	}
	int cnt = 0;
	for (int i = 2; i < s.length() - 1;i++) {
		if (s[i] == 'C') {
			cnt++;
		}
	}
	if (cnt != 1) {
		flag = 1;
	}

	for (int i = 0; i < s.length(); i++) {
		if (s[i] > 'A' && s[i] <= 'Z' && s[i] != 'C') {
			flag = 1;
		}
	}
	if (flag == 0) {
		cout << "AC";

	}
	else cout << "WA";


}

Measured memory_bytes: 256
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# dp[i+1][j] i番目までの魔法を使ってモンスターへの攻撃jにする魔力の最小値
# (j=0の時まだ攻撃していない)
H, N = lr()
INF = 10 ** 10
dp = [INF] * (H+10**4+10)
dp[0] = 0
for i in range(N):
    a, b = lr()
    for j in range(a, H+a+1):
        if dp[j-a] == INF:
            continue
        dp[j] = min(dp[j], dp[j-a] + b)

answer = min(dp[H:])
print(answer)


Measured memory_bytes: 42332
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    ll sum=0;
    vector <ll> v(n);
    generate(all(v),nxtl);
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
            sum+=(v[i]*v[j]);
    }
    cout<<sum<<endl;
    
    return 0;   
}


 
 


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


int main(){
  long long n;
  cin >> n;
  long long a[n];
  for (int i=0;i<n;i++){
    cin >> a[i];
    a[i] -= i+1;
  }
  sort(a,a+n);
  long long b;
  if(n%2==0) b = a[n/2];
  else b = a[(n-1)/2];
  long long sad = 0;
  for(int i=0;i<n;i++){
    sad += abs(a[i]-b);
  }
  cout << sad << endl;
  return 0;
}


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

#define endl '\n'

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

    long long resp=0,k,i,j,c;
    cin >> k;
    for (i=1; i<=k; i++){
        for (j=1; j<=k; j++){
            for (c=1; c<=k; c++){
                resp += __gcd(i,__gcd(j,c));
            }
        }
    }
    cout << resp << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;




int main(void) {

    int n,k;
    cin>>n>>k;
    int ans=0;
    while(n>0){
        n/=k;
        ans++;
    }
    fin(ans);
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int n[5],
		i,j;
	
	scanf("%d %d %d %d %d",&n[0],&n[1],&n[2],&n[3],&n[4]);
	
	for(i=0;i<5;i++){
		int V=n[i],V_n=i;
		
		for(j=i+1;j<5;j++){
			if(n[j]>V){
				V=n[j];
				V_n=j;
			}
		}
		n[V_n]=n[i];
		n[i]=V;
	}
	printf("%d %d %d %d %d\n",n[0],n[1],n[2],n[3],n[4]);
	
	return 0;
}

Measured memory_bytes: 0
import itertools

N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
c = [[int(s) - 1 for s in input().split()] for _ in range(N)]

m0 = [0] * C
m1 = [0] * C
m2 = [0] * C
for i, j in itertools.product(range(N), repeat=2):
    if (i + j) % 3 == 0: m0[c[i][j]] += 1
    if (i + j) % 3 == 1: m1[c[i][j]] += 1
    if (i + j) % 3 == 2: m2[c[i][j]] += 1

ans = float('inf')
for x, y, z in itertools.permutations(range(C), 3):
    point = 0
    for i in range(C): point += D[i][x] * m0[i]
    for i in range(C): point += D[i][y] * m1[i]
    for i in range(C): point += D[i][z] * m2[i]
    ans = min(ans, point)

print(ans)


Measured memory_bytes: 5492
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
using namespace std;

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


int main(){
    int n;
    cin >> n;
    while(n--){
        string s;
        cin >> s;

        set<string> set;
        for(int i = 1; i < s.size(); i++){
            string t = s.substr(0, i), u = s.substr(i, s.size() - i);
            set.insert(t + u);
            set.insert(u + t);
            reverse(ALL(t));
            set.insert(t + u);
            set.insert(u + t);
            reverse(ALL(u));
            set.insert(t + u);
            set.insert(u + t);
            reverse(ALL(t));
            set.insert(t + u);
            set.insert(u + t);
        }
        int res = set.size();
        cout << res << endl;
    }
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,C,count=1;
  cin>>A;
  vector<int> v(A);
  C=v.at(0);
  rep(0,A)cin>>v.at(i);
  rep(1,A){
    if(v.at(i)>=v.at(0)&&v.at(i)>=C){
      count+=1;
    }
    if(v.at(i)>=C)C=v.at(i);
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


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


		if(N >= 1 && N<= 81)
		{
			for(int i = 1; i<=9; i++)
			{
				if( ((N%i) == 0) && ((N/i) <= 9))
					flag = true;
			}
		}

		if(flag == true)
			System.out.println("Yes");
		else
			System.out.println("No");
		
	}

}

Measured memory_bytes: 23764