akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using vpll = vector<pll>;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define RREP(i, n) for(ll i = n-1; i >= 0; i--)
#define FOR(i, a, b) for(ll i = a; i <= (ll)(b); i++)
#define RFOR(i, a, b) for(ll i = a; i >= (ll)(b); i--)

#define SIZE(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));

#define PB push_back
#define MP make_pair
#define F first
#define S second

#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

#define MAX 100100

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M; cin >> N >> M;
    vector<vector<ll>> G(N + 1);
    ll d[N + 1]; 
    FOR(i, 0, N) d[i] = INF;
    // d[1] = 0;
    REP(i, M) {
        ll A, B; cin >> A >> B;
        G[A].PB(B); 
        G[B].PB(A);      
    }
    queue<ll> Q;
    Q.push(1);
    while(!Q.empty()) {
        ll i = Q.front(); Q.pop();
        for(auto j : G[i]) {
            if (d[j] != INF) continue;
            d[j] = i;
            Q.push(j);
        }
    }
    bool flag = true; FOR(i, 1, N) if (d[i] == INF) flag = false;
    if(flag) {
        cout << "Yes" << endl;
        FOR(i, 2, N) cout << d[i] << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 12900
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;
 
#define LOCAL  1
#define UPLOAD 2
 
#define ll long long
const long long INF = 1LL << 60;
 
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';
#define REP(i,M) for(int i=0;i<M;i++)
 
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

  ll N = input();
  map<ll,ll> A;
  vector<ll>  C;
  for(int i=0;i<N;i++){
    int j = input();
    A[j]++;
    C.push_back(j);
  }

  ll sum = 0;
  for(auto iter:A){
    sum += iter.second*(iter.second-1)/2;
  }
  
  for(int i=0;i<N;i++){
    output(sum - A[C[i]] + 1);
  }
  
  return 0;
}

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

