akhauriyash/Code-Regression huggingface dataset:
n,k,q = map(int, input().split())
a = list(map(int, input().split()))
num_set = set(a)

def parse(b):
    ret = []
    tmp = []
    for ai in a:
        if ai >= b:
            tmp.append(ai)
        else:
            if len(tmp) >= k:
                tmp.sort(reverse=True)
                for i in range(k-1,len(tmp)):
                    ret.append(tmp[i])
            tmp = []
    else:
        if len(tmp) >= k:
            tmp.sort(reverse=True)
            for i in range(k-1,len(tmp)):
                ret.append(tmp[i])
            tmp = []
    return ret

ans = 10**10

for b in num_set:
    lis = parse(b)
    if len(lis) < q:
        continue
    ans_tmp = sorted(lis)[q-1] - min(lis)
    ans = min(ans, ans_tmp)

print(ans)


Measured memory_bytes: 47196
n = int(input())
m = n
import math
size = int(math.log10(n) + 1)
#print(size)

ls = []
for i in range(size-1, -1, -1):
  r = int(n//(10**i))
  n = n - r*10**i
  ls.append(r)
  
#print(sum(ls), m%sum(ls))
#print(type(n), type(sum(ls)))
if m%sum(ls) == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <cstdio>
#include <cctype>
#include <utility>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	int n = in(), at = -in();
	pair<int, int> m = {in(), at}, t;
	while (n--) {
		int a = -in();
		t = {in(), a};
		m = max(m, t);
	}
	outl(-m.second, ' ', m.first);
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
#include <functional>
#include <numeric>
#include <iostream>

using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MOD = (int)1e9 + 7;

class modint {
  int v;
public:
  modint (): v(0) { }
  modint (ll v): v((v + MOD) % MOD) { }

  bool operator== (modint x) { return v == x.v; }
  bool operator!= (modint x) { return v != x.v; }

  modint operator+ (modint x) { return v + x.v; }
  modint operator- (modint x) { return v - x.v; }
  modint operator* (modint x) { return (ll)v * x.v; }

  modint& operator+= (const modint x) { return *this = (*this + x); }
  modint& operator-= (const modint x) { return *this = (*this - x); }
  modint& operator*= (const modint x) { return *this = (*this * x); }

  int operator* () { return v; }
};

#define debug(format, ...) printf(format, __VA_ARGS__);

string s;
int ans = 1000;

int main() {
  cin >> s;
  for(char c : s) {
    string u = s;
    int cnt = 0;
    while(1) {
      bool good = true;
      for(int i = 0; i < u.size(); i++) {
        if(u[i] != c) good = false;
      }
      if(good) break;

      string t;
      for(int i = 0; i+1 < u.size(); i++) {
        t += (u[i] == c || u[i+1] == c) ? c : u[i];
      }
      u = t;
      cnt += 1;
    }
    ans = min(ans, cnt);
  }
  printf("%d\n", ans);
  return 0;

}


Measured memory_bytes: 764
#include<iostream>
using namespace std;
int main()
{
    double d,t,s,div=0;
    cin>>d>>t>>s;
    div=d/s;
    if(div<=t)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <ctime>

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define Set(i, v) memset(i, v, sizeof i)

using namespace std;

const int N = 100010;

int P[N], n;

int main(){
	scanf("%d", &n);
	bool flag = false;
	int ans = 0;
	For(i, 1, n){
		scanf("%d", &P[i]);
		if(i == P[i]){
			if(!flag) ++ans, flag = true;
			else flag = false;
		}
		else flag = false;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
N = int(input())
s = [int(input()) for _ in range(N)]

ans = sum(s)
if ans % 10 != 0:
    print(ans)
else:
    s = sorted(s)
    for i in range(N):
        if (ans - s[i]) % 10 != 0:
            ans -= s[i]
            break
    if ans % 10 != 0:
        print(ans)
    else:
        print(0)

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

namespace atcoder.abc168.a
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = getIntParam() % 10;

            string ret;
            switch (N)
            {
                case 3:
                    ret = "bon";
                    break;
                case 0:
                case 1:
                case 6:
                case 8:
                    ret = "pon";
                    break;
                default:
                    ret = "hon";
                    break;
            }
            Console.WriteLine(ret);
        }
        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }
        static decimal getDecimalParam()
        {
            return decimal.Parse(Console.ReadLine());
        }
        static decimal[] getDecimalParams()
        {
            return Console.ReadLine().Split(' ').Select(i => decimal.Parse(i)).ToArray();
        }

    }
}


