akhauriyash/Code-Regression huggingface dataset:
//C - Train Ticket:  
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    string s;
    int a, b, c, d;
    cin >> s;
    a = s[0] - '0';
    b = s[1] - '0';
    c = s[2] - '0';
    d = s[3] - '0';
    if(a + b + c + d == 7) {
        printf("%d+%d+%d+%d=7\n", a, b, c, d);
    } else if(a + b + c - d == 7) {
        printf("%d+%d+%d-%d=7\n", a, b, c, d);
    } else if(a + b - c + d == 7) {
        printf("%d+%d-%d+%d=7\n", a, b, c, d);
    } else if(a - b + c + d == 7) {
        printf("%d-%d+%d+%d=7\n", a, b, c, d);
    } else if(a + b - c - d == 7) {
        printf("%d+%d-%d-%d=7\n", a, b, c, d);
    } else if(a - b - c + d == 7) {
        printf("%d-%d-%d+%d=7\n", a, b, c, d);
    } else if(a - b + c - d == 7) {
        printf("%d-%d+%d-%d=7\n", a, b, c, d);
    } else if(a - b - c - d == 7) {
        printf("%d-%d-%d-%d=7\n", a, b, c, d);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
const int N = 1e5+7;

string s;
ll k;

int main(){

  cin >> s >> k;

  if(s[0] != '1'){
    cout << s[0] << endl;
    return 0;
  }

  int p;
  REP(i,s.size()){
    if(s[i] != '1'){
      p = i+1;
      break;
    }
  }
  if(k < p) cout << s[0] << endl;
  else cout << s[p-1] << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();
    if (k <= a+b){
      System.out.println(Math.min(a,k));
    }
    else{
      System.out.println(a-(k-(a+b)));
    }
  }

}

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

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

  int ans;
  if(n>=10){
    ans=r;}
  else{
    ans=r+100*(10-n);}

  printf("%d\n",ans);

  return 0;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vint a(N);
  rep(i, N) cin >> a[i];
  map<int, int> mp;
  rep(i, N) mp[a[i]]++;
  int ans = 0;
  rep(i, N) {
    chmax(ans, mp[a[i]-1]+mp[a[i]]+mp[a[i]+1]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7040
n, k = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = n  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans = 0
for i in range(k-1, n):
    ko = (a[i]*cmb(i,k-1,p))%p
    ans = (ans + ko )%p
#print(ans)

for i in range(n-k+1):
    #print(a[i], cmb(n-i-1,k-1,p))

    ko = (a[i] * cmb(n-i-1,k-1,p) )%p
    ans = (ans - ko )%p

print(ans)

Measured memory_bytes: 78248
/*  */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000")

#define sti				set<int>
#define stpii			set<pair<int, int> >
#define mpii			map<int,int>
#define vi				vector<int>
#define pii				pair<int,int>
#define vpii			vector<pair<int,int> >
#define rep(i, a, n) 	for (int i=a;i<n;++i)
#define per(i, a, n) 	for (int i=n-1;i>=a;--i)
#define clr				clear
#define pb 				push_back
#define mp 				make_pair
#define fir				first
#define sec				second
#define all(x) 			(x).begin(),(x).end()
#define SZ(x) 			((int)(x).size())
#define lson			l, mid, rt<<1
#define rson			mid+1, r, rt<<1|1
#define getBits(x)		__builtin_popcount(x)
#define getBitIdx(x)	__builtin_ffs(x)

typedef long long LL;
const int maxn = 1005;
const int mod = 1e9+7;
bool visit[maxn];
int a[maxn], na = 0;
int C[maxn];
LL dp[maxn];

void init() {
	memset(visit, true, sizeof(visit));
	visit[0] = visit[1] = false;
	a[na++] = 1;
	for (int i=2; i<maxn; ++i) {
		if (visit[i]) {
			a[na++] = i;
			for (int j=i+i; j<maxn; j+=i)
				visit[j] = true;
		}
	}
}

inline int getId(int x) {
	return lower_bound(a, a+na, x) - a;
}

void solve(int n) {
	if (n == 1) {
		puts("1");
		return ;
	}
	
	for (int i=2; i<=n; ++i) {
		int x = i;
		for (int j=2; j*j<=x; ++j) {
			if (x%j == 0) {
				int id = getId(j);
				while (x%j == 0) {
					x /= j;
					++C[id];
				}
			}
		}
		if (x > 1) {
			int id = getId(x);
			++C[id];
		}
	}
	
	dp[0] = 1;
	for (int i=1; i<na; ++i) {
		// if (C[i] == 0) {
			// dp[i] = dp[i-1];
			// continue;
		// }
		
		dp[i] = dp[i-1] * (1 + C[i]) % mod;
	}
	
	LL ans = dp[na-1];
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// #ifndef ONLINE_JUDGE
		// freopen("data.in", "r", stdin);
		// freopen("data.out", "w", stdout);
	// #endif
	
	int n;
	
	init();
	cin >> n;
	solve(n);
	
	// #ifndef ONLINE_JUDGE
		// printf("time = %ldms.\n", clock());
	// #endif
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int i, j;
  for(i = 1; i <= 9; i++)
  {
    for(j = 1; j <= 9; j++)
    {
      printf("%dx%d=%d\n", i, j, i * j);
    }
  }
  return 0;
}


Measured memory_bytes: 2668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int a; cin >> a;
	rep1(i,10000){
		if(i*a%360 == 0){
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,i,mod=1e9+7,ans=0;
  cin>>n;
  vector<int64_t> a(n),b(n);
  for(i=0;i<n;i++) cin>>a.at(i);
  b.at(n-1)=a.at(n-1);
  for(i=n-2;i>=0;i--) b.at(i)=(a.at(i)+b.at(i+1))%mod;
  for(i=0;i<n-1;i++) ans=(ans+a.at(i)*b.at(i+1)%mod)%mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 6416
#include <algorithm>
#include <bitset>
#include <complex>
#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>
#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>
using namespace std;
using ll = long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod = 1e9 + 7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
#define INF 1e+9
#define P pair<int, int>;
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main()
{
	string s, t;
	cin >> s >> t;
	sort(all(s));
	sort(all(t));
	reverse(all(t));
	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


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

int main(){
  long long a,b,c,k;
  cin>>a>>b>>c>>k;
  if(a>=k){
  cout<<k<<endl;
  }
  else if(a+b>=k){
  cout<<a<<endl;
  }
  else{
  cout<<a-(k-a-b)<<endl;
  }
}

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

const ll INF = 1LL << 60;

ll h[100010];

ll dp[100010];

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

    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    dp[0] = 0;

    
    for (int i = 0; i < N; ++i) {
        chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }

    cout << dp[N-1] << endl;
}

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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define prll(v) for (auto i: v) cout << i << " ";

int main() {
    fast
    ll n, k, v;
    cin >> n >> k;
    ll a = 0;
    REP(i, 0, n) {
        cin >> v;
        if (v >= k)
            a++;
    }
    cout << a << endl;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    double x[n],y[n];
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i];
    }
    double sum = 0;
    int den = 1;
    for(int i=0;i<n;i++){
        den = den*(i+1);
        for(int j=0;j<n;j++){
            if(j==i)
                continue;
            double dist = (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);
            dist = sqrt(dist);
            sum += dist;
        }
    }
    cout << fixed << setprecision(6) << sum/n;
}

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

int main(void){
  char A[3],B[3];
  int c=0;
  for(int i = 0;i<3;i++){
    cin >> A[i];
  }
  for(int i = 0;i<3;i++){
    cin >> B[i];
  }
  for(int i = 0;i<3;i++){
    if(A[i] == B[i]){
      c++;
    }
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right; sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

m, k = wi()

if 2 ** m < k:
    print(-1)
elif k == 0:
    for i in range(2 ** m):
        for j in range(2):
            ansli.append(i)
    for i in range(len(ansli)):
        print(ansli[i], "", end="")
else:
    for i in range(2 ** m):
        if i != k:
            tmp ^= i
    if tmp == k:
        ansli.append(k)
        for i in range(2 ** m):
            if i != k:
                ansli.append(i)
        ansli.append(k)
        for i in range(2 ** m - 1, -1, -1):
            if i != k:
                ansli.append(i)
        for i in range(len(ansli)):
            print(ansli[i],"",end="")
    else:
        print(-1)

Measured memory_bytes: 18000
#include <iostream>
using namespace std;
int main(void){
	int n,a,b,c;
	cin>>n;
	for (;n--;){
		cin>>a>>b>>c;
		if (a>b) swap(a,b);
		if (b>c) swap(b,c);
		if (a*a+b*b==c*c)
			cout<<"YES\n";
		else
			cout<<"NO\n";
	}
}

Measured memory_bytes: 1120
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll h[n];
    for(int i=0;i<n;i++){
    	cin >> h[i];
    }
    ll num = 0, ans = 0;
    for(int i=1;i<n;i++){
    	if(h[i-1] >= h[i]){
    		num++, ans = max(ans, num);
    	}
    	else{
    		num = 0;
    	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef 	long long 							ll;
#define		mod									1000000007
#define 	ppi 								pair<ll,ll>
#define 	all(v) 								v.begin(),v.end()
#define 	prq									priority_queue
#define 	vi 									vector<ll>
#define     vip									vector<ppi>
#define 	forn(i,a,b)  						for(i=a;i<b;i++)
#define 	ford(i,a,b)   						for(i=a;i>b;i--)
#define 	endl 								"\n";
#define 	p_b 								push_back
#define 	m_p 								make_pair
#define     umap								unordered_map<ll,ll>
#define     uset                                unordered_set<ll>
#define     Stack								stack<ll>
#define     Queue								queue<ll>
#define     F									first
#define     S 									second				
void print1D(vector<ll> &v)
{
	cout<<"Debug Array:  ";
	for(ll i=0;i<v.size();i++)
 	   cout<<v[i]<<" ";
	cout<<"-----------------------------\n"; 
}

void print2D(vector<vector<ll>> &v)
{
	cout<<"Debug2d: ";
	ll n = v.size(),m=v[0].size();
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<n;j++)
		{
			cout<<v[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<"--------------------------------------\n";
}

void printS(string &s)
{
	ll l=s.length(),i;
	cout<<"String: ";
	for(i=0;i<l;i++)
	{
		cout<<s[i];
	}
	cout<<"\n---------------------------------------\n";
}

void vectorInput(vector<ll> &v)
{
	ll n=v.size();
	for(ll i=0;i<n;i++){
	   cin>>v[i];
   }
}

void pairInput(vector<ppi> &vp)
{
	ll n = vp.size(),i,j,k;
	for(i=0;i<n;i++)
	{
		cin>>vp[i].F>>vp[i].S;
	}
}

void swap(ll &a,ll &b)
{
	ll t=a;
	a=b;
	b=t;
}

void sol()
{
	
	ll i,j,k,n,m,ans=0,d;
	cin>>n>>d;
	vip vp(n);
	pairInput(vp);
	for(i=0;i<n;i++)
	{
		ll x = vp[i].first;
		ll y = vp[i].S;
	//	cout<<x*x+y*y<<" ";
		if(x*x+y*y<=d*d)
		{
			ans++;
		}
	}
	cout<<ans;
}

/*<----------------------------------------------------------------------------------------------------------------------------------------------->*/

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
	ll test=1;
//	cin>>test;
	while(test--)
	{
		sol();
		
	}
}

Measured memory_bytes: 6348
#include<iostream>
using namespace std;
 
int Merge(int A[],int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int i,j,k;
  int L[n1+1],R[n2+1];
   
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1]=1000000001;
  R[n2]=1000000001;
   
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }else{
      A[k]=R[j];
      j++;
    }
  }
  return right-left;
}
 
int Merge_Sort(int A[],int left,int right){
  int mid,res=0;
  if(left+1<right){
    mid=(left+right)/2;
 
    res+=Merge_Sort(A,left,mid);
    res+=Merge_Sort(A,mid,right);
    res+=Merge(A,left,mid,right);
     
  }
  return res;
}
 
int main(){
  int i,x,n,S[500000]; 
  cin>>n;
  for(i=0;i<n;i++)cin>>S[i];
 
  x=Merge_Sort(S,0,n);
   
  for(i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<S[i];
  }
  cout<<endl;
  cout<<x<<endl;
  return 0;
}

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

int main(){
    long long N, K, ans=0;
    cin >> N >> K;
    if(K%2==0)
	ans = pow(N/K, 3)+pow(N/(K/2)-N/K, 3);
    else
	ans = pow(N/K, 3);
    cout << ans <<endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int mini = INF;
    for (int z = 0; z <= max(X, Y) * 2; z += 2)
    {
        int x_price = (X - (z / 2)) * A;
        int y_price = (Y - (z / 2)) * B;
        if (x_price < 0)
            x_price = 0;
        if (y_price < 0)
            y_price = 0;
        int total = x_price + y_price + (z * C);
        mini = min(mini, total);
    }
    cout << mini << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11,mod=1e9+7;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
class DisjSet { 
    int *parent, n,*sze; 
public: 
    DisjSet(int n) 
    { 
        parent = new int[n]; 
        sze=new int [n];
        this->n = n; 
        makeSet(); 
    } 
    void makeSet() 
    { 
        for (int i = 0; i < n; i++) 
        { 
            parent[i] = i; sze[i]=1;
        } 
    } 
    int find(int x) 
    { 
        if (parent[x] != x) { 
            parent[x] = find(parent[x]); 
        } 
        return parent[x]; 
    } 
    int getsize(int x)
    {
        return sze[find(x)];
    }
    void Union(int x, int y) 
    { 
        int xset = find(x); 
        int yset = find(y); 
        if (xset == yset) 
            return; 
        if (sze[xset] < sze[yset])
       { 
            parent[xset] = yset; 
            sze[yset]+=sze[xset];
        } 
        else if (sze[xset] > sze[yset])
       { 
            parent[yset] = xset; 
            sze[xset]+=sze[yset];
        } 
        else 
        { 
            parent[yset] = xset; 
            sze[xset]+=sze[yset];
        } 
    } 
}; 
void sol(void)
{
cin>>n>>m;
DisjSet f(n+1);
while(m--)
{
    cin>>a>>b;
    f.Union(a,b);
}
int mx=0;
for(int i=1;i<=n;i++)
{
  mx=max(mx,f.getsize(i));
}
cout<<mx;
return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    sol();
}


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

int main() {
    int n;
    cin >> n;
    string ans = "";
    REP(i,n) ans += "ACL";
    cout<< ans << endl;

    return 0;
}


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

int p[10][10], x, y, s, md;

bool inpaper(int x, int y){
    return x >= 0 && x < 10 && y >= 0 && y < 10;
}

void drop(int x, int y, int s){
    int i, j;
    if( s == 1 ){
        for(i = -1; i <= 1; i++){
            for(j = -1; j <= 1;  j++){
                if( inpaper(x+i, y+j) &&
                    i + j >= -1 && i + j <= 1 &&
                    i - j >= -1 && i - j <= 1 ){
                    p[x+i][y+j]++;
                    if(p[x+i][y+j] > md) md = p[x+i][y+j];
                }
            }
        }
    }else if( s == 2 ){
        for(i = -1; i <= 1; i++){
            for(j = -1; j <= 1; j++){
                if( inpaper(x+i, y+j) ){
                    p[x+i][y+j]++;
                    if(p[x+i][y+j] > md) md = p[x+i][y+j];
                }
            }
        }
    }else{
        for(i = -2; i <= 2; i++){
            for(j = -2; j <= 2; j++){
                if( inpaper(x+i, y+j) && 
                    i+j >= -2 && i+j <= 2 &&
                    i-j >= -2 && i-j <= 2){
                    p[x+i][y+j]++;
                    if(p[x+i][y+j] > md) md = p[x+i][y+j];
                }
            }
        }
    }
}

int main(){
    md = 0;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10;j++){
            p[i][j] = 0;
        }
    }
    while( scanf("%d,%d,%d", &x, &y, &s) != EOF ){
        drop(x, y, s);
    }
    int empt = 0;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10;j++){
            empt += p[i][j]?0:1;
        }
    }
    printf("%d\n%d\n", empt, md);
    
    return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;

int main(){
    int n,m;
    std::cin >>n>> m;
    std::vector<int> l(m),r(m);
    rep(i,m)std::cin >> l[i]>>r[i];
    int a=0,b=INF;
    rep(i,m){
        a=max(a,l[i]);
        b=min(b,r[i]);
    }
    
    std::cout << max(0,b-a+1) << std::endl;
}

Measured memory_bytes: 1024
import sys
def input(): return sys.stdin.readline().strip()

def main():
    N, T = map(int, input().split())
    cv = [tuple(map(int, input().split())) for _ in range(N)]
    cv = sorted(cv, key=lambda x : x[0])

    dp = [[0]*(T+1) for _ in range(N+1)]
    dp_ext = [[0]*(T+1) for _ in range(N+1)]

    values = [v for c, v in cv]
    max_values = [max(values[i:]) for i in range(N)]
    # 貰うdp
    for i in range(N):
        cost, value = cv[i]
        for now in range(cost, T+1):
            old = now - cost
            dp[i+1][now] = max(dp[i][now], dp[i][old] + value)

        for j in range(1, T+1):
            dp[i+1][j] = max(dp[i+1][j], dp[i+1][j-1])
        
        for j in range(1, T+1):
            dp_ext[i+1][j] = max(dp[i+1][j], dp[i][j-1] + max_values[i], dp_ext[i][j])

    print(dp_ext[N][T])

if __name__ == "__main__":
    main()

Measured memory_bytes: 177416
#include<iostream>
using namespace std;
int main()
{
  int H, W;
  cin >> H >> W;
  while(H!=0 && W!=0)
  {
  for(int i=0;i<H;i++)
  {
        for(int j=0;j<W;j++)
        {
        cout << "#";
        }
        cout << endl;
  }
  cout << endl;
  cin >> H >> W;
  }
   return 0;
  }



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

class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader in = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(in);
		
		String[] buf = (br.readLine()).split(" ");
		int n = Integer.parseInt(buf[0]);
		int m = Integer.parseInt(buf[1]);
		
		ArrayList<Integer> matrix = new ArrayList<Integer>();
		
		for (int i = 0; i < n; i++) {
			buf = (br.readLine()).split(" ");
			
			for (int j = 0; j < m; j++) {
				matrix.add(Integer.parseInt(buf[j]));
			}
		}
		
		
		ArrayList<Integer> vector = new ArrayList<Integer>();
		for (int i = 0; i < m; i++) {
			int num_element = Integer.parseInt(br.readLine());
			vector.add(num_element);
		}
		
		ArrayList<Integer> answer = new ArrayList<Integer>();
		
		for (int i = 0; i < n; i++) {
			int temp = 0;
			for (int j = 0; j < m; j++) {
				temp += matrix.get(i*m+j) * vector.get(j);
			}
			answer.add(temp);
		}
		
		for (int i = 0; i < n; i++) {
			System.out.println(answer.get(i));
		}
	}
}

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