int main(){
  ll n,a,b ;
  cin >> n >> a >> b;
  ll c = a + b;
  ll count = 0;
  ll d = n / c;
  ll f = d * a;
  count += f;
  ll e = n % c;
  if(e >= a)count += a;
  else if( e < a)count +=e;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
from fractions import gcd


def solve(n, ax):
    lcm = 1
    for ai in ax:
        lcm = lcm*ai//gcd(lcm, ai)
    m = lcm-1
    return sum(list(map(lambda x: m % x, ax)))


if __name__ == '__main__':
    n = int(input())
    ax = list(map(int, input().split()))
    print(solve(n, ax))


Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int s = 0;
  for(int i = 0; i < 10; i++) {
    for(int j = 0; j < 10; j++) {
      if(i * j == N) {
        cout << "Yes" << endl;
        s++;
        break;
      }
      else{
      }
      if(s == 1){
      break;
      }
    }
  }
  if(s == 0) {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
from collections import defaultdict
d = defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  a[i]-=i+1
  d[a[i]]+=1
ans=0
b = min(a)
for i in a:
  ans+=i-b
a = sorted(set(a))
c = 0
i = 0
while i<len(a)-1:
  c+=d[a[i]]
  if c-(n-c)>0:
    print(ans)
    exit()
  ans+=(c-(n-c))*(a[i+1]-a[i])
  i+=1
print(ans)

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

    
   int main(){
       int H, W;
       scanf("%d %d", &H, &W);
       int h,w;
       scanf("%d %d", &h, &w);
       int ans;
       ans=H*W;
       ans-=h*W;
       ans-=w*H;
       ans+=h*w;
       printf("%d",ans);
       return 0;
   }

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
#define all(obj) obj.begin(), obj.end()
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);

using namespace std;

typedef unsigned long long ull;
typedef int long long ll;
constexpr ll bigNum = 1000000007;

signed main()
{
    fast;
    //ここから本体
    int n;
    cin >> n;
    vector<string> a(n);
    for (int i = 0; i < n; i++)
    {
        string x;
        cin >> x;
        sort(all(x));
        a[i] = x;
    }
    sort(all(a));

    ll ans = 0;
    ll c = 1;
    for (int i = 0; i < n - 1; i++)
    {
        if (a[i] == a[i + 1])
            c++;
        else
        {
            ans += (c * (c - 1)) / 2;
            c = 1;
        }
    }
    ans += (c * (c - 1)) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define mid ((l+r)>>1)

const int N=190;
char str[N][N];
int n,m,tmp,sum[N][N],dp[N][N][N][18];

bool check(int lx,int rx,int ly,int ry) {
	int res=sum[rx][ry]-sum[lx-1][ry]-sum[rx][ly-1]+sum[lx-1][ly-1];
	if(res==0||res==(rx-lx+1)*(ry-ly+1)) return true;
	return false;
}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) scanf("%s",str[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+(bool)(str[i][j]=='.');
	// for(int x=1;x<=n;++x)
	// 	for(int L=1;L<=m+1;++L)
	// 		for(int k=0;k<18;++k) dp[x][L][L-1][k]=1<<30;
	// for(int x=1;x<=n;++x)
	// 	for(int L=1;L<=m;++L) for(int R=L;R<=m;++R) {
	// 		int l=x,r=n,ans=l-1;
	// 		while(l<=r) check(x,mid,L,R)?ans=mid,l=mid+1:r=mid-1;
	// 		dp[x][L][R][0]=ans;
	// 	}
		for (int i=1;i<=n;i++)
		for (int j=1;j<=m+1;j++)
			for (int k=0;k<17;k++)
				dp[i][j][j-1][k]=1<<30;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			for (int k=j;k<=m;k++){
				int now=i-1,l=i,r=n;
				while (l<=r){
					if (check(i,mid,j,k)) now=mid,l=mid+1;
					else r=mid-1;
				}
				dp[i][j][k][0]=now;
			}
	// for(tmp=1;dp[1][1][m][tmp-1]<n;++tmp) {
	// 	for(int x=1;x<=n;++x)
	// 		for(int L=1;L<=m;++L)
	// 			for(int R=L;R<=m;++R)
	// 				dp[x][L][R][tmp]=dp[dp[x][L][R][tmp-1]+1][L][R][tmp-1];
	// 	for(int x=1;x<=n;++x)
	// 		for(int L=1;L<=m;++L)
	// 			for(int R=L;R<=m;++R) {
	// 				int res=L;
	// 				while(res<R&&
	// 					min(dp[x][L][res][tmp-1],dp[x][res+1][R][tmp-1])<=
	// 					min(dp[x][L][res+1][tmp-1],dp[x][res+2][R][tmp-1])) ++res;
	// 				dp[x][L][R][tmp]=
	// 					max(dp[x][L][R][tmp],min(dp[x][L][res][tmp-1],dp[x][res+1][R][tmp-1]));
	// 			}
	// }
	// printf("%d\n",tmp-1);
	int ans=1;
	for (;dp[1][1][m][ans-1]<n;ans++){
		for (int i=1;i<=n;i++)
			for (int j=1;j<=m;j++)
				for (int k=j;k<=m;k++)
					dp[i][j][k][ans]=dp[dp[i][j][k][ans-1]+1][j][k][ans-1];
		for (int i=1;i<=n;i++)
			for (int j=1;j<=m;j++)
				for (int k=j,p=j;k<=m;k++){
					while (p<k&&min(dp[i][j][p][ans-1],dp[i][p+1][k][ans-1])<=min(dp[i][j][p+1][ans-1],dp[i][p+2][k][ans-1])) ++p;
					dp[i][j][k][ans]=max(dp[i][j][k][ans],min(dp[i][j][p][ans-1],dp[i][p+1][k][ans-1]));
				}
	}
	printf ("%d",ans-1);
	return 0;
}

Measured memory_bytes: 471552
#include<iostream>
using namespace std;
int main(){
    int y;
    y = 0;
    while(true){
        int x;
        cin >> x;
        if(x == 0) break;
        y += 1;
        cout << "Case" << " " <<  y << ":" << " " << x << endl; 
    }
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < n - 1; i++) {
    double t = v.back(); v.pop_back();
    t += v.back(); v.pop_back();
    t /= 2;
    v.push_back(t);
  }
  cout << fixed << setprecision(10) << v[0] << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	n := nextInt()
	for i := 0; i < n; i++ {
		data := nextInts(3)
		fmt.Fprintln(out, checkTriangle(data))
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	return a
}

func checkTriangle(i []int) string {
	if checkSt(i[0], i[1], i[2]) || checkSt(i[1], i[2], i[0]) || checkSt(i[2], i[0], i[1]) {
		return "YES"
	}
	return "NO"
}
func Sq(x int) int {
	return x * x
}

func checkSt(a, b, c int) bool {
	return (Sq(a) + Sq(b)) == Sq(c)
}



Measured memory_bytes: 1152
using System;
using System.Collections.Generic;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            string N1 = Console.ReadLine();
            string N2 = Console.ReadLine();
            string[] Ans = new[] {"1", "2", "3" };
            var list = new List<string>();
            list.AddRange(Ans);

            list.Remove(N1);
            list.Remove(N2);

            string[] vs = list.ToArray();
            Console.WriteLine(vs[0]);
        }
    }
}


Measured memory_bytes: 11104
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <fstream>
#include <cstdio>
#include <stdio.h>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

