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

#define REP(i,n) for(int i=0;i<(n);i++)
#define int long long
#define ALL(x) (x).begin(),(x).end()
typedef pair<int, int> P;

struct data{
    string name;
    int cost,T,num,val,count;
};

bool comp(const pair<double,string>&p1,const pair<double,string>&p2){
    if(p1.first!=p2.first)return p1.first>p2.first;
    else return p1.second<p2.second;
}
void solve() {
    int N;cin>>N;
    if(N==0)exit(0);
    vector<pair<double,string>>v;
    REP(i,N){
        string L;cin>>L;
        int p,a,b,c,d,e,f,s,m;cin>>p>>a>>b>>c>>d>>e>>f>>s>>m;
        int time = 0;
        time+=(a+b+c+d+e);
        time+=(m-1)*(d+e);
        int val = 0;
        val+=f*s*m;
        val-=p;
        double eff = (double)val/time;
        v.push_back({eff,L});
    }
    sort(ALL(v),comp);
    //reverse(ALL(v));
    REP(i,N){
        cout<<v[i].second<<endl;
    }
    cout<<"#"<<endl;
}

signed main() {
	while (true)solve();
}



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

#define int        long long
// #define mp      make_pair
#define eb         emplace_back
#define pb         push_back
#define ss         second
#define ff         first
#define IOS        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod        998244353
#define MOD        (1000*1000*1000+7)
#define MN         LLONG_MIN
#define MX         LLONG_MAX
#define v1d        vector<int>
#define v2d        vector<vector<int>>
#define vip        vector<pair<int,int> >
#define v1s        vector<string>
#define pa         pair<int,int>
#define mxpq(T)    priority_queue <T>
#define mnpq(T)    priority_queue<T,vector<T>,greater<T>>
#define print(v)   for(auto i:v)cout<<i<<" ";cout<<"\n";
#define p2d(v)     for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)     for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)     for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define endl       "\n"
#define input(b,n) for(int i=0;i<n;i++)cin>>b[i];
#define Sort(v)    sort(v.begin(),v.end())
#define RSort(v)   sort(v.rbegin(),v.rend())
#define all(v)     v.begin(),v.end()
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//string s = bitset<64>(a).to_string();
int lb = 1000;
#define Exit    lb--;if(lb<0){cout<<"exit";exit(0);}

void azmuth(int n=12){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<setprecision(n)<<fixed;
    #ifndef ONLINE_JUDGE
         freopen("input.txt",  "r",  stdin);
         freopen("output.txt", "w", stdout);
    #endif
}

//____________________________________________________________________________________


void solve(){
    int a,b;cin >> a >> b;
    cout << a*b;
}

int32_t main(){
    // azmuth();
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    


    return 0;
}

Measured memory_bytes: 3636
def test():
	mod = 10**9 + 7
	n, m = map(int, input().split())
	if abs(n-m) > 1:
		print(0)
		exit()
	i_n = n
	i_m = m
	np = 1
	mp = 1
	while True:
		np = (np%mod) * (i_n%mod)
		mp = (mp%mod) * (i_m%mod)
		i_n -= 1
		i_m -= 1
		if i_n < 1:
			i_n = 1
		if i_m < 1:
			i_m = 1
		if i_n == 1 and i_m == 1:
			break
	s = 2 if n == m else 1
	r = (mp*np*s) % (10**9 + 7)
	print(r)
test()

Measured memory_bytes: 38512
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    X, K, D = read_values()
    X = abs(X)
    k = X // D
    if k >= K:
        print(X - K * D)
    else:
        K -= k
        X -= k * D
        print(X if K % 2 == 0 else D - X)


if __name__ == "__main__":
    main()



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

