akhauriyash/Code-Regression huggingface dataset:
const numberList = require('fs').readFileSync('/dev/stdin','utf8').trim().split(' ').map(e => parseInt(e))

const k = numberList[0]
const x = numberList[1]

blackStones = []


for(var i=x-k+1;i<x+k;i++) {
  i >= -1000000 && i<= 1000000 ? blackStones.push(i) : null
}

console.log(blackStones.join(' '))


Measured memory_bytes: 7372
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1000000007;
const int N = 2000010;
ll fact[N], invf[N];

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    x %= mod;
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(fact[n], invf[n-r]);
}

ll nCr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

void init_f(){
    fact[0] = 1;
    FOR(i,1,N-1){
        fact[i] = (fact[i-1] * i) % mod;
    }
    invf[N-1] = divll(1, fact[N-1]);
    FORR(i,N-1,1){
        invf[i-1] = (invf[i] * i) % mod;
    }
}

ll calc(ll r, ll c){
    if (r < 0) return 0;
    if (c < 0) return 0;
    ll ret = 0, x = 1;
    REP(i,r+c){
        x = (x * 2) % mod;
        if (i >= r) x = (x + mod - nCr(i, r)) % mod;
        if (i >= c) x = (x + mod - nCr(i, c)) % mod;
        ret = (ret + x) % mod;
    }
    return ret;
}

int main(void){
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    init_f();

    ll ans = calc(r2, c2) - calc(r2, c1 - 1) - calc(r1 - 1, c2) + calc(r1 - 1, c1 - 1);
    ans %= mod;
    ans = (ans + 2 * mod) % mod;
    cout << ans << endl;

    return 0;
}


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

using namespace std;