template <typename T>
void printArr(const T * arr, int s, int fn) {
    for (int i = s; i <= fn; ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <typename T>
long long minArr(const T * arr, int s, int fn) {
    ll res = 1e16 + 1;
    for (int i = s; i <= fn; ++ i) {
        res = min(res, arr[i]);
    }
    return res;
}

template <typename T>
void printVec(const T * arr) {
    for (int i = 0; i < sz(arr); ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <class T>
bool uax(T&a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool uin (T&a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 4e6 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const ll P = 53;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int a[N];

int main () {
    to_pray();
    
    int n, k, cnt = 0;
    cin >> n >> k;
    
    for (int i = 1; i <= n; ++ i) {
    	cin >> a[i];
    	if (a[i] >= k)
    		++cnt;
    }
    
    cout << cnt;
    
    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  string S;
  cin >> S;
  int month = 0;
  repp(i, 5, 6) { month += pow(10, 6 - i) * (S[i] - '0'); }

  if (month <= 4) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
}

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

int main(){
    int N;
    cin >> N;
    char ORI[N], SEL[N], BUB[N];
    int ori[N], sel[N], bub[N];
    int n;
    char c;
    for(int i = 0; i < N; i++){
        cin >> ORI[i] >> ori[i];
        SEL[i] = ORI[i];
        sel[i] = ori[i];
        BUB[i] = ORI[i];
        bub[i] = ori[i];
    }

    bool flag = true;
    while(flag == true){
        flag = false;
        for(int j = N - 1; j > 0; j--){
            if(bub[j] < bub[j - 1]){
                n = bub[j];
                c = BUB[j];
                bub[j] = bub[j - 1];
                BUB[j] = BUB[j - 1];
                bub[j - 1] = n;
                BUB[j - 1] = c;
                flag = true;
            }
        }
    }
    for(int i = 0; i < N; i++){
        if(i == N - 1){
            cout << BUB[i] << bub[i] << endl;
        } else {
            cout << BUB[i] << bub[i] << " ";
        }
    }

    string judge = "Stable";
    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            for(int a = 0; a < N - 1; a++){
                for(int b = a + 1; b < N; b++){
                    if(ori[i] == ori[j]){
                        if(ori[i] == sel[b] && ORI[i] == SEL[b]){
                            if(ori[j] == sel[a] && ORI[j] == SEL[a]){
                                judge = "Not stable";
                                break;
                            }
                        }
                    }
                }
            }
        }
    }

    cout << judge << endl;


    int minj;
    for(int i = 0; i < N; i++){
        minj = i;
        for(int j = i; j < N; j++){
            if(sel[j] < sel[minj]){
                minj = j;
            }
        }
        if(i != minj){
            n = sel[i];
            c = SEL[i];
            sel[i] = sel[minj];
            SEL[i] = SEL[minj];
            sel[minj] = n;
            SEL[minj] = c;
        }
    }
    for(int i = 0; i < N; i++){
        if(i == N - 1){
            cout << SEL[i] << sel[i] << endl;
        } else {
            cout << SEL[i] << sel[i] << " ";
        }
    }

    judge = "Stable";
    for(int i = 0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            for(int a = 0; a < N - 1; a++){
                for(int b = a + 1; b < N; b++){
                    if(ori[i] == ori[j]){
                        if(ori[i] == sel[b] && ORI[i] == SEL[b]){
                            if(ori[j] == sel[a] && ORI[j] == SEL[a]){
                                judge = "Not stable";
                                break;
                            }
                        }
                    }
                }
            }
        }
    }

    cout << judge << endl;    

    return 0;
}


Measured memory_bytes: 3216
import java.util.Scanner;

public class Main {

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

		int[] s = new int[13];
		int[] h = new int[13];
		int[] c = new int[13];
		int[] d = new int[13];

		for (int i = 0; i < 13; i++) {
			s[i] = 0;
			h[i] = 0;
			c[i] = 0;
			d[i] = 0;
		}
		int rest = sc.nextInt();
		for (int k = 1; k < rest * 2; k = k + 2) {

			String mark = sc.next();

			int number = sc.nextInt();

			if (mark.equals("S")) {
				s[number - 1] = 1;
			}
			if (mark.equals("H")) {
				h[number - 1] = 1;
			}
			if (mark.equals("C")) {
				c[number - 1] = 1;
			}
			if (mark.equals("D")) {
				d[number - 1] = 1;
			}

		}

		for (int j = 1; j <= 13; j++) {
			if (s[j - 1] == 0)
				System.out.println("S " + j);
		}
		for (int j = 1; j <= 13; j++) {
			if (h[j - 1] == 0)
				System.out.println("H " + j);
		}
		for (int j = 1; j <= 13; j++) {
			if (c[j - 1] == 0)
				System.out.println("C " + j);
		}
		for (int j = 1; j <= 13; j++) {
			if (d[j - 1] == 0)
				System.out.println("D " + j);
		}

	}

}



Measured memory_bytes: 26360
n,W=map(int,input().split())
w,v=[],[]
dp=[[0]*(W+1) for i in range(n+1)]
for i in range(n):
    wi,vi=map(int,input().split())
    w.append(wi)
    v.append(vi)
for i in range(n):
    for w_sum in range(1,W+1):
        if w_sum - w[i]>=0:
            dp[i+1][w_sum]=max(dp[i][w_sum],dp[i][w_sum - w[i]]+v[i])
        else:
            dp[i+1][w_sum]=dp[i][w_sum]
print(dp[-1][-1])

Measured memory_bytes: 120796
prev=lambda n,i,d: i-d if i-d>=0 else n+i-d
N,x=map(int,input().split())
A=list(map(int,input().split()))
dp = A[:]
ans=sum(dp)
for d in range(1,N+1):
    for i in range(N):
        p = prev(N,i,d)
        dp[i]=min(dp[i], A[p])
    ans=min(ans,sum(dp)+d*x)
print(ans)


Measured memory_bytes: 43244
from collections import defaultdict
n,k=map(int, input().split())
A=[int(i)-1 for i in input().split()]
now=0
loop=[]
dd = defaultdict(int)
if k>=n:
    while k!=0:
        k-=1
        now = A[now]
        if dd[now]>0:
            break
        else:
            dd[now]+=1
        if k==0:
            print(now)
            exit()
        loop.append(now)
    loop = loop[loop.index(now):]
    loop.append(now)
    t = len(loop)-1
    a=(k%t)
    while a>0:
        a-=1
        now = A[now]
    print(now+1)
else:
    while k!=0:
        k-=1
        now = A[now]
    print(now+1)


Measured memory_bytes: 32624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,d,i,m,j,k,p,s=0;
    ll a[12][12];
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            d=0;
            for(k=0;k<m;k++)
            {
                d+=((a[i][k]-a[j][k])*(a[i][k]-a[j][k]));
            }
            p=sqrt(d);
            if((p*p)==d)
                s++;
        }
    }
    cout<<s<<endl;
}



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

ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
int main()
{
    ll n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=(i*(n/i)*(n/i+1))/2;

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


Measured memory_bytes: 3680
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n[2],i,j,a,m;
  while(scanf("%d %d",&n[0],&n[1]),n[0]){
    int d[3][30]={};
    for(i=0;i<2;i++){
      for(j=0;j<n[i];j++){
	scanf("%d",&a);
	d[i][a]++;
      }
    }
    for(i=m=0;i<25;i++)m+=MAX(d[0][i],d[1][i])*i;
    printf("%d\n",m);
  }
  return 0;
}

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

