akhauriyash/Code-Regression huggingface dataset:
/*author : Yashvardhan
Sunday, August 18, 2019
5:41 PM
*/

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

typedef long long ll;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))
#define printArr(name,from,to) for(int x = from; x < to; x++) cout << name[x] << " ";


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod(pow(takemod(a), mod-2,mod));}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n;
	cin>>n;

	vector<double> arr;
	for(int i = 0; i < n; i++){
		int x;
		cin>>x;
		arr.pb((double) x);
	}
	

	for(int i = 0; i < n - 1; i++){
		sort(all(arr));
		double val = (arr[0] + arr[1])/ (double) 2;
		vector<double> tmp;
		for(int j = 2; j < arr.size(); j++) tmp.pb(arr[j]);
		tmp.pb(val);
		arr = tmp;
	}

	cout<<setprecision(10)<<fixed;
	cout<<arr[0]<<endl;

	t2 = clock();
	cerr<<endl<<t2-t1<<endl;
	
	return 0;
}



Measured memory_bytes: 256
#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>;

const int MOD = 1000000007;
int dist1[100005];
int dist2[100005];
bool checked[100005];
vector<int> E[100005];
int n, k;

ll dfs(int v) {
    checked[v] = true;
    ll res = k - dist1[v] - dist2[v];
    for (int u: E[v]) {
        if (checked[u]) continue;
        dist1[u]++;
        dist2[u] += dist1[v];
        dist1[v]++;
        res *= dfs(u);
        res %= MOD;
    }
    return res;
}