void solve()
{
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	long xs[x], ys[y], zs[z];
	for (int i = 0; i < x; i++) cin >> xs[i];
	for (int i = 0; i < y; i++) cin >> ys[i];
	for (int i = 0; i < z; i++) cin >> zs[i];
	long xys[x * y];
	for (int i = 0; i < x; i++)
		for (int j = 0; j < y; j++)
		{
			xys[i*y+j] = xs[i] + ys[j];
		}

	sort(xys, xys + x*y);
	sort(zs, zs + z);
	reverse(xys, xys + x*y);
	reverse(zs, zs + z);

	vector<long> ans;
	for (int i = 0; i < min(x*y, k); i++)
	{
		for (int j = 0; j < min(z, k - i); j++)
		{
			ans.push_back(xys[i] + zs[j]);
		}
	}
	sort(ans.rbegin(), ans.rend());
	for (int i = 0; i < k; i++)
	{
		cout << ans[i] << endl;
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 42852
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;


int main(){
  const string key = "keyence";
  string S; cin >> S;
  int k = S.size()-7;
  if (k == 0 && S == key) {cout << "YES" << endl; return 0;} 
  
  for(int i=0; i < S.size()-k+1 ; i++){
    string ans;
    ans = S.substr(0,i)+S.substr(i+k);
    if(ans == key) {cout << "YES" << endl; return 0;}
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<cstring>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;

int main() {
    char ch;
    int alpha[26];
    rep( i, 26 ) {
        alpha[i] = 0;
    }
    while ( scanf("%c", &ch) != EOF ){
        int num;
        ch = tolower(ch);
        num = ch - 'a';
        alpha[ num ]++;
    }
    rep ( i, 26 ) {
        printf("%c : %d\n", i + 'a', alpha[i]);
    }

    return 0;
}


Measured memory_bytes: 3224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
int main(){
    int n;
    double total1 = 0, total2 = 0, total3 = 0;
    double dist1, dist2, dist3, distc = 0;
    cin >> n;
    int x[n], y[n];
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    for(int i = 0; i < n; i++){
        cin >> y[i];
    }
    for(int i = 0; i < n; i++){
        total1 += abs(x[i] - y[i]);
        total2 += pow(abs(x[i] - y[i]), 2);
        total3 += pow(abs(x[i] - y[i]), 3);
        if(distc < abs(x[i] - y[i])){
            distc = abs(x[i] - y[i]);
        }
    }
    dist1 = total1;
    dist2 = sqrt(total2);
    dist3 = cbrt(total3);
    printf("%.6f\n", dist1);
    printf("%.6f\n", dist2);
    printf("%.6f\n", dist3);
    printf("%.6f\n", distc);
    return 0;
}


Measured memory_bytes: 3380
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[5], k, i, j;
    rep(i, 5) {
      cin >> a[i];
    }
    cin >> k;

    rep(i, 4) {
      FOR(j, i + 1, 5) {
        if (a[j] - a[i] > k) {
          cout << ":(\n";
          return 0;
        }
      }
    }

    cout << "Yay!\n";
    return 0;
}


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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll n, x, y;
    cin >> n >> x >> y;
    vector<vector<ll>> d(n + 1, vector<ll>(n + 1, INF));
    rep(i, 1, n + 1){
        rep(j, 1, n + 1){
            d[i][j] = abs(j - i);
        }
    }
    d[x][y] = 1;
    int i = x;
    rep(j, 1, n + 1){
        rep(k, 1, n + 1){
            d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
        }
    }
    i = y;
    rep(j, 1, n + 1){
        rep(k, 1, n + 1){
            d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
        }
    }
    vector<int> ans(n + 1);
    rep(i, 1, n + 1){
        rep(j, i, n + 1){
            ans[d[i][j]]++;
        }
    }
    rep(i, 1, n){
        cout << ans[i] << "\n";
    }
}


Measured memory_bytes: 31616
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
 
const long INF = (1l << 30);
const long LINF = (1l << 60);

long n;
long w[105];
long ans = LINF;

int main(){
	scanf("%ld", &n);
	for(int i = 0; i < n; i++){
		scanf("%ld", &w[i]);
	}
	for(int t = 0; t < n; t++){
		long s[2] = {0, 0};
		for(int i = 0; i < n; i++){
			if(i <= t){
				s[0]+=w[i];
			}else{
				s[1]+=w[i];
			}
		}
		//printf("%ld %ld %ld\n", t, s[0], s[1]);
		
		ans = std::min(ans, std::abs(s[0] - s[1]));
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll unsigned long long
#define f(a,b) for(int i=a;i<b;i++)
#define nitro cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define mod 1000000007
#define m (ll)1e20
using namespace std;
ll dp[200][100009];
ll solve(int weight[],int value[],int n,int w)
{
    if(n==0||w==0)
        return dp[n][w]=0;
    if(dp[n][w]!=-1)
        return dp[n][w];
    if(weight[n-1]>w)
        return dp[n][w]=solve(weight,value,n-1,w);
    else
        return dp[n][w]=max(value[n-1]+solve(weight,value,n-1,w-weight[n-1]),solve(weight,value,n-1,w));
}
int main()
{
    int n,w;
    cin>>n>>w;
    int arr[n],value[n];
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
        cin>>arr[i]>>value[i];
    cout<<solve(arr,value,n,w)<<endl;
}


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

class Program
{
    static void Main()
    {
        var ABC = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var K = int.Parse(ReadLine());

        var ans = ABC.Max() * (1 << K) + ABC.OrderBy(x => x).Take(2).Sum();

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


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

struct node{
    int right;
    int left;
    int parent;
};

typedef struct node Node;
#define NIL -1

Node T[25];

void preorder(int u){
    if(u==NIL)return;
    printf(" %d",u);
    preorder(T[u].left);
    preorder(T[u].right);
}

void inorder(int u){
    if(u==NIL)return;
    inorder(T[u].left);
    printf(" %d",u);
    inorder(T[u].right);
}

void postorder(int u){
    if(u==NIL)return;
    postorder(T[u].left);
    postorder(T[u].right);
    printf(" %d",u);
}



int main(){
    int n, i,id;
    int left,right;
    int root;
    scanf("%d",&n);
    for(i=0;i<n;i++)T[i].parent=NIL;
    for(i=0;i<n;i++){
        scanf("%d%d%d",&id,&left,&right);
        T[id].left=left;
        T[id].right=right;
        if(left!=NIL)T[left].parent=id;
        if(right!=NIL)T[right].parent=id;
    }
    for(i=0;i<n;i++)if(T[i].parent==NIL)root=i;
    printf("Preorder\n");
    preorder(root);
    printf("\nInorder\n");
    inorder(root);
    printf("\nPostorder\n");
    postorder(root);
    printf("\n");
    return 0;
}



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

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

	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if (i * j == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve(){
	while (true) {
		string s;
		cin >> s;
		if (s == "0") return;
		int dp[12] = {};
		int ans = 0;
		for (int i = 0; i < s.length(); ++i) {
			int new_dp[12] = {};
			REP(q, 11) {
				int hoge = q * 10 + s[i] - '0';
				new_dp[hoge % 11] += dp[q];
			}
			if (s[i] != '0') {
				new_dp[s[i] - '0']++;
			}
			ans += new_dp[0];
			REP(q, 11) {
				dp[q] = new_dp[q];
			}
		}
		cout << ans << endl;
	}
}

#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 3360
#include<stdio.h>

int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		int b,c,d;
		scanf("%d%d%d",&b,&c,&d);
		int max=b;
		if(b<c)max=c;
		if(max<d)max=d;
		if(max*max==b*b+c*c+d*d-max*max)printf("YES\n");
		else printf("NO\n");
	}
}



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

int main()
{
	int n;
	cin>>n;
	
	int x;
	for(int i=1;i<=9;i++){
		if((i-1)*111<n&&n<=i*111) x=i*111;
	}
	
	cout<<x<<endl;
	
	return 0;
}


Measured memory_bytes: 256
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main()
    {
        string[] beta = new string[600];

        string[] mark = new string[5];
        int[] num = new int[14];
        mark[0] = "S";
        mark[1] = "H";
        mark[2] = "C";
        mark[3] = "D";
        string[] card = new string[600];
        for (int i = 1; i < 14; i++)
        { num[i] = i; }

        ///52枚のカードの生成
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0; j < 13; j++)
            {
                int k = j + 1;
                if (i == 1)
                { card[j] = mark[0] + " " + k; }
                if (i == 2)
                { card[j + 13] = mark[1] + " " + k; }
                if (i == 3)
                { card[j + 26] = mark[2] + " " + k; }
                if (i == 0)
                { card[j + 13 + 26] = mark[3] + " " + k; }
            }
        }


        int alpha = int.Parse(Console.ReadLine());
        for (int i = 0; i < alpha; i++)
        {
            beta[i] = Console.ReadLine();

            for (int x = 0; x < 60; x++)
            {
                if (beta[i] == card[x])
                { card[x] = null; }
            }
        }




        for (int i = 0; i < 60; i++)
        {
            Console.Write(card[i]);
            if (card[i] != null)
            { Console.WriteLine(); }
        }
    }
}


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

using ll = long long int;
ll ar[51], n, a;
ll dp[51][51][2510];

ll rec( ll pos, ll cnt, ll sum ) {
    if( pos == n ) {
        if( !cnt ) return 0;
        if( sum % cnt ) return 0;
        else return ( sum / cnt ) == a;
    }
    ll &ret = dp[pos][cnt][sum];
    if( ~ret ) return ret;
    ret = rec( pos+1, cnt+1, sum+ar[pos] ) + rec( pos+1, cnt, sum );
    return ret;
}

int main() {
    #ifdef LU_SERIOUS
        freopen( "in.txt", "r", stdin );
    #endif // LU_SERIOUS
    while( cin >> n >> a ) {
        for( int i=0; i<n; i++ ) cin >> ar[i];
        memset( dp, -1, sizeof dp );
        cout << rec( 0, 0, 0 ) << "\n";
    }
    return 0;
}


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

typedef long long ll;

const int maxn = 200005;

vector<ll>aa, bb, cc;
int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm

    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    aa.resize(a), bb.resize(b), cc.resize(c);
    for( ll &i : aa )cin >> i;
    for( ll &i : bb )cin >> i;
    for( ll &i : cc )cin >> i;

    sort(aa.begin(), aa.end());
    reverse(aa.begin(), aa.end());
    sort(bb.begin(), bb.end());
    reverse(bb.begin(), bb.end());
    sort(cc.begin(), cc.end());
    reverse(cc.begin(), cc.end());

    priority_queue<ll, vector<ll>, greater<ll> >q;
    ll sol = 0;
    for( int i = 0; i < x; i++ )
        q.push(aa[i]), sol += aa[i];
    for( int i = 0; i < y; i++ )
        q.push(bb[i]), sol += bb[i];

    for( int i = 0; i < c; i++ ){
        if( q.empty() )break;
        ll v = q.top();
        if( v < cc[i] ){
            sol -= v;
            sol += cc[i];
            q.pop();
        }
    }

    cout << sol << "\n";
    return 0;
}


Measured memory_bytes: 4852
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();                   //マスの長さ0~nマスあるからn+1マスある
        int m = sc.nextInt();                   //料金所の個数
        int x = sc.nextInt();                   //現在地1~n-1
        List<Integer> cost = new ArrayList<>(); //料金所の位置
        int left = 0;                           //xより左にある料金所の数
        int right = 0;                          //xより右にある料金所の数

        //input
        for(int i = 0;i < m;i++){
            int num = sc.nextInt();
            cost.add(num);
        }

        for(int i = 1;i <= n;i++){
            int index = 0;
            if(i < x && cost.contains(i)){
                left++;
                index++;
            }else if(i > x && cost.contains(i)){
                right++;
                index++;
            }
        }
        System.out.println(Math.min(left,right));
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>

using namespace std;

int x[101];
int y[101];
int main(){
    int N;
    int M;
    int X;
    int Y;
    cin >> N >> M >> X >> Y;
    for(int i = 0; i < N; i++){
        cin >> x[i];
    }
    x[N] = X;
    for(int i = 0; i < M; i++){
        cin >> y[i];
    }
    y[M] = Y;
    if(*max_element(x, x + N + 1) < *min_element(y, y + M + 1)){
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
ll dp[10010][110][2] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string K;
    ll D;
    cin >> K >> D;
    dp[0][0][0] = 1;
    ll keta = K.size();
    rep(i,0,keta){
        ll v = K[i] - '0';
        rep(j,0,D){
            rep(mask,0,2){
                ll end = (mask ? 10 : v+1);
                rep(d,0,end){
                    dp[i+1][(j + d) % D][mask || d < v] += dp[i][j][mask] % MOD;
                    dp[i+1][(j + d) % D][mask || d < v] %= MOD;
                }
            }
        }
    }
    ll ans = (dp[keta][0][0] + dp[keta][0][1] - 1 + MOD) % MOD;
    print(ans);


    
}

Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 11111
int tra[111][111][111],tr2[111];
int nap[MAX];
int dp[111][111];
int main(){
  int s,t,u,n,o,d;
  cin>>s>>t>>u>>n>>o>>d;
  int e[t],c[t];
  for(int i=0;i<t;i++) cin>>e[i]>>c[i];
  int h[n],a[n];
  for(int i=0;i<n;i++) cin>>h[i]>>a[i];
  
 
  memset(nap,0,sizeof(nap));
  for(int i=0;i<n;i++){
    for(int j=a[i];j<MAX;j++){
      nap[j]=max(nap[j],nap[j-a[i]]+h[i]);
    }
  }
  
  //for(int i=1;i<MAX;i++) nap[i]=max(nap[i],nap[i-1]);
  
  //for(int j=0;j<MAX;j++) if(nap[j]) cout<<j<<" "<<nap[j]<<endl;
  
  memset(tra,-1,sizeof(tra));
  tra[0][0][0]=0;
  for(int i=0;i<t;i++){
    for(int j=0;j<=u;j++){
      for(int k=0;k<=s;k++){
	if(tra[i][j][k]<0) continue;
	tra[i+1][j][k]=max(tra[i+1][j][k],tra[i][j][k]);
	if(j+1<=u&&k+e[i]<=s) 
	  tra[i+1][j+1][k+e[i]]=max(tra[i+1][j+1][k+e[i]],tra[i][j][k]+c[i]);
      }
    }
  }
  
  for(int k=0;k<=s;k++) tr2[k]=tra[t][u][k];//,cout<<k<<" "<<tra[t][u][k]<<endl;

  memset(dp,-1,sizeof(dp));
  dp[0][s]=0;
  for(int i=0;i<d;i++){
    for(int j=0;j<=s;j++){
      if(dp[i][j]<0) continue;
      for(int k=0;k<=j;k++){
	if(tr2[k]<0) continue;
	dp[i+1][min(j-k+o,s)]=max(dp[i+1][min(j-k+o,s)],dp[i][j]+nap[tr2[k]]);
      }
    }
  }
  int ans=-1;
  for(int k=0;k<=s;k++) ans=max(ans,dp[d][k]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 8532
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#define ll long long
#define pb push_back
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1e9+10;
const ll llinf=1e16+10;
const int maxn=1e5+10;
const int maxm=1e5+10;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n,m;
struct node
{
    ll st,d;
    node(){st=d=0;}
}tree[maxm*4];
int op[maxn];
ll ans;
void add(int left,int right,ll x,int l,int r,int rt)
{
    if(left==l&&right==r)
    {
        tree[rt].st+=x;
        tree[rt].d++;
        return ;
    }
    if(left>right)
    {
        add(left,m,x,l,r,rt);
        add(1,right,m-left+1+x,l,r,rt);
    }
    else
    {
        int mid=(l+r)/2;
        if(left>=mid+1) add(left,right,x,mid+1,r,rt*2+1);
        else if(right<=mid) add(left,right,x,l,mid,rt*2);
        else
        {
            add(left,mid,x,l,mid,rt*2);
            add(mid+1,right,x+mid+1-left,mid+1,r,rt*2+1);
        }
    }
}
void refresh(int l,int r,int rt)
{
    if(l==r)
    {
        ans=max(ans,tree[rt].st);
        return ;
    }
    int mid=(l+r)/2;
    tree[rt*2].st+=tree[rt].st;
    tree[rt*2].d+=tree[rt].d;
    refresh(l,mid,rt*2);
    tree[rt*2+1].st+=tree[rt].st+tree[rt].d*(mid+1-l);
    tree[rt*2+1].d+=tree[rt].d;
    refresh(mid+1,r,rt*2+1);
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(~scanf("%d %d",&n,&m))
    {
        ans=0;
        for(int i=1;i<=n;i++)
            scanf("%d",&op[i]);
        for(int i=1;i<n;i++)
        {
            if((op[i]+1)%m==(op[i+1])%m)
              continue;
            if(op[i]+2>m)
                add((op[i]+2)%m,op[i+1],1,1,m,1);
            else add(op[i]+2,op[i+1],1,1,m,1);
        }
        refresh(1,m,1);
        ll sum=0;
        for(int i=1;i<n;i++)
        {
            sum+=((op[i+1]-op[i])%m+m)%m;
        }
        printf("%lld\n",sum-ans);
    }
    return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
using namespace std;
typedef tuple<int,int,int> T;
const int M = 256;

int main(){
    int N;
    while(cin>>N,N){
        vector<int> I(N);
        for(auto &i:I)cin>>i;
        double entropy = 1e20;
        int occur[M];
        T ans;
        for(int S=0;S<16;S++){
            for(int A=0;A<16;A++){
                for(int C=0;C<16;C++){
                    int R = S;
                    fill(occur,occur+M,0);
                    for(auto i:I){
                        R=(A*R+C)%M;
                        occur[(R+i)%M]++;
                    }
                    double H = 0;
                    sort(occur,occur+M);
                    for(int i=0;i<M;i++){
                        if(occur[i])H-=double(occur[i])/N*log(double(occur[i])/N);
                    }
                    if(entropy>H){
                        entropy=H;
                        ans=T(S,A,C);
                    }
                }
            }
        }
        int S,A,C;
        tie(S,A,C)=ans;
        cout<<S<<' '<<A<<' '<<C<<endl;
    }
    return 0;
}

Measured memory_bytes: 3300
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
int main() 
{ 
	ll n;
	cin>>n;
	ll a[n+1],b[n+1],c[n+1];
	for(ll i=1;i<=n;i++)
		cin>>a[i]>>b[i]>>c[i];
	ll dp[n+1][4];
	dp[1][1]=a[1];
	dp[1][2]=b[1];
	dp[1][3]=c[1]; 
	for(ll i=2;i<=n;i++)
	{
		dp[i][1]=a[i]+max(dp[i-1][2],dp[i-1][3]);
		dp[i][2]=b[i]+max(dp[i-1][1],dp[i-1][3]);
		dp[i][3]=c[i]+max(dp[i-1][2],dp[i-1][1]);
	}	
	cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
	return 0;

}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

//////////////////ここの値は必ず確認！！！！！////////////////////
//---------------------------------------------------------//
const int MOD = 1e9+7;
const int MAXR = 510000;
//---------------------------------------------------------//

template<ll mod> class modint{
public:
    ll val=0;
    //コンストラクタ
    modint(ll x=0){while(x<0)x+=mod;val=x%mod;}
    //コピーコンストラクタ
    modint(const modint &r){val=r.val;}
    //算術演算子
    modint operator -(){return modint(-val);} //単項
    modint operator +(const modint &r){return modint(*this)+=r;}
    modint operator -(const modint &r){return modint(*this)-=r;}
    modint operator *(const modint &r){return modint(*this)*=r;}
    modint operator /(const modint &r){return modint(*this)/=r;}
    //代入演算子
    modint &operator +=(const modint &r){
        val+=r.val;
        if(val>=mod)val-=mod;
        return *this;
    }
    modint &operator -=(const modint &r){
        if(val<r.val)val+=mod;
        val-=r.val;
        return *this;
    }
    modint &operator *=(const modint &r){
        val=val*r.val%mod;
        return *this;
    }
    modint &operator /=(const modint &r){
        ll a=r.val,b=mod,u=1,v=0;
        while(b){
            ll t=a/b;
            a-=t*b;swap(a,b);
            u-=t*v;swap(u,v);
        }
        val=val*u%mod;
        if(val<0)val+=mod;
        return *this;
    }
    //等価比較演算子
    bool operator ==(const modint& r){return this->val==r.val;}
    bool operator <(const modint& r){return this->val<r.val;}
    bool operator !=(const modint& r){return this->val!=r.val;}
};

using mint = modint<MOD>;

//入出力ストリーム
istream &operator >>(istream &is,mint& x){//xにconst付けない
    ll t;is >> t;
    x=t;
    return (is);
}
ostream &operator <<(ostream &os,const mint& x){
    return os<<x.val;
}

//累乗
mint modpow(const mint &a,ll n){
    if(n==0)return 1;
    mint t=modpow(a,n/2);
    t=t*t;
    if(n&1)t=t*a;
    return t;
}

//二項係数の計算
mint fac[MAXR+1],finv[MAXR+1],inv[MAXR+1];
//テーブルの作成
void com_init() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    FOR(i,2,MAXR){
        fac[i]=fac[i-1]*mint(i);
        inv[i]=-inv[MOD%i]*mint(MOD/i);
        finv[i]=finv[i-1]*inv[i];
    }
}
//演算部分
mint com(ll n,ll k){
    if(n<k)return 0;
    if(n<0)return 0;
    if(k==0) return 1;
    return fac[n]*finv[k]*finv[n-k];
}

int main() {
    com_init();
    int H,W,A,B; cin >> H >> W >> A >> B;
    mint ans = 0;
    REP(i,H-A){
        ans += com(i+B-1,i)*com(W-B-1+H-i-1, H-i-1);
    }
    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 15600
import java.lang.reflect.Array;
import java.util.*;

public class Main {

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

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        Arrays.sort(arr);

        int distance = arr[arr.length-1] - arr[0];
        System.out.println(distance);
    }
}


Measured memory_bytes: 21972
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;

import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;

public class Main {
    static final Scanner sc = new Scanner(System.in);
    
    public static void main(String[] args) {
        int N = nint();
        int T = nint();
        int[] A = nints(N);
        
        int min = Integer.MAX_VALUE;
        int[] profit = new int[N];
        
        for (int i = 0; i < N; i++) {
            min = Math.min(min, A[i]);
            profit[i] = A[i] - min;
        }
        
        Map<Integer, Long> map = Arrays.stream(profit).boxed().collect(groupingBy(i -> i, counting()));
        Long ans = map.entrySet().stream().reduce((e1, e2) -> e1.getKey() > e2.getKey() ? e1 : e2).get().getValue();
        System.out.println(ans);
    }
    
    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

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

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

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0);
    }

    private static char[][] nchars2(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}

Measured memory_bytes: 60224
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
#define MOD 1000000007
int n,m;
int a[100100],b[100100];
set<int> s;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		s.insert(a[i]);
	}
	scanf("%d",&m);
	int ans = 0;
	for(int i=0;i<m;i++){
		scanf("%d",&b[i]);
		if(s.find(b[i])!=s.end())ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
const double pi = acos(-1);
const int sz = 200002;
int n, m, q, k;
ll xorAllEle(vector<ll>a) 
{ 
  ll ans = 0;
  for(ll i = 0; i<n; i++) ans ^= a[i];
  return ans;
} 
int main() {
	io
	cin>>n;
	vector<ll>a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
    ll all = xorAllEle(a);
	for(int i = 0; i<n; i++) {
		ll x = all^a[i];
		cout<<x<<' ';
	}
}


Measured memory_bytes: 6336
//
//  main.cpp
//  switches
//
//  Created by Dong Truong on 5/31/19.
//  Copyright © 2019 Dong Truong. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <vector>

using namespace std;

int n,m,p[11],kq,d[11];
vector <int> g[11];

void nhap()
{
    cin>>n>>m;
    for (int i=1;i<=m;++i)
    {
        int k;cin>>k;
        for (int j=1;j<=k;++j)
        {
            int x;cin>>x;
            g[i].push_back(x);
        }
    }
    for (int i=1;i<=m;++i) cin>>p[i];
}
void check()
{
    for (int i=1;i<=m;++i)
    {
        int o=0;
        for (int j=0;j<g[i].size();++j)
            if (d[g[i][j]]==1) ++o;
        if (o%2!=p[i]) return;
    }
    ++kq;
}
void backtrack(int x)
{
    for (int i=0;i<=1;++i)
    {
        d[x]=i;
        if (x==n)
        {
            check();
        }
        else backtrack(x+1);
    }
}
int main(int argc, const char * argv[]) {
    // insert code here...
    //std::cout << "Hello, World!\n";
    //freopen("a.inp","r",stdin);
    nhap();
    backtrack(1);
    cout<<kq;
    return 0;
}


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

int main(){
  int N, K;
  cin>>N>>K;
  
  vector<int> p(N);
  rep(i, N){
    cin>>p.at(i);
  }
  sort(p.begin(), p.end());
  
  int ans=0;
  rep(i, K){
    ans+=p.at(i);
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];
int p=0;
bool prim[maxii];

void prime()
{
    for(int i=3;i*i<=maxii;i+=2)
    {
        if(prim[i]==false)
        {
            for(int j=i*i;j<=maxii;j+=i+i)
            {
                prim[j]=true;
            }
        }
    }
    arr[3]=1;
    for(int i=3;i<=maxii;i+=2)
    {
        int x=(i+1)/2;
        //cout<<i<<" "<<x<<endl;
        if(prim[i]==false && prim[x]==false && x%2!=0 )
        {
            arr[i]=1;
        }
    }

}

int main()
{
    prime();
    for(int i=1;i<=maxii;i++)
    {
        arr[i]=arr[i]+arr[i-1];
        //cout<<arr[i]<<" "<<i<<endl;
    }
    int q;
    sc(q)
    for(int i=1;i<=q;i++)
    {
        int x,y;
        sc(x)
        sc(y)
        pf(arr[y]-arr[x-1]);
    }

}







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

typedef long long ll;

int main(){
    ll a, b, c;
    scanf("%lld%lld%lld", &a, &b, &c);
    if(a+b>=c)
        printf("%lld\n",b+c);
    else
        printf("%lld\n",b*2+a+1);

     return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<ctime>
#include<climits>
#include<queue>
#include<fstream>
#include<deque>
#include<iomanip>
#include<list>
#include<stack>
#include<sstream>
#include<string>
#include<cctype>
#include<cstdio>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-10
#define F first
#define S second
#define all(n) n.begin(),n.end()
#define pb push_back
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define INF (1<<27)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const int dx[4] = {-1,0,+1,0};
const int dy[4] = {0,-1,0,+1};

class Solve{
private:
  int d;
  int imap[110][110];
public:

  Solve(int n):d(n){}
  ~Solve(){}

  int Connect(P p){
    int cnt = 0;
    rep(i,4){
      int nx = p.F+dx[i],ny = p.S+dy[i];
      if(!(0<=nx && nx <d && 0<= ny && ny < d))continue;
      if(imap[ny][nx] == 1)cnt++;
    }
    return cnt;
  }


  void display(){
      cout << "--- in display ---" << endl;
      rep(i,d){
	rep(j,d){
	  if(imap[i][j] == 1)cout << '#';
	  else cout << ' ';
	}
	cout << endl;
      }
      cout << endl;
    }


  void run(){
    rep(i,d+1)rep(j,d+1)imap[i][j] = 0;

    rep(i,d){
      imap[0][i] = 1;
      imap[i][0] = 1;
      imap[i][d-1] = 1;
    }

  


    P pos = P(d-1,d-1);
    int dir = 0;
    int cnt = 0;
    bool fin = false;
    while(true){

      int nx,ny;
      nx  = pos.F,ny = pos.S;
      while(true){
	//cout << "nx = " << nx << ",ny = "<< ny << ",dir = " << dir << endl;
	//display();


	if(!(Connect(P(nx,ny)) == 2 || Connect(P(nx,ny)) == 1)){
	  imap[ny-dy[dir]][nx-dx[dir]] = 0;
	  //cout << "Lase nx = " << nx << ",ny = "<< ny << endl;
	  //cout << "FIN! connnect = " << Connect(P(nx,ny)) << endl;
	  fin = true;
	  break;
	}

	if(imap[ny+dy[dir]][nx+dx[dir]] == 1){
	  //cout << "IN nx = " << nx+dx[dir] << ",ny = " << ny+dy[dir] << endl;
	  imap[ny][nx] = 0;
	  cnt--;
	  break;
	}
	imap[ny][nx] = 1;
	cnt++;	


	nx += dx[dir],ny += dy[dir];
      }
      //cout << "------ cnt = " << cnt << endl;
      if(fin){
	//cout << "dir = " << dir << endl;
	break;
      }
      if(cnt == 0)break;
      cnt =0;

      pos.F = nx-dx[dir],pos.S = ny-dy[dir];
      dir++;
      dir = dir%4;
    }

    rep(i,d){
      rep(j,d){
	if(imap[i][j] == 1)cout << '#';
	else cout << ' ';
      }
      cout << endl;
    }
    

  }


};


int main(){
  int T;
  cin >> T;
  while(T-- > 0){
    int _n;
    cin >> _n;
    Solve ans = Solve(_n);
    ans.run();
    if(T != 0)cout << endl;
  }
return 0;
}

Measured memory_bytes: 1200
n,*t=map(int,open(0).read().split())
c=sorted(t[-n:])
q=[1]
f=q*n
e=[[]for _ in f+q]
for a,b in zip(t[:-n:2],t[1:-n:2]):e[a]+=b,;e[b]+=a,
while q:v=q.pop();n-=1;f[v-1]=c[n];q+=[w for w in e[v]if f[w-1]<2]
print(sum(c[:-1]),*f)

Measured memory_bytes: 6752
N, M = [int(_) for _ in input().split()]

MOD = 10**9+7

def factorize(n):
    from math import sqrt
    m = int(sqrt(n)) + 1
    p = [True] * m
    result = {}
    for x in range(2, m):
        if p[x]:
            p[x * 2::x] = [False] * ((m - 1) // x - 1)
            i = 0
            while 1:
                d, q = divmod(n, x)
                if q == 0:
                    n = d
                    i += 1
                    result[x] = i
                else:
                    break
    if n > 1:
        result[n] = 1
    return result

def C(x, y):
    r = 1
    s = 1
    for i in range(y):
        r *= (x - i)
    for i in range(y):
        s *= (i + 1)
    return (r // s) % MOD

result = 1

for x in factorize(M).values():
    result = result * C(N + x - 1, x) % MOD

print(result)


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)

using namespace std;

long int gcd(long int a, long int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

long int lcm(long int a, long int b)
{
    return a * b / gcd(a, b);
}

int main()
{
    int a, b;
    cin >> a >> b;

    cout << lcm(a, b) << endl;
}

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

int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
 
int main(){
  string N; cin >> N;
  int n=stoi(N);
  int k=N.size();
  vector<int> MY(k);
  for(int i=0;i<k;i++){
    MY.at(i)=ctoi(N.at(i));
  }
  int sora=0;
  for (int i=0;i<k;i++){
    sora+=MY.at(i);
  }
  if(n%sora==0){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m ;
  cin >> n >> m ;
  cout << n*(n-1)/2 + m*(m-1)/2 <<endl ;
  
  
  
  return 0 ;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 3e2+10;
const ll INF = 1e18;
const ll M = 998244353;

ll cnt1,cnt2,cnt3;
double dp[MAX][MAX][MAX];

int main()
{
    ll n,i,j,k,l,p,q,x,y;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> l;
        if(l==1)
            cnt1++;
        else if(l==2)
            cnt2++;
        else
            cnt3++;
    }
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n;j++)
        {
            for(k=0;k<=n;k++)
            {
                l = i+j+k;
                if(l==0 or l>n)
                    continue;
                dp[i][j][k] += (1.0*n)/l;
                if(k>0)
                    dp[i][j][k] += (((1.0*k)/l)*dp[i][j][k-1]);
                if(j>0)
                    dp[i][j][k] += (((1.0*j)/l)*dp[i][j-1][k+1]);
                if(i>0)
                    dp[i][j][k] += (((1.0*i)/l)*dp[i-1][j+1][k]);
            }
        }
    }
    cout << setprecision(15) << dp[cnt3][cnt2][cnt1];
}

Measured memory_bytes: 114328
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(M)]

import sys
sys.setrecursionlimit(10**8)
class Scc:
    def __init__(self,n):
        self.n = n
        self.edges = []

    def add_edge(self,fr,to):
        assert 0 <= fr < self.n
        assert 0 <= to < self.n
        self.edges.append((fr, to))

    def scc(self):
        csr_start = [0] * (self.n + 1)
        csr_elist = [0] * len(self.edges)
        for fr,to in self.edges:
            csr_start[fr + 1] += 1
        for i in range(1,self.n+1):
            csr_start[i] += csr_start[i-1]
        counter = csr_start[:]
        for fr,to in self.edges:
            csr_elist[counter[fr]] = to
            counter[fr] += 1

        self.now_ord = self.group_num = 0
        self.visited = []
        self.low = [0] * self.n
        self.ord = [-1] * self.n
        self.ids = [0] * self.n
        def _dfs(v):
            self.low[v] = self.ord[v] = self.now_ord
            self.now_ord += 1
            self.visited.append(v)
            for i in range(csr_start[v], csr_start[v+1]):
                to = csr_elist[i]
                if self.ord[to] == -1:
                    _dfs(to)
                    self.low[v] = min(self.low[v], self.low[to])
                else:
                    self.low[v] = min(self.low[v], self.ord[to])
            if self.low[v] == self.ord[v]:
                while 1:
                    u = self.visited.pop()
                    self.ord[u] = self.n
                    self.ids[u] = self.group_num
                    if u==v: break
                self.group_num += 1
        for i in range(self.n):
            if self.ord[i] == -1: _dfs(i)
        for i in range(self.n):
            self.ids[i] = self.group_num - 1 - self.ids[i]

        groups = [[] for _ in range(self.group_num)]
        for i in range(self.n):
            groups[self.ids[i]].append(i)
        return groups

scc = Scc(N)
for a,b in AB:
    scc.add_edge(a,b)
ans = scc.scc()
print(len(ans))
for row in ans:
    print(*[len(row)] + row)

Measured memory_bytes: 260676
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int N;
    cin >> N;
    vector<int> f(N + 1, 0);
    for (int x = 1; x * x <= N; x++) {
        for (int y = 1; y * y <= N; y++) {
            for (int z = 1; z * z <= N; z++) {
                if (x * x + y * y + z * z + x * y + y * z + z * x <= N) {
                    f[x * x + y * y + z * z + x * y + y * z + z * x]++;
                }
            }
        }
    }
    for (int i = 1; i <= N; i++) {
        cout << f[i] << endl;
    }
    
    return 0;
}

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

int asc(const void* a, const void* b) {
    return *(int*)b - *(int*)a;
}
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    if (n == m) printf("Yes");
    else printf("No");
}


Measured memory_bytes: 128
#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	int n,a,b,c;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i = 0; i < n; i++){
			scanf("%d %d %d",&a,&b,&c);
			if(a == 100 || b == 100 || c == 100 || a + b >= 180 || a+b+c >= 240){
				printf("A\n");
			}else if((a + b + c >= 210) || (a+b+c>=150 && (a >= 80 || b >= 80))){
				printf("B\n");
			}else{
				printf("C\n");
			}
		}

	}
    return 0;
}



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

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

  vector<int> W(N);
  for (int i = 0; i < N; i++) {
    cin >> W.at(i);
  }

  int minimun = 100000;
  for (int i = 0; i < N - 1; i++) {
    int s1 = 0, s2 = 0;
    for (int j = 0; j <= i; j++) {
      s1 += W.at(j);
    }
    for (int j = i + 1; j < N; j++) {
      s2 += W.at(j);
    }
    minimun = min(minimun, abs(s1 - s2));
  }
  cout << minimun << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
sum=0
for i in range(n):
    sum+=b[a[i]-1]
    if i>=1 and a[i]==a[i-1]+1 and i<=len(c):
        sum+=c[a[i-1]-1]
print(sum)

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

struct pos {
  int x;
  int y;
};

int getpq(int N, vector<pos> P) {
  int p, q;
  int sum, minsum = 100, cnt;
  for (int i = 0; i < N; i++) {
    for (int j = 0; i < N; i++) {
      p =P.at(i).x - P.at(j).x;
      q =P.at(i).y - P.at(j).y;
      if (p==0 && q==0) continue;
      sum = N;
      for (int k = 0; k < N; k++) {
        for (int l = 0; l < N; l++) {
          if ((P.at(k).x - P.at(l).x) == p && (P.at(k).y - P.at(l).y) == q) {
            sum--;
          }
        }
      }
      minsum = min(minsum, sum);
    }
  }
  return minsum;
}
 
int main() {
  int N;
  cin >> N;
  vector<pos> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i).x >> p.at(i).y;
  }

  int ans;
  if (N == 1) {
    ans = 1;
  } else {
    ans = getpq(N,p);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256