akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    while(true) {
        int H;
        cin >> H;
        if(H == 0) break;

        vector< vector<int> > block(H + 2, vector<int>(7, -1));
        REP(i, H) {
            REP(j, 5) cin >> block[i+1][j+1];
        }

        bool update = true;
        int ans = 0;
        while(update) {
            update = false;
            FOR(i, 1, H) {
                int prev = -1, cont = 0;
                FOR(j, 1, 6) {
                    if(block[i][j] == prev && block[i][j] > 0) cont++;
                    else {
                        if(cont >= 3) {
                            ans += cont * prev;
                            REP(k, cont) {
                                block[i][j-1-k] = 0;
                            }
                            update = true;
                        }
                        prev = block[i][j];
                        cont = 1;
                    }
                }
            }

            // 0の部分を詰める
            bool has_zero = false;
            if(update) has_zero = true;
            REP(cnt, H) {
                has_zero = false;
                FORR(i, H, 1) {
                    FOR(j, 1, 5) {
                        if(block[i][j] == 0) {
                            block[i][j] = block[i-1][j];
                            block[i-1][j] = 0;
                        }
                    }
                }
            }
            // cerr << "-------------------------------" << endl;
            // FOR(i, 1, H) {
            //     FOR(j, 1, 5) cerr << block[i][j];
            //     cerr << endl;
            // }
            // cerr << "-------------------------------" << endl;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3168
#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() {
	int n, l; cin >> n >> l;
	vector<string> vec(n);
	for (int i = 0; i < n; i++) cin >> vec[i];
	sort(vec.begin(), vec.end());
	string ans;
	for (int i = 0; i < n; i++) ans += vec[i];
	cout << ans << endl;
	return 0;
 }

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	
	int n;cin >> n;
	vector<int> v(n);
	REP(i, n)cin >> v[i];
	
	int ma = 0;
	int ans = 0;
	
	REP(i, n){
		if(ma <= v[i])ans++;
		ma = max(ma, v[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;
int dp[13][203];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,K,S;cin>>N>>K>>S;
        if(N+K+S==0) break;
        
        memset(dp,0,sizeof(dp));
        
        dp[0][0]=1;
        
        for(int i=1;i<=N;i++){
            for(int k=S;k>=i;k--){
                for(int j=0;j<K;j++){
                    dp[j+1][k]+=dp[j][k-i];
                }
            }
        }
        
        cout<<dp[K][S]<<endl;
    }
}



Measured memory_bytes: 3032
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,c,cnt;
	int flg;
	int i,j,k,l,m;
	int len,len2;
	char na[26];
	char s[101];
	cnt=0;
	
	scanf("%d",&n);
	scanf("%s",na);
	len=strlen(na);
	for(i=0;i<n;i++){
		scanf("%s",s);
		len2=strlen(s);
		for(j=0;j<len2;j++){
			if(na[0]==s[j]){
				c=0;
				for(k=j+1;k<len2;k++){
					c++;
					if(na[1]==s[k]){
						flg=0;
						m=0;
						m=k+c;
						for(l=2;l<len;l++){
							if(len2<m){
								flg=1;
							}
							else if(na[l]!=s[m]){
								flg=1;
							}
							m+=c;
						}
						if(flg==0){
						cnt++;
						break;
						}
					}
				}
					if(flg==0){
					break;
					}
			}
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // exit()
#include <string.h>         // strcmp()

#define N_LIST 1000020

typedef struct list_tbl
{
	int key;
	struct list_tbl* prev;
	struct list_tbl* next;
} list_t;

int lineno;
list_t list[N_LIST];
int ix;
list_t* head;
list_t* tail;
list_t* room;

void
cleanup(int ecode)
{
	exit(ecode);
}

void
insert(int key)
{
	list_t* l;

	if (ix >= N_LIST)
	{
		fprintf(stderr, "line %d: List overflow. size%d\n", lineno, N_LIST);
		cleanup(1);
	}

	if (room == 0)
		l = &list[ix++];
	else
	{
		l = room;
		room = l->next;
	}

	l->key = key;
	l->next = head;
	list_t* next = head;
	head = l;

	if (next == NULL)
	{
		l->prev = tail;
		tail = l;
	}
	else
	{
		l->prev = next->prev;
		next->prev = l;
	}
}

void
delete(int key)
{
	list_t* next;
	list_t** pnext;
	list_t* l;

	pnext = &head;
	for (l = head; l != NULL && l->key != key; l = l->next)
		pnext = &l->next;

	if (l == NULL)
		return;

	next = l->next;
	*pnext = next;

	if (next == NULL)
		tail = l->prev;
	else
		next->prev = l->prev;

	l->next = room;
	room = l;
}

void
delete_first()
{
	list_t* t = head;
	head = head->next;
	if (head == NULL)
		tail = NULL;
	else
		head->prev = NULL;

	t->next = room;
	room = t;
}

void
delete_last()
{
	list_t* t = tail;
	tail = tail->prev;
	if (tail == NULL)
		head = NULL;
	else
		tail->next = NULL;

	t->next = room;
	room = t;
}

int
main(int argc, char** argv)
{
	char command[15];
	int x = 0;
	int n = 0;
	list_t* l;
	int i;

	head = NULL;
	tail = NULL;
	room = NULL;
	ix = 0;

	scanf("%d", &n);
	lineno = 0;
	for (i = 0; i < n; ++i)
	{
		lineno++;
		scanf("%s", command);
		if (strcmp(command, "insert") == 0)
		{
			scanf("%d", &x);
			insert(x);
		}
		else if (strcmp(command, "delete") == 0)
		{
			scanf("%d", &x);
			delete(x);
		}
		else if (strcmp(command, "deleteFirst") == 0)
			delete_first();

		else if (strcmp(command, "deleteLast") == 0)
			delete_last();
	}

	const char* sep = "";
	for (l = head; l != NULL; l = l->next)
	{
		printf("%s%d", sep, l->key);
		sep = " ";
	}

	printf("\n");
	return 0;
}

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

using ll = long long;

ll a[200010];

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

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

    ll ans=0;

    for(int i=1;i<n;i++)
    {
        if(a[i-1]>a[i])
        {
            ans+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }

    cout<<ans<<"\n";

    return 0;
}


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

// unite, findはO(a),
#include <bits/stdc++.h>
using namespace std;

struct UnionFind
{
    vector< int > data;

    UnionFind(int sz)
    {
        data.assign(sz, -1);
    }

    bool unite(int x, int y)
    {
        x = find(x), y = find(y);
        if(x == y) return(false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return(true);
    }

    int find(int k)
    {
        if(data[k] < 0) return(k);
        return(data[k] = find(data[k]));
    }

    int size(int k)
    {
        return(-data[find(k)]);
    }

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


int main() {
    int N, M; cin >> N >> M;
    UnionFind uf = UnionFind(N);
    while (M--) {
        int x, y, z; cin >> x >> y >> z;
        uf.unite(x-1, y-1);
    }
    vector<bool> c(N,false);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (!c[uf.find(i)]) {
            ans++;
            c[uf.find(i)] = true;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;

const int mx = 3e3 + 9;

int A, B, C, D, E, F;
double density = 0;
int ans1 = 0, ans2 = 0;

bool calc[mx][mx];

bool check_dissolved(int sug, int wat) {
    double req = (sug * 100.0) / E;
    if (req <= wat) return true;
    return false;
}

void solve(int sug, int wat) {
    if (sug >= mx or wat >= mx) return;
    if (calc[sug][wat]) return;
    calc[sug][wat] = 1;
    if (sug + wat > F) return;

    double dd = 0;
    if (wat + sug != 0) {
        dd = 100 * sug;
        dd /= (wat + sug);
    }

    if (dd >= density) {
        ans1 = wat + sug;
        ans2 = sug;
        density = dd;
    }

    solve(sug, wat + 100 * A);
    solve(sug, wat + 100 * B);
    if (check_dissolved(sug + C, wat)) solve(sug + C, wat);
    if (check_dissolved(sug + D, wat)) solve(sug + D, wat);
}

int main() {
    cin >> A >> B >> C >> D >> E >> F;
    solve(0, 0);
    cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 6680
#include<cstdio>
using namespace std;
#define R for(i=0;i++<n;)
#define S(s) int s;scanf("%d",&s);
#define P(x) R printf("%d%c",x[i-1],i<n?32:10);
int main(void){S(n)int a[n],b[n],i;R a[i-1]=b[n-i]=i*n;R{S(p)a[--p]+=i,b[p]+=i;}P(a)P(b)}


Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		//入力
		int N = sc.nextInt();
		int p[]=new int[N];
		for(int i=0;i<N;i++)
		{
			p[i]=sc.nextInt();
		}
		//変数
		int answer=0;
		int max=0;
		//処理
		for(int i=0;i<N;i++)
		{
			max=Math.max(max,p[i]);
		}
		for(int i=0;i<N;i++)
		{
			if(max==p[i])
			{
				p[i]=max/2;
				//System.out.println(p[i]);
				break;
			}
		}
		for(int i=0;i<N;i++)
		{
			answer+=p[i];
		}
		// 出力
		System.out.println(answer);
	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    double sum = 0;
    double pro = 1;
    for (auto &&x : v)
    {
        pro *= x;
    }
    for (auto &&x : v)
    {
        sum += pro / x;
    }
    
    double ans = pro / sum;
    cout << setprecision(7) << ans << "\n";
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        n: usize,
        ab_: [(i32, i32); n],
        cd_: [(i32, i32); n],
    }
    let mut ab = ab_.clone();
    ab.sort();
    let mut cd = cd_.clone();
    cd.sort();

    let mut ret = 0;
    for (c, d) in cd.iter() {
        let mut idx = 0;
        let mut ymax = -1;
        for i in 0..ab.len() {
            if ab[i].0 >= *c {
                break;
            }
            if ab[i].1 < *d && ab[i].1 > ymax {
                ymax = ab[i].1;
                idx = i;
            }
        }

        if ymax == -1 {
            continue;
        }
        ab.remove(idx);
        ret += 1;
    }

    println!("{}", ret);
}


Measured memory_bytes: 2164
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = n/100;
		if (n<=a*111) System.out.println(a*111);
		else System.out.println((a+1)*111);

	}
}


Measured memory_bytes: 22996
#include <stdio.h>

int main(void){

    int x, y, z;

    scanf("%d %d", &x, &y); 

    if (x > y) {
        z = y;
        y = x;
        x = z;
    }

    while(1){

        z = x;
        x = y % x;
       if(x == 0){
            printf("%d\n", z);
            break;
        } 
        y = z;
    }

    return 0;
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long N;
  cin>>N;
  
     bool flag=1;
     for(int i=0;i<=N && flag;i++)
     {
         if(int(i*1.08)==N)
         {cout<<i;flag=0;}
     }
     if(flag) cout<<":(";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[101000];
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    for (int i=1; i<=n; i++) scanf("%lld",&a[i]);
    sort(a+1,a+1+n);
    if (n==1) {
        if (a[1]==m) cout<<"POSSIBLE"<<endl;
        else cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    if (a[n]<m) {
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    long long  x=__gcd(a[1],a[2]);
    for (int i=3; i<=n; i++) x==__gcd(x,a[i]);
    for (int i=1;i<=n;i++){
        if ( a[i]>=m && (a[i]-m) % x==0 ){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


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

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = [ord(s)-65 for s in input()]
T = [ord(t)-65 for t in input()]

acc1 = [0] + list(accumulate(S))
acc2 = [0] + list(accumulate(T))

# 3つのタイプを判定(0: aが残る, 1: bが残る, 2: 何も残らない)
def check(cnta, cntb):
    if cnta == cntb:
        return 2
    elif cnta < cntb:
        cntb -= cnta
        if cntb % 3 == 0:
            return 2
        elif cntb % 3 == 1:
            return 1
        else:
            return 0
    else:
        cnta -= cntb
        if cnta % 3 == 0:
            return 2
        elif cnta % 3 == 1:
            return 0
        else:
            return 1

Q = INT()
for _ in range(Q):
    l1, r1, l2, r2 = MAP()

    ln1 = r1 - l1 + 1
    ln2 = r2 - l2 + 1
    # 累積和を使ってO(1)でAとBの個数を取得
    cntb1 = acc1[r1] - acc1[l1-1]
    cnta1 = ln1 - cntb1
    cntb2 = acc2[r2] - acc2[l2-1]
    cnta2 = ln2 - cntb2
    # 同じタイプかどうか判定する
    if check(cnta1, cntb1) == check(cnta2, cntb2):
        YES()
    else:
        NO()


Measured memory_bytes: 13824
while True:
    (n, x) = [int(i) for i in input().split()]
    if n == x == 0:
        break
    count = 0
    for a in range(n if n < x else x, 2, -1):
        for b in range(a-1, 1, -1):
            if a + b > x:
                continue
            for c in range(b-1, 0, -1):
                s = a + b + c
                if s == x:
                    count += 1
                    break
                elif s < x:
                    break
    print(count)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
ll x[MAX_N];

int main2() {
  int N = nextInt();
  int K = nextInt();
  REP(i, N) x[i] = nextInt();
  ll ans = 1LL << 61;

  for (int i = 0; i + K <= N; i++) {
    int l = x[i];
    int r = x[i+K-1];
    ll cur = 0;
    if (l < 0 && r < 0) {
      cur = abs(l);
    } else if (l > 0 && r > 0) {
      cur = abs(r);
    } else {
      l = abs(l);
      r = abs(r);
      cur = min(l, r) * 2 + max(l, r);
    }
    chmin(ans, cur);
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

int main() {
    int n;
    vector<int> numbs;
    int numb;
    int counter = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> numb;
        numbs.push_back(numb);
    }
    int min = numbs[0];
    for(int i = 0; i < n; i++) {
        if(numbs[i] <= min) {
            counter++;
            min = numbs[i];
        }
    }
    cout << counter << endl;
}

Measured memory_bytes: 1400
rperf = 10
fperb = 3
buildings = 4

n = int(input())

rooms = [[[0 for i in range(rperf)] for j in range(fperb)] for k in range(buildings)]
for i in range(n):
    b, f, r, v = map(int, input().split())
    b, f, r = b-1, f-1, r-1 
    if rooms[b][f][r]+v < 0:
        rooms[b][f][r] = 0
    else:
        rooms[b][f][r] += v

for i in range(buildings):
    if i>0:
        print("####################")
    for j in range(fperb):
        floor = ""
        for k in range(rperf):
            floor += " " + str(rooms[i][j][k])
        print(floor)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, l   l>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()

int n, a, c, cnt[100005];
int main(){
    cin >> n;
    fox(l, n){
        cin >> a;
        if (a>n) c++;
        else cnt[a]++;
    }
    fox1(l, n){
        if (cnt[l]==0 || cnt[l]==l) continue;
        if (cnt[l]>l) c+=cnt[l]-l;
        else c+=cnt[l];
    }
    cout << c;
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	
	deque<int> b;
	bool isFor = true;
	rep(i,n){
		if(isFor) b.push_back(a[i]);
		else b.push_front(a[i]);
		isFor = !isFor;
	}

	if(isFor){
		rep(i,b.size()) cout << b[i] << " ";
		cout << endl;
	}else{
		rep(i,b.size()) cout << b[b.size()-1-i] << " ";
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define ll long long
inline int read(){
    int num=0,w=0;
    char ch=0;
    while(!isdigit(ch)){
        w|=ch=='-';
        ch=getchar();
    }
    while(isdigit(ch)){
        num=(num<<3)+(num<<1)+(ch^48);
        ch=getchar();
    }
    return w?-num:num;
}

//快速写
inline void write(int x)
{
    if(x<0){
        putchar('-');
        x=-x;
    }
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
vector<vector<int> >v(15,vector<int>(15,-1));//全初始为-1
int main()
{
   int n=read();
   //int kk =1;
   for(int i=0;i<n;i++){
       int a =read();
       for(int j=0;j<a;j++){
           int b,c;cin >>b>>c;
           v[i][--b] = c;//赋值
       }
      // kk++;
   }
   int ma =0 ;
   for(int i = (1<<n)-1;i>0;i--){
       bitset<16> bit(i);
        vector<int> vv(n,-1);//全初始为-1，这个是用来判断是否与之前的v冲突用的数组，这个数组存的是按当前情况下，说谁的是真话是假话
        for(int j=0;j<n;j++){
            if(bit[j]==1)vv[j] =1;//真话
            else vv[j]=0;//假话
        }
        bool ok =1;
        for(int j=0;j<n;j++){
            if(bit[j]==0)continue;//都说j是假话
            for(int k =0;ok&&k<n;k++){
                if(v[j][k]==-1)continue;//v,vv都说k是假的不用管
                if(vv[k]!=v[j][k])ok = false;//vv说k是假的情况下，v说k是真的，或者相反导致冲突
            }
        }
        if(ok){
            int cnt =0 ;
            for(int i=0;i<n;i++){
                if(bit[i])cnt++;//找说真话的人
            }
            ma = max(cnt,ma);//找最大的说真话的人
        }
   }

cout<<ma<<endl;
    return 0;
}/* 6
  1 2 0
  1 1 0
  1 2 0
 1 1 0
1 2 0
  1 1 0*/

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

main()
{
	long long n, ans;
    cin >> n;
    ans = n;
	for (int i = 1; i < n; ++i)
	{
        long long u, v;
        cin >> u >> v;
		if (u > v) swap(u, v);
        ans += i * (n - i + 1);
        ans -= u * (n - v + 1);
	}
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 3736
#include <stdio.h>
#include <stdlib.h>

long max(long a,long b);
long min(long a,long b);

int main(void){
    long retval=-10000000010;
    int n;
    scanf("%d",&n);
    long* R=(long*)malloc(sizeof(long)*n);
    for(int i=0;i<n;i++){
        scanf("%ld",&(R[i]));
    }
    long minimum=R[0];
    for(int i=1;i<n;i++){
        retval=max(R[i]-minimum,retval);
        minimum=min(minimum,R[i]);
    }
    printf("%ld\n",retval);
    return 0;
}

long max(long a,long b){
    if(a>b){return a;}
    else{return b;}
}
long min(long a,long b){
    if(a<b){return a;}
    else{return b;}
}



Measured memory_bytes: 3412
#include<stdio.h>

int main(void){
   int N, D; /* N, Dは1以上20以下の整数 */
   int ans, rem;

   scanf("%d%d", &N, &D);

   ans = N / (D*2+1);
   rem = N % (D*2+1);

   if(rem != 0){
       ans = ans + 1;
   }
  
   printf("%d\n", ans);


	return 0;
}

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

public class Main
{
  public static void main(String[] args) throws IOException
  {
     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     StringTokenizer tokenizer1 = new StringTokenizer(br.readLine());
     int a = Integer.parseInt(tokenizer1.nextToken());
     int b = Integer.parseInt(tokenizer1.nextToken());
     int ans = maximum(a,b);
     System.out.println(ans);
  }
  public static int maximum(int a,int b)
  {
    int x = a + b;
    int y = a - b;
    int z = a * b;
    
    int ans1 = Math.max(x,y);
    int ans = Math.max(ans1,z);
    return ans;
  }
}


Measured memory_bytes: 22484
let input = ''

process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on('data', function(chunk) {
  input += chunk
})
process.stdin.on('end', function() {
  input = input.trim().split('\n')
  main()
})

function main() {
  return console.log(input[0].split("").reverse().join(""))
}


Measured memory_bytes: 15252
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	fore(i,0,5){
		int x; cin>>x;
		if(!x)cout<<i+1<<"\n";
	}
}

Measured memory_bytes: 3648
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n,m = map(int,input().strip().split())
    a = list(map(int, input().strip().split()))

    print(max(n-sum(a),-1))


if __name__ == '__main__':
    main()

Measured memory_bytes: 83568
integer N
integer,allocatable,dimension(:)::A
integer premax,maxnum,cnt
read*,N
allocate(A(N))
do i=1,N
  read*,A(i)
end do
premax=0
maxnum=A(1)
cnt=1
do i=2,N
  if(A(i)>maxnum)then
    premax=maxnum
    maxnum=A(i)
    cnt=1
  else if(A(i)==maxnum)then
    cnt=2
  else if(A(i)>=premax)then
    premax=A(i)
  endif
end do
do i=1,N
  if(A(i)/=maxnum.or.cnt==2)then
    print"(i0)",maxnum
  else
    print"(i0)",premax
  endif
end do
end


Measured memory_bytes: 2304
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x1, x2, x3, y1, y2, y3, ax, by, g1, g2, g3;
		while (sc.hasNext()) {
			x1 = sc.nextDouble();
			y1 = sc.nextDouble();
			x2 = sc.nextDouble();
			y2 = sc.nextDouble();
			x3 = sc.nextDouble();
			y3 = sc.nextDouble();
			ax = sc.nextDouble();
			by = sc.nextDouble();
			g1 = (x3-x2)*(by-y2)-(y3-y2)*(ax-x2);
			g2 = (x1-x3)*(by-y3)-(y1-y3)*(ax-x3);
			g3 = (x2-x1)*(by-y1)-(y2-y1)*(ax-x1);
			if ((g1 >= 0 & g2 >= 0 & g3 >= 0)|(g1 < 0 & g2 < 0 & g3 < 0)) {
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 23288
#include <iostream>

using namespace std;

int main()
{
    int w,n;
    scanf("%d", &w);
    scanf("%d", &n);
    int amida[w + 1];
    for(int i = 1; i <= w; i++) amida[i] = i;
    for(int i = 0; i < n; i++) {
        int a, b;
        scanf("%d,%d", &a, &b);
        swap(amida[a], amida[b]);
    }
    for(int i = 1; i <= w; i++) cout << amida[i] << endl;
    return 0;
}

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

int n, m, q, a[100000], b[100000], v[100000], d[100000], c[100000];
vector<int> graph[100000];
int memo[100000][11];

void func(int n, int length, int color) {
	if (memo[n][length] != 0) {
		return;
		//cout << "end" << endl;
	}
	//cout << "n:" << n << " length:" << length << endl;
	memo[n][length] = color;
	
	if (length == 0) {
		return;
		//cout << "end" << endl;
	}
	func(n, length - 1, color);
	for (int i = 0; i < graph[n].size(); i++) {
		func(graph[n][i], length - 1, color);
	}
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		graph[a[i]-1].push_back(b[i]-1);
		graph[b[i]-1].push_back(a[i]-1);
	}

	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> v[i] >> d[i] >> c[i];
	}

	for (int i = q-1; i >= 0; i--) {
		func(v[i] - 1, d[i], c[i]);
	}

	for (int i = 0; i < n; i++) {
		cout << memo[i][0] << endl;
	}
}

Measured memory_bytes: 12792
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
ll n, t, a[100100];
map<ll, ll> mp;
int main(void){
    // Your code here!
    cin >> n >> t;
    for (ll i = 0; i < n; i++) cin >> a[i];
    ll sma = a[0];
    for (ll i = 1; i < n; i++){
        sma = min(sma, a[i - 1]);
        mp[a[i] - sma]++;
    }
    auto itr = mp.end(); itr--;
    cout << itr->second << endl;
}


Measured memory_bytes: 7296
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

int testcase_ends() {
  char buf[8];
  scanf("%s", buf);
  std::string s = buf;
  if (s == "#") return 1;

  std::vector<int> a(3), b{31, 5, 1};
  for (auto& ai: a) scanf("%d", &ai);

  if (a < b) {
    printf("HEISEI %d %d %d\n", a[0], a[1], a[2]);
  } else {
    printf("? %d %d %d\n", a[0]-30, a[1], a[2]);
  }
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



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


int main(){
  char ch;
  int i;
  int a[26]={};
  while (cin>>ch){
    if (ch>='a'&&ch<='z')a[ch-'a']++;
    else if (ch>='A'&&ch<='Z')a[ch-'A']++;
  }
  for (i=0;i<26;i++){
    cout<<char('a'+i)<<" : "<<a[i]<<endl;
  }
}



Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define INF (1000000000000000000LL)

typedef pair<long long,int> PLLI;

int main()
{
    int N,M,K,S;
    cin >> N >> M >> K >> S;

    long long P,Q;
    cin >> P >> Q;

    vector<long long> town(N);
    for(int i=0; i<N; ++i) town[i]=P;

    town[N-1]=0;

    queue<PLLI> q;
    set<int> zom;
    for(int i=0; i<K; ++i) {
        int temp;
        cin >> temp;
        town[temp-1]=INF;
        q.push(PLLI(S,temp-1));
        zom.insert(temp-1);
    }

    vector<int> road[N];
    vector<int> temp_road[N];
    for(int i=0; i<M; ++i) {
        int a,b;
        cin >> a >> b;
        temp_road[a-1].push_back(b-1);
        temp_road[b-1].push_back(a-1);
        if(zom.count(a-1)==0 && zom.count(b-1)==0) {
            road[a-1].push_back(b-1);
            road[b-1].push_back(a-1);
        }
    }

    while(!q.empty()) {
        PLLI p=q.front(); q.pop();
        long long d = p.first;
        int t = p.second;
        --d;
        for(auto x : temp_road[t]) {
            if(town[x]==P) {
                town[x]=Q;
                if(d!=0) q.push(PLLI(d,x));
            }
        }
    }

    priority_queue<PLLI,vector<PLLI>,greater<PLLI> > pq;
    vector<long long> cost(N);

    for(int i=0; i<N; ++i) cost[i]=INF;

    cost[0]=0;
    pq.push(PLLI(0,0));

    while(!pq.empty()) {
        PLLI p=pq.top(); pq.pop();
        long long c=p.first;
        int t=p.second;

        if(t==N-1) break;
        if(cost[t]<c) continue;

        for(auto x : road[t]) {
            if(cost[x]<=c+town[x]) continue;
            cost[x]=c+town[x];
            pq.push(PLLI(cost[x],x));
        }
    }

    cout << cost[N-1] << endl;

    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        // 入力
        int n = int.Parse(Console.ReadLine());
        int[] p = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] q = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var k1 = "";
        var k2 = "";
        for (int i = 0; i < n; i++)
        {
            k1 += p[i];
            k2 += q[i];

        }

        var dic = new Dictionary<int, int>() { };
        var count = 0;

        var src = new List<string>() { };
        for (int i = 0; i < n; i++)
        {
            src.Add((i+1).ToString());
        }

        foreach (var permutation in Permutations(src, n))
        {
            var tmp = string.Join("", permutation);
            dic.Add(int.Parse(tmp), count);
            count++;
        }

        var ans= Math.Abs(dic[int.Parse(k1)] - dic[int.Parse(k2)]);
        Console.WriteLine(ans);
    }


    static List<List<T>> Permutations<T>(List<T> src, int n)
    {
        // nは1以上かつsrcの長さよりも短い必要がある。
        int len = src.Count;
        if (!(0 < n && n <= len))
        {
            throw new ArgumentOutOfRangeException();
        }

        var permutations = new List<List<T>>();
        var queue = new Queue<List<int>>(Enumerable.Range(0, len).Select(i => new List<int>() { i }));
        while (queue.Any())
        {
            var indexes = queue.Dequeue();

            if (indexes.Count == n)
            {
                permutations.Add(indexes.Select(index => src[index]).ToList());
                continue;
            }

            for (int index = 0; index < len; index++)
            {
                if (indexes.Contains(index))
                {
                    continue;
                }

                var newIndexes = new List<int>(indexes);
                newIndexes.Add(index);
                queue.Enqueue(newIndexes);
            }
        }

        return permutations;
    }
}


Measured memory_bytes: 37524
from itertools import product
def main():
    N = int(input())
    if N == 0:
        return 0
    l = set()
    while N != 0:
        if N > 0:
            r = plus(N)
            l.add(r)
            N -= pow(2, r)
        else:
            r = minus(N)
            l.add(r)
            N += pow(2, r)
    s = [0] * (max(l)+1)
    for i in range(max(l)+1):
        if i in l:
            s[i] = 1
    s.reverse()
    return ''.join(str(i) for i in s)
    #for i in product(range(2), repeat=9):
    #    r = 0
    #    for j, v in enumerate(i):
    #        r += v * pow(-2, j)
    #    l.append((r, i))
    #l.sort()
    #for x in l:
    #    print(x)
def plus(N):
    p = 0
    n = 0
    while True:
        p += pow(2, n)
        if p >= N:
            break
        n += 2
    return n
def minus(N):
    p = 0
    n = 1
    while True:
        p -= pow(2, n)
        if p <= N:
            break
        n += 2
    return n

print(main())


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

using namespace std;

int main() {

	int A, B;

	cin >> A >> B;

	if(A == 1) A = 14;
	if(B == 1) B = 14;

	if(A > B) cout << "Alice" << endl;
	if(A < B) cout << "Bob" << endl;
	if(A == B) cout << "Draw" << endl;

	return 0;
}

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

using namespace std;

int main(){
	int a[10];
	for (int i = 0; i < 10; i++){
		cin >> a[i];
	}
	sort(a, a+10, less<int>());
	for (int i = 9; i >= 7; i--){
		cout << a[i] << endl;
	}
}

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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll sum = 0;
	vector<ll> vec;
	for (ll i = 1, a; i <= n; i++) {
		cin >> a;
		ll z = i + -1e10;
		sum += abs(z - a);
		if (a - z > 0) vec.push_back(a - z);
	}
	sort(vec.rbegin(), vec.rend());
	ll ans = sum;
	ll z = 0;
	while (vec.size()) {
		ll y = vec.back() - z;
		z += y;
		ll L = n - vec.size();
		sum += L * 1ll * y;
		sum -= y * 1ll * vec.size();
		ans = min(ans, sum);
		vec.pop_back();
		while (vec.size() && vec.back() == y)
			vec.pop_back();
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <map>
#include <vector>
#include <set>
#define llint long long

using namespace std;

llint N;
llint a[100005];
vector<llint> vec;
map<llint, llint> mp;
set<llint> s;

llint anticube(llint x)
{
	llint c;
	for(llint i = 2; i <= 2500; i++){
		c = i*i*i;
		if(x < c) break;
		while(x % c == 0) x /= c;
	}
	return x;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> a[i];
	for(int i = 1; i <= N; i++) a[i] = anticube(a[i]);
	
	for(int i = 1; i <= N; i++) mp[a[i]]++;
	
	llint ans = 0;
	for(auto it = mp.begin(); it != mp.end(); it++){
		if(it->first == 1){
			ans++;
			continue;
		}
		if(s.count(it->first)) continue;
		llint inv = anticube(it->first * it->first);
		ans += max(it->second, mp[inv]);
		s.insert(inv);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define repi(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
using namespace std;
typedef long long ll;

int main() {
  int a,b,c,d; cin >> a >> b >> c >> d;
  bool can = false;
  if(abs(a-c) <= d) can = true;
  if(abs(a-b) <= d && abs(b-c) <= d) can = true;
  cout << (can ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
 int a;
  cin>>a;
  vector <int> v(a+1);
  int tmp;
  for (int i=0; i<a-1;i++){
    cin >>tmp;
    v.at(tmp)=v.at(tmp)+1;
  }
  for (int i=1; i<=a;i++){
    cout << v.at(i)<<endl;
  }
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;


int main(void){
	int a,b;
	while(cin >> a >> b,a){
		int change=b-a;
		int ans[3];
		ans[2]=change/1000;
		change%=1000;
		ans[1]=change/500;
		change%=500;
		ans[0]=change/100;
		cout << ans[0]  << " " << ans[1] << " " << ans[2] << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      if((A+B)%2==0){
        System.out.println((A+B)/2);
      }else{
        System.out.println("IMPOSSIBLE");
      }
    }
}

Measured memory_bytes: 35828
import sys

base = [0, 0, 0]
out = 0

N = int(sys.stdin.readline())

point = 0
inning = list()

def choice(event):
    global base, out, point
    if event == "HIT":
        point += base.pop()
        base = [1] + base
    elif event == "HOMERUN":
        point += sum(base) + 1
        base = [0, 0, 0]
    elif event == "OUT":
        out += 1
        if out == 3:
            inning.append(point)
            point = 0
            out = 0
            base = [0, 0, 0]

for line in sys.stdin.readlines():
    line = line.strip()
    choice(line)

for i in inning:
    print i

Measured memory_bytes: 5396
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
 
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  int ans=0;
  rep(i,0,n)
  {
    rep(j,i+1,n) ans+=a[i]*a[j];
  }
  cout<<ans;


}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var A, B int

	fmt.Scanf("%d\n%d\n", &A, &B)
	r := map[int]struct{}{
		1: {},
		2: {},
		3: {},
	}
	delete(r, A)
	delete(r, B)
	for k := range r {
		fmt.Println(k)
	}
}


Measured memory_bytes: 512
import sys

n = int(input())
list_w = list(map(int, input().split()))
min_sum_square = sys.maxsize
for i in range(1, n):
    min_sum_square = min(min_sum_square, (sum(list_w[:i]) - sum(list_w[i:])) ** 2)
print(int(min_sum_square ** (1/2)))

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M;
	cin >> N >> M;
	vector<bool>AC(N+1, false);
	VI tmp(N + 1, 0);
	int ac = 0, wa = 0;

	REP(i, M) {
		int p;
		string S;
		cin >> p >> S;

		if (!AC[p]) {
			if (S == "AC") {
				AC[p] = true;
				ac++;
				wa += tmp[p];
			}
			else tmp[p]++;
		}
	}

	cout << ac << " " << wa << endl;

	return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(15);
    int A, B;
    cin >> A >> B;
    if(A+B > 9){
        cout << "error" << endl;
    }
    else{
        cout << A + B << endl;
    }
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



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

    int x = Div(a, d), y = Div(c, b);
    cout << (x >= y ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3620
/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГИ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define zhfs main
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define re return
#define forn(i, n) for (int i = 1; i <= n; i++)
const int MX = 5007;
bool canl[MX][MX], canr[MX][MX];
int a[MX];
int near[MX][MX];
int zhfs()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	canl[0][0] = true;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < MX; j++)
		{
			if (canl[i][j])
			{
				canl[i + 1][j] = true;
				if (j + a[i + 1] < MX)
				{
					canl[i + 1][j + a[i + 1]] = true;
				}
			}
		}
	}
	for (int i = 0; i <= n; i++)
	{
		near[i][MX - 1] = MX * MX;
		for (int j = MX - 2; j >= 0; j--)
		{
			near[i][j] = near[i][j + 1];
			if (canl[i][j]) near[i][j] = j;
		}
	}
	canr[n + 1][0] = true;
	for (int i = n + 1; i >= 1; i--)
	{
		for (int j = 0; j < MX; j++)
		{
			if (canr[i][j])
			{
				canr[i - 1][j] = true;
				if (j + a[i - 1] < MX)
				{
					canr[i - 1][j + a[i - 1]] = true;
				}
			}
		}
	}
	int res = 0;
	for (int i = 1; i <= n; i++)
	{
		bool bad = false;
		for (int gor = 0; gor < MX; gor++)
		{
			if (!canr[i + 1][gor]) continue;
			int want = k - a[i] - gor;
			int can = near[i - 1][max(0, want)];
			if (gor + can >= k - a[i] && gor + can <= k - 1)
			{
				bad = true;
			//	cerr << i << " " << can << " " << gor << endl;
			}
		}
		if (!bad) res++;
	}
	printf("%d\n", res);
}



Measured memory_bytes: 147072