int main()
{
    int i,j,q,flag=0;
    char a[105],b[105],a1[105];
    gets(a);
    gets(b);
    q=strlen(a);
    for(j=0; j<=q; j++)
    {

        for(i=1; a[i]!='\0'; i++)
        {
            a1[0]=a[q-1];
            a1[i]=a[i-1];
        }

        for(i=0;i<q;i++)
        {
            a[i]=a1[i];
        }
        if(strcmp(a,b)==0)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
        printf("Yes\n");
    else
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i, n) FOR(i,0,n)

using namespace std;
typedef long long ll;
const int INF = 1e9;
int h,w;
char board[8][8];

bool check(){
    REP(i,h){
        REP(j,w){
            if(board[i][j]=='#'){
                if(i==0){
                    if(j==0){
                        if(board[i+1][j]==board[i][j+1]) return false;
                    }
                    else {
                        if(board[i][j-1]!='#') return false;
                        if(j==w-1){
                            if(board[i+1][j]=='#') continue;
                            else return false;
                        }
                        if(board[i+1][j]==board[i][j+1]) return false;
                    }
                }
                else if(i!=h-1){
                    if(j==0){
                        if(board[i-1][j]!='#') return false;
                        if(board[i][j+1]==board[i+1][j]) return false;
                        continue;
                    }
                    if(board[i-1][j]==board[i][j-1]) return false;
                    if(j==w-1){
                        if(board[i+1][j]!='#') return false;
                        continue;
                    }
                    if(board[i+1][j]==board[i][j+1]) return false;
                }
                else {
                    if(j==w-1) return true;
                    if(j==0){
                        if(board[i-1][j]!=board[i][j+1]) return false;
                        else continue;
                    }
                    if(board[i-1][j]==board[i][j-1]) return false;
                    if(board[i][j+1]!='#') return false;
                }
            }
        }
    }
}

void solve(){
    if(check()) cout << "Possible\n";
    else cout << "Impossible\n";
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w;
    REP(i,h){
        REP(j,w){
            cin >> board[i][j];
        }
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <memory.h>
#include <algorithm>
#include <vector>

using namespace std;

#define MAX_N 1000005
long long N;

bool primes[MAX_N];
vector<long long> factors;

void gen_primes() {
  memset(primes, 1, sizeof(primes));
  primes[0] = false;
  primes[1] = false;

  for (int i = 2; i < MAX_N; i++) {
    if (primes[i]) {
      for (int j = i*2; j < MAX_N; j+= i) {
        primes[j] = false;
      }
    }
  }
}

void gen_factors() {
  for (int i = 0; i < MAX_N; i++) {
    if (primes[i]) {
      for (long long j = i; j < MAX_N; j*=i) {
        factors.push_back(j);
      }
    }
  }
}

void solve() {
  gen_primes();
  gen_factors();
  sort(factors.begin(), factors.end());

  // for (int i = 0; i < factors.size(); i++) printf("%lld\n", factors[i]);

  int ans = 0;
  int cur = 0;
  long long k = N;
  while (cur < k && cur < factors.size()) {
    if (k % factors[cur] == 0) {
      k /= factors[cur];
      ans++;
    }
    cur++;
  }
  if (k > cur) ans++;
  printf("%d\n", ans);
}

int main() {
  scanf("%lld", &N);

  solve();
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#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=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

// const ll MOD=1000000007ll;
const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll fact[364364], fact_inv[364364];

ll mod_pow(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1){
			res=res*a%MOD;
		}
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll comb(ll n, ll r){
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a, b;
	ll k;
	cin>>n>>a>>b>>k;
	fact[0]=1;
	REP(i, n){
		fact[i+1]=fact[i]*(i+1)%MOD;
	}
	fact_inv[n]=mod_pow(fact[n], MOD-2);
	FORR(i, 0, n){
		fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	}
	ll ans=0;
	REP(i, n+1){
		if((k-i*a)%b==0){
			int j=(k-i*a)/b;
			if(j>=0 && j<=n){
				ans=(ans+comb(n, i)*comb(n, j)%MOD)%MOD;
				// DEBUG(i);
				// DEBUG(comb(n, i));
				// DEBUG(j);
				// DEBUG(comb(n, j));
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}


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

typedef struct
{
    char a;
    int num;
} data;

//バブルソートと比較し安定か安定じゃないか確かめる

int main()
{
    data data[36], data1[36], data2[36], tmp_data;
    int i, j, n, minj, s = 0, flag = 0, flag2 = 0;

    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        scanf(" %c %d", &data[i].a, &data[i].num);
        // printf("",data[i].a,data[i].num);
        data1[i] = data[i];
        data2[i] = data[i];
    }

    //for(i=0;i<n;i++)printf("%c%d  i=%d\n",data[i].a,data[i].num,i);

    //バブルソート
    flag = 1;
    while (flag)
    {
        flag = 0;
        for (j = n - 1; j > s; j--)
        {
            //printf("hoge1\n");
            if (data1[j - 1].num > data1[j].num)
            {
                tmp_data = data1[j - 1];
                data1[j - 1] = data1[j];
                data1[j] = tmp_data;
                flag = 1;
            }
        }
        s++;
    }

    for (i = 0; i < n; i++)
    {
        printf("%c%d", data1[i].a, data1[i].num);
        if (i != n - 1)
            printf(" ");
    }
    printf("\nStable\n");

    //セレクションソート
    for (i = 0; i < n; i++)
    {
        minj = i;
        for (j = i; j < n; j++)
        { //printf("hoge2\n");
            if (data2[j].num < data2[minj].num)
            {
                minj = j;
            }
        }
        //printf("hoge3\n");
        tmp_data = data2[i];
        data2[i] = data2[minj];
        data2[minj] = tmp_data;
    }

    for (i = 0; i < n; i++)
    {
        printf("%c%d", data2[i].a, data2[i].num);
        if (i != n - 1)
            printf(" ");
        if (data1[i].a != data2[i].a)
            flag2 = 1;
    }
    printf("\n");

    if (flag2 == 0)
        printf("Stable\n");
    else
        printf("Not stable\n");
    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<ll,int> P;
const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<ll> a(n),d, F;
    vector<P> I(m);
    priority_queue<P> qp;
    // vector<int> b(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    rep(i,n){
        qp.push(P{a[i],1});
    }
    rep(i,m){
        ll c;int b;
        cin >> b >> c;
        qp.push(P{c,b});
    }
    ll ans = 0;
    rep(i,n){
        ll x = qp.top().first;
        int c = qp.top().second;qp.pop();
        ans += x;
        if(c>1){
            c--;
            qp.push((P){x,c});
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8688
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int[] a = new int[n];
	for(int i=0; i<n; i++) {
		a[i] = sc.nextInt();
	}
	int[] b = new int [100000];
	int ans = 1;
	for(int i=0; i<n; i++) {
		b[a[i]]++;
	}
	for(int i=1; i<n-1; i++) {
		if(b[i-1]+b[i]+b[i+1]>ans) {
			ans = b[i-1]+b[i]+b[i+1];
		}		
	}
	System.out.println(ans);
}
}


Measured memory_bytes: 50056
//#define _GLIBCXX_DEBUG

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

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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll d,t,s;cin>>d>>t>>s;
  ans1(s*t>=d);
  return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL A, B, C, K, ans;

int main()
{
	in >> A >> B >> C >> K;
	ans = (K % 2 == 0 ? A - B : B - A);
	if (abs(ans) > 1000000000000000000) out << "Unfair" << std::endl;
	else out << ans << std::endl;
	return 0;
}

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

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,(n))


class BMixJuice {
public:
	void solve(std::istream& in, std::ostream& out) {
    int k, n;
    in >> n >> k;
    vector<int> p(n);
    REP(i,n) in >> p[i];

    sort(p.begin(),p.end());

    int sum = 0;
    REP(i,k){
      sum += p[i];
    }
    out << sum << endl;
	}
};


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


Measured memory_bytes: 3640
#include<cstdio>
int main(){
int x,y;
for(;;){
    std::scanf("%d%d",&x,&y);
    if(x == 0 && y == 0){
        break;
    }
    else if(x < y){
        std::printf("%d %d\n", x, y);
    }
        else {
            std::printf("%d %d\n", y, x);
        }
    }
}


Measured memory_bytes: 2656
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

#define debug(x) cout << #x << ": " << x << endl;
#define ll long long
#define mod 1000000007

int N, K, A[1<<20], msort[1<<20], msortb[1<<20], maxm[1<<20], minm[1<<20];

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);
  cin >> N >> K;
  for(int i = 0;i < N;i++) cin >> A[i];
  msort[0] = 1;
  for(int i = 1;i < N;i++) {
    if(A[i] > A[i-1]) msort[i] = msort[i-1]+1;
    else msort[i] = 1;
  }
  msortb[0]=0;
  for(int i = 1;i < N;i++) {
    if(msort[i] >= K) msortb[i] = 1;
    else msortb[i] = msortb[i-1];
  }

  set<int> s;
  int ans = 1;
  for(int i = 0;i < K;i++) s.insert(A[i]);

  for(int i = K;i < N;i++) {
    s.insert(A[i]);
    int minv = *s.begin();
    int maxv = *s.rbegin();

    s.erase(A[i-K]);

    int possible = 1;
    if(minv == A[i-K] and maxv == A[i]) possible = 0;
    if(msortb[i-K] and (msort[i] >= K)) possible = 0;

    ans += possible;
  }

  cout << ans << endl;

  return 0;
}


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

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

long long solve(long long N, long long A, long long B) {
    if (A > B) swap(A, B);
    if ((A % 2) == (B % 2)) {
        return (B - A) / 2;
    }
    long long res = min(max(A-1, B-1), max(N-A, N-B));
    if (B-A > 0) res = min(res, A+solve(N, 1, B-A));
    if (A+N-B+1 <= N) res = min(res, N-B+1+solve(N, A+N-B+1, N));
    return res;
}

int main() {
    long long N, A, B;
    cin >> N >> A >> B;
    cout << solve(N, A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template< typename T >
vector< T > slide_min(const vector< T > &v, int k)
{
	deque< int > deq;
	vector< T > ret;
	for (int i = 0; i < v.size(); i++) {
		while (!deq.empty() && v[deq.back()] >= v[i]) {
			deq.pop_back();
		}
		deq.push_back(i);
		if (i - k + 1 >= 0) {
			ret.emplace_back(v[deq.front()]);
			if (deq.front() == i - k + 1) deq.pop_front();
		}
	}
	return ret;
}

template< typename T >
vector< T > operator-(const vector< T > &v) {
	vector< T > res(v.size());
	for (int i = 0; i < v.size(); i++) res[i] = -v[i];
	return res;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;

	vector<int> P(N);
	for (int i = 0; i < N; i++) {
		int p; cin >> p;
		P[i] = p;
	}

	auto smin = slide_min(P, K);
	auto smax = -slide_min(-P, K);
	DMP(smin, smax);

	int cnt1 = 0;
	for (int i = 0; i < N - K; i++) if (smin[i] == P[i] && smax[i + 1] == P[i + K]) cnt1++;

	int seq = 0, cnt2 = 0;
	for (int i = 0; i < N - 1; i++) {
		if (P[i] < P[i + 1]) seq++;
		else seq = 0;
		if (seq == K - 1) cnt2++;
	}

	DMP(N - K + 1, cnt1, cnt2);
	cout << N - K + 1 - cnt1 - max(cnt2 - 1, 0) << "\n";

	return 0;
}

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

using namespace std;

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

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

	string s[n];
	map<string, int> mp;
	for(int i=0;i<n;i++){
		cin >> s[i];
		auto itr = mp.find(s[i]);
		if( itr != mp.end() ) {
			mp[s[i]]++;
		} else {
			mp[s[i]] = 1;
		}
	}
	int max = 0;
	for(int i=0;i<n;i++){
		if(max<mp[s[i]]) max = mp[s[i]];
	}
	for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
		if (itr->second==max){
			cout << itr->first << endl;
		}
    }
	return 0;
}

Measured memory_bytes: 25360
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl;}
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

int main(void){
    int N;
    cin >> N;

    vector<pair<int, int> > A(N);
    rep(i, N){
        int tmp;
        cin >> tmp;

        A[i] = make_pair(tmp, i + 1);
    }
    sort(ALL(A));

    rep(i, N) cout << A[i].second << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;

int f(int x)
{
    int s = 0;
    while (x)
    {
        s += x%10;
        x/=10;
    }
    return s;
}

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 10*n;
    for (int a = 1; a < n; a++)
    {
        int b = n - a;
        int res = f(a) + f(b);
        if (res < ans)
            ans = res;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ha 1000000007
#define inv2 500000004
using namespace std;

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}

const int N=200010;
const int M=8000;
int fac[M+10],ifac[M+10];
int f[M/2+10][M/2+10],base=M/4+2;
int n,A[N],B[N];

int Pow(int a,int b)
{
    int ans=1;
    for(;b;b>>=1,a=1ll*a*a%ha)
        if(b&1) ans=1ll*ans*a%ha;
    return ans;
}

void Init()
{
    fac[0]=1;
    for(int i=1;i<=M;i++)
        fac[i]=1ll*fac[i-1]*i%ha;
    ifac[M]=Pow(fac[M],ha-2);
    for(int i=M-1;i>=0;i--)
        ifac[i]=1ll*ifac[i+1]*(i+1)%ha;
}

int C(int n,int m){return 1ll*fac[n]*ifac[m]%ha*ifac[n-m]%ha;}

int main()
{
    Init(); n=read();
    for(int i=1;i<=n;i++)
    {
        A[i]=read(),B[i]=read();
        f[base-A[i]][base-B[i]]++;
    }
    for(int i=1;i<=M/2+2;i++)
        for(int j=1;j<=M/2+2;j++)
            f[i][j]=(f[i][j]+(f[i-1][j]+f[i][j-1])%ha)%ha;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        ans=(ans+f[A[i]+base][B[i]+base])%ha;
        ans=(ans-C(2*A[i]+2*B[i],2*A[i]))%ha;
    }
    ans=(ans+ha)%ha;
    ans=1ll*inv2*ans%ha;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 68928
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <random>

#include <fstream>
#include <vector>
#include <algorithm>

#define ll long long int

using namespace std;

int main(void)
{

    
    int a;
    
    cin >> a;
    
    cout << a +(a*a) + (a*a*a);
    
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;

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

vector<ll> factorize(ll n){
    vector<ll> res;
    for(ll i=2;i*i<=n;i++){
        if(n%i) continue;
        res.emplace_back(i);
        while(n%i==0) n/=i;
    }
    if(n!=1) res.emplace_back(n);
    return res;
}

int main(){
    ll a,b; cin>>a>>b;
    ll n=gcd(a,b);
    auto v=factorize(n);
    ll ans=v.size()+1;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
a = {}
b = {}
for i in range(n // 2):
    key_a = l[i * 2]
    key_b = l[i * 2 + 1]
    if key_a in a:
        a[key_a] = a[key_a] + 1
    else:
        a[l[i * 2]] = 1
    if key_b in b:
        b[key_b] = b[key_b] + 1
    else:
        b[key_b] = 1
a = sorted(a.items(), key=lambda x: x[1], reverse=True)
b = sorted(b.items(), key=lambda x: x[1], reverse=True)
# a = list(a.items())
# b = list(b.items())
# print(a)
# print(b)
ca_max = a[0][0]
cb_max = b[0][0]
ca_max_num = a[0][1]
cb_max_num = b[0][1]
same_num = ca_max_num + cb_max_num
if ca_max == cb_max:
    if len(a) > 1:
        next_ca_max = a[1][1]
    else:
        next_ca_max = 0
    if len(b) > 1:
        next_cb_max = b[1][1]
    else:
        next_cb_max = 0
    same_num = max(ca_max_num + next_cb_max, cb_max_num + next_ca_max)
print(n - same_num)

Measured memory_bytes: 22720
#include<bits/stdc++.h>
#define ll long long
#define N 200010
using namespace std;
template <typename T> void read(T &x){
	x=0;char c=getchar();int fh=1;
	while (!isdigit(c)){if (c=='-')fh=-1;c=getchar();}
	while (isdigit(c))x=x*10+c-'0',c=getchar();
	x*=fh;
}
int n,a[N];
bool pa(int x){
	priority_queue<int> b;
	map<int,int> c;c.clear();
	while (!b.empty()) b.pop();
	for (int i=1;i<=n;i++){
		if (a[i]<=a[i-1]){
			if (x==1) return false;
			while (!b.empty()&&b.top()>a[i]){c[b.top()]=0;b.pop();}
			c[a[i]]++;if (c[a[i]]==1) b.push(a[i]);
			int y=a[i];
			while (c[y]>=x){
				b.pop();c[y]=0;
				if (y==1) return false;
				y--;c[y]++;if (c[y]==1) b.push(y);
			}
		}
	}
	return true;
}
int main(){
	read(n);
	for (int i=1;i<=n;i++)read(a[i]);
	int l=1,r=n,mid;
	if (n>100) if (pa(100)) r=100;
	while (l<r){
		mid=(l+r)/2;
		if (pa(mid)) r=mid;else l=mid+1;
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 9856
import std.stdio;
import std.conv;
import std.string;
void main(){
  string back="+";
  int ans=0,num;
  while(num=to!int(chomp(readln())),1){
    if(back=="+") ans+=num;
    else if(back=="-") ans-=num;
    else if(back=="*") ans*=num;
    else if(back=="/") ans/=num;
    back=chomp(readln());
    if(back=="="){writeln(ans);break;}
  }
}

Measured memory_bytes: 1044
/* -------------------------------- Template -------------------------------- */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

// template<typename T> constexpr T inf = [](){ assert(false); };
// template<> constexpr int inf<int> = 1e9;
// template<> constexpr ll inf<ll> = 1e18;
// template<> constexpr ld inf<ld> = 1e30;

struct yes_no : std::numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve();

int main() {
  std::locale loc(std::locale(), new yes_no);
  std::cout << std::boolalpha << std::setprecision(12) << std::fixed;
  std::cout.imbue(loc);
  solve();
  return 0;
}

using namespace std;

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

using P = complex<ld>;

ld x[1024], y[1024], r[1024];
ld d[1024];
bool visited[1024];

void solve() {
  int N;
  cin >> x[0] >> y[0];
  cin >> x[1] >> y[1];
  cin >> N;
  REP(i,N) cin >> x[i+2] >> y[i+2] >> r[i+2];
  REP(i,1024) d[i] = 1e18;
  d[0] = 0;
  REP(i,N+2) {
    ld mi_d = 1e18;
    int p = -1;
    REP(j,N+2) {
      if (visited[j]) continue;
      if (d[j] < mi_d) { mi_d = d[j]; p = j; }
    }
    visited[p] = true;
    REP(j,N+2) {
      chmin(d[j], d[p] + max(0.0L, abs(P(x[p] - x[j], y[p] - y[j])) - r[p] - r[j]));
    }
  }
  cout << d[1] << endl;
  return;
}


Measured memory_bytes: 384
"use strict";

function totalH(H) {
    return H.reduce((a,b)=>a+b)
}

function main(arg) {
    const input = arg.trim().split("\n");
    const N = Number(input.shift())
    const H = input[0].split(" ").map(h=>Number(h))
    
    //console.log(N)
    //console.log(H)

    let counter = 0
    while(totalH(H) > 0) {
        // find where is the largest part in current layer
        let len = 0
        let maxLen=0
        let lastH=N-1
        for(let i=0; i<N; i++) {
            if(H[i]>0) {
                len++
                //console.log(`len countup ->${len}`)
                if(i===N-1) {
                    maxLen = len-1
                    lastH=i
                }
            } else {
                //console.log(`len=${len}`)
                if(maxLen < len) {
                    //console.log(`i=${i}, len=${len}`)
                    maxLen = len-1
                    lastH=i-1
                }
                len=0
            }
            //if(i===N-1 && H[i]>0) {
            //}
        }
        if(len==N) maxLen = N-1
        let l=lastH-maxLen, r=lastH
        //console.log(`maxLen=${maxLen}, lastH=${lastH}, l=${l}, r=${r}`)
        for(let i=l; i<=r; i++) {
            if(H[i]>0) {
                H[i]--
            }
        }
        //console.log(H)
        counter++
    }
    console.log(counter)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  bool graph[h][w];
  int ans[h][w] = {};
  rep(i, h) {
    string s;
    cin >> s;
    rep(j, w) {
      if (s[j] == '#')
        graph[i][j] = true;
      else
        graph[i][j] = false;
    }
  }
  int x = 1, null = 0;
  rep(i, h) {
    int cnt = 0;
    rep(j, w) {
      if (graph[i][j] && cnt >= 1) {
        cnt++;
        x++;
        ans[i][j] = x;
      } else if (graph[i][j]) {
        cnt++;
        ans[i][j] = x;
      } else {
        ans[i][j] = x;
      }
    }
    if (cnt == 0) {
      null++;
    } else {
      int s = i;
      while (null > 0) {
        rep(k, w) ans[s - null][k] = ans[s][k];
        null--;
      }
      x++;
    }
  }
  while (null > 0) {
    rep(i, w) ans[h - 1 - null + 1][i] = ans[h - 1 - null][i];
    null--;
  }
  rep(i, h) {
    rep(j, w) cout << ans[i][j] << " ";
    cout << endl;
  }
  return 0;
}

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

void solve(vector<vector<int>> A,vector<int> ansr,vector<int> ansc){
	for(int i = 0;i < ansr.size();i++){
		for(int k = 0;k < ansc.size();k++){
			ansr[i] += A[i][k];
			ansc[k] += A[i][k]; 
		}
	}
	for(int i = 0;i < ansr.size();i++){
		for(int k = 0;k < ansc.size();k++){
			cout << A[i][k] << " "; 
		}
		cout << ansr[i] << endl;
	}
	int ans;
	for(int k = 0;k < ansc.size();k++){
		cout << ansc[k] << " ";
		ans += ansc[k];
	}
	cout << ans << endl;
}

int main(){
	int r,c;
	cin >> r >> c;
	vector<vector<int>> A(r,vector<int>(c));
	for(int i = 0;i < r;i++){
		for(int k = 0;k < c;k++){
			cin >> A[i][k];
		}
	}
	vector<int> ansr(r);
	vector<int> ansc(c);
	solve(A,ansr,ansc);
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, K;
    cin >> N >> K;
    cout << (K == 1 ? 0 : (N - K) )  << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

int main(void)
{
	ll n, a, b;
	while(scanf("%lld%lld%lld", &n, &a, &b)==3)
	{
		ll m=n%(a+b);
		ll l=n/(a+b);

		ll ans=l*a+min(m, a);
		printf("%lld\n", ans);
	}
	return 0;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint a(n+2);
  a[0] = 0;
  reps(i, 1, n+1) cin >> a[i];
  a[n+1] = 0;
  int sum = 0;
  rep(i, n+1) sum += llabs(a[i]-a[i+1]);

  reps(i, 1, n+1) {
    cout << sum - llabs(a[i-1]-a[i]) - llabs(a[i]-a[i+1]) + llabs(a[i-1]-a[i+1]) << endl;
  }

  return 0;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');

                int n = int.Parse(input[0]);
                int m = int.Parse(input[1]);

                if (n == 0 && m == 0) break;

                int ans = n * m;

                while (ans > n)
                {
                    ans = ((ans - n) * m - 1) / (m - 1);
                }
                sb.AppendLine(ans.ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int arr[n-1];
    for(int i=0;i<n-1;i++)cin>>arr[i];
    int h[n];
    for(int i=0;i<n;i++){
        h[i] = 0;
    }
    for(int i:arr){
        h[i]++;
        
    }
    for(int i=1;i<n;i++){
        cout<<h[i]<<"\n";
    }
    cout<<"0\n";
    return 0;
}

Measured memory_bytes: 5144
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = ReadLine();
            string ans = "";
            for (int i = 0; i < s.Length; i++)
            {
                switch(s[i]){
                    case '0':
                        ans += "0";
                        break;
                    case '1':
                         ans += "1";
                         break;
                    case 'B':
                        if (ans.Length>0)
                        {
                            ans = ans.Remove(ans.Length-1);
                        }
                        break;
                }
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			(a).begin(),(a).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				(1000 * 1000 * 1000 * 2)
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<int, int>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// 枝定義
struct Edge
{
	int	from;
	int	to;
	Edge(){}
	Edge(int a, int b): from(a), to(b){}
};

// dfs
vector<vector<int>>	G;
vector<bool>		isUsed;
void dfs(int from, int to)
{
	for (auto nextTo : G[to]) {
		if (from != nextTo) {
			if (!isUsed[nextTo]) {
				isUsed[nextTo] = true;
				dfs(to, nextTo);
			}
		}
	}
}

// メイン
int main()
{
	int N, M;
	cin >> N >> M;
	vector<Edge>	edgeList;
	REP(i, M) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		edgeList.emplace_back(a, b);
	}

	int ans = 0;
	REP(i, M) {
		// グラフ作成
		G.clear();
		G.resize(N);
		for (int j = 0; j < M; j++) {
			if (i != j) {
				const auto &edgeOne = edgeList[j];
				G[edgeOne.from].emplace_back(edgeOne.to);
				G[edgeOne.to].emplace_back(edgeOne.from);
			}
		}
		
		// 手繰る
		int startPos = 0;
		isUsed.clear();
		isUsed.resize(N, false);
		isUsed[startPos] = true;
		dfs(-1, startPos);
		
		// 到達してないところがないか
		for (int j = 0; j < N; j++) {
			if (!isUsed[j]) {
				ans++;
				break;
			}
		}
	}

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


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

int main(){
    long long X;
    cin >> X;
    long long cnt_500=0, cnt_5=0;
    cnt_500 = X / 500;
    X -= 500*cnt_500;
    cnt_5 = X / 5;
    long long sum = 0;
    sum = cnt_500 * 1000 + cnt_5 * 5;
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int N,i,j,c1,c2;
  scanf("%d",&N);
  int d[N];
  for(i=1;i<=N;++i){
    scanf("%d",&d[i]);
  }
  c1=0;
  for(i=1;i<=N-1;++i){
    for(j=i+1;j<=N;++j){
  c2=c1+d[i]*d[j];
  c1=c2;
    }
  }
  printf("%d\n",c2);
}

Measured memory_bytes: 128
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length === 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public async getNumbers(): Promise<number[]> {
      return (await this.getLine()).split(' ').map((x) => +x);
    }

    public async getStrings(): Promise<string[]> {
      return (await this.getLine()).split(' ');
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function solve() {
    const sc = new Scanner();
    const [N, M, C]: number[] = await sc.getNumbers();
    const B: number[] = await sc.getNumbers();
    const A: number[][] = [];
    for (let i = 0; i < N; i += 1) {
      A.push(await sc.getNumbers());
    }
    let ans = 0;
    for (let i = 0; i < N; i += 1) {
      let t = C;
      for (let j = 0; j < M; j += 1) {
        const tA = A[i][j];
        const tB = B[j];
        t += tA * tB;
      }
      if (t > 0) ans += 1;
    }
    console.log(ans);
    sc.close();
  }

  solve();
}


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

using namespace std;
using ll = long long;

void solve(ll n, vector<ll> p) {
  int ans{};
  for (auto i=0; i!=n-2; ++i) {
    if ((p[i]<p[i+1]&&p[i+1]<p[i+2])
        || (p[i]>p[i+1]&&p[i+1]>p[i+2])) ++ans;
  }
  cout << ans << endl;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  solve(n, move(p));
  return 0;
}


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

#define ul unsigned long long
#define ll long long 

int main()
{
  int a[9];
  for (int i=0;i<9;i++) cin>>a[i];
  int n;
  cin>>n;
  int cb;
  for (int i = 0; i < n; i++)
  {
    cin>>cb;
    for (int j=0;j<9;j++) {
      if (a[j]==cb) a[j]=0;
    }
  }

  string re="No";
  int ids[8][3] = {
      {0, 1, 2},
      {3,4,5},
      {6,7,8},
      {0,3,6},
      {1,4,7},
      {2,5,8},
      {0,4,8},
      {2,4,6}
  };
  for (int i=0;i<8;i++) {
    bool cj = (a[ids[i][0]] == 0) && (a[ids[i][1]] == 0) && (a[ids[i][2]] == 0);
    if (cj) {
      re="Yes";
      break;
    }
  }

  cout<<re<<endl;

  return 0;
}


Measured memory_bytes: 256
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


N, K = map(int, input().split())
A = list(map(int, input().split()))
G = A[0]
for a in A:
    G = gcd(a, G)
print('POSSIBLE' if K % G == 0 and K <= max(A) else 'IMPOSSIBLE')

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 5e5+10;
const ll INF = 1e18;

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

char s[N];
int nexta[N][27];
int ans[N][19];

void make(){
	FILL(nexta,-1);
	FILL(ans,-1);
	int n=strlen(s),x;
	for(int i=n-1;i>=0;i--){
		x=s[i]-'a';
		nexta[i][x]=i+1;
		REPP(c,x+1,27)
			if (nexta[i][c-1]!=-1) nexta[i][c]=nexta[nexta[i][c-1]][c-1];
		if (nexta[i][26]!=-1){
			REP(c,x) nexta[i][c]=nexta[nexta[i][26]][c];
			ans[i][0]=nexta[i][26];
			REPP(lvl,1,19) if (ans[i][lvl-1]!=-1) ans[i][lvl]=ans[ans[i][lvl-1]][lvl-1];
		}
	}
}

bool find(int l, int r){
	for(int i=18;i>=0;i--)
		if (ans[l][i]!=-1&&ans[l][i]<=r+1) l=ans[l][i];
	return l==r+1;
}

int main(){
	scanf("%s",s);
	make();
	int q,l,r;
	scanf("%d",&q);
	REP(i,q){
		scanf("%d%d",&l,&r);
		l--,r--;
		if (find(l,r)) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

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

int main(int, char **) {
  int64_t N;
  int64_t M;
  std::cin >> N >> M;

  int64_t Ai;
  int64_t kakaru_hi = 0;
  for (int64_t i = 0; i < M; ++i) {
    std::cin >> Ai;
    kakaru_hi += Ai;
  }
  if (kakaru_hi <= N) {
    std::cout << N - kakaru_hi << std::endl;
    ;
  } else {
    std::cout << -1 << std::endl;
  }
}


Measured memory_bytes: 3196
# -*- coding: utf-8 -*-


def main():
    n = int(input())

    # See:
    # https://www.youtube.com/watch?v=S1IkBhwnuYU
    # KeyInsight
    # 取り出した部分列が昇順かつ連続した数字が並んでいるかどうか

    # ■できた部分
    # N - 部分列の長さの最大値が答え

    # ■できなかった部分
    # 判定方法：
    # piの値が並び替え前にどこに位置しているかをメモ
    # 昇順かつ連続して並んでいる部分列の長さを数える
    p = [0 for _ in range(n)]

    # See:
    # https://atcoder.jp/contests/agc024/submissions/2532965
    for i in range(n):
        x = int(input())
        x -= 1
        p[x] = i

    len_max = 1
    count = 1

    for i in range(1, n):
        if p[i] > p[i - 1]:
            count += 1
        else:
            count = 1

        # WAが取れなかった原因：部分列の最大値の更新ができていない場合があった
        # 例：すべて昇順に並んでいる
        len_max = max(len_max, count)

    print(n - len_max)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11056
// The Genome Database of All Space Life
import java.util.*;

public class Main {
	static String formula;
	static int pos;
	static int n;
	static StringBuilder sb;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			formula = sc.next();
			n = sc.nextInt();
			if (formula.equals("0") && n == 0)
				break;
			pos = 0;
			sb = new StringBuilder();
			parse();
			if (n >= sb.length())
				System.out.println(0);
			else
				System.out.println(sb.charAt(n));
		}
		sc.close();
	}

	static void parse() {
		while (pos < formula.length() && sb.length() <= n + 1)
			term();
	}

	static void term() {
		if (sb.length() > n + 1) {
			pos = formula.length();
			return;
		}
		if (Character.isUpperCase(formula.charAt(pos))) {
			if (sb.length() <= n + 1)
				sb.append(formula.charAt(pos));
			pos++;
			return;
		}
		int n = number();
		if (formula.charAt(pos) != '(') {
			for (int i = 0; i < n; i++)
				sb.append(formula.charAt(pos));
			pos++;
			return;
		}
		pos++;
		for (int i = 0; i < n - 1; i++) {
			int t = pos;
			while (pos < formula.length() && formula.charAt(pos) != ')')
				term();
			pos = t;
		}
		while (pos < formula.length() && formula.charAt(pos) != ')')
			term();
		pos++;
		return;
	}

	static int number() {
		int result = 0;
		while (Character.isDigit(formula.charAt(pos))) {
			result *= 10;
			result += formula.charAt(pos++) - '0';
		}
		return result;
	}
}

Measured memory_bytes: 93992