akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

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

	vector<long long> A;
	vector<long long> filteredA;
	vector<pair<long long, long long>> A_i;
	for (long long i = 0; i < N; ++i) {
		long long a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());


	if (0 <= A[0]) {
		for (long long i = 0; i < A.size() - 1;) {
			if (0 < A[i]) {
				A_i.push_back(make_pair(A[0], A[i + 1]));
				A[0] = A[0] - A[i + 1];
				A.erase(A.begin() + i + 1);
			}
			else {
				++i;
			}
		}
	}
	else if (A[A.size() - 1] < 0){
		A_i.push_back(make_pair(A[A.size() - 1], A[A.size() - 2]));
		A[A.size() - 1] -= A[A.size() - 2];
		A.erase(A.begin() + A.size() - 2);
	}
	else {
		int k = 0;
		for (long long i = 0; i < A.size() - 1;) {
			if (A[i] > 0) {
				A_i.push_back(make_pair(A[0], A[i + 1]));
				A[0] = A[0] - A[i + 1];
				A.erase(A.begin() + i + 1);
			}
			else {
				++i;
			}
		}
	}
	for (long long i = 0; i < A.size() - 1; ++i) {
		A_i.push_back(make_pair(A[A.size() - 1], A[i]));
		A[A.size() - 1] -= A[i];
	}


	sort(A.rbegin(), A.rend());
	cout << A[0] << endl;
	for (long long i = 0; i < A_i.size(); ++i) {
		cout << A_i[i].first << " " << A_i[i].second << endl;
	}


	return 0;
}

Measured memory_bytes: 4336
import sys
import math
import collections
from collections import deque
#n = int(input())
#a, b = map(int, sys.stdin.readline().split())
s = input()
#x = sys.stdin.readline().split()

if len(s) % 2 != 0:
    print("No")
    sys.exit()


for i in range(int(len(s)/2)):
    if s[2 * i] == "h" and s[2 * i + 1] == "i":
        continue
    else:
        print("No")
        sys.exit()

print("Yes")


Measured memory_bytes: 3436
L = []
l1 = set(tuple(map(int,input().split())))
l2 = set(tuple(map(int,input().split())))
l3 = set(tuple(map(int,input().split())))
L.append(l1)
L.append(l2)
L.append(l3)
L += [{0,1},{0,2},{0,3},{0,4}]

def dfs(left_town, current_town):
    if left_town == []:
        return 1

    ret = 0
    for t in left_town:
        if {current_town, t} in L:
            ret += dfs([left_town[index] for index,val in enumerate(left_town) if not val==t],t)
    
    if ret == 0:
        return 0
    else:
        return 1

ans = "YES" if dfs([1,2,3,4],0)==1 else "NO"
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <iostream>
#define LL long long
using namespace std;
LL rec[55][55][2501];
int main()
{
    int a[60];
    memset(rec,0,sizeof(rec));
    int n,x;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
        rec[0][0][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            for(int w=0;w<=2500;w++)
            {
                if(rec[i-1][j-1][w]>0)
                {
                    rec[i][j][w+a[i]]+=rec[i-1][j-1][w];
                    rec[i][j-1][w]+=rec[i-1][j-1][w];
                    //printf("%d %d %d %d\n",i,j,w+a[i],rec[i][j][w+a[i]]);
                    //printf("%d %d %d %d\n",i,j-1,w,rec[i][j-1][w]);
                    //printf("\n");
                }
            }
        }
    }
    LL s=0;
    for(int j=1;j<=n;j++)
    {
        for(int i=1;i<=2500;i++)
        {
            if(i%j==0&&i/j==x)
            {
                s+=rec[n][j][i];
            }

        }
    }
    printf("%lld\n",s);
   // cout << "Hello world!" << endl;
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}


using namespace std;

int n, a, b;
int maxi;
VI ans;

void dorzuc(int x) {
	FOR(j,maxi-x+1,maxi+1) {
		ans.pb(j);
	}
	maxi -= x;
}

int main() {
	read3(n, a, b);
	maxi = n;
	if ((a+1)*1LL*(b+1) < n+1) {
		printf("-1\n");
		return 0;
	} 
	if (a+b > n+1) {
		printf("-1\n");
		return 0;
	}
	dorzuc(a);
	b--;
	while (b > 0) {
		if (maxi - a >= b-1) {
			dorzuc(a);
			b--;
		} else {
			dorzuc(maxi-b+1);
			FORD(j,maxi,1) {
				ans.pb(j);
			}
			break;
		}
	}
	if (ans.size() != n) {
		printf("-1\n");
		return 0;
	}
	FORE(i, ans) {
		printf("%d ", *i);
	}
	printf("\n");
}



Measured memory_bytes: 3440
/* be name khoda */

#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

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

const ll maxn = 510;
const ll maxnlg = 20;