using namespace std;

const int N = 1e3 + 10;
const int M = 2e5 + 10;

bool ans[M];
int n, m, tot;
int Min[N][N], Max[N][N];
vector<pair<int, int> > g[N];

void dfs(int *a, int x, int v)
{
	if(!a[x])a[x] = v;
	else return;
	for(int i = 0; i < (int)g[x].size(); i++)
		dfs(a, g[x][i].first, v);
}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		g[x].push_back(make_pair(y, ++tot));
	}
	for(int x = 1; x <= n; x++)
	{
		Min[x][x] = Max[x][x] = 1;
		for(int i = 0; i < (int)g[x].size(); i++)
		{
			int y = g[x][i].first;
			dfs(Min[x], y, g[x][i].second);
		}
		for(int i = g[x].size() - 1; ~i; i--)
		{
			int y = g[x][i].first;
			dfs(Max[x], y, g[x][i].second); 
		}
	}
	for(int x = 1; x <= n; x++)
	{
		for(int i = 0; i < (int)g[x].size(); i++)
		{
			int y = g[x][i].first, num = g[x][i].second;
			bool flag1 = Min[y][x] > 0;
			bool flag2 = (Min[x][y] && Min[x][y] != num) || (Max[x][y] && Max[x][y] != num);
			if((flag1 && !flag2) || (!flag1 && flag2))ans[num] = 1;
		}
	}
	for(int i = 1; i <= tot; i++)
		if(ans[i])puts("diff");
		else puts("same");
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int> > G;
int d[111],f[111],u[111];
void dfs(int v,int& p){
  if(u[v]) return;
  u[v]=1;
  sort(G[v].begin(),G[v].end());
  d[v]=++p;
  for(int u:G[v]) dfs(u,p);
  f[v]=++p;
}
signed main(){
  int n;
  cin>>n;
  G.resize(n,vector<int>());
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      c--;
      G[u].push_back(c);
    }
  }
  int p=0;
  for(int i=0;i<n;i++)
    if(!u[i]) dfs(i,p);
  for(int i=0;i<n;i++) cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;;
  return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define N 100005