int n,d;
int points[10][10];
int pairs=0;
int main() {
    cin>>n>>d;
    for(int i=0; i<n; i++)
        for(int j=0; j<d; j++)
            cin>>points[i][j];
    for(int i=0; i<n-1; i++) {
        for(int j=i+1; j<n; j++) {
            int dist=0;
            for(int k=0; k<d; k++) {
                dist+=(points[i][k]-points[j][k])*(points[i][k]-points[j][k]);
            }
            if((int)sqrt(dist)*(int)sqrt(dist)==dist)
                pairs++;
        }
    }
    cout<<pairs;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, K, S;
  cin >> N >> K >> S;
  int64_t padding = (S < 1e9L) ? S + 1 : 1;
  for (int64_t i = 0; i < N; ++i) {
    if (i != 0) {
      cout << " ";
    }
    if (i < K) {
      cout << S;
    } else {
      cout << padding;
    }
  }
  cout << endl;
  return 0;
}


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

int main()
{
    cout << fixed << setprecision(10);
    int n,m;
    cin >> n >> m;
    int arr[n];
    int sum=0;
    for(int i=0;i<n;i++) {
        cin >> arr[i];
        sum+=arr[i];
    }
    
    int x = 4*m;
    double y = (sum*1.0)/x;
    sort(arr,arr+n);
    
    int c=0;
    for(int i=n-1;i>=0;i--) {
        if(arr[i]<y) {
            break;
        }
        c++;
    }
    
    if(c>=m)
    cout << "Yes" << endl;
    else
    cout << "No" << endl;
    

    
    return 0;
}