ll H, W, h, w;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> H >> W >> h >> w;
    if (H % h) {
        cout << "Yes\n";
        ll A = maxn;
        ll B = -A * (h - 1) - 1;
        fori (i, H) {
            fori (j, W) {
                cout << ((i + 1) % h ? A : B) << ' ';
            }
            cout << '\n';
        }
    } else if (W % w) {
        cout << "Yes\n";
        ll A = maxn;
        ll B = -A * (w - 1) - 1;
        fori (i, H) {
            fori (j, W) {
                cout << ((j + 1) % w ? A : B) << ' ';
            }
            cout << '\n';
        }
    } else {
        cout << "No\n";
    }

}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(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 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vll path;
//***********//
int main() {
    int N, K;
    cin >> N >> K;
    vl A(N);
    for (i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    int ok = N, ng = -1;
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        vector<vector<int>> dp(N + 1, vector<int>(K+1, -1));
        dp[0][0] = 1;
        int cnt = 0;
        for (i = 0; i < N;i++) {
            if (i == mid) continue;
            for(j=0;j<=K;j++) {
                dp[cnt + 1][j] = dp[cnt][j];
            }
            for (j = 0; j <= K; j++) {
                if (j - A[i] >= 0) dp[cnt + 1][j] = max(dp[cnt+1][j],dp[cnt][j - A[i]]);
            }
            cnt++;
        }
        bool pos = false;
        for (i = max(0LL, K - A[mid]); i < K; i++) {
            if (dp[N - 1][i] == 1) pos = true;

        }
        if (pos) ok = mid;
        else ng = mid;
    }
    cout << ng + 1 << endl;
}

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

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

    int count = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= K; j++){
            if(S - i - j <= K && S - i - j >= 0) count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
     
int main() {
	int r, c;
	cin >> r >> c;
	int num[r+1][c+1];
	
	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c+1; j++){
			num[i][j]=0;
		}
	}
	
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
		    cin >> num[i][j];
            num[r][j] += num[i][j];
            num[i][c] += num[i][j];
            num[r][c] += num[i][j];
		   
		}
	}
	
	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c; j++){
		    cout << num[i][j] << " ";
		}
		cout << num[i][c] << endl;
	}
	return 0;
}