Measured memory_bytes: 27540
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    vector<int> a(4, 0);
    rep(i, 6){
        int b;
        cin >> b;
        --b;
        ++a[b];
    }
    sort(a.begin(), a.end());
    if(a[3] == 3){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<ll> A(N), check(N, 0);
    rep(i, N) {
        cin >> A[i];
        check[A[i]]++;
    }

    bool flag = true;
    ll ans = 1;
    for (int i = 1 - (N % 2); i < N; i += 2) {
        if (i == 0) {
            if (check[i] != 1) {
                flag = false;
                break;
            }
        } 
        else {
            if (check[i] != 2) {
                flag = false;
                break;
            }
        }
        ans *= check[i];
        ans %= MOD;
    }

    cout << (flag ? ans : 0) << endl;
    return 0;
}

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

int main() {
  int K,X;
  cin>>K>>X;
  if(-1000000>X-K+1){
    for(int i=1;i<X+K;i++){
      cout<<i<<endl;
      }
    }
  else if(1000000<X+K-1){
    for(int i=X-K+1;i<1000001;i++){
      cout<<i<<endl;
      }
    }
  else{
    for(int i=X-K+1;i<X+K;i++){
      cout<<i<<endl;
      }
    }
  
}


Measured memory_bytes: 256
n = int(input())
l = [int(input()) for _ in range(n)]
dp = [[0]*5 for _ in range(n+1)]
for i in range(n):
  dp[i+1][0] = dp[i][0] + l[i]
  dp[i+1][1] = min(dp[i][:2]) + (l[i] % 2 if l[i] else 2)
  dp[i+1][2] = min(dp[i][:3]) + (l[i] + 1) % 2
  dp[i+1][3] = min(dp[i][:4]) + (l[i] % 2 if l[i] else 2)
  dp[i+1][4] = min(dp[i][:5]) + l[i]
print(min(dp[n]))

Measured memory_bytes: 67848
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var K = long.Parse(Console.ReadLine());
            var N = 50;
            var answer = new long[N];
            var r = K % N;
            for (var i = 0; i < r; i++)
            {
                answer[i] = (N - 1) + (K / N) + 1;
            }
            for (var i = r; i < N; i++)
            {
                answer[i] = (N - 1 - r) + (K / N);
            }
            Console.WriteLine(N);
            Console.WriteLine(string.Join(" ", answer));
        }
    }
}