int main() {
    cin >> n >> k;
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    ll ans = dfs(0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10112
n,m=map(int, input().split())
import numpy as np
xyz=np.array([list(map(int,input().split())) for i in range(n)])
ans=0
if m>0:
    for i in range(8):
        a=np.dot(xyz,np.array(((-1)**i,(-1)**(i//2),(-1)**(i//4))))
        ans=max(ans,np.sum(np.sort(a)[-m:]))
print(ans)

Measured memory_bytes: 12524
#include <stdio.h>
int main()
{
    int n;
    int p[4][3][10] = {0};

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int b, f, r, v;
        scanf("%d %d %d %d", &b, &f, &r, &v);
        p[b-1][f-1][r-1] += v;
    }
    for (int b = 0; b < 4; b++)
    {
        for (int f = 0; f < 3; f++)
        {
            for (int r = 0; r < 10; r++)
            {
                printf(" %d", p[b][f][r]);
            }
            printf("\n");
        }
        if(b != 3){
        printf("####################\n");
        }
    }
}


Measured memory_bytes: 2048
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;
	rep(i,0,n){
		string s;
		cin >> s;
		vector<char> c;
		rep(j,0,s.size()) c.push_back(s[j]);
		vsort(c);
		string M = "" , m = "";
		rep(j,0,s.size()) M += c[j];
		rvsort(c);
		rep(j,0,s.size()) m += c[j];
		
		//cout << M << " " << m << endl;

		cout << stoi(m) - stoi(M) << endl;
	}
	ret 0;
}


Measured memory_bytes: 3164
N = list(map(int, input()))     # 整数を桁毎のリストとして読み込む
L = len(N)
K = int(input())
D = K + 2                       # 状態数
dp = [[[0] * D for i in range(L + 1)] for j in range(2)]

def min2(x,y):
    return x if x < y else y

"""
dp[0][i][*]: 上からi桁目までが N と一致
dp[1][i][*]: 上からi桁目までで N である事が確定
dp[*][*][j]: 0 でない数字の個数が j 個
"""
dp[0][0][0] = 1
for i in range(L):
    for j in range(D):
        for k in range(10):
            if k < N[i]:
                dp[1][i+1][min2(j + (k!=0), D-1)] += dp[0][i][j] + dp[1][i][j]
            elif k == N[i]:
                dp[0][i+1][min2(j + (k!=0), D-1)] += dp[0][i][j]
                dp[1][i+1][min2(j + (k!=0), D-1)] += dp[1][i][j]
            else:
                dp[1][i+1][min2(j + (k!=0), D-1)] += dp[1][i][j]

res = dp[0][L][K] + dp[1][L][K]
print(res)

Measured memory_bytes: 73964
public class Main {


  private static void solve() {
    int n = ni();
    char[] s = ns();
    int q = ni();

    for (int t = 0; t < q; t++) {
      int k = ni();
      long ret = 0;
      long dm = 0;
      long[] cnt = new long[2];

      for (int i = 0; i < n; i++) {
        if (s[i] == 'D') {
          cnt[0]++;
        } else if (s[i] == 'M') {
          cnt[1]++;
          dm += cnt[0];
        } else if (s[i] == 'C') {
          ret += dm;
        }

        if (i >= k - 1) {
          if (s[i - k + 1] == 'D') {
            cnt[0]--;
            dm -= cnt[1];
          } else if (s[i - k + 1] == 'M') {
            cnt[1]--;
          }
        }
      }
      System.out.println(ret);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 32388
s = input()
while(1):
    if s.endswith('dream'):
        s = s[:-5]
    elif s.endswith('dreamer'):
        s = s[:-7]
    elif s.endswith('eraser'):
        s = s[:-6]
    elif s.endswith('erase'):
        s = s[:-5]
    else:
        print("NO")
        quit()
    if s == '':
        break
print("YES")

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

#define mem(arr, i) fill(arr, arr + sizeof(arr), i)
#define MEM(arr, i) memset(arr, i, sizeof(arr))
#define Push push_back
#define Pair make_pair
#define ALL(x) x.begin(), x.end()
#define X first
#define Y second
#define ACCEL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef pair<pll,lli> p3l;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
typedef vector<p3l> v3L;
typedef vector<vcL> vvL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
      lli   mod = 1000000007;

/// templates ///

const lli maxN = 2E5;

vcL inv(maxN+5, 1);
vcL fac(maxN+5, 1);

void ADD(lli &x, lli y) {
	x += y;
	if (x >= mod) x -= mod;
	if (x < 0) x += mod;
}

void MUL(lli &x, lli y) {
	x *= y;
	x = (x % mod + mod) % mod;
}

lli mypow(lli b, lli e) {
	lli ans = 1;
	while (e) {
		if (e & 1) MUL(ans, b);
		MUL(b, b);
		e >>= 1;
	}
	return ans;
}

lli modinv(lli n) {
	return mypow(n, mod - 2);
}

void calcInv(lli n) {
	for (int i = 2; i <= n; ++i) {
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	}
}

void calcFac(lli n) {
	for (int i = 2; i <= n; ++i) {
		fac[i] = fac[i - 1] * i % mod;
	}
}

lli cm(lli a, lli b) {
	lli ans = 1;
	if (a < b) return 0;

	MUL(ans, inv[fac[a - b]]);
	MUL(ans, inv[fac[b]]);
	MUL(ans, fac[a]);

	return ans;
}

lli Lucas(lli n, lli m) {
	if (m == 0) return 1;
	return cm(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;
}

lli doLucas(lli n, lli m) {
	calcInv(mod);
	calcFac(mod);
	return Lucas(n, m);
}

/// coding area ///

const lli maxn = 1E5 + 5;
lli ans = 0;
vcL adj[maxn];
vcL indeg(maxn, 0);
vcL len(maxn, 0);

void precal() {

	return;
}

void dfs(int now) {
	for (auto x : adj[now]) {
		len[x] = max(len[x], len[now] + 1);
		ans = max(ans, len[x]);
		if (--indeg[x] == 0) {
			dfs(x);
		}
	}
}

void solve() {
	lli n, m;
	cin >> n >> m;
	
	for (int i = 0; i < m; ++i) {
		lli a, b;
		cin >> a >> b;
		adj[a].Push(b);
		++indeg[b];
	}
	
	for (int i = 1; i <= n; ++i) {
		if (indeg[i] == 0) {
			indeg[i] = -1;
		}
	}
	
	for (int i = 1; i <= n; ++i) {
		if (indeg[i] == -1) {
			dfs(i);
		}
	}
	
	cout << ans << '\n';
}

int main() {
	precal();
	int t = 1;
	#ifdef LOCAL
		t = INT_MAX;
	#else
		ACCEL;
	#endif
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}



Measured memory_bytes: 13568
//#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>
#include<complex>

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;

int N, C;
pii S[100010];
pii LS[100010], RS[100010];
pii SUMLS[100010], SUMRS[100010];

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

	cin >> N >> C;

	rep(i, 0, N)
	{
		cin >> S[i].first >> S[i].second;
	}

	sort(S, S + N);

	rep(i, 0, N)
	{
		LS[i] = RS[i] = S[i];
		RS[i].first = C - LS[i].first;
	}

	SUMLS[0] = mp(0, -1);
	SUMRS[N] = mp(0, -1);
	int sum = 0;
	pii maxp = mp(0, -1);
	rep(i, 0, N)
	{
		sum += LS[i].second;
		if (chmax(maxp.first, sum - LS[i].first))
		{
			maxp.second = i;
		}
		SUMLS[i + 1] = maxp;
	}

	sum = 0;
	maxp = mp(0, -1);

	rrep(i, 0, N)
	{
		sum += RS[i].second;
		if (chmax(maxp.first, sum - RS[i].first))
		{
			maxp.second = i;
		}
		SUMRS[i] = maxp;
	}

	int ans = 0;
	rep(i, 0, N + 1)
	{
		int res = SUMLS[i].first;
		chmax(ans, res);
		if (SUMLS[i].second != -1)
		{
			res -= LS[SUMLS[i].second].first;
		}
		res += SUMRS[i].first;
		chmax(ans, res);
	}

	rrep(i, 0, N + 1)
	{
		int res = SUMRS[i].first;
		chmax(ans, res);
		if (SUMRS[i].second != -1)
		{
			res -= RS[SUMRS[i].second].first;
		}
		res += SUMLS[i].first;
		chmax(ans, res);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <set>
#include <map>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 5e18;
const unsigned long long HASHBASE=1222827239ull;
/////////////////////////

/////////////////////////
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    long long l,r;
    cin>>l>>r;
    long long t = l%2019;
    if(r-l>=2019-t || l%2019 == 0)
    {
        cout<<0<<endl;
    }
    else
    {
        long long minnum=INF64;
        for(long long i=l;i<=r;++i)
        {
            for(long long j=i+1ll;j<=r;++j)
            {
                minnum=min(minnum,i*j%2019);
            }
        }
        cout<<minnum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

typedef struct{
int p;
int l,r;
}Tree;

Tree A[MAX];

int Dep(int);

main(){
int i,j,n;
int num,deg,c,k=0;

scanf("%d",&n);
for(i=0;i<n;i++){
A[i].p=-1;
A[i].l=-1;
A[i].r=-1;
}
for(i=0;i<n;i++){
scanf("%d%d",&num,&deg);
for(j=0;j<deg;j++){
scanf("%d",&c);
if(j==0)A[num].l=c;
else A[k].r=c;
k=c;
A[c].p=num;
}
}
for(i=0;i<n;i++){
printf("node %d: parent = %d, depth = %d",i,A[i].p,Dep(i));
if(Dep(i)==0)printf(", root, [");
else if(A[i].l==-1)printf(", leaf, [");
else printf(", internal node, [");
j=A[i].l;

while(j!=-1){
printf("%d",j);
j=A[j].r;
if(j!=-1){
printf(", ");
}
}
printf("]\n");
}
return 0;
}

int Dep(int num){
int dep=0;
while(A[num].p!=-1){
num=A[num].p;
dep++;
}
return dep;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define viii vector <pair<ll,pair<ll,ll> > >
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<endl
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define inf 999999999999999999
#define sp << " " <<
#define endl "\n"
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);
#define sz size()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
double calcAngle(double h, double m)
{
    double hour_angle = 0.5 * (h * 60 + m);
    double minute_angle = 6 * m;

    double angle = abs(hour_angle - minute_angle);

    angle = min(360 - angle, angle);

    return angle;
}
void solve(){
double a,b,h,m;
cin>>a>>b>>h>>m;
double angle=calcAngle(h,m);
double ans=sqrt(a*a+b*b-2*a*b*cos((angle*pi)/180));
fixd(16);
cout<<ans<<endl;
}
int main()
{   fast;
    ll t=1;
   // cin>>t;
    fr(zz,1,t+1){
    solve();
    }
}


Measured memory_bytes: 4180
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    s = input()
    c = collections.Counter(s)

    l = len(s)
    total = l * (l - 1) // 2

    for ci in c.values():
        tmp = ci * (ci - 1) // 2
        total -= tmp

    print(total + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9612
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define E endl
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(9)

int main()
{
	ll n,k;
	cin>>n;
	string a;
	cin>>a;
	ll ans=0;
	for(ll i=0;i<n-2;i++)
	{
		if(a[i]=='A' && a[i+1]=='B' && a[i+2]=='C')
		ans++;
	}
	cout<<ans;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<utility>
#include<string>
#include<algorithm>

using namespace std;
string c[15];
int ans;
bool t[100000005];

map<string,bool> memo;

int ku[4];
int n,k;

//void shokika();
void kumi();
void ku2();
void ku3();
void ku4();

main(){
  int i,j,l,t;
  while(1){
    //    shokika();
    memo.clear();
    ans=0;
    //    puts("W");
    cin >> n >> k;
    if(n==0 && k==0) break;

    for(i=0;i<n;i++){
      cin >> c[i];
    }
    /*
    for(i=0;i<n;i++){
      cout << c[i] <<endl;
    }
    puts("");
    */
    for(i=0;i<n-(k-1);i++){
      for(j=i+1;j<n-(k-2);j++){
	if(2<k){
	  for(l=j+1;l<n-(k-3);l++){
	    if(3<k){
	      for(t=l+1;t<n-(k-4);t++){
		ku[0]=i;
		ku[1]=j;
		ku[2]=l;
		ku[3]=t;
		kumi();
	      }
	    }
	    else{
	      ku[0]=i;
	      ku[1]=j;
	      ku[2]=l;
	      kumi();
	    }
	  }
	}
	else{
	  ku[0]=i;
	  ku[1]=j;
	  kumi();
	}
      }
    }

    /*
      for(i=0;i<n;i++){
      cout << c[i] <<endl;
    }
    puts("");
    */
    cout << ans << endl;
  }
}

void kumi(){
    if(k==2) ku2();
    else if(k==3) ku3();
    else ku4();
}

void ku2(){
  string temp;
  temp=c[ku[0]];
  temp+=c[ku[1]];
  if(memo[temp]!=true){
    memo[temp]=true;
    ans++;
    //    cout << "ku2..." << temp <<endl;
  }
  temp=c[ku[1]];
  temp+=c[ku[0]];
  if(memo[temp]!=true){
    memo[temp]=true;
    ans++;
    // cout << "ku2..." << temp <<endl;
  }
}

void ku3(){
  int i,j,l;
  string temp;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(i!=j){
	for(l=0;l<3;l++){
	  if(l!=i && l!=j){
	    temp=c[ku[i]];
	    temp+=c[ku[j]];
	    temp+=c[ku[l]];
	    if(memo[temp]!=true){
	      memo[temp]=true;
	      ans++;
	      //	      cout << "ku3..." << temp <<endl;
	    }
	  }
	}
      }
    }
  }
}

void ku4(){
  int i,j,l,t;
  string temp;
  for(i=0;i<4;i++){
    for(j=0;j<4;j++){
      if(i!=j){
	for(l=0;l<4;l++){
	  if(l!=i && l!=j){
	    for(t=0;t<4;t++){
	      if(t!=i && t!=j && t!=l){
		temp=c[ku[i]];
		temp+=c[ku[j]];
		temp+=c[ku[l]];
		temp+=c[ku[t]];
		if(memo[temp]!=true){
		  memo[temp]=true;
		  ans++;
		  //  cout << "ku4..." << temp <<endl;
		}
	      }
	    }
	  }
	}
      }
    }
  }
}

/*
  void shokika(){
  fill(t,t+100000005,false);
  }
*/

Measured memory_bytes: 0
(defmacro defsolver (name vars &body body)
  `(defun ,name ()
     (let (,@(mapcar #'list
            vars
            (mapcar (constantly '(read))
                vars)))
       ,@body)))

(defsolver solution-a ()
  (let ((l (loop repeat 4 collect (read-char))))
    (format t "~:[Good~;Bad~]"
	    (some #'(lambda (i)
		      (eq
		       (nth i l)
		       (nth (1+ i) l)))
		  '(0 1 2)))))

(solution-a)

Measured memory_bytes: 15332
def solve(inp):
    N = int(inp.readline().strip())
    D = list(map(int, inp.readline().strip().split(' ')))

    r = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            r += D[i] * D[j]

    return str(r)


def test(s):
    from io import StringIO
    print(solve(StringIO(s)))


def main():
    import sys
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    # test('50\n' + '100 ' * 50)
    main()


Measured memory_bytes: 3064
program prob5
    implicit none
    integer(8) :: n
    integer(8), allocatable :: a(:)
    integer(8) :: i, p, q, tmp, tmpi
    
    read(*,*) n
    allocate(a(n))
    read(*,*) a

    call msort(a)
    tmp = a(n)

    tmpi = -1
    do i = n-1, 1, -1
        if(tmp == a(i)) then
            p = tmp
            tmpi = i !tmpi番目とtmpi+1番目は同じ
            exit
        else
            tmp = a(i)
        end if
    end do

    if(tmpi <= 2) then
        write(*,*) "0"
        stop
    end if

    tmp = a(tmpi-1)
    q = 0
    do i = tmpi - 2, 1, -1
        if(tmp == a(i)) then
            q = tmp
            exit
        else
            tmp = a(i)
        end if
    end do

    write(*,*) p * q


    deallocate(a)

    stop
contains


  !
  ! swap two arguments
  !
subroutine swap(a, b)
    implicit none
    integer(8), intent(inout) :: a, b

    integer(8) :: c

    c = a
    a = b
    b = c

  end subroutine swap

  !
  ! merge sort
  !
  recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)

    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if

    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))

    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x

    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do

    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n

    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort


end program prob5   

Measured memory_bytes: 4548
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
ll W;
ll w[102];
ll v[102];

int main()
{
	cin >> n >> W;
	for (int i = 0;i < n;i++) {
		cin >> w[i] >> v[i];
	}

	int count[4];memset(count, 0, sizeof(count));
	priority_queue<int> q[4];

	for (int i = 0;i < n;i++) {
		int k = w[i] - w[0];
		count[k]++;
		q[k].push(v[i]);
	}

	vector<int> v[4];

	for (int i = 0;i < 4;i++) {
		while (!q[i].empty()) {
			v[i].push_back(q[i].top());
			q[i].pop();
		}
	}

	ll ans = 0;

	//for (int i = 0;i < 4;i++) { if (count[i] == 0) count[i] = 1;}

	for(int i0=0;i0<=count[0];i0++)
		for (int i1 = 0;i1<=count[1];i1++)
			for (int i2 = 0;i2<=count[2];i2++)
				for (int i3 = 0;i3 <= count[3];i3++) {
					//cout << i0 << "-" << i1 << "-" << i2 << "-" << i3 << endl;

					ll temp = 0;
					for (int i = 0;i < i0;i++) {
						temp = temp + (ll)v[0][i];
					}

					for (int i = 0;i < i1;i++) {
						temp = temp + (ll)v[1][i];
					}

					for (int i = 0;i < i2;i++) {
						temp = temp + (ll)v[2][i];
					}

					for (int i = 0;i < i3;i++) {
						temp = temp + (ll)v[3][i];
					}
					ll sum = w[0] * i0 + (w[0] + 1)*i1 + (w[0] + 2)*i2 + (w[0] + 3) * i3;
					if (sum <= W) { ans = std::max(ans, temp); }

				}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 384
n, a, b, c = map(int, input().split())
q = [input() for i in range(n)]
ab, ac, bc = "AB", "AC", "BC"
ans = []
for i in range(n):
  
  if((q[i] == ab and a == b == 0)
  or (q[i] == ac and a == c == 0) 
  or (q[i] == bc and b == c == 0)):
      print("No")
      exit()
      
  elif(q[i] == ab and [a, b, c] == [1, 1, 0] and i != n - 1):
    if q[i+1] == ac: 
      a, b = a+1, b-1
      ans.append("A")
    else:
      a, b = a-1, b+1
      ans.append("B")     
      
  elif(q[i] == ac and [a, b, c] == [1, 0, 1] and i != n - 1):
    if q[i+1] == ab:
      a, c = a+1, c-1
      ans.append("A")
    else:
      a, c = a-1, c+1
      ans.append("C")
      
  elif(q[i] == bc and [a, b, c] == [0, 1, 1] and i != n - 1):
    if q[i+1] == ab:
      b, c = b+1, c-1
      ans.append("B")
    else:
      b, c = b-1, c+1
      ans.append("C")
      
  elif q[i] == ab:
    if a > b:
      a, b = a-1, b+1
      ans.append("B")
    else:
      a, b = a+1, b-1
      ans.append("A")
      
  elif q[i] == ac:
    if a > c:
      a, c = a-1, c+1
      ans.append("C")
    else:
      a, c = a+1, c-1
      ans.append("A")
      
  elif q[i] == bc:
    if b > c:
      b, c = b-1, c+1
      ans.append("C")
    else:
      b, c = b+1, c-1
      ans.append("B")

print("Yes")
for i in range(n):
  print(ans[i])

Measured memory_bytes: 17108
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n = ni()
A = lma()
prev=0
ans=0
for a in A:
    if a<prev:
        ans+=(prev-a)
    prev=max(a,prev)
print(ans)


Measured memory_bytes: 33528
from itertools import combinations
box=list(list(input())[0] for i in range(int(input())))
count=[0,0,0,0,0]
for i in box:
    if i=="M":count[0] +=1
    elif i=="A":count[1] +=1
    elif i=="R":count[2] +=1
    elif i=="C":count[3] +=1
    elif i=="H":count[4] +=1
point=0
for i,j,k in combinations(count,3):
    point +=i*j*k
print(point)

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

void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
#define rep(i, n)for(int i=0; i<n; i++)

long long INF = 1000000007;

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

  if(s[s.size()-1] == 's')
    cout << s <<"es"<< endl;
  else
    cout<<s<<"s"<<endl;
  return 0;
}


Measured memory_bytes: 3628
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

void solve(long long n, long long k){
	LL cnt1=0,cnt2=0;
	for(int i=1; i<=n; ++i) {
		if (i%k==0)
			++cnt1;
		else if (k%2==0 && i%k==k/2)
			++cnt2;
	}	
	LL ans=cnt1*cnt1*cnt1+cnt2*cnt2*cnt2;
	cout<<ans<<endl;
}

int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	long long N;
	long long K;
	scanf("%lld",&N);
	scanf("%lld",&K);
	solve(N, K);
	return 0;
}



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

int main() {
	long long int  h,m=1;
	double l;
	long long int a;

	scanf("%lld", &h);
	l = floor(log2(h));
	a = pow(2, l + 1) - 1;
	printf("%lld", a);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>  // setw
#include <algorithm> // sort next_permutation count __gcd reverse etc.
#include <set>
#include <list>
#include <map>
#include <memory>
#include <numeric> // accumulate
#include <complex>
#include <functional>
#include <utility>
#include <iterator>
#include <vector>
#include <limits>
#include <stack>
#include <queue>
#include <deque>
#include <typeinfo>
#include <fstream> // freopen
#include <cstdio> // scanf printf
#include <cstdlib> // abs exit atof atoi
#include <string> // memset
#include <cstring>
#include <cfloat>
#include <cassert>
#include <cmath> // fabs
#include <cctype> // tolower toupper
#include <ctime> // srand
#include <sstream> // stringstream
#include <bitset>

#define reb(i,b,n) for(int i=(int)(b); i<(int)(n); i++)
#define rep(i,n) reb(i,0,n)
#define rreb(i,b,n) for(int i = b-1; i >= n; i--)
#define rrep(i,n) reb(i,n,0)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define reach(it,v) for(__typeof((v).rbegin()) it=(v).rbegin();it!=(v).rend();it++)
#define vall(x) (x).begin(), (x).end()
#define rvall(x) (x).rbegin(), (x).rend()
#define vsort(v) sort(vall(v))
#define rvsort(v) sort(rvall(v))
#define len(array) (sizeof (array) / sizeof *(array))
#define aall(x) x, x+len(x)
#define asort(x) sort(aall(x))
#define rasort(a, type) sort(aall(a), greater<type>())
#define afill(a, v) fill(aall(a), v)
#define afill2(a, v, type) fill((type *)a, (type *)(a + len(a)), v)
#define sz(x) (int)(x).size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define pb push_back
#define _USE_MATH_DEFINES
#define priArr(table, n) rep(i,n){cout<<table[i]<<' ';}cout<<'\n';
#define priAr2(table,W,H) rep(y,H){rep(x,W)cout<<table[y][x]<<' ';cout<<'\n';}
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = ["<<(x)<<"]"<<endl;

using namespace std;
using std::stringstream;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class F, class T> inline void convert(const F &f, T &t){stringstream ss;ss<<f;ss>>t;}
template<class T> inline T sqr(T x) {return x*x;}

typedef long long ll; typedef unsigned long long ull;
typedef pair <int, int> P; typedef pair <int, P> PP;
typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<string> vs;
typedef vector<ll> vl; typedef vector<P > vP; typedef vector<char> vc;
typedef long double ld;

const static int INF = 0x3f3f3f3f;
const static ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const static double EPS = 1e-9;
const static ll MOD = 1000000007LL;

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

int main(int argc, char *argv[])
{
    ll h, w;
    ll ans;
    cin >> h >> w;

    if ((h == 1) || (w == 1)) {
        cout << 1 << endl;
        return 0;
    }

    ans = w * (h/2);

    if ((h % 2) != 0) {
        ans += w/2;

        if ((w % 2) != 0) {
            ans += 1;
        }
    }


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, const char * argv[]) {
    
    int n[3] ;
    
    std::cin >> n[0] >> n[1] >> n[2] ;
    
    for (int i=2; i>=0; i--) {
        for (int j=i; j>=0; j--) {
            if (n[i] < n[j]){
                int c = n[i];
                n[i] = n[j] ;
                n[j] = c ;
            }
        }
    }
    
    std::cout << n[0] << " " << n[1] << " " << n[2] << std::endl ;
    
    return 0;
}


Measured memory_bytes: 3068
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;



int main() {
    int d,i,j,k;
    int c[26];
    int s[365][26];
    cin >> d;
    for(i = 0; i < 26; ++i) cin >> c[i];
    for(i = 0; i < d; ++i) for(j = 0; j < 26; ++j) cin >> s[i][j];

    int arr[365] = {};

    int t1,t2,s1,s2, diff, count;
    count = 0;
    int max, loc;
    int a[26] = {};
    int b[26] = {};
    for(i = 0; i < 365; ++i) {
        for(j = 0; j < 26; ++j) {
            b[j] = s[i][j]+a[j]*c[j];
            a[j]++;
        }
        max = *max_element(b,b+26);
        loc = find(b,b+26,max)-b;
        arr[i] = loc;
        a[loc] = 0;
    }
    
    
    while(true) {
        label1:
        for(i = 0; i < d; ++i) {
            for(j = 0; j < 26; ++j) {
                if(arr[i]==j) continue;
                if(count>20000000) goto label2;
                ++count;
                for(s1 = i+1; s1 < d; ++s1) {
                    if(arr[s1]==arr[i]) break;
                }
                for(t1 = i-1; t1 >= 0; --t1) {
                    if(arr[t1]==arr[i]) break;
                }
                for(s2 = i+1; s2 < d; ++s2) {
                    if(arr[s2]==j) break;
                }
                for(t2 = i-1; t2 >= 0; --t2) {
                    if(arr[t2]==j) break;
                }
                diff = s[i][j]-s[i][arr[i]]+(((s1-i)*(s1-i-1))/2+((i-t1)*(i-t1-1))/2-((s1-t1)*(s1-t1-1))/2)*c[arr[i]] + (-((s2-i)*(s2-i-1))/2-((i-t2)*(i-t2-1))/2+((s2-t2)*(s2-t2-1))/2)*c[j];
                if(diff>0) {
                    arr[i] = j;
                    goto label1;
                }
            }
        }
    }
    label2:
    for(i = 0; i < d; ++i) {
        cout<<(arr[i]+1)<<"\n";
    }


    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>
// 多倍長整数型
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
     
#define INF 1e9
#define LINF 1e19
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
     
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
     
const ll MOD = 1e9 + 7;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int l = a + b, r = c + d;
    if(l < r)cout << "Right" << endl;
    else if(l > r)cout << "Left" << endl;
    else cout << "Balanced" << endl;
}





Measured memory_bytes: 3108
H, W, K = [int(_) for _ in input().split()]
S = [list(input()) for _ in range(H)]
for h in range(H):
    f = None
    for w in range(W):
        if S[h][w] == '#':
            S[h][w] = W * h + w
            if f is None:
                for w2 in range(w):
                    S[h][w2] = S[h][w]
            f = S[h][w]
        elif f is not None:
            S[h][w] = f
f = None
for h in range(H):
    if S[h][0] == '.':
        if f:
            S[h] = S[h - 1][:]
    elif f is None:
        f = True
        for h2 in range(h):
            S[h2] = S[h][:]
v_i = {v: i + 1 for i, v in enumerate(set(sum(S, [])))}
print('\n'.join([' '.join([str(v_i[v]) for v in a]) for a in S]))


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

ll Ok(ll n,ll x){
  if(x == 0)return 0;
  if(n%x == n/x)return x;
  return 0;
}

int main(){
  ll n; cin >> n;
  ll cnt = 0;
  for(int i = 1; 1LL*i*i <= n; ++i){
    if(n%i==0){
      cnt += Ok(n,i-1);
      if(1LL*i*i!=n)cnt += Ok(n,n/i-1);
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3628
n = int(input())
d_list = [ int(v) for v in input().split() ]
depth_list = [ 0 for i in range(n) ]
for i in d_list:
    depth_list[i] += 1


ld = len(depth_list)

ans = 1
mod = 998244353

if d_list[0] != 0:
    ans = 0
if depth_list[0] > 1:
    ans = 0
else:
    for i in range(1,ld-1):
        if depth_list[i] == 0 and depth_list[i+1] > 0:
            ans = 0

if ans != 0:
    for i in range(ld-1):
        ans *= pow(depth_list[i],depth_list[i+1],mod)
        ans %= mod
print(ans%mod)

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


int main() {
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    for (int i = 1; i <s.length(); ++i) {
        if(s[i-1]==s[i]){
            cout<<"no"<<endl;
            return 0;
        }
    }
    cout<<"yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n; cin >> n;

    vector<long long> a(n);
    for(long long i = 0; i < n; i++) {
        cin >> a[i];
    }

    long long alice = 0, bob = 0;

    sort(a.rbegin(), a.rend());

    for(long long i = 0; i < n; i++){
        if(i & 1) bob += a[i];
        else alice += a[i];
    }

    cout << alice - bob;

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;
#define ll long long
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
using namespace std;
int a[100000][3];
ll n,m,cnt;
int main() {
    cin >> n >> m;
    REP(i,n) {
        int h;
        cin >> h;
        a[i][0] = h;
        a[i][1] = 1;
    }
    REP(i,m) {
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        if(a[x][0] <= a[y][0]) {
            a[x][1] = 0;
        }
        if(a[y][0] <= a[x][0]) {
            a[y][1] = 0;
        }
    }
    REP(i,n) {
        if(a[i][1]) {
            cnt++;
        }
    }
    
    cout << fixed << cnt;
}

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

int main(){
    ll n,k;
    ll ans=0;
    cin>>n>>k;
    if(k==0){
        cout<<n*n<<endl;
        return 0;
    }
    for(int b=k+1;b<n+1;b++){
        ans+=n/b*(b-k);
        ans+=max((ll)0,n%b-k+1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
double x[100],y[100],t,u,a,b,s;n,i,j,k,c;main(m){for(;m=scanf("%d",&n),i=n;printf("%d\n",m)){for(;i--;scanf("%lf,%lf",x+i,y+i));for(i=n;j=--i;)for(;j--;)if(s=(u=acos(hypot(x[j]-x[i],y[j]-y[i])/2))<9)for(t=atan2(y[j]-y[i],x[j]-x[i]);c=0,s+3;s-=2)for(a=x[i]+cos(b=t+s*u),b=y[i]+sin(b),k=n;k--;)hypot(a-x[k],b-y[k])<1.1&&++c>m?m=c:0;}}

Measured memory_bytes: 0
import numpy as np

x_1, y_1, x_2, y_2 = map(int, input().split())

P_1 = np.array([x_1, y_1])
P_2 = np.array([x_2, y_2])
vec_12 = P_2 - P_1
vec_13 = np.array([-vec_12[1], vec_12[0]])
P_3 = P_1 + vec_13
P_4 = P_2 + vec_13
print(P_4[0], P_4[1], P_3[0], P_3[1])


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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    ll q, h, s, d, n; cin >> q >> h >> s >> d >> n;
    ll ans = 0;
    ll t = min({q*4, h*2, s});
    if(n % 2 == 1){
        if(t*2 <= d){
            ans = t*n;
        }else{
            ans = t + (d*(n/2));
        }
    }else{
        t *= 2;
        ans = min(t, d) * (n/2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vec_i;

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;
const int MOD = 1e9+7;

int main()
{
	int h,w;
	cin >> h >> w;

	vector<vec_i> dp(h+1, vec_i(w+1, 0));	

	rep(i, h){
		rep(j, w){
			char c;
			cin >> c;
			if(i == 0 && j == 0){
				dp[i+1][j+1] = 1;
			}else if(c == '.'){
				dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j]) % MOD;
			}else{
				dp[i+1][j+1] = 0;
			}
		}
	}
	cout << dp[h][w] << endl;
}

Measured memory_bytes: 4224
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
//#include <bits/stdc++.h>
#define rep(i,n) for (long int i = 1; i < (n); ++i)
using namespace std;

int main(){
    long int K;
    cin>>K;
    if (K%2==0 || K%5==0){
        cout<<-1<<endl;
        return 0;
    }
    long int n=0,a=7,sum=0;
    rep(i,1000000){
        sum+=a;
        if (sum%K==0){
            n=i;
            break;
        }
        a=10*a;
        a=a%K;
    }
    if (n==0) cout<<-1<<endl;
    else cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;



int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    double sum = 0.0;
    long i;
    for(i=0; i<n; i++) {
        double x;
        scanf("%lf", &x);

        char str[5]={0};
        scanf("%s", str);

        if(strcmp(str, "JPY")==0) {

        }
        else {
            x *= 380000.0; 
        }
        sum += x;
    }

    printf("%.10f\n", sum);

    return 0;
}



Measured memory_bytes: 128
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
      String[] t=sc.nextLine().split(" ");
 
//    String nyuA=sc.nextLine();
 //  String nyuB=sc.nextLine();

//int n=Integer.parseInt(nyu);

int N=Integer.parseInt(t[0]);
int K=Integer.parseInt(t[1]);

//Queue<String> qA = new ArrayDeque<>();

//System.out.println(pre.toUpperCase());

long data=(long)K;

for(int i=0;i<N-1;i++){
data*=(long)(K-1);
}
System.out.println(data);
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
int main ()
{
	int a[3];
	for (int i=0; i<3; i++)
	{
		scanf ("%d", &a[i]);
	}
	if (a[0]==5&&a[1]==5&&a[2]==7||a[0]==5&&a[1]==7&&a[2]==5||a[0]==7&&a[1]==5&&a[2]==5)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const ll mod= 1e9+7;
long double PI = acosl(-1);
const ll infl = 1e17;
const int inf = 2e9+100;
const int nmax = 2e5+10;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

int h,w;
vector<string>s;

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

bool thikase(int i, int j){
    if(i<h and i>=0 and j<w and j>=0 and s[i][j]!='#') return true;
    return false;
}

int work(pii sorc){
    if(s[sorc.first][sorc.second]=='#') return 0;
    vector<vector<int> >d(h, vector<int>(w) );
    for(int i=0; i<h; i++) for(int j=0; j<w; j++) d[i][j] = inf;
    queue<pii>q;
    q.push(sorc);
    d[sorc.first][sorc.second] = 0;

    while(!q.empty()){
        pii u = q.front();
        q.pop();
        int i1 = u.first, j1= u.second;
        for(int k=0; k<4; k++){
            if(thikase(i1+dx[k], j1+dy[k]) and d[i1+dx[k]][j1+dy[k]] > d[i1][j1] + 1){
                q.push({i1+dx[k], j1+dy[k]}), d[i1+dx[k]][j1+dy[k]] = d[i1][j1] + 1;
            }
        }
    }
    int mx = 0;
    for(auto z : d) for(auto z1 : z) if(z1!=inf) mx=max(mx, z1);
    return mx;
}

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

    cin>>h>>w;
    s.resize(h);
    for(auto &z : s) cin>>z;

    int ret = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            ret = max(ret, work({i,j}));
        }
    }
    cout<<ret<<endl;

}


Measured memory_bytes: 256