Measured memory_bytes: 3120
#include<iostream>
#include<cstdio>
using namespace std;
char str[10];
int main(){
    while(~scanf("%s",str+1)){
        if(str[3]==str[4]&&str[5]==str[6]){
            puts("Yes");
        }else{
            puts("No");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;
typedef long long ll;
ll dp[100005];
ll h[100005];

int main() {
		int n, k;
		cin >> n >> k;

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

		ll INF = 1e13;
		
		for (int i = 0; i < n; i++) {
			dp[i] = INF;
		}
		dp[0] = 0;
		for (int i = 1; i < n; i++) {
			for (int j = max(i - k, 0); j < i; j++) {
				dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
			}
		}

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

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
long long r,d,x;
int main(){
	cin>>r>>d>>x;
	for(int i=1;i<=10;i++)
		x=x*r-d,cout<<x<<'\n';
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, x = map(int, input().split())
    A = list(map(int, input().split()))

    res = 0
    if A[0] > x:
        res += A[0] - x
        A[0] = x

    for i in range(1, n):
        if A[i - 1] + A[i] > x:
            res += A[i] + A[i - 1] - x
            A[i] -= A[i] + A[i - 1] - x

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 14432
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define ip pair<ll,ll>
#define vii vector<ll>
#define vpp vector<ip>
#define vdd vector<ld>
#define vb vector<bool>
#define pi  pair<ll,ip>
#define sc(x) scanf("%lli",&x)
#define c(x) cin >> x
#define fo(i,k,n) for( int i=k;i<n;i++)
#define hu 200010
#define pq priotity_queue<ll>
#define pqs priority_queue<ll,vii,greater<ll>>
#define ppq priority_queue<ip,vpp,greater<ip>>
#define INF INT_MAX
#define ff first
#define ss second
using namespace std;
const ll M = 1000000000+7;
//Grid Movement
ll dx[] = {-1, 0, 1, 0};
ll dy[] = {0, -1, 0, 1};

ld Pi= acos(-1);

ll lcm(ll a,ll b)
{
    return (a*b)/(__gcd(a,b));
}

ll mex(ll x, ll y) 
{ 
	ll res = 1;	  
	x = x % M; 
	if (x == 0) return 0; 
	while (y > 0) 
	{ 
		if (y & 1) 
		res = (res*x) % M; 
		y = y>>1; 
		x = (x*x) % M; 
	} 
	return res; 
} 

bool comp(ll comp1,ll comp2)
{
    return comp1>comp2;
}

void yes()
{
    printf("YES\n");
}

void no()
{
    printf("NO\n");
}

ll inv(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
 
    if (m == 1)
      return 0;
 
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
 
    if (x < 0)
       x += m0;
 
    return x;
}

void sieve(ll n)
{
    vii primes(n+1);
    vb is_prime(n+1);
	is_prime.resize(n+1);
	primes.resize(n+1);
 
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i<=n; i++)
	{
	    if(is_prime[i])
	    {
	    	primes.pb(i);
	        for (int j = i*i; j<=n; j+=i)
	            is_prime[j] = false;
	    }
	}
}

void solve()
{
    ll n;
    sc(n);
   string s;
   cin >> s;
   ll wl = 0,rr=0;
   for(auto it:s)if(it=='R')rr++;
   if(rr==n or rr==0)
   {
       printf("0");
       return ;
   }
   if(s[0]=='W')wl=1;
   else rr--;
   ll ans = max(wl,rr);
   fo(i,1,n)
   {
       if(s[i]=='W')wl++;
       else rr--;
       ans = min(ans,max(wl,rr));
   }
   printf("%lli",ans);
   
}

int main()
{
    ll t=1;
   // sc(t);
    while(t--) solve();
}





Measured memory_bytes: 3844
x = gets.to_i
ans = 1
x.downto(4) do |v|
  b = 2
  while b ** 2 <= v do
    p = 2
    while b ** p <= v do
      if b ** p == v
        ans = v
        break
      end
      p += 1
    end
    break if ans > 1
    b += 1
  end
  break if ans > 1
end
puts ans


Measured memory_bytes: 1788
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
char a[16];
int main()
{
	int N;
	scanf("%d", &N);
	scanf("%s", a);
	int len = strlen(a);
	if(N >= 3200)
	{
		for(int i = 0; i < len; i++)
		{
			printf("%c", a[i]);
		}
	}
	else
	{
		printf("red");
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define REP(i,a,e) for(int i=(a);i<=(e);++i)
using namespace std;
#define PERSIMMON 1
#define MAX 102

int main(){
	while(true){
		int ans = 0;
		int t = 0, tt = 0;
		int t_bak_col = 0;
		int t_for_col = 0;
		int t_bak_row = 0;
		int t_for_row = 0;
		int map[MAX][MAX] = {{0,},};
		int N;
		int W,H;
		int S,T;
		scanf("%d",&N);
		if( N == 0 ) break;
		scanf("%d%d", &W, &H);
		for(int i = 0; i < N; ++i){
			int ti, tj;
			scanf("%d%d", &tj, &ti);
			map[ti][tj] = PERSIMMON;
		}
		scanf("%d%d", &S, &T);

		REP(i,1,T)REP(j,1,S){
			t += map[i][j];
			tt += map[i][j];
		}

		ans = max(ans,t);
		REP(j,1,W-S+1){
			REP(i,1,H-T+1){
				ans = max(ans,t);

				t_bak_row = 0;
				t_for_row = 0;
				REP(tj,j,j+S-1){
					t_bak_row += map[i][tj];
					t_for_row += map[i+T][tj];
				}
				t -= t_bak_row;
				t += t_for_row;
			}
			t_bak_col = 0;
			t_for_col = 0;
			REP(ti,1,T){
				t_bak_col += map[ti][j];
				t_for_col += map[ti][j+S];
			}
			tt -= t_bak_col;
			tt += t_for_col;
			t = tt;
		}

		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 0
import sys
import numpy as np

input = sys.stdin.readline

N, K = map(int, input().split())
*T, = map(int, input().split())

INF = float("inf")  # pythonでの無限大の作り方
DP = [INF for i in range(N)]

def chmin(a, b):
     if a > b:
          return b
     return a

DP[0] = 0
"""
# 2重for文ではTLE
for i in range(1, N):
    for j in range(1, K+1):
        if i-j >= 0:
            DP[i] = chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i]))
"""
"""
# list内包表記でもTLE (2重for文よりはマシ)
for i in range(1, N):
    DP[i] = min([chmin(DP[i], DP[i-j] + abs(T[i-j] - T[i])) for j in range(1, K+1) if i-j >= 0])
"""

DP = np.zeros(N, dtype=int)
T = np.array(T)

for i in range(1, N):
    start = max(0, i-K)
    DP[i] = min(DP[start:i] + np.abs(T[i] - T[start:i]))

print(int(DP[-1]))

Measured memory_bytes: 22820
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

int main() {
	ios::sync_with_stdio(false);
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int tot1 = H1 * 60 + M1;
	int tot2 = H2 * 60 + M2;
	cout << max(0, (tot2 - K) - tot1) << endl;
}

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

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

    vector<pair<int,int> > z;
    vector<int> a(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        z.push_back(make_pair(a[i],i));
    }
    sort(z.rbegin(), z.rend());

    vector<int> v(n*4, -1);
    {
        set<int> ss;
        for(i=0; i<n; i++) {
            int id=z[i].second;
            auto it=ss.insert(id).first;
            {
                auto it2=it;
                it2++;
                if(it2!=ss.end()) {
                    v[4*id+2]=(*it2);
                    it2++;
                    if(it2!=ss.end()) {
                        v[4*id+3]=(*it2);
                    }
                }
            }
            {
                auto it2=it;
                if(it2!=ss.begin()) {
                    it2--;
                    v[4*id+1]=(*it2);
                    if(it2!=ss.begin()) {
                        it2--;
                        v[4*id]=(*it2);
                    }
                }
            }
        }
    }

    ll ans=0;
    for(i=0; i<n; i++) {
        int tmp0=0, tmp1=i+1;
        if(v[4*i+1]>=0) {
            tmp0=v[4*i+1]-v[4*i];
            tmp1=i-v[4*i+1];
        }
        int tmp2=n-i, tmp3=0;
        if(v[4*i+2]>=0) {
            int last=(v[4*i+3]<0? n: v[4*i+3]);
            tmp3=last-v[4*i+2];
            tmp2=v[4*i+2]-i;
        }
        ans += ((ll)tmp0*tmp2 + (ll)tmp1*tmp3)*a[i];
    }
    printf("%lld\n", ans);

    return 0;
}



Measured memory_bytes: 7668
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
    SPEED;
    int n,k;
    cin>>n>>k;
    int a[n],dp[k+1]={0},flag=0;
    vector <int> chk;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<=k)
        chk.push_back(a[i]);
    }
    n=chk.size();
    if(n==0)
    {
        cout<<"Second";
        return 0;
    }
    for(int i=1;i<=k;i++)
    {
        int f=0;
        for(int j=0;j<n;j++)
        {
            if(i-chk[j]>=0 && dp[i-chk[j]]==0)
            f=1;
        }
        dp[i]=f;
    }
    if(dp[k])
    cout<<"First";
    else
    cout<<"Second";
}

Measured memory_bytes: 4464
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
      	int B = sc.nextInt();
      	
		if(A%2==1 && B%2==1){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
      
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b << endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,a,an;
  cin>>n;
  an=n;
  while(n--){
    cin>>a;
    if(a==1)an--;
    for(int i=2;i*i<=a;i++)
      if(a%i==0){
	an--;
	break;      
      }
  }
  cout<<an<<endl;
  return 0;
}

Measured memory_bytes: 1160
import std.algorithm,
       std.string,
       std.stdio,
       std.range,
       std.conv;

void main() {
  string N = readln.chomp;
  auto A = readln.chomp.split.to!(ulong[]).sort!"a<b",
       B = readln.chomp.split.to!(ulong[]).sort!"a<b",
       C = readln.chomp.split.to!(ulong[]).sort!"a<b";
  ulong ans;

  foreach (b; B) {
    ans += A.lowerBound(b).length * C.upperBound(b).length;
  }

  writeln(ans);
}


Measured memory_bytes: 12372
def dump(f)
  f.each do |r|
    r.each{|c| print c}
    puts
  end
end

def bomb(f, x, y)
  if f[y][x] == "1"
    f[y][x] = "0"

    1.upto(3) do |i|
      bomb(f, x+i, y) if x + i <  8 && f[y][x+i] == "1"
      bomb(f, x-i, y) if x - i >= 0 && f[y][x-i] == "1"
      bomb(f, x, y+i) if y + i <  8 && f[y+i][x] == "1"
      bomb(f, x, y-i) if y - i >= 0 && f[y-i][x] == "1"
    end
  end

  f
end

gets.to_i.times do |i|
  gets

  f = 8.times.map{ gets.chomp.split(//) }

  x = gets.chomp.to_i
  y = gets.chomp.to_i

  bomb(f, x - 1, y - 1)

  puts "Data #{i+1}:"
  dump(f)
end

Measured memory_bytes: 8832
import sys
def rr(): return sys.stdin.readline().rstrip()
def rri(): return int(rr())
def rrl(): return list(map(int, rr().split()))
def rrt(): return tuple(map(int, rr().split()))
def rrle(): return (line.rstrip() for line in sys.stdin.readlines())
def rrtl(): return [tuple(map(int, l.split())) for l in rrle()]
from collections import defaultdict
def mus(d=lambda: 0): return defaultdict(lambda: defaultdict(d))
def dd0(d=lambda: 0): return defaultdict(d)
def ms(x, y, d=0): return [[0]*y for i in range(x)]
def ar(x, d=0): return [d]*x
def ppm(m, n=0, x=0, y=0): print("\n".join(("\t".join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))
def ppa(a, n): print("\t".join(map(str, a[0:n])))
def ppl(a=0, x=[1]): x[0]=a or (x[0]+1); print("-"+"- -"*14+"-# "+str(x[0]-2)+" #-"+"- -"*14+"-")
def fltn(a): (i for sub in a for i in sub)
def yn(x): return "YES" if x else "NO"
from itertools import accumulate
from itertools import groupby
def grp(x): return ((i, sum(1 for _ in g)) for i, g in groupby(x))
import math
#def rnar(): return (*rrl(), rrl())
#def rn(): return (*rrl(),)
def dpp(a, b=""): print("#| {} |#:^ {} ^:".format(a, b))

def read():
    return (rri(),)

def solve(x):
    arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    ans = arr[x-1]
    return ans

if __name__ == "__main__":
    #test_count = rri()
    test_count = 1
    for _ in range(test_count):
        input_data = read()
        result = solve(*input_data)
        print(result)


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

bool kaibun(string S, int i, int j) {
  while (i < j) {
    if (S[i] != S[j]) return false;
    i++;
    j--;
  }
  return true;
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  bool can1 = kaibun(S, 0, N-1);
  bool can2 = kaibun(S, 0, (N-1)/2-1);
  bool can3 = kaibun(S, (N+3)/2-1, N-1);
  if (can1 && can2 && can3) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll n, m;
vector<vector<ll>> g;
vector<vector<ll>> rg;
vector<ll> t;
void dfs(ll now, vector<int> &visited){
    visited[now] = 1;
    rep(i, g[now].size()){
        ll next = g[now][i];
        if(visited[next]) continue;
        dfs(next, visited);
    }
    t.push_back(now);
}
int main(void){

    cin >> n >> m;
    g.resize(n);
    rg.resize(n);
    vector<int> appeared(n, 0);
    rep(i, n - 1 + m){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        rg[b].push_back(a);
        appeared[b] = 1;
    }
    ll root = 0;
    rep(i, n){
        if(!appeared[i]){
            root = i;
            break;
        }
    }

    vector<int> visited(n, 0);
    dfs(root, visited);

    reverse(all(t));

    map<ll,ll> mp;
    rep(i, t.size()){
        mp[t[i]] = i;
    }

    rep(i, n){
        sort(all(rg[i]), [&mp](const ll &f, const ll &s){
            return mp[f] > mp[s];
        });
    }
    vector<ll> ans(n);
    rep(i, n){
        if(rg[i].size() == 0){
            ans[i] = 0;
        } else {
            ans[i] = rg[i][0] + 1;
        }
    }

    rep(i, ans.size()){
        cout << ans[i] << endl;
    }

    
}


Measured memory_bytes: 27548
#include<stdio.h>
int main(void)
{
	int e,y,M,T,S,H;
	scanf("%d %d",&e,&y);
	if(e==0){
		if(1868<=y&&1911>=y){
			printf("M%d\n",44-(1911-y));
		}
		if(1912<=y&&1925>=y){
			printf("T%d\n",14-(1925-y));
		}
		if(1926<=y&&1988>=y){
			printf("S%d\n",63-(1988-y));
		}
		if(1989<=y&&2016>=y){
			printf("H%d\n",28-(2016-y));
		}
	}
	else if(e==1){
		printf("%d\n",1867+y);
	}
	else if(e==2){
		printf("%d\n",1911+y);
	}
	else if(e==3){
		printf("%d\n",1925+y);
	}
	else{
		printf("%d\n",1988+y);
	}
	return 0;
}


Measured memory_bytes: 2752
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,x;
    cin >> n >> x;
    if(n == 2) {
        if(x == 2) {
            Yes(1);
            cout << "1\n2\n3\n" << endl;
        } else Yes(0);
        return 0;
    }
    if(x >= 2 and x <= 2*n-2) {
        Yes(1);
        vi ans;
        rep(i,2*n-1) {
            if(x == 2) {
                if(i+1 <= x-2 or i+1 >= x+3) ans.pb(i+1);
            } else {
                if(i+1 <= x-3 or i+1 >= x+2) ans.pb(i+1);
            }
        }
        vi v(4);
        if(x == 2) {
            v[0] = x+1;
            v[1] = x;
            v[2] = x-1;
            v[3] = x+2;
        } else {
            v[0] = x-1;
            v[1] = x;
            v[2] = x+1;
            v[3] = x-2;
        }
        rep(i,n-2) cout << ans[i] << '\n';
        rep(i,4) cout << v[i] << '\n';
        rep2(i,n-2,2*n-5) cout << ans[i] << '\n';
    } else {
        Yes(0);
    }
}


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

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

    ll h,w;
    cin >> h >> w;

    if((h * w) % 3 == 0){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1e12;
    vector<ll> a(3);
    ll x,y;
    if(w % 2 == 0){
        x = y = w / 2;
    } else {
        x = w / 2;
        y = x + 1;
    }
    for(ll i = 1; i < h; i++){
        a[0] = w * i;
        a[1] = x * (h - i);
        a[2] = y * (h - i);
        sort(a.begin(),a.end());
        ans = min(ans,a[2] - a[0]);
    }

    if(h % 2 == 0){
        x = y = h / 2;
    } else {
        x = h / 2;
        y = x + 1;
    }
    for(ll i = 1; i < w; i++){
        a[0] = h * i;
        a[1] = x * (w - i);
        a[2] = y * (w - i);
        sort(a.begin(),a.end());
        ans = min(ans,a[2] - a[0]);
    }

    for(ll i = 1; i < h; i++){
        if((h - i) % 2 == 0){
            x = y = (h - i) / 2;
        } else {
            x = (h - i) / 2;
            y = x + 1;
        }
        a[0] = w * i;
        a[1] = w * x;
        a[2] = w * y;
        sort(a.begin(),a.end());
        ans = min(ans,a[2] - a[0]);
    }

    for(ll i = 1; i < w; i++){
        if((w - i) % 2 == 0){
            x = y = (w - i) / 2;
        } else {
            x = (w - i) / 2;
            y = x + 1;
        }
        a[0] = h * i;
        a[1] = h * x;
        a[2] = h * y;
        sort(a.begin(),a.end());
        ans = min(ans,a[2] - a[0]);
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define se second
#define fi first
#define N 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

struct node
{
	int a , b;
	bool operator < (node const &x) const
	{
		if(a == x.a) return b < x.b;
		return a < x.a;
	}
}x[N];
pair<int , int>p[N];
int n ;

inline void sol1(int cnt)
{
	int one=0,two=0,l=0,r=0;
	rep(i,1,cnt)
	{
		if(p[i].se > 0) 
		{
			one ++ ;
			if(one == n / 2 + 1) l = p[i].fi;
		}
		else
		{
			two ++ ;
			if(two == n / 2 + 1) r = p[i].fi;
		}
	}
	cout << r - l + 1 << '\n';
}

inline void sol2(int cnt)
{
	int one=0,two=0;
	int l1=-1,r1=-1,l2=-1,r2=-1;
	rep(i,1,cnt)
	{
		if(p[i].se>0)
		{
			one++;
			if(one == n / 2) l1 = p[i].fi;
			else if(one == n / 2 + 1) l2 = p[i].fi;
		}
		else
		{
			two ++ ;
			if(two == n / 2) r1 = p[i].fi; 
			else if(two == n / 2 + 1) r2 = p[i].fi;
		}
	}
	cout << r1 - l1 + 1 + r2 - l2 << '\n';
	
}
signed main()
{
	n=read(); rep(i,1,n) x[i].a=read(),x[i].b=read();
	sort(x+1,x+1+n); int cnt=0;
	rep(i,1,n)
	{
		p[++cnt].fi=x[i].a; p[cnt].se=i;
		p[++cnt].fi=x[i].b; p[cnt].se=-i;
	}
	sort(p+1,p+cnt+1);
	if(n&1) sol1(cnt); else sol2(cnt);
	return 0;
}


Measured memory_bytes: 8320
#include <iostream>

typedef long long ll;

using namespace std;

int main()
{
  ll sum = 0;
  ll N,K;

  cin >> N >> K;

  if ( K == 0 ) {
    sum = N*N;
  } else {
    for ( int i = K+1; i <= N; ++i ) {
      sum += ( (N/i)*(i-K) );

      if ( (N%i) >= K ) {
        sum += (N%i)-K+1;
      }
    }
  }

  cout << sum << "\n";
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char *argv[]) {
  int N, M, K;
  std::cin >> N >> M >> K;

  for (int i = 0; i <= N; i++) {
    for (int k = 0; k <= M; k++) {
      if (i * k + (N - i) * (M - k) == K) {
        std::cout << "Yes" << std::endl;
        return 0;
      }
    }
  }
  std::cout << "No" << std::endl;

  return 0;
}


Measured memory_bytes: 256
Y = 365
loop do
    n = gets.to_i
    break if n == 0

    a = (0..Y).map {|i| [0] * (i+1) }
    input = (1..n).map { gets.split.map(&:to_i) }.sort_by {|_, j, _| j}
    input.each do |i, j, w|
        b = (0..Y).map { [0] * (Y+1) }
        (0..Y).each do |k|
            (0..k).each do |l|
                max = a[k][l]
                if k >= j
                    x, y = i - 1, l
                    x, y = y, x if y > x
                    m = a[x][y] + w
                    max = m if m > max
                end
                if l >= j
                    m = a[k][i-1] + w
                    max = m if m > max
                end
                b[k][l] = max
            end
        end
        a = b
    end
    p a[-1][-1]
end

Measured memory_bytes: 34056
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long int ans,n,m;
char arr[1005][1005];
long long int dp[1005][1005];
long long solve(long long int x,long long int y)
{
    if(x>n||x<=0)
        return 0;
    if(y>m||y<=0)
        return 0;
    if(x==1&&y==1)
    {
        dp[1][1]=1;
        return 1;
    }    
    if(arr[x][y]=='#')
    {
        dp[x][y]=0;
        return 0;
    }    
    if(dp[x][y]!=-1)
       return dp[x][y];
    dp[x][y]=(solve(x-1,y)+solve(x,y-1))%mod;
    //cout  << x  << " " << y  << " " << dp[x][y] << endl;
      return dp[x][y];
}
int main()
{
    long long int k,a,b,i,j;
    char ch;
    cin >> n >> m;
    //cin >> ch;
    for(i=1;i<=n;i++)
      for(j=1;j<=m;j++)  
    {
        cin >> arr[i][j];
    }
   for(i=0;i<1005;i++)
    for(j=0;j<1005;j++)
        dp[i][j]=-1;
   //cout << n << m; 
   cout << solve(n,m) << endl;
   /*for(i=1;i<=n;i++)
   {
    for(j=1;j<=m;j++)
        cout << arr[i][j];
    cout << endl;
   }*/
   return 0;
}

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

int bubbleSort(int *A, unsigned N)
{
	bool flag = true;
	int count = 0;
	while (flag) {
		flag = false; 
		for (int i = N - 1; i >= 1; i--)
		{
			if (A[i] < A[i - 1])
			{
				swap(A[i], A[i - 1]);
				count++;
				flag = true;
			}
		}
	}
	return count;
}

int main() {
	unsigned N = 0;
	cin >> N;
	int *A = new int[N];
	for (int i = 0; i < N; i++)
		cin >> A[i];
	int sort_time = bubbleSort(A, N);
	for (int i = 0; i < N; i++){
		cout << A[i];
                if(i!=(N-1))
                   cout<<' ';
}
	cout << endl;
	cout << sort_time<<endl;
	return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


//割引券は半額券
int main(){
    ll n,m;cin>>n>>m;
    vector<ll> a(n);
    priority_queue<ll> q;
    rep(i,n){
        cin>>a[i];
        q.push(a[i]);
    }
    rep(i,m){
        ll x=q.top();q.pop();
        x/=2;
        q.push(x);
    }
    ll ans=0;
    while(!q.empty()){
        ans+=q.top();q.pop();
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2168
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
typedef long long LL;
int n,k,cnt1,cnt2;
LL ans;

int main()
{
	scanf("%d%d",&n,&k);
	rep(i,1,n) if(i%k==0) ++cnt1;
	rep(i,1,n) if(!(k&1) && i%k==(k>>1)) ++cnt2;
	ans=(LL)cnt1*cnt1*cnt1+(LL)cnt2*cnt2*cnt2;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
import sys
from heapq import *

MAX_INT= 10 ** 10

n = int(input())
adj_list = []

for _ in range(n):
  commands = sys.stdin.readline().split()
  lst = [ commands[i:i+2] for i in range(2, len(commands), 2)]
  adj_list.append(lst)

def dijkstra():
  # initialization
  visited = [False] * n
  dist_arr = [MAX_INT] * n
  pq = []
  prev = [None] * n

  # append 0 to pqs
  pq = [(0, 0)]
  dist_arr[0] = 0

  while len(pq) > 0:
    dist, idx = heappop(pq)
    visited[idx] = True

    # updating current values in dist
    for edge in adj_list[idx]:
      cur_idx, cur_dist = [ int(e) for e in edge]
      if visited[cur_idx]: continue

      new_dist = dist + cur_dist

      if new_dist < dist_arr[cur_idx]:
        dist_arr[cur_idx] = new_dist
        heappush(pq, (dist_arr[cur_idx], cur_idx))

  return dist_arr

distArr = dijkstra()
for i in range(n):
  print(i, distArr[i])



Measured memory_bytes: 6616
#include <stdio.h>

int main (void )
{
    int i,j,k=0;
 scanf("%d",&i);
    int a[500];

  for (j=1;j<=i;++j)
  scanf("%d",&a[j]);

  for (j=1;j<=i;++j)
  {
      if (j%2!=0)
        if (a[j]%2!=0)
          ++k;

  }
printf("%d",k);
return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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; }

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

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


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N,M;
    cin>>N>>M;
    vector<ll> v;
    for(ll x = 1; x * x <= M; x++){
        if(M % x == 0){
            v.push_back(x);
            v.push_back(M / x);
        }
    }
    sort(all(v));
    //print(v);
    ll ans = 0;
    for(ll x:v){
        if(N <= M/x){
            ans = x;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	string a,b;
	cin>>a>>b;
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>

/*
なんでWAナノカ本当にわからん
*/

using ll = long long;

#define onWall(x, y) (x % r == 0 || y % c == 0)

using namespace std;

using P = pair<int, int>;
#define fi first
#define se second

int main() {
    int r, c, n;
    cin >> r >> c >> n;
    vector<int> wall;
    P points[200000];
    for (int i=0, x1, x2, y1, y2; i<n; i++) {
        cin >> x1 >> y1 >> x2 >> y2;
        points[i] = {x1, y1};
        points[i+n] = {x2, y2};
        if (onWall(x1, y1) && onWall(x2, y2)) {
            wall.push_back(i);
            wall.push_back(i+n);
        }
    }
    auto to_line = [&](P p){
        int x = p.fi, y = p.se;
        if (y==0) return x;
        if (x==r) return r+y;
        if (y==c) return r+c+r-x;
        return r+c+r+c-y;
    };
    sort(wall.begin(), wall.end(), [&](int a, int b) {
        P ap = points[a], bp = points[b];
        return to_line(ap) < to_line(bp);
    });
    stack<int> st;
    for (auto w:wall) {
        w %= n;
        if (!st.empty() && w == st.top()) st.pop();
        else st.push(w);
    }
    cout << (st.empty() ? "YES" : "NO") << '\n';
    return 0;
}

Measured memory_bytes: 2936
n=gets.to_i
a=[0]+gets.split.map(&:to_i)+[0]

d=0
(n+1).times do|i|
  d+=(a[i+1]-a[i]).abs
end
n.times do|i|
  p d-(a[i+1]-a[i]).abs-(a[i+2]-a[i+1]).abs+(a[i+2]-a[i]).abs
end


Measured memory_bytes: 18936
N, M = map(int, input().split())
A = [0 for i in range(M)]
B = [0 for i in range(M)]
C = [0 for i in range(M)]
dist = [[float('inf') for j in range(N)] for i in range(N)]
for i in range(M):
	A[i], B[i], C[i] = map(int, input().split())
	dist[A[i]-1][B[i]-1] = C[i]
	dist[B[i]-1][A[i]-1] = C[i]

for k in range(N):
	for i in range(N):
		for j in range(N):
			dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])

count = 0
for i in range(M):
	if dist[A[i]-1][B[i]-1] < C[i]:
		count = count+1

print(count)

Measured memory_bytes: 3700
#include <iostream>
using namespace std;
typedef long long ll;

int main () {
  int N;
  cin>>N;
  int a[100];
  for (int i=0; i<N; i++) {
    cin >> a[i];
  }
  ll sum=0;
  for (int i=0; i<N; i++) {
    for (int j=i+1; j<N; j++) {
      sum+=a[i]*a[j];
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3608
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "next", long, "cost");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, a, b;
    scan(n, a, b);
    auto x = aryread();
    iota(n - 1).map!(t => min(a * (x[t + 1] - x[t]), b)).sum.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

void dfs(int node, vector<vector<int>> &g, vector<int> &seen, vector<int> &depth) {
    seen[node] = 1;
    for(auto temp : g[node]) {
        if(seen[temp])
            continue;
        depth[temp] = depth[node] + 1;
        dfs(temp, g, seen, depth);
    }
}

int main() {
    //ifstream cin("d.in");

    int n; cin >> n;
    vector<vector<int>> g(n);

    for(int i = 0; i < n - 1; ++i) {
        int a, b; cin >> a >> b;
        a -= 1;
        b -= 1;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    vector<int> seen(n, 0);
    vector<int> depth(n, 0);
    
    int radius = 1e9;
    int64_t best_leaves = numeric_limits<int64_t>::max();

    for(int i = 0; i < n; ++i) {
        seen = vector<int> (n, 0);
        depth = vector<int> (n, 0);
        dfs(i, g, seen, depth);
        int64_t leaves = 1;
        int max_d = 0;
    
        for(int d = 0; d < n; ++d) {
            int maxx = 0;
            for(int j = 0; j < n; ++j)
                if(depth[j] == d) {
                    max_d = d;
                    maxx = max(maxx, int(g[j].size()) - (j != i));
                }
            if(maxx > 0)
                leaves = 1LL * leaves * maxx;
        }

        if(radius > max_d) {
            radius = max_d;
            best_leaves = leaves;
        } else if(radius == max_d) {
            best_leaves = min(best_leaves, leaves);
        }
    }

    for(int node = 0; node < n; ++node) {
        for(int v : g[node]) {
            vector<vector<int>> w(n + 1);
            for(int i = 0; i < n; ++i)
                for(int j : g[i]) {
                    if(i == node and j == v)
                        continue;
                    if(i == v and j == node)
                        continue;
                    w[i].push_back(j);
                }
            w[node].push_back(n);
            w[n].push_back(node);

            w[v].push_back(n);
            w[n].push_back(v);
            
            seen = vector<int> (n + 1, 0);
            depth = vector<int> (n + 1, 0);

            dfs(n, w, seen, depth);
            int64_t leaves = 1;
            int max_d = 0;

            for(int d = 0; d <= n; ++d) {
                int maxx = 0;
                for(int j = 0; j <= n; ++j) 
                    if(depth[j] == d) {
                        max_d = d;
                        maxx = max(maxx, int(w[j].size()) - (j != n));
                    }
                if(maxx > 0)
                    leaves = 1LL * leaves * maxx;
            }
            
            if(max_d - 1 < radius) {
                radius = max_d - 1;
                best_leaves = leaves;
            } else if(max_d - 1 == radius) {
                best_leaves = min(best_leaves, leaves);
            }
        }
    }

    cout << radius + 1 << " " << best_leaves << "\n";
}

Measured memory_bytes: 256