#define M 10000000000
#define endl "\n"
using namespace std;

int m, k;

int h[N];

long long  MAX = 0;


int dp[N];


int minCost(int n)
{

	if (n == 0)
		return 0;


	if (dp[n] != -1)
		return dp[n];


	int option = 1000000001;


	for (int i = n - 1; i >= max(0, n - k); --i)
	{

		option = min(option, abs(h[n] - h[i]) + minCost(i));
		//cout << i << " " << abs(h[n] - h[i]) << endl;


	}


	return dp[n] = option;

}


int32_t main()
{

	cin >> m >> k;




	for (int i = 0; i < m; ++i) {
		cin >> h[i];

		MAX += h[i];
	}


	memset(dp, -1, sizeof(dp));


	cout << minCost(m - 1) << endl;

}

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

typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

int n;
const int MAXS = 5e5;
int fen[MAXS + 3];
int a[MAXS + 3];
deque<int> elems[MAXS + 3];
vii queries[MAXS + 3];

void update(int pos, int delta){
    while(pos <= n){
        fen[pos] += delta;
        pos += pos & (-pos);
    }
}

int query(int pos){
    int answer = 0;
    while(pos){
        answer += fen[pos];
        pos -= pos & (-pos);
    }
    return answer;
}

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
    cin>>n;
    int q; cin>>q;
    vii arq;
    bool vis[n+2] = {};
    for (int i=1; i<=n; i++){
        cin>>a[i];
        elems[a[i]].pb(i);
        if (!vis[a[i]]){
            update(i, 1);
            vis[a[i]] = 1;
        }
    }
    for (int i=0; i<q; i++){
        int l,r; cin>>l>>r;
        queries[l].pb(ii(i, r));
    }
    
    vii ans;
    for (int i=1; i<=n; i++){
        //first answer all, then update:
        for (int j=0; j<queries[i].size(); ++j){
            int r = queries[i][j].second;
            int index = queries[i][j].first;
            int cans = query(r);
            ans.pb(ii(index, cans));
        }
        int el = a[i];
        int pos = elems[el].front();
        elems[el].pop_front();
        update(pos, -1);
        if (!elems[el].empty()) update(elems[el].front(), 1);
    }
    sort(all(ans));
    for (int i=0; i<q; i++){
        cout<<ans[i].second<<'\n';
    }
    
	return 0;
}
/*
NARCO
*/


Measured memory_bytes: 371376
n,y=map(int,input().split())