Measured memory_bytes: 256
//B - Minor Change
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first


using namespace std;

int minimum_operations(string& A, string& B)
{
	int n = A.length();
	int count =0;
	for (int i = 0; i < n; ++i)
	{
		if (A[i] == B[i])
		{
			continue;
		}
		else{
			count++;
		}
	}
	return count;
} 
int main()
{
	std::ios::sync_with_stdio(false);
	string s, t;
	cin>>s>>t;
	cout<<minimum_operations(s, t)<<endl;
	return 0;
}


Measured memory_bytes: 3836
#define _CRT_SECURE_NO_WARNINGS
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
int main() {
	while (true) {
		int n, m;
		bool pair[501][501] = { false };
		bool invite[501] = { false };
		scanf("%d%d", &n, &m);
		if (n == 0 && m == 0) break;
		for (int i = 1;i <= m;++i) {
			int a, b;
			scanf("%d%d", &a, &b);
			pair[a][b] = true;
			pair[b][a] = true;
		}
		queue<int> q;
		queue<int> wow;
		q.push(1);
		while (q.empty() == false) {
			int sw = q.front();q.pop();
			for (int i = 1;i <= n;++i) {
				if (pair[sw][i] == true) {
					wow.push(i);
					invite[i] = true;
				}
			}
		}
		while (wow.empty() == false) {
			int qw = wow.front();wow.pop();
			for (int i = 1;i <= n;++i) {
				if (pair[qw][i] == true) {
					invite[i] = true;
				}
			}
		}
		invite[1] = false;
		int num = 0;
		for (int i = 1;i <= n;++i) {
			if (invite[i] == true) num++;
		}
		printf("%d\n", num);
	}
	return 0;
}


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