Measured memory_bytes: 27620
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string s; cin >> s;
	char c = s[0];
	int sum = 0;
	for (int i = 1; i < s.size(); i++){
		if (s[i] != c) {
			sum++;
			c = s[i];
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 512
import java.io.*;

public class Main {
	
		public static void main(String[] args) throws IOException{
			
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] str = br.readLine().split(" ");
			
			int a= Integer.parseInt(str[0]);
			int b = Integer.parseInt(str[1]);
			
			int div = a / b;
			int amari = a % b;
			//String syosu = String.format("%.5f",((double)a/(double)b));
			double syosu = (double)a/(double)b;
			
			//System.out.println(div + " " + amari + " " + syosu);
			System.out.printf("%d %d %5f", div, amari, syosu);
		}

}

Measured memory_bytes: 24668
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int main(){
  int n; cin>>n;
  map<string,int>mp;
  rep(i,n){
    string s; cin>>s;
    mp[s]++;
  }
  int mx = 0;
  for (auto p:mp) mx = max(p.second, mx);
  for (auto p:mp) if (p.second==mx) cout << p.first<< endl;
}

Measured memory_bytes: 19228
/*input
2 2
*/

#include <iostream>

using namespace std;

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

	int total = 0;

	for(int i=0;i<=K;i++){
		for(int j=0;j<=K;j++){
			int k = S - i - j;
			if(k >= 0 && k <= K) total++;
		}
	}

	cout << total << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

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

    int ret = 0;
    int now = 1;
    while (now < n) {
	now *= 3;
	ret++;
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 3080
class Card:
    def __init__(self, s, n):
        self.suit = s
        self.num = n

class FindingMissingCards:
    def __init__(self):
        self.allCards = []
        for s in ["S","H","C","D"]:
            for n in range(1,14):
                self.allCards.append(Card(s,n))
    def find(self, cards):
        for c in cards:
            for ac in self.allCards:
                if c.num == ac.num and c.suit == ac.suit:
                    self.allCards.remove(ac)
        for c in self.allCards:
            print "%s %d" % (c.suit, c.num)

if __name__ == "__main__":
    n = int(raw_input())
    cards = []
    for i in range(n):
        s, n = raw_input().split()
        cards.append(Card(s, int(n)))

    fmc = FindingMissingCards()
    fmc.find(cards)

Measured memory_bytes: 6392
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	ll n, m;
  	cin >> n >> m;
  	if(n==1 || m==1) cout << 1 << '\n';
  	else cout << (n*m+1)/2 << '\n';

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
int ans[500][500];
//---------------------------------------------------------------------------------------------------
void dfs(int l, int r, int level) {
    if(l + 1 == r) return;
    int c = (l + r) / 2;

    rep(x, l, c) rep(y, c, r) ans[x][y] = ans[y][x] = level;

    dfs(l, c, level + 1);
    dfs(c, r, level + 1);
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    dfs(0, N, 1);

    rep(i, 0, N) {
        rep(j, i + 1, N) {
            if(j != i + 1) printf(" ");
            printf("%d", ans[i][j]);
        }
        printf("\n");
    }
}







Measured memory_bytes: 1536
#include<complex>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int V[4] = {10,50,100,500};
int C[4],I[4],R[4],A[4];
int pay;
const int T[4] = {INT_MAX,INT_MAX,INT_MAX,INT_MAX};

void ret(int sum){
  int A = sum;
  for(int i=3;i>=0;i--){
    int t = min(A/V[i],T[i]);
    A -= t*V[i];
    R[i] = t;
  }
}

int main(){
  bool first = false;
  while(cin >> pay && pay){
    rep(i,4)cin >> C[i];
    int pre = INT_MAX;
    A[0] = A[1] = A[2] = A[3] = -1;
    rep(i,C[0]+1){//10
      rep(j,C[1]+1){//50
	rep(k,C[2]+1){//100
	  rep(l,C[3]+1){//500
	    int sum = i*10+j*50+k*100+l*500;
	    if(sum < pay)continue;
	   
	    I[0] = i,I[1] = j,I[2] = k,I[3] = l;
	    ret(sum-pay);	    
	    int total = 0;
	    bool ok = true;
	    rep(m,4){
	      total += C[m] - I[m] + R[m];
	      //if(I[m] != R[m])ok = false;
	      assert(C[m] >= I[m]);
	    }	    

	    if(total < pre){
	      rep(m,4)A[m] = I[m];
	      pre = total;
	    }	    

	  }
	}
      }
    }

    if(first)cout << endl;
    first = true;
    rep(i,4){
      if(A[i] == 0)continue;
      cout << V[i] << " " << A[i] << endl;
    }


  }
return 0;
}



/*
Way to check the time of processing speed

clock_t start,end;
start = clock();

------function-------

end = clock();
cout << setiosflags(ios::fixed) << setprecision(10) << (double)(end-start)/CLOCKS_PER_SEC << endl;


*/

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

int main() {
    string s; cin >> s;
    long long bc = 0, bp = 0; for (int i = 0; i < s.size(); i++) if(s[i]=='B'){bc++;bp+=i;}
    cout << (s.size()-1 + s.size()-bc) * bc / 2 - bp << endl;
    /**
    bool debug = true;
    string s; cin >>s;
    int w=0;
    for (auto c: s) if(c=='W'){w++;}
    if (debug) cout << s << endl << "----" << endl;

    int left_white = 0, ret = 0, t;
    for (int i = 0; i < w; i++) {
        t = s.substr(left_white, s.size()).find('W');
        if (t==0) {
            // do nothing
        }
        else {
            s[left_white] = 'W';
            if (t>0) s[left_white+t] = 'B';
            ret += t;
        }
        if (debug) cout << s << " " << t << endl;
        left_white++;
    }
    if (debug) cout << "----" << endl << s << endl;
    */
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,a,b,a1,b1;
	cin>>n>>a>>b;
	a1=a;
	b1=b;
	long long ans=0;
	if((b-a)%2==0)
		ans=(b-a)/2;
	else
	{
		long long cnt=min(b-1,n-a);
		long long w=a-1;
		long long m=n-b;
		long long cnt2=0,cnt3=0,cnt4=0;
		cnt2+=m;
		a1=a1+m+1;
		cnt2+=(n-a1)/2+1;
		cnt3+=w;
		b1=b1-w-1;
		cnt3+=(b1-1)/2+1;
		cnt4=min(cnt2,cnt3);
		ans=min(cnt,cnt4);
	}
	cout<<ans;
	return 0;	
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		public void Exec()
		{
			var array = Console.ReadLine().Split(' ').Select(i => double.Parse(i)).ToArray();

			double a = array[0];
			double b = array[1];
			double c_rad = array[2] / 180.0 * Math.PI;
			double height = b * Math.Sin(c_rad);
			double area = a * height / 2.0;
			double c = Math.Sqrt(a * a + b * b - 2.0 * a * b * Math.Cos(c_rad));
			double length = a + b + c;

			Console.WriteLine($"{area:f6}");
			Console.WriteLine($"{length:f6}");
			Console.WriteLine($"{height:f6}");

			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 20536
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

struct Trie {
    const char base;
    struct Node {
        array<int, 26> child; // 子の頂点番号 存在しなければ-1
        array<ll, 26> cnt;
        Node() {
            for(int i = 0; i < 26; i++) {
                child[i] = -1;
                cnt[i] = 0LL;
            }
        }
    };
    vector<Node> nodes;
    Trie(char base) : base(base) { nodes.emplace_back(Node()); }
    void insert(const string &s) {
        int now = 0;
        int n = (int)s.size();
        for(int i = 0; i < n - 1; i++) {
            int nxt = nodes[now].child[s[i] - base];
            if(nxt == -1) {
                nodes[now].child[s[i] - base] = (int)nodes.size();
                nxt = (int)nodes.size();
                nodes.emplace_back(Node());
            }
            now = nxt;
        }
        nodes[now].cnt[s.back() - base]++;
    }
    ll get(const string &s, vector<int> &exist) {
        ll res = 0;
        int now = 0;
        int n = (int)s.size();
        for(int i = 0; i < n; i++) {
            for(int k = 0; k < 26; k++) {
                if(exist[i] & (1 << k)) {
                    res += nodes[now].cnt[k];
                }
            }
            int nxt = nodes[now].child[s[i] - base];
            if(nxt == -1) {
                return res;
            }
            now = nxt;
        }
        return res;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<string> s(N);
    for(int i = 0; i < N; i++) {
        cin >> s[i];
        reverse(ALL(s[i]));
    }
    sort(ALL(s), [](const string &a, const string &b) {
        return (a.size() < b.size());
    });

    Trie trie('a');
    ll ans = 0;
    for(int i = 0; i < N; i++) {
        int n = (int)s[i].size();
        vector<int> exist(n + 1, 0);
        for(int j = n - 1; j >= 0; j--) {
            exist[j] = exist[j + 1] | (1 << (s[i][j] - 'a'));
        }
        ans += trie.get(s[i], exist);
        trie.insert(s[i]);
    }
    cout << ans << endl;
}

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

int main(){
	int ary[10];
	for(int i=0;i<10;i++){
		cin>>ary[i];
	}
	for(int i=0;i<10;i++){
		for(int j=i+1;j<10;j++){
			if(ary[i]<ary[j]){
				swap(ary[i], ary[j]);
			}
		}
	}
	cout<<ary[0]<<endl;
	cout<<ary[1]<<endl;
	cout<<ary[2]<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

using namespace std;

struct Edge{
    int from, to;
    lint cost;
};

int n, m;
vector<Edge> edges;
vector<lint> dis;

bool reverseBellmanFord(void){
    rep(i, 2 * n){
        rep(j, m){
            Edge e = edges[j];
            if(dis[e.from] != -LLINF && dis[e.to] < dis[e.from] + e.cost){
                dis[e.to] = dis[e.from] + e.cost;
                if(i >= n-1 && e.to == n-1){
                    return true;
                }
            }
        }
    }
    return false;
}

int main(){
    cin >> n >> m;
    edges.resize(m);
    rep(i, m){
        int a, b;
        lint c;
        cin >> a >> b >> c;
        a--;
        b--;
        edges[i].from = a;
        edges[i].to = b;
        edges[i].cost = c;
    }
    dis.resize(n, -LLINF);
    dis[0] = 0;
    if(reverseBellmanFord()){
        cout << "inf" << endl;
    }else{
        cout << dis[n-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    vector<ll> b(m);
    rep(i,m)cin>>b[i];
    vector<ll> sa(n+1,0);
    rep(i,n){
        sa[i+1]=sa[i]+a[i];
    }
    vector<ll> sb(m+1,0);
    rep(i,m){
        sb[i+1]=sb[i]+b[i];
    }

    ll ans=0;
    rep(i,n+1){
        ll j=m;
        while(j>=0){
            if(sa[i]+sb[j]<=k){
                ans=max(i+j,ans);
                break;
            }else{
                --j;
                --m;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9548
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
static const int INF=(1<<29);

using namespace std;
int main(){
    int m,n;
    cin>>m>>n;
    int coin[n];
    rep(i,n){
        cin>>coin[i];
    }
    int cn[n][m+1];
    for(int i=0;i<=m+1;i++){
        if(i%coin[0]==0){
            cn[0][i]=i/coin[0];
        }else{
            cn[0][i-1]=INF;
        }
    }
    
    for(int i=1;i<n;i++){
        for(int j=0;j<=m;j++){
            if(j-coin[i]>=0){
            cn[i][j]=min(cn[i-1][j],cn[i][j-coin[i]]+1);
            }else{
                cn[i][j]=cn[i-1][j];
            }
            
        }
    }
    //cout<<cn[n][m];
    
  /*  rep(j,n){
    rep(i,m+1){
        cout<<cn[j][i]<<" ";
    }
        cout<<endl;
    }*/
    cout<<cn[n-1][m]<<endl;





return 0;
}



Measured memory_bytes: 6988
#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vpii vector<pair<int, int>>
#define pii pair<int, int>
#define ar array
#define vvll vector<vll>
#define repa(i, b, n) for (int i = b; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1e9
#define MP make_pair
#define ll long long int
#define M 1000000007
#define all(a) a.begin(), a.end()
// debugging
#define db(x) cout << x << "\n";
#define db1(x) cout << #x << "=" << x << "\n"
#define db2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << "\n"
#define db3(x, y, z) cout << #x << "=" << x << ", " << #y << "=" << y << ", " << #z << "=" << z << "\n"
#define dba(x)       \
    for (auto i : x) \
    cout << i << "\t"
#define dbm(x)                \
    for (auto i : x)          \
    {                         \
        for (auto j : i)      \
            cout << j << " "; \
        cout << "\n";         \
    }
#define MOD 1000000007
using namespace std;
const int maxN = 100000;
void solve()
{
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, x;
    cin >> n >> m >> x;
    vvi a(n, vi(m + 1, 0));
    vi pri(n, 0);
    rep(i, n)
    {

        rep(j, m + 1)
        {
            cin >> a[i][j];
        }
    }
    int ans = INT_MAX;
    for (int i = 0; i < (1 << n); i++)
    {
        vi temp(m + 1, 0);
        for (int j = 0; j <= 12; j++)
        {
            if (i & (1 << j))
            {
                for (int k = 0; k < m + 1; k++)
                {
                    temp[k] += a[j][k];
                }
            }
        }
        int f = 0;
        for (int i = 1; i <= m; i++)
        {
            if (temp[i] < x)
                f = 1;
        }
        if (f == 0)
            ans = min(ans, temp[0]);
    }
    if (ans == INT_MAX)
        cout << -1;
    else
        db(ans);
}

Measured memory_bytes: 3584
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

const double EPS=(1e-10);
typedef long long ll;
typedef pair<int,int> pii;
bool EQ(double a,double b){
  return abs((a)-(b))<EPS;
}
void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}

void solve(){
    const string e="egg";
    const string c="chicken";
    string s;
    cin>>s;
    vector<string> vs;
    for(int i=0;i<s.size();i++){
        if(s.substr(i,3)==e)vs.push_back(s.substr(i,3));
        else if(s.substr(i,c.size())==c)vs.push_back(s.substr(i,c.size()));
    }
    vector<vector<string> > vvs;
    vector<string> tmp;
    for(int i=0;i<vs.size();i++){
        if(tmp.size()==0||tmp[tmp.size()-1]!=vs[i])
            tmp.push_back(vs[i]);
        else{
            vvs.push_back(tmp);
            tmp.clear();
            tmp.push_back(vs[i]);
        }
    }
    if(tmp.size())vvs.push_back(tmp);
    int sz=0;
    int id=0;
    string res;
    for(int i=0;i<vvs.size();i++){
        if(sz<vvs[i].size()){
            res=vvs[i][vvs[i].size()-1];
            sz=vvs[i].size();
        }
    }
    cout<<res<<endl;
}
int main(){

    solve();

    return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    string s, t;
    cin >> s >> t;

    bool flag = false;
    auto is = s.find(t);
    if(is == string::npos){
        reverse(ALL(s));
        reverse(ALL(t));
        rep(i, s.size())if(s[i]=='?'||s[i]==t.front()){
            ll pos = 0;
            while((s[i+pos]==t[pos]||s[i+pos]=='?')&&i+pos<s.size())pos++;
            if(pos >= t.size()){
                rep(j, t.size())s[i+j]=t[j];
                flag = true;
                break;
            }
        }
        reverse(ALL(s));
    }
    else flag = true;

    if(!flag){
        cout << "UNRESTORABLE"  << endl;
        return 0;
    }
    rep(i, s.size()){
        if(s[i] == '?')cout << 'a';
        else cout << s[i];
    }

}

Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))

m = 10 ** 9
for i in range(N - K + 1):
    temp = min(abs(x[i + K - 1]), abs(x[i])) + abs(x[i + K - 1] - x[i])
    m = min(temp, m)
print(m)

Measured memory_bytes: 62576
#include<iostream>
using namespace std;
int main(){
	int a=0,b=0;
	//for(;;){
		while(cin>>a>>b){
		if(a+b<10)cout<<"1"<<endl;
		else if(a+b<100)cout<<"2"<<endl;
		else if(a+b<1000)cout<<"3"<<endl;
		else if(a+b<10000)cout<<"4"<<endl;
		else if(a+b<100000)cout<<"5"<<endl;
		else if(a+b<1000000)cout<<"6"<<endl;
		else if(a+b<10000000)cout<<"7"<<endl;
		else if(a+b<100000000)cout<<"8"<<endl;
		else if(a+b<1000000000)cout<<"9"<<endl;
	}
}

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

int main(){
  int K;cin>>K;
  vll ans={1,2,3,4,5,6,7,8,9,
  19,29,39,49,59,69,79,89,99,
199,299,399,499,599,699,799,899,999};

  //digit は、「その」桁数から3を引いたもの。
  for (int digit=0;digit<12;++digit){
    ll base=0;
    for (int i=0;i<=digit;++i){
      base+=9*(ll)pow(10,i);
    }
    for(int k=100;k<=999;++k){
      ll upper=k*(ll)pow(10,digit+1);
      int a=k/100;
      int b=(k-a*100)/10;
      int c=(k-a*100-b*10);
      ll num=upper+base;

      if(a>=digit+2){
        if(b==9&&c==9){
          ans.push_back(num);
        }
      }

      else{
        if ((11*a+b>=digit+1)&&(c==9)){
          ans.push_back(num);
        }
        else if (11*a+b<digit+1){
          ans.push_back(num);
        }
      }
    }
  }

  for (int k=0;k<K;++k){
    cout << ans[k] << endl;
  }

  return 0;
}

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

using namespace std;
typedef long long ll;
long long mod = 1000000007;
const int INF = 100100100;

int main(){
  int n;
  cin >> n;
  int mark = 1;
  for(int i=0;i<n;i++){
    int a; cin >> a;
    if(a == mark){
      mark++;
    }
  }
  mark--;
  if(mark != 0){
    cout << n - mark << endl;
  }else{
    cout << -1 << endl;
  }
} 

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int X = sc.nextInt();
      int[] m = new int[N];
      
      // 残りのお菓子の素を算出
      for(int i=0; i<N; i++){
        m[i] = sc.nextInt();
        X = X - m[i];
      }  
      
      Arrays.sort(m);
      
      System.out.println(N + X/m[0]);
    }  
} 

Measured memory_bytes: 22740
#!/usr/bin/env python3
#写経
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

#　縦に並んだ入力を受け取りたい時はread().split()をとる zip(m,m)で分ける
N,U,V = map(int,readline().split())
m = map(int,read().split())
AB = zip(m,m)

#tree の受け取り：頂点の数＋１のリストを用意して、それぞれの頂点が辺を貼るnodeを全てリストに保存
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
#全探索して入力頂点からの距離を返す
#全ての頂点に対して、
def dfs(v):
    dist = [-1] * (N+1)
    stack = [v]
    dist[v] = 0
    while stack:
        v = stack.pop()
        dw = dist[v] + 1
        for w in graph[v]:#頂点から辺が貼られている頂点に対して
            if dist[w] >= 0:#すでに訪れている
                continue
            dist[w] = dw#訪れてないなら更新
            stack.append(w)
    return dist

DU,DV = dfs(U),dfs(V)
 
answer = 0
#元の場所以外の全ての頂点を探索する
for u,v in zip(DU[1:],DV[1:]):
    if u < v:#逃げる方が先につく中で最短を探す
        x = v - 1
        if answer < x:
            answer = x
 
print(answer)

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	int D[60];
	cin >> N;
	rep(i, 0, N)
	{
		cin >> D[i];
	}

	int ans = 0;
	rep(i, 0, N)rep(j, i + 1, N)
	{
		ans += D[i] * D[j];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 2001

char resultTable[SIZE];
int n,q,elems[20];

bool calc(int number,int sum,int index){
	if(sum == number){
		return true;
	}else if(sum > number || index == n)
		return false;
	else{
		return (calc(number,sum+elems[index],index+1) || calc(number,sum,index+1));
	}
}

bool judge(int number){
	if(resultTable[number] == 'y')
		return true;
	else if(resultTable[number] == 'n')
		return false;
	else{
		if(calc(number,0,0)){
			resultTable[number] = 'y';
			return true;
		}else{
			resultTable[number] = 'n';
			return false;
		}
	}
}

int main(){

	for(int i = 0;i < SIZE; i++) resultTable[i] = 's';

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

	scanf("%d",&q);

	int tmp;
	for(int i = 0; i < q; i++){
		scanf("%d",&tmp);
		if(judge(tmp)){
			printf("yes\n");
		}else{
			printf("no\n");
		}
	}
}

Measured memory_bytes: 1012
#include <iostream>

using namespace std;

int main()
{
	int i, j, k, a, b, c, d, ans;
	cin >> a; cin >> b; cin >> c; cin >> d;

	if (a < c) {
		if (c < b) {
			if (b < d)
				ans = b - c;
			else
				ans = d - c;
		}
		else
			ans = 0;
	}
	else if (a < d) {
		if (d < b)
			ans = d - a;
		else
			ans = b - a;
	}
	else
		ans = 0;

	cout << ans << endl;

	return 0;
}

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

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************
ll mod=1000000007;
pair<ll,ll> independent(vector<vector<int>> &graph,int u,vector<int> &vis)
{
    vis[u]=1;
    if(graph[u].size()==1 && vis[graph[u][0]]==1)
    {
        return make_pair(2,1);
    }
    else{
        ll ans1=1,ans2=1;
        for(int i=0;i<graph[u].size();i++)
        {
            int v=graph[u][i];
            
            if(vis[v]==0)
            {
                auto pr=independent(graph,v,vis);
                ans1*=(pr.first)%mod;
                ans1%=mod;
                ans2*=(pr.second)%mod;
                ans2%=mod;
            }
        }
        return make_pair((ans1+ans2)%mod,ans1);
    }
}

void solve()
{

	int n;
    cin >> n;
    vector<vector<int>> graph(n);
    vector<int> vis(n);
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        cin >> u >> v;
        u--,v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    vis[n-1]=1;
    auto pr=independent(graph,n-1,vis);
    cout << pr.first << endl;
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 9984
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    n, m = iim()
    C = list(iim())

    dp = [n] * (n + 1)
    dp[0] = 0
    for co in C:
        for i in range(co, n+1):
            dp[i] = min(dp[i], dp[i-co] + 1)
    print(dp[n])

if __name__ == "__main__":
    resolve()



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

#define MAX 10000
#define INFTY (1 << 29)

class DisjointSet
{
public:
  vector<int> rank, p;

  DisjointSet() {}
  DisjointSet(int size)
  {
    rank.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++)
    {
      makeSet(i);
    }
  }

  void makeSet(int x)
  {
    p[x] = x;
    rank[x] = 0;
  }

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

  void unite(int x, int y)
  {
    link(findSet(x), findSet(y));
  }

  void link(int x, int y)
  {
    if (rank[x] > rank[y])
    {
      p[y] = x;
    }
    else
    {
      p[x] = y;
      if (rank[x] == rank[y])
      {
        rank[y]++;
      }
    }
  }

  int findSet(int x)
  {
    if (x != p[x])
    {
      p[x] = findSet(p[x]);
    }
    return p[x];
  }
};

class Edge
{
public:
  int source, target, cost;
  Edge(int source = 0, int target = 0, int cost = 0) : source(source), target(target), cost(cost) {}
  bool operator<(const Edge &e) const
  {
    return cost < e.cost;
  }
};

int kruskal(int N, vector<Edge> edges)
{
  int totalCost = 0;
  sort(edges.begin(), edges.end());
  DisjointSet dset = DisjointSet(N + 1);

  for (int i = 0; i < N; i++)
  {
    dset.makeSet(i);
  }

  int source, target;
  for (int i = 0; i < edges.size(); i++)
  {
    Edge e = edges[i];
    if (!dset.same(e.source, e.target))
    {
      totalCost += e.cost;
      dset.unite(e.source, e.target);
    }
  }
  return totalCost;
}

int main()
{
  int N, M, cost;
  int source, target;

  cin >> N >> M;
  vector<Edge> edges;
  for (int i = 0; i < M; i++)
  {
    cin >> source >> target >> cost;
    edges.push_back(Edge(source, target, cost));
  }

  cout << kruskal(N, edges) << endl;

  return 0;
}


Measured memory_bytes: 5384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a*b /gcd(a,b);}

#define pii pair<int,int>
bool func(pii a,pii b){
  return a.second<b.second;
}

int main(){
  int N; cin>>N;
  pii p[N];
  int a;
  REP(i,N){
    cin >> a;
    p[i] = make_pair(i+1,a);
  }
  sort(p,p+N,func);
  REP(i,N){ printf("%d ",p[i].first);}
}

Measured memory_bytes: 1536
#[derive(Default)]
//NOTE
//declare variables to reduce the number of parameters for dp and dfs etc.
struct Solver {}

impl Solver {
    fn solve(&mut self) {
        let stdin = std::io::stdin();
        let mut scn = Scanner {
            stdin: stdin.lock(),
        };
        let n: usize = scn.read();
        let mut ab: Vec<_> = (0..n)
            .map(|_| {
                let a: usize = scn.read();
                let b: usize = scn.read();
                (a, b)
            })
            .collect();
        ab.sort_by_key(|x| x.1);
        let mut time = 0;
        let mut ok = true;
        ab.iter().for_each(|(a, b)| {
            time += a;
            if time > *b {
                ok = false;
            }
        });
        if ok {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| {
            let mut solver = Solver::default();
            solver.solve()
        })
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 5344
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
#define int long long
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}

ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}



int32_t main(){
  fastio;
  int tot=0;
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  for(int i=0;i<n;i++){
    for(int j =i+1;j<n;j++){
      tot+=v[i]*v[j];
    }

  }
  cout << tot << endl;
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 3596