flag=0
for i in range(n+1):
    for j in range(n-i+1):
        if y-(10000*i + 5000*j)>=0 and (y-(10000*i + 5000*j))//1000 + i + j==n:
            print(i,j,(y-(10000*i + 5000*j))//1000)
            flag=1
            break
    if flag==1:
        break
if flag==0:
    print(-1,-1,-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, ans, ansb, i, x;
    long long min=10000000000;
    cin >> n;
    vector<int> a;
    for(i=0;i<n;i++){
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    ans=a[n-1];
    for(i=0;i<n-1;i++){
        if(abs(a[i]-(ans/2))<=min){
            ansb=a[i];
            min=abs(a[i]-(ans/2));
        }
    }
    cout << ans << " " << ansb <<endl;
    return 0;
}


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

int main(){
  ll a, b, c, d, check = 0;
  bool flag = true;
  cin >> a >> b >> c >> d;
  while(flag){
    if(check%2 == 0){
      c -= b;
    }else{
      a -= d;
    }
    if(a <= 0){
      cout << "No" << endl;
      flag = false;
    }else if(c <= 0){
      cout << "Yes" << endl;
      flag = false;
    }
    check++;
  }
  return 0;
}


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

ll choose2(ll n) {
    return n*(n-1)/2;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    rep(i,n) a.at(i)--;
    vector<int> cnt(n);
    rep(i,n) cnt.at(a.at(i))++;
    ll tot = 0;
    rep(i,n) tot += (long) cnt.at(i)*(cnt.at(i) - 1)/2;
    rep(i,n) {
        ll ans = tot;
        ans -= cnt.at(a.at(i))*(cnt.at(a.at(i)) - 1)/2;
        ans += (cnt.at(a.at(i)) - 1)*(cnt.at(a.at(i)) - 2)/2;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>s) {
		string ans = "No";
		REP(i, s.size()) if(s[i]=='7') ans="Yes";
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define INF pow(10, 9) + 7
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define chmax(x, y) x = max(x, y)
#define print(x) cout << x << "\n"
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;

void solve(){
	
	ll N, K, cnt, num;
	cin >> N >> K;
	string S;
	cin >> S;
	
	vl v(0);
	ll num0 = 0;
	ll ans = 0;
	ll ind = 0;
	
	if(S[0] == '1'){
		
		while(ind < N){
			
			cnt = 0;
		
			while(ind < N && S[ind] == '1'){
				cnt += 1;
				ind += 1;
			}
			v.push_back(cnt);
			
			cnt = 0;
			
			while(ind < N && S[ind] == '0'){
				cnt += 1;
				ind += 1;
			}
			v.push_back(cnt);
			num0 += 1;
		
		}
		
		cnt = 0;
		num = v.size();
		
		if(num0 <= K) ans = N;
		
		else{
			
			rep(i, 2 * K + 1) cnt += v[i];
			
			rep(i, num0 - K + 1){
				
				chmax(ans, cnt);
				cnt -= v[2 * i];
				cnt -= v[2 * i + 1];
				cnt += v[2 * i + 2 * K + 1];
				if(2 * i + 2 * K + 1 + 1 < num)  cnt += v[2 * i + 2 * K + 1 + 1];
			
			}
			
		}

	}
	
	else{
		
		ind = 0;
		
		while(ind < N){
			
			cnt = 0;
		
			while(ind < N && S[ind] == '0'){
				cnt += 1;
				ind += 1;
			}
			v.push_back(cnt);
			
			cnt = 0;
			
			while(ind < N && S[ind] == '1'){
				cnt += 1;
				ind += 1;
			}
			v.push_back(cnt);
			num0 += 1;
		
		}
		
		cnt = 0;
		num = v.size();
		
		if(num0 <= K) ans = N;
		
		else{
			
			rep(i, 2 * K) cnt += v[i];
			
			rep(i, num0 - K + 1){
				
				chmax(ans, cnt);
				if(i == 0)  cnt -= v[0];
				else{
					cnt -= v[2 * i - 1];
					cnt -= v[2 * i];
				}
				cnt += v[2 * i + 2 * K];
				if(2 * i + 2 * K + 1 < num)  cnt += v[2 * i + 2 * K + 1];
			
			}
			
		}

	}
	
	print(ans);

}	

int main(){
    
    fastio;
	solve();
    
	return 0;
	
}


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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1e9 + 7;
const int N = 1e6 + 5;

typedef long long ll;

int n, u[N], c = 1, a, b;
vector <int> g[N];

void dfs(int v, int pr)
{
      for(int to : g[v])
      {
            if(to == pr) continue;
            dfs(to, v);
            if(u[to]) u[v] = 1, c ++;
      }
}

void f(int v, int pr, int cnt)
{
      for(int to : g[v])
      {
            if(to == pr || !u[to]) continue;
            if((cnt + 1) <= (c + 1) / 2)
            {
                  u[to] = 2;
                  f(to, v, cnt + 1);
            }
      }
}

void dfs1(int v, int pr)
{
      for(int to : g[v])
      {
            if(to == pr || (u[to] && u[to] != u[v])) continue;
            u[to] = u[v];
            dfs1(to, v);
      }
}

int main()
{
      scanf("%d", &n);

      for(int i = 1; i < n; i ++)
      {
            int a, b;
            scanf("%d %d", &a, &b);
            g[a].pb(b);
            g[b].pb(a);
      }

      u[n] = 1;
      dfs(1, 0);
      u[1] = 2;
      f(1, 1, 1);
      dfs1(1, 0);
      dfs1(n, 0);
      for(int i = 1; i <= n; i ++)
            if(u[i] == 2) a ++;
            else b ++;

      if(a > b)
            cout << "Fennec" << endl;
      else
            cout << "Snuke" << endl;
}


Measured memory_bytes: 34176
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
constexpr double PI = 3.141592653589793;
constexpr int INF = 1e9 + 10;
constexpr ll INFL = 1e18 + 10;

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

using namespace std;
// cout << setprecision(20) << ans << "\n";

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

  int a, b, x;
  cin >> a >> b >> x;
  if (a * a * b < x * 2) {
    // cout << "more than half"
    //      << "\n";
    // これを満たすiを求める。x * 2 == a * a * (b - i) * 2 + a * a * i
    // 2x/a/a = 2b-i
    // 2b-2x/a/a=i
    // 2baa-2x=iaa
    double ad = (double)a;
    double bd = (double)b;
    double xd = (double)x;
    double i = 2.0 * a * a * b - 2.0 * x;
    double ans = atan2(a * a * a, i);
    ans *= 180.0 / PI;
    ans = 90.0 - ans;
    cout << setprecision(20) << ans << "\n";
  } else {
    double ad = (double)a;
    double bd = (double)b;
    double xd = (double)x;
    // double i = x / a * 2.0 / b;
    double i = x * 2.0;
    double ans = atan2(b * a * b, i);
    ans *= 180.0 / PI;
    cout << setprecision(20) << ans << "\n";
  }

  return 0;
}


Measured memory_bytes: 4168
#include<bits/stdc++.h>//万能库
using namespace std;
int n;
long long f[87];//开longlong，防爆
int main()
{
    cin>>n;
    f[0]=2;//初始化
    f[1]=1;
    for(int i=2;i<=n;i++)
        f[i]=f[i-1]+f[i-2];//套用公式
    cout<<f[n];//输出第n个
}

Measured memory_bytes: 256
def main():

    S = input()
    d = [int(S[i]) for i in range(4)]
    cur = [[d[0], S[0]]]
    for i in range(1, 4):
        temp = []
        for v, s in cur:
            temp.append([v + d[i], s + "+" + S[i]])
            temp.append([v - d[i], s + "-" + S[i]])
        cur = temp

    # print(cur)

    for v, s in cur:
        if v == 7: return s + "=7"
    return ""

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3316
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef tuple<int,int,bool> Tb;

ll gcd(ll a, ll b) {
    while(1) {
        if(a < b) swap(a, b);
        if(!b) break;
        a %= b;
    }
    return a;
}

int abc118_c(){
    //入力
    int n;
    cin >> n;
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    ll ans=a[0];

    //処理
    for(int i=1; i<n; ++i) ans = gcd(a[i],ans);
    
    
    //出力
    cout << ans << ENT;
    return 0;
}

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


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

map<ll, vector<int>> mp;
ll A[200000];
int N;
ll K;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        A[i]--;
    }
    mp[0].push_back(0);
    ll sum = 0;
    for(int i = 0; i < N; i++){
        sum += A[i];
        sum %= K;
        mp[sum].push_back(i+1);
    }
    ll ans = 0;
    for(auto iter = mp.begin(); iter != mp.end(); iter++){
        vector<int> v = iter->second;
       // cout << iter->first << ' ' << v.size() << endl;
        for(int i = 0; i < v.size(); i++){
            auto p = lower_bound(v.begin(), v.end(), v[i]+K);
            ans += (p-v.begin())-i-1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 23736
s = int(input())
l = [s]
i = s
while s:
    if i % 2 == 0:
        l.append(i // 2)
        i //= 2
    else:
        l.append(i * 3 + 1)
        i = i * 3 + 1
    if l.count(i) == 2:
        l2 = [j for j, x in enumerate(l) if x == i]
        print(l2[1] + 1)
        exit()

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

int main() {
    vector<int> pqr(3);
    for (auto& e : pqr) cin >> e;

    cout << accumulate(pqr.begin(), pqr.end(), 0) - *max_element(pqr.begin(), pqr.end()) << endl;
}


Measured memory_bytes: 256
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    H,W = LMIIS()
    MOD = H*W
    S = [input() for _ in range(H)]


    def tansaku(S,V,y,x,length):

        
        if  x >= 1 and S[y][x-1] == '.' and V[y][x-1] > length+1:
            V[y][x-1] = length+1
            tansaku(S,V,y,x-1,length+1)


        if x < W-1 and S[y][x+1] == '.' and V[y][x+1] > length+1:
            V[y][x+1] = length+1
            tansaku(S,V,y,x+1,length+1)


        if y >= 1 and S[y-1][x] == '.' and V[y-1][x] > length+1:
            V[y-1][x] = length+1
            tansaku(S,V,y-1,x,length+1)


        if y < H-1 and S[y+1][x] == '.' and V[y+1][x]> length+1:
            V[y+1][x] = length+1
            tansaku(S,V,y+1,x,length+1)

        return
    
    def getmax():
        max_length = 0
        for h in range(H):
            for w in range(W):
                V = [[MOD] * W for _ in range(H)]
                if S[h][w] == '.':
                    V[h][w] = 0
                    tansaku(S,V,h,w,0) 
                for v in V:
                    v = list(map(lambda x:x%MOD,v))
                    max_length = max(v+[max_length])
                    # print(V)
        return max_length
    
    print(getmax())
    






if __name__ == '__main__':
    main()

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

int main(){
  string s="0000";cin>>s[0]>>s[1]>>s[2]>>s[3];;
  string t="1479";
  sort(s.begin(), s.end());
  cout<<(s==t?"YES":"NO")<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1100000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)};
const int max_n = 1 << 20;

signed main() {
	int n;cin>>n;int d[50];rep(i,n)cin>>d[i];
  int ans = 0;
  rep(i,n){
    repd(j,i+1,n){
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    int n,m;
    cin>>n>>m;
	n=(n*(n-1))/2;
	m=(m*(m-1))/2;
	cout<<n+m<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 256
from itertools import combinations
from collections import defaultdict


N = int(input().strip())

Pos = defaultdict(set)
Neg = defaultdict(set)
for i in range(N):
    A = int(input())
    for j in range(A):
        x, y = map(int, input().strip().split())
        if y == 1:
            Pos[i + 1].add(x)
        else:
            Neg[i + 1].add(x)


def check(positive):
    positive_set = set(positive)
    for x in positive_set:
        if len(Pos[x] - positive_set) != 0:
            return False
        if len(Neg[x].intersection(positive_set)) != 0:
            return False
    return True


people_list = list(range(1, N + 1))
ans = 0
for i in range(N, 0, -1):
    positives = combinations(people_list, i)
    for p in positives:
        if check(p):
            ans = i
            break
    if ans > 0:
        break

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef function<bool (int64_t x)> FT;
int64_t f(int64_t i, int64_t e, const FT &g)
  {int64_t m = 0, t = e;
  while (llabs(i - e) > 1) {m = (i + e) / 2; if (g(m)) i = m; else e = m;}
  return g(i) ? i : t;}
int main()
  {string s, t; cin >> s >> t;
  map<char, vector<int>> m;
  for (int i = 0; i < s.size(); ++i) m[s[i]].push_back(i);
  auto i = 0LL, ans = 0LL;
  for (auto c: t)
    {auto &is = m[c];
    if (is.empty()) {puts("-1"); return 0;}
    auto g = [&](int64_t x) {return i <= is[x];};
    auto j = f(is.size() - 1, -1, g);
    if (j == -1)
      {ans += s.size();
      i = 0; i = is[f(is.size() - 1, -1, g)] + 1;}
    else i = is[j] + 1;}
  ans += i; cout << ans << endl;}

Measured memory_bytes: 4244
/*
 * atcoder/abc99/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

const int INF = 200000;
int N, M;
vector<int> A;
int dp[100100][20];

void solve() {
  cin >> N;
  A.push_back(1);
  int n = 6;
  while (n <= N) {
    A.push_back(n);
    n *= 6;
  }
  n = 9;
  while (n <= N) {
    A.push_back(n);
    n *= 9;
  }
  M = A.size();
  for (int n=0; n<=N; n++) {
    for (int m=0; m<M; m++) {
      dp[n][m] = INF;
    }
  }

  for (int n=0; n<=N; n++) {
    for (int m=0; m<M; m++) {
      if (n==0) { dp[0][m] = 0; continue; }
      if (m==0) { dp[n][0] = n; continue; }
      int a = A[m];
      chmin(dp[n][m], dp[n][m-1]);
      if (n-a >= 0) chmin(dp[n][m], 1 + dp[n-a][m]);
    }
  }

  cout << dp[N][M-1] << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 8064
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);

    string str;
    cin>>str;
    if(str[2] == str[3] && str[4] == str[5]){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }

    return 0;
}


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

void swap(int *x, int *y)
{
	int temp = *x;
	*x = *y;
	*y = temp;
}

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(a < b) swap(&a, &b);
	if(a < c) swap(&a, &c);
	if(b < c) swap(&b, &c);
	printf("%d\n", abs(a-b)+abs(b-c));
	return 0;
}

Measured memory_bytes: 128
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

main = do
    n<- getLine
    a<- map (read::String->Int) <$> replicateM (read n) getLine
    print $ maximum $ zipWith (-) (tail a ++ [-(10^9)]) (scanl1 min a)



Measured memory_bytes: 173148
n = gets.to_i
li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
p li[n-1]

Measured memory_bytes: 1788
from heapq import heapify, heappop, heappush
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
G = []
for _ in [0]*M:
    a, b, c = map(int, input().split())
    heappush(G, (c, a, b))


class UnionFind:
    def __init__(self, n=0):
        self.d = [-1]*n
        self.u = n

    def root(self, x):
        if self.d[x] < 0:
            return x
        self.d[x] = self.root(self.d[x])
        return self.d[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if x > y:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        self.u -= 1
        return True

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def size(self, x):
        return -self.d[self.root(x)]

    def num_union(self):
        return self.u


u = UnionFind(N)
ans = 0
while u.num_union() > 1:
    c, a, b = heappop(G)
    if u.same(a, b):
        continue
    u.unite(a, b)
    ans += c
print(ans)



Measured memory_bytes: 23704
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def inc(n):
  ans = 0
  i = 1
  while True:
    if n - i >= 0:
      n -= i
      i += 1
      ans += 1
    else:
      break
  return ans

import collections

n = int(input())

c = collections.Counter(prime_factorize(n))

num = c.values()

ans = 0

for i in num:
  ans += inc(i)

print(ans)


Measured memory_bytes: 9460