public class Main {
    public static void main(String[] args) {
    	MyScanner sc = new MyScanner();
   		int num=Integer.parseInt(sc.nextLine());
		long te = 0;
      	for(int i = 0;i<=num;i++){
          if(!(i%3==0) && !(i%5==0)){
             te += i;
          }
        }
      	System.out.println(te);
    }
}

class MyScanner {
      BufferedReader br;
      StringTokenizer st;
 
      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }
 
      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
    try {
       str = br.readLine();
    } catch (IOException e) {
       e.printStackTrace();
    }
    return str;
      }
 
   }

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ce = 0;
  int cw = 0;
  rep (i, n) if (s[i] == 'E') ++ce;

  int ans = 3e5 + 1;
  rep (i, n){
    if (s[i] == 'E') --ce;
    if ((i-1 >= 0) && (s[i-1] == 'W')) ++cw;
    int temp = ce + cw;
    if (ans > temp) ans = temp;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

using Int = int;

struct ModInt {
    static constexpr Int mod = 1e9 + 7;
    Int v;

    ModInt(long long _v = 0) : v(set(_v)) {}
    ModInt(const ModInt &r) : v(set(r.v)) {}

    inline static Int set(const auto x) { return x < 0 ? (x % mod) + mod : x % mod; }
    inline void set() { v = set(v); }

    bool operator<(ModInt r) const { return v < r.v; }
    bool operator>(ModInt r) const { return r.v < v; }
    bool operator==(ModInt r) const { return v == r.v; }
    bool operator!= (ModInt r) const { return v != r.v; }

    ModInt operator-() const { return ModInt(v ? mod - v : v); }
    ModInt &operator=(const ModInt &r) { if (this != &r) v = set(r.v); return *this; }
    ModInt &operator+=(ModInt r) { (v += r.v) %= mod; return *this; }
    ModInt &operator-=(ModInt r) { (v -= r.v - mod) %= mod; return *this; }
    // ModInt &operator*=(ModInt r) { v = (__uint128_t(v) * r.v) % mod; return *this; }
    ModInt &operator*=(ModInt r) { v = 1ULL * v * r.v % mod; return *this; }
    ModInt &operator/=(ModInt r) { *this *= r.inv(); return *this; }
    ModInt operator+(ModInt r) const { return ModInt(*this) += r; }
    ModInt operator-(ModInt r) const { return ModInt(*this) -= r; }
    ModInt operator*(ModInt r) const { return ModInt(*this) *= r; }
    ModInt operator/(ModInt r) const { return ModInt(*this) /= r; }

    ModInt inv() const {
        long long a = v, b = mod, u = 1, w = 0;
        while (b) {
            long long t = a / b;
            std::swap(a -= t * b, b);
            std::swap(u -= t * w, w);
        }
        return ModInt(u);
    }

    ModInt pow(Int e) {
        ModInt a = *this, x(1);
        for ( ; 0 < e; e >>= 1) { if (e & 1) x *= a; a *= a; }
        return x;
    }
    inline ModInt pow(ModInt &e) { return pow(e.v); }
};
std::ostream &operator<<(std::ostream &os, const ModInt &r) { return os << r.v; }
std::istream &operator>>(std::istream &is, ModInt &r) { is >> r.v; r.set();return is; }

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

    ModInt h, w, k;
    cin >> h >> w >> k;

    const int sz = w.v - 1;
    vector<vector<ModInt>> dp(h.v + 1, vector<ModInt>(w.v));
    dp[0][0] = 1;
    for (int i = 1; i <= h.v; ++i) {
        for (int s = 0; s < 1 << sz; ++s) {
            bool valid = true;
            for (int j = 1; j < sz; ++j)
                if ((s >> (j - 1) & 1) && (s >> j & 1)) {
                    valid = false;
                    break;
                }
            if (!valid) continue;

            for (int j = 0; j < w.v; ++j) {
                int nxt = j;
                if (0 < j && (s >> (j - 1) & 1)) --nxt;
                if (j < w.v - 1 && (s >> j & 1)) ++nxt;
                dp[i][nxt] += dp[i - 1][j];
            }
        }
    }

    cout << dp[h.v][k.v - 1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a;
long long l;
int main()
{
    cin>>a;
    l=a.size();
    for(int i=0;i<l;i++)
    {
    	if(a[i]==',')cout<<" ";
    	else cout<<a[i];
    }
    cout<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np

class unionfind: #ノード数nを読み込む
    def __init__(self,n): #コンストラクタ
        self.parent = list(range(n))
    def find(self,a): #根を探す、そのつど根を更新
        if self.parent[a] == a: return a #自分が根だったら終了
        p = self.find(self.parent[a])
        self.parent[a] = p #根をダイレクトに更新
        return p
    def unite(self,a,b): #ランク度外視で根を合体する
        pa,pb = self.find(a),self.find(b)
        if pa == pb: return 0 #根が一緒なら何もせず終了
        self.parent[pa] = pb
    def same(self,a,b):
        pa,pb = self.find(a),self.find(b)
        return pa == pb

n,m = map(int,input().split())
ab = np.array([list(map(int,input().split())) for i in range(m)])
a,b = ab.T[0] -1, ab.T[1] -1

ans = 0
for i in range(m): #除外する辺を決める
    uf = unionfind(n)
    connect = 0
    for j in range(m): #i以外の辺についてuniteしていく
        if i != j and not uf.same(a[j],b[j]): uf.unite(a[j],b[j]) ; connect += 1
    ans += 0 if connect == n-1 else 1
print(ans)



Measured memory_bytes: 14544
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
ll modpow(ll a,ll b){
    a%=mod;
    if(b==0)return 1;
    if(b&1)return a*modpow(a,b-1)%mod;
    ll k=modpow(a,b/2);
    return k*k%mod;
}
int main(){
    ll n,ans=0;cin>>n;
    vi dp(n-1);
    vi v(n);
    rep(i,n)cin>>v[i];
    dp[0]=1;
    REP(i,2,n){
        dp[0]*=i;
        dp[0]%=mod;
    }
    REP(i,1,n-1)dp[i]=dp[0]*modpow(i+1,mod-2)%mod;
    REP(i,1,n-1)dp[i]+=dp[i-1];
    rep(i,n-1){
        ans+=dp[i]*(v[i+1]-v[i])%mod;
        ans%=mod;
    }
    out(ans);
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main(){
  int N,K;
  cin >> N >> K;
  vint P(N);
  cin >> P;
  sort(P.begin(),P.end());
  int ans = 0;
  REP(i,K){
    ans += P[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <tuple>

using lint = long long;

int ipow(int x, int e) {
    return (e == 0 ? 1 : x * ipow(x, e - 1));
}

std::vector<std::pair<lint, lint>> enumerate(int m) {
    std::vector<lint> xs(m), ys(m);
    for (int i = 0; i < m; ++i) {
        std::cin >> xs[i] >> ys[i];
    }

    std::vector<std::pair<lint, lint>> ret;
    for (int t = 0; t < ipow(3, m); ++t) {
        int nt = t;
        lint dx = 0, dy = 0;
        for (int i = 0; i < m; ++i) {
            int k = nt % 3;
            nt /= 3;
            if (k == 0) {
                dx += xs[i];
                dy += ys[i];
            } else if (k == 1) {
                dx -= xs[i];
                dy -= ys[i];
            }
        }
        ret.emplace_back(dx, dy);
    }
    return ret;
}

void solve() {
    int n;
    lint diff;
    std::cin >> n >> diff;

    auto fore = enumerate(n / 2), back = enumerate(n - n / 2);
    std::sort(fore.begin(), fore.end());
    std::sort(back.rbegin(), back.rend());

    lint ans = 0;
    int r = 0;
    std::deque<std::pair<lint, lint>> que;

    for (auto f : fore) {
        lint dx, dy;
        std::tie(dx, dy) = f;

        while (r < (int)back.size() && dx + back[r].first >= -diff) {
            while (!que.empty() &&
                   que.back().second <= back[r].second) {
                que.pop_back();
            }
            que.emplace_back(back[r++]);
        }

        while (!que.empty() &&
               dx + que.front().first > diff) {
            que.pop_front();
        }

        if (!que.empty()) ans = std::max(ans, dy + que.front().second);
    }

    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}



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

using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B;
  int R = C + D;
  if (L > R) {
    cout << "Left";
  } else if (L == R) {
    cout << "Balanced";
  } else {
    cout << "Right";
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cassert>
using namespace std;

// value, color
using Card = pair<int, char>;

const int S = 9;
bool ansFlag = true;

bool check(vector< Card > cards) {
  char col = cards[0].second;

  // check (color)
  for(int k=0; k<3; k++) {
    if(cards[k].second != col) {
      return false;
    }
  }

  // check (number)
  bool ok1 = true, ok2 = true;
  sort(cards.begin(), cards.end());
  int val = cards[0].first;

  // same number
  for(int k=0; k<3; k++) {
    if(cards[k].first != val) {
      ok1 = false;
    }
  }

  // stair
  for(int k=1; k<3; k++) {
    // printf("val = %d, cur = %d\n", val, cards[k].first);
    if(cards[k].first != val + 1) {
      ok2 = false;
    }
    val = cards[k].first;
  }

  return ok1 || ok2;
}

void solve(vector< Card > cards, int iter, vector<int> checked) {
  /*
  printf("iter = %d:", iter);
  for(int i=0; i<S; i++) {
    printf(" %d", checked[i]);
  }
  printf("\n");
  */

  if(iter == 3) {
    ansFlag = true;
    return;
  }
  for(int i=0; i<9; i++) {
    if(checked[i]) continue;
    for(int j=i+1; j<9; j++) {
      if(checked[j]) continue;
      for(int k=j+1; k<9; k++) {
        if(checked[k]) continue;
        assert(i != j && j != k && k != i);
        if(check(vector< Card >{cards[i], cards[j], cards[k]})) {
          checked[i] = checked[j] = checked[k] = true;
          solve(cards, iter+1, checked);
          checked[i] = checked[j] = checked[k] = false;
        }
      }
    }
  }
}

int main() {
  int T; cin >> T;
  while(T--) {
    vector<int> vals(S);
    vector<char> chrs(S);

    vector< Card > cards(S);
    for(int i=0; i<S; i++) cin >> vals[i];
    for(int i=0; i<S; i++) cin >> chrs[i];
    for(int i=0; i<S; i++) cards[i] = make_pair(vals[i], chrs[i]);

    vector<int> checked(S);
    ansFlag = false;
    solve(cards, 0, checked);

    cout << (ansFlag ? 1 : 0) << endl;
  }
  return 0;
}



Measured memory_bytes: 3044
#include <iostream>
#include <queue>
#include <climits>
#define ll int
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
// #define int long long
using namespace std;
#define remin(x,y) x= min(x,y)

int n,m;
char grid[21][21];
int dis[21][21][21][21];

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);
    
    cin>>n>>m;
    int N =n,M =m;
    for(int i =1;i<=n;i++){
        for(int j =1;j<=m;j++){
            cin>>grid[i][j];
        }
    }
    for(int i =1;i<=n;i++){
        for(int j =1;j<=m;j++){
            for(int x=1;x<=n;x++){
                for(int l = 1;l<=m;l++){
                    dis[i][j][x][l]=100000;
                    if(i ==x && j==l)dis[i][j][x][l]=0;
                }
            }
        }
    }


    for(int i=1;i<=n;i++){
        for(int j =1;j<=m;j++){
            if(grid[i][j]=='#')continue;
            if(grid[i+1][j] != '#' && (i+1) <=n){
                remin(dis[i][j][i+1][j],1);
             //   remin(dis[i+1][j][i][j],1);   
            }
            if(grid[i-1][j] != '#' && (i-1) >=1){
                remin(dis[i][j][i-1][j] ,1);
               // remin(dis[i-1][j][i][j] , 1);   
            }
            if(grid[i][j+1] != '#' && (j+1) <=m){
                remin(dis[i][j][i][j+1] ,1);
               // remin(dis[i][j+1][i][j] ,1);
            }
            if(grid[i][j-1] != '#' && (j-1) >=1){
                remin(dis[i][j][i][j-1] , 1);
               // remin(dis[i][j-1][i][j] , 1);
            }
               
        }
    }
// for(int i =1;i<=n;i++){
//         for(int j =1;j<=m;j++){
//             for(int x=1;x<=n;x++){
//                 for(int l = 1;l<=m;l++){
//                         cout<<dis[i][j][x][l]<< " -> " << i << " " << j << " " << x << " " << l << endl;
                    
//                 }
//             }
//         }
//     }

    for(int k=1; k<=N; k++) {
    for(int l=1; l<=M; l++) {
        // For each source vertex (i,j)
        for(int i=1; i<=N; i++) {
            for(int j=1; j<=M; j++) {
                // For each destination vertex (r,c)
                for(int r=1; r<=N; r++) {
                    for(int c=1; c<=M; c++) {
                        // Apply the triangle rule
                        int alternative = dis[i][j][k][l] + dis[k][l][r][c];
                        if(alternative < dis[i][j][r][c]) {
                            dis[i][j][r][c] = alternative;
                        }
                    }
                }
            }
        }
    }
}

    int ans = 0;
    for(int i =1;i<=n;i++){
        for(int j =1;j<=m;j++){
            for(int x=1;x<=n;x++){
                for(int l = 1;l<=m;l++){
                    if((i!=x||j!=l) && grid[i][j] !='#' && grid[x][l]!='#'){
                        ans=max(ans,dis[i][j][x][l]);
                  //      cout<<dis[i][j][x][l]<< " -> " << i << " " << j << " " << x << " " << l << endl;
                    }
                }
            }
        }
    }


    cout<<ans<<endl;
}   

Measured memory_bytes: 1024