akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int k, n;
  cin >> k >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  long long path_sum = 0;
  int max = 0;

  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      path_sum += k - a.at(i) + a.at(0);
    } else {
      path_sum += a.at(i + 1) - a.at(i);
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      if (k - a.at(i) + a.at(0) > max) {
        max = k - a.at(i) + a.at(0);
      }
    } else {
      if (a.at(i + 1) - a.at(i) > max) {
        max = a.at(i + 1) - a.at(i);
      }
    }
  }
  cout << path_sum - max;
}


Measured memory_bytes: 1792
def popcount(x):
    return bin(x).count("1")

def f(x):
    if x == 0:
        return 1
    return f(x%popcount(x))+1

n = int(input())
x = input()
xx = int(x,2)
p = x.count("1")
stand1 = xx%(p+1)
if p != 1:
    stand2 = xx%(p-1)
for i in range(n):
    if x[i] == "1":
        if p != 1:
            k = stand2
            k -= pow(2,n-i-1,p-1) 
            k %= p-1
        else:
            print(0)
            continue
    else:
        k = stand1
        k += pow(2,n-i-1,p+1)
        k %= p+1
    print(f(k))

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

int main(){
  int n, alice, sum;
  cin >> n;
  alice = 0;
  sum = 0;
  vector<int> number(n);
  for(int i = 0; i < n; i++){
    cin >> number.at(i);
    sum += number.at(i);
  }
  sort(number.begin(),number.end());
  reverse(number.begin(),number.end());
  for(int i = 0; i < n; i += 2){
    alice += number.at(i);
  }
  cout << 2 * alice - sum << endl;
}

Measured memory_bytes: 256
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using V = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 10e9+7LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
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 (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    IN(n, m);
    VIN(ll, v, n);
    ll s = 0;
    rep(i, n)
    {
        s += v[i];
    }
    ll a = 0;
    rep(i, n)
    {
        if (v[i] >= (double)s/4/m) ++a;
    }
    yn(a >= m);
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
s=[i for i in input()]
a=0
if s[0]=="A":
    if s[2:-1].count("C")==1:
        s.remove("A")
        s.remove("C")
        S=[i.upper() for i in s]
        if set(S)&set(s)==set():
          a+=1
print("AC" if a==1 else "WA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int sumOfDigits(int n) {
	int total = 0;
	while (n > 0) {
		total += n % 10;
		n /= 10;
	}
	return total;
}

int main() {
	int n;
	cin >> n;
	int d = sumOfDigits(n);
	if (n % d == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000
typedef long long ll;
 
int main(){
    char a,b;
    cin>>a>>b;
    if(a>b)cout<<'>';
    else if(a<b)cout<<'<';
    else cout<<'=';
    return 0;
}

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

int main(){

	int n, a,count,amari;

	scanf("%d",&n);

	count = 0;

	for(int i = 0; i < n; i++){
		scanf("%d",&a);

		amari = 10;

		int x = 0;

		if(a == 2) {
			count = count + 1;	
			//printf("count%d\n",count);
		}
		else if(a%2==1){
			for(int i = 2; i < sqrt(a)+1; i++){
				amari = a%i;	
				//printf("amari %d\n",amari);
				if(amari == 0) x = x + 1;
			}
			if(x==0) count = count + 1;
			//printf("count %d\n",count);
		}
	}

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

	return 0;
}

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

#define ll long long
#define MOD 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define INF (ll)1e9
#define fora(i,a,b) for(ll i=a;i<b;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp(x,y) make_pair(x,y)
#define mli map<ll,int>
#define mll map<ll,ll>

using namespace std;

int main()
{   ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    ll n;
    cin>>n;
    ll num;
    num = (int)(sqrt(n))+1;
    ll dist[n+1]={0};

    fora(i,1,num+1)
    {
        fora(j,1,num+1)
        {
            fora(k,1,num+1)
            {ll val=0;
                val = i*i + j*j + k*k+i*j+j*k+k*i;
                if(val>n)
                continue;
                dist[val]++;
            }
        }
    }

    fora(i,1,n+1)
    cout<<dist[i]<<endl;
    return 0;
}




Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
	int h, w;
	
	cin >> h >> w;
	
	string str[26][26];
	
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> str[i][j];
		}
	}
	
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (str[i][j] == "snuke") {
				printf("%c%d\n", 'A' + j, i + 1);
				break;
			}
		}
	}
	
	return (0);
}

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

int main() {
	int N,tmp;
	cin >> N;
	vector<int>A(N);
	priority_queue<int,vector<int>,greater<int>>P;
	for (size_t i = 0; i < N; i++)
	{
		cin >> A.at(i);
	}
	for (size_t i = 0; i < 100; i++)
	{
		tmp = 0;
		for (size_t j = 0; j < N; j++)
		{
			tmp += pow(abs(int(i - A.at(j))), 2);
		}
		P.push(tmp);
	}
	cout << P.top();
}

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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str() // int to string
#define boost ios_base::sync_with_stdio(false)
#define deb(x) cout << #x" = " << x << '\n'
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

int a[5];

int main() {
//    freopen("input.in", "r", stdin);
	scanf("%d %d %d", a+0, a+1, a+2);
	sort(a, a+3);
	int res = 1234567;
	while(1) {
//		printf("%d %d %d\n", a[0], a[1], a[2]);
		res = min(res, abs(a[1]-a[0]) + abs(a[2]-a[1]));
		if(!next_permutation(a, a+3)) break;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())

l=[]
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            l.append(500*i+100*j+50*k)
n=0
for i in range(len(l)):
    if l[i]==x:
        n+=1
print(n)

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

int main() {
	while (1) {
		long long int x, y; cin >> x >> y;

		if (x == 0 && y == 0) break;

		if (x <= y) {
			cout << x << ' ' << y << endl;
		}
		else { cout << y << ' ' << x << endl; }

	}
}


Measured memory_bytes: 3112
// 質問用
// 詳しい質問は39行目から始まります
#include<iostream>
#include<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
/* 方針:操作2は(i-j)%2==0なる
i番目とj番目のみを交換できるので、
偶数番目同士、奇数番目同士では自由に交換できるが
1,3,5…番目と2,4,6…番目の間では操作1でしか交換ができず
よって、a[i]の値を小さい順に0,1,…n-1で置き換え、
a[i](添え字は0〜n-1)とiの
偶奇が違うところの数を数えて2で割れば解ける
(ここが違っていたら教えてください) */
int main(){
  int n,ans=0; cin>>n;
  /* 名前の通り、与えられたa(この後ソートされる)
　　　、もともとのaを保管するためのmoto、
     座標圧縮後の配列zaatuを用意する*/
  int a[n],moto[n],zaatu[n];
  rep(i,n){
    cin>>a[i];
    moto[i]=a[i];
  }
  sort(a,a+n);
  /*mapを用いて小さい順にa[i]の値にiを対応づける*/
  map<int,int> mp;
  rep(i,n){
    mp[a[i]]=i;
  }
  /*作った対応をもとに配列motoを0〜n-1に置き換える*/
  rep(i,n){
    zaatu[i]=mp[moto[i]];
  }
  /*zaatu[i]とiの偶奇が違うところを数えたい…けれど*/
  rep(i,n){
    int x=zaatu[i];
  /*ここでエラーが発生します
  (zaatu[i]をa[i]に置き換えるとREは消えます)
  ここでエラーが発生する原因が分かりません。
  どなたか教えていただけないでしょうか。*/
    if(x%2!=i%2){
      ans++;
    }
  }
  cout<<ans/2;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define MOD2 1000000009
#define endl "\n"
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vll std::vector<int>

int main()
{   
    IOS;
        #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
        #endif


   ll k;
   cin >> k;
   string s, s2 = "";
   cin >> s;
   if(s.size() > k) {
    for(int i = 0; i < k; i++) {
        s2 += s[i];
    }
    s2 += "...";

    cout << s2;
    return 0;

   }
   cout << s;


        
        
    


return 0;
}

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

bool is_prime(int n)
{
	for(int i=2;i*i<=n;i++)
		if(n%i==0)return false;
	return n != 1;
}
int solve(int n)
{
	for(int i=n;i>=0;i--){
		if(i==19)
			return i;
		if(i==13)
			return i;
		if(i%2!=0 && (i-2)%2!=0 && (i-6)%2!=0 && (i-8)%2!=0){
			if(i%3!=0 && (i-2)%3!=0 && (i-6)%3!=0 && (i-8)%3!=0){
				if(i%5!=0 && (i-2)%5!=0 && (i-6)%5!=0 && (i-8)%5!=0){
					if(i%7!=0 && (i-2)%7!=0 && (i-6)%7!=0 && (i-8)%7!=0){
						if(i%11!=0 && (i-2)%11!=0 && (i-6)%11!=0 && (i-8)%11!=0){
							if(is_prime(i)){
								if(is_prime(i-2)){
									if(is_prime(i-6)){
										if(is_prime(i-8)){
												return i;
										}
										i-=8;
										continue;
									}
									i-=6;
									continue;
								}
								i-=2;
								continue;
							}
							i--;
							continue;
						}
						i--;
						continue;
					}
					i--;
					continue;
				}
				i--;
				continue;
			}
			i--;
			continue;
		}
	}
	return 0;
}

int main()
{
	int n;
	while(cin >> n){
		if(n == 0)
			break;
		cout << solve(n) <<endl;
	}
	return 0;
}

Measured memory_bytes: 864
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define mex 1000005
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//vector<int> adj[mex];
//a+b=a^b+2*(a&b)

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS

int main(){
	fast
	
	
	int a[10005];
	memset(a,0,sizeof(a));
	for(int i=1;i<100;i++){
		for(int j=1;j<100;j++){
			for(int k=1;k<100;k++){
				int y=i*i+j*j+k*k+i*j+i*k+j*k;
				if(y<=10000)
				 a[y]+=1;
			 }
		 }
	 }
	 int n;
	 cin>>n;
	 for(int i=1;i<=n;i++)
	  cout<<a[i]<<endl;
}


Measured memory_bytes: 3692
#include<stdio.h>
int main(void){

  int a,b,c,d,r;
  double f;

  scanf("%d%d",&a,&b);
  f = (double)a / b;
  d = f;
  r = a % b;

  printf("%d %d %f\n",d,r,f);

  return 0;
}

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

int main(){
  long long h, n;
  cin >>h>>n;
  vector<int> a(n);
  for(int i=0; i<n; i++){
  	cin >> a.at(i);
    h -=a.at(i);
  }
  if(h<=0){
  	cout << "Yes" << endl;
  }
  else{
  	cout << "No" << endl;
  }
}


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

#define inf 1e18

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

#define tc ll t;cin >> t;while(t--)

#define ff first
#define ss second
#define pb push_back

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	vector <ll> lin(3,0);
	vector <ll> rin(3,0);
	ll x,y,z;
	cin >> lin[0] >> lin[1] >> lin[2];
	for1(i,n-1){
		cin >> x >> y >> z;
		rin[0] = max(lin[1]+x,lin[2]+x);
		rin[1] = max(lin[2]+y,lin[0]+y);
		rin[2] = max(lin[0]+z,lin[1]+z);
		for0(j,3){
			lin[j] = rin[j];
		}
	}
	cout << max(max(lin[0],lin[1]),lin[2])<<endl;

return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int N;
    cin >> N;
    vector <int> C(N), V(N);
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }
    int max_mask = (1 << N);
    int ans = -1e9;
    for (int mask = 0; mask < max_mask; mask++) {
        int X = 0;
        int Y = 0;
        for (int i = 0; i < N; i++) {
            if (mask & (1 << i)) {
                X += V[i];
                Y += C[i];
            }
        }
        ans = max(ans, X - Y);
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    A, B = i2nn()
    if A == B:
        print(A + B)
    elif A > B:
        print(A + A - 1)
    else:
        print(B + B - 1)

main()


Measured memory_bytes: 38384
N,M = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)
A_list = A[:M]

vote_sum = sum(A)
ans = 0

for i in A_list:
    if i/vote_sum < 1/(4*M):
        print("No")
        break
    else:
        ans +=1
if ans == M:
    print("Yes")

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

int main(){
 int n;
  cin >> n;
  double x[n+10];
  string u[n+10];
  for (int i=0;i<n;i++){
  cin >> x[i] >> u[i];
  }
  
  double ans = 0;
  
  for (int i=0;i<n;i++){
  if (u[i] == "BTC") {
    ans += 380000.0*x[i];
  }
else {
  ans += x[i];
}
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
void solve(){
    int n;
    cin>>n;
    if(n%10==3) cout<<"bon";
    else if(n%10==0||n%10==1||n%10==6||n%10==8)
    cout<<"pon";
    else
    cout<<"hon";
}
int  main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
    //cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3640
from sys import stdin

def main():

    input = stdin.readline

    S = str(input()[:-1])
    T = str(input()[:-1])

    ans = 1000

    for i in range(len(S)-len(T)+1):
        cnt = 0
        for j in range(len(T)):
            if S[i+j] != T[j]:
                cnt += 1
        
        ans = min(ans,cnt)

    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

using LL=long long int;
const int mod=1000000007;
int H,W,A,B,N;

LL s[200005],inv[200005];

LL qpow(LL a,int b){
	LL ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}

void init(){
	s[0]=1;
	for(int i=1;i<=N;i++) 
		s[i]=s[i-1]*i%mod;
	inv[0]=1;
	inv[N]=qpow(s[N],mod-2);
	for(int i=N-1;i>0;i--)
		inv[i]=inv[i+1]*(i+1)%mod;
}

LL C(int a,int b){
	if(a==0 || b==0) return 1;
	return s[a]*inv[b]%mod*inv[a-b]%mod;
}

int main(){
	cin>>H>>W>>A>>B;
	N=H+W-2;
	init();
	
	LL ans=0;
	for(int i=B+1;i<=W;i++){
		ans+=C(H-A-2+i,i-1)%mod*C(A-1+W-i,A-1)%mod;
		ans=ans%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
/**
*    created: 17.05.2020 12:08:36
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int k(int m){
    int a = m;
    int i = 0;
    while(a!=0){
        i++;
        a /= 10;
    }
    return i;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(k(i)%2){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  string s;
  cin>>s;
  map<char,int>k;
  for(int i=0;i<s.size();i++){
    k[s[i]]++;
  }
  cout<<2*min(k['0'],k['1'])<<endl;
  return 0;
}

Measured memory_bytes: 3732
//2020-04-12 17:29:15
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}

int main()
{
    ll kk;cin>>kk;
    ll sum=0;
    rep(i,1,kk+1){
        rep(j,1,kk+1){
            rep(k,1,kk+1)sum+=__gcd(__gcd(i,j),k);
        }
    }
    cout<<sum;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int g[55][55];

int main() {
  int N,M,a,b;
  int ans=0;
  cin>>N>>M;
  vector<int>c(N);
  for(int i=0;i<N;i++)c[i]=0;
  for(int i=0;i<N;i++)for(int j=0;j<N;j++)g[i][j]=0;
  for(int i=0;i<M;i++){
    cin>>a>>b;
    a--;b--;
    c[a]++;c[b]++;
    g[a][b]++;
    g[b][a]++;
  }
  for(int i=0;i<N;i++){
    if(c[i]==1){
      ans++;
      for(int j=0;j<N;j++){
        if(g[i][j]==1){
          c[i]--;
          c[j]--;
          g[i][j]--;
          g[j][i]--;
        }
        }
        i=-1;
      }
    }
    cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    vector<int> a;
    int q;
    cin >> q;
    rep(i, q){
        int n;
        cin >> n;
        switch (n)
        {
        case 0:
            int x;
            cin >> x;
            a.push_back(x);
            break;
        case 1:
            int p;
            cin >> p;
            cout << a[p] << endl;
            break;
        default:
            a.pop_back();
            break;
        }
    }

    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> a(N);
    rep (i, N) {
        cin >> a[i];
    }

    ll cnt = 0;
    ll cnt2 = 0;
    ll cnt4 = 0;
    rep (i, N) {
        if (a[i]%4 == 0) {
            cnt4++;
        } else if (a[i]%2 == 0) {
            cnt2++;
        } else {
            cnt++;
        }
    }

    if (cnt2) {
        cnt++;
    }

    if (cnt <= cnt4+1) {
        Yes;
    } else {
        No;
    }
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace Matrix_Vector_Multiplication
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int m = int.Parse(input[1]);
            int[,] nm = new int[n, m];
            int[] m1 = new int[m];
            int[] ans = new int[n];
            for (int i = 0; i < n; ++i)
            {
                input = Console.ReadLine().Split(' ');
                for (int j = 0; j < m; ++j)
                {
                    nm[i, j] = int.Parse(input[j]);
                }
            }
            for (int i = 0; i < m; ++i)
            {
                m1[i] = int.Parse(Console.ReadLine());
            }

                for (int i = 0; i < n; ++i)
                {
                    for (int j = 0; j < m; ++j)
                    {
                        ans[i] += nm[i, j] * m1[j];
                    }
                }

            for (int i = 0; i < n; ++i)
            {
                Console.WriteLine(ans[i]);
            }
        }
    }
}


Measured memory_bytes: 9332
N, M = map(int, input().split())
H = list(map(int, input().split()))
memo = [1]*N

for i in range(M):
    Ai, Bi = map(int, input().split())
    if H[Ai-1] <= H[Bi-1]:
        memo[Ai-1] = 0
    if H[Bi-1] <= H[Ai-1]:
        memo[Bi-1] = 0

print(sum(memo))


Measured memory_bytes: 20096
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    int n;
    cin>>n;

    if ( n % 2 == 0 )
    {
        cout<<1/(float)2<<endl;
    }
    else
    {
        cout<<((n/2)+1)/(float)n<<endl;
    }
    
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    if (a[i] == a[i + 1]) {
      ans++;
      i++;
    }
  }
  Cout(ans);
  return 0;
}

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

using namespace std;

long long a[200010];
long long b[200010];
int main() {

    int n,m,k;
    cin >> n >> m >> k;

    for (int i = 0; i < n; ++i)
        cin >> a[i];

    for (int i = 0; i < m; ++i)
        cin >> b[i];

    for (int i = 1; i < n; ++i)
        a[i] += a[i - 1];

    for (int i = 1; i < m; ++i)
        b[i] += b[i - 1];

    a[n] = b[m] = 1e9;

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        long long dk = k - a[i];
        if(dk < 0) break;
        ans = max(ans, i + 1);
        int p = upper_bound(b, b + m, dk) - b;
        p--;
        ans = max(ans, p + i + 2);
    }

    for (int i = 0; i < m; ++i) {
        long long dk = k - b[i];
        if(dk < 0) break;
        ans = max(ans, i + 1);
        int p = upper_bound(a, a + n, dk) - a;
        p--;
        ans = max(ans, p + i + 2);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6688
// C - Vacant Seat

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

const int V = 0;
const int M = 1;
const int F = 2;

int conv(string s) {
	if (s == "Vacant") return V;
	else if (s == "Male") return M;
	else return F;
}

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

	string s;

	cout << 0 << endl << flush;
	cin >> s;
	int t = conv(s);

	if (t == V) return 0;

	int head = t;
	int l = 0;
	int r = N - 1;

	while(1) {
		int m = (l + r + 1) / 2;
		//cout << l << " " << m << " " << r << endl; // **** debug ****
		cout << m << endl << flush;
		cin >> s;
		int t = conv(s);

		if (t == V) return 0;

		if ((m - l) % 2 == 1) {
			if (t == head) {
				r = m;
			} else {
				l = m;
				head = t;
			}
		} else {
			if (t == head) {
				l = m;
			} else {
				r = m;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3700
#include<stdio.h>
int main(){
        int a,b,c,cnt=0;
        scanf("%d %d %d",&a,&b,&c);
        for(int i=a;i<=b;++i){
                if(c%i==0)++cnt;
        }
        printf("%d\n",cnt);
        return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <math.h>
using namespace std;

int main()
{
	int N;
	std::cin >> N;
	string S;
	int count[4] = { 0 };
	for (int i = 0; i < N; i++) {
		std::cin >> S;
		if (S == "AC")
			count[0]++;
		else if (S == "WA")
			count[1]++;
		else if (S == "TLE")
			count[2]++;
		else if (S == "RE")
			count[3]++;
	}

	std::cout << "AC x " << count[0] << std::endl;
	std::cout << "WA x " << count[1] << std::endl;
	std::cout << "TLE x " << count[2] << std::endl;
	std::cout << "RE x " << count[3] << std::endl;

	
	return 0;
}

	


Measured memory_bytes: 3604
n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
for begin in range(n):
    step = 1
    while begin+2*step<n:
        if s[begin]!=s[begin+step] and s[begin+step]!=s[begin+2*step] and s[begin+2*step]!=s[begin]:
            ans -= 1
        step += 1
print(ans)


Measured memory_bytes: 67820
N, T = map(int, input().split())
alist = []

for i in range(N):
    ct = list(map(int, input().split()))
    alist.append(ct)

blist = list(filter(lambda x: x[1] <= T, alist))

if blist == []:
    print("TLE")

else:
    blist.sort(reverse=False)
    print(blist[0][0])

Measured memory_bytes: 3060
N = int(raw_input())
ans = ''
while N != 0 and N != 1:
	if N % (-2) == 0:
		ans = '0' + ans
		N = N / (-2)
	else:
		ans = '1' + ans
		N = N / (-2) + 1
ans = str(N) + ans
print ans

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    
    vector<ll> dp(13, 0);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        vector<ll> ndp(13, 0);
        int val = (s[i] == '?' ? -1 : s[i] - '0');
        for (int j = 0; j < 13; j++) {
            if (val == -1) {
                for (int k = 0; k < 10; k++) {
                    int nex = (j * 10 + k) % 13;
                    (ndp[nex] += dp[j]) %= MOD;
                }
            } else {
                int nex = (j * 10 + val) % 13;
                (ndp[nex] += dp[j]) %= MOD;
            }
        }
        dp = move(ndp);
    }

    cout << dp[5] << endl;
    return 0;
}

Measured memory_bytes: 512
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# 最小公倍数
def gcd(a, b):
  if a < b:
      a, b = b, a
  while a % b != 0:
      a, b = b, a % b
  return b
 
# 最大公約数 
def lcm(a, b):
    y = a*b / gcd(a, b)
    return int(y)

# N = INT()
# print(N)
N, A, B = MAP()
# guusuu
if (A - B) % 2 == 0:
  s = B - A
  ans = s // 2
  print(ans)
# kisuu
else:
  # if N - A <= B
  # k = B - A
  # m = min(N - A, B)
  if A - 1 <= N - B:
    # A ni tikazuku
    # 最初の移動
    s = A - 1
    # Bが残り移動する距離
    b = B - (A - 1) - 1

    ans = s + (b + 1) // 2
    # print(ans)
  else:
    s = N - B
    a = N - (A + s) + 1
    ans = s +  a // 2
    # ans = A + s + 1
    # ans = ans // 2
  print(ans)
  #   ans =(B - A + 1)//2

  # else:
  #   a = N - (A +  N - B )
  #   ans = a // 2
  # print(ans)
    



  # print(ans - k)
  # if A <= N - B:
  #   print(B - A)
  # else:
  #   print(B - A)
  # # k = B - A
  # ans = k+min(N - A, N - B)
  # B - min(N - A, N - B)
  # print(ans)




Measured memory_bytes: 5196
#include <bits/stdc++.h>
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;


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


  int a, b;
  cin >> a >> b;

  pr(a - (a > b ? 1 : 0));

  return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli n;
vector<lli> v;

lli dp[100100];

int main(){

	cin>>n;
	v.resize(n+2);

	REP(i,0,n)dp[i]=INF;
	dp[0]=0;

	REP(i,0,n)cin>>v[i];
	v[n]=INF,v[n+1]=INF;

	REP(i,0,n){
		dp[i+1] = min(dp[i+1],dp[i] + abs(v[i]-v[i+1]));
		dp[i+2] = min(dp[i+2],dp[i] + abs(v[i]-v[i+2]));
	}
	cout<<dp[n-1]<<endl;

    return 0;
}


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

int main() {
    int n, a, b;
    cin >> n >> a>> b;
    cout << ((b-a)%2 ? "Borys" : "Alice") << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) clog<<#x<<": "<<x<<endl
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define pb push_back
#define mod 1000000007
#define vi vector<int>
#define si set<int>
#define pi pair<int,int>
#define li list<int>
#define fi first
#define in insert
#define se second
#define mkp make_pair
#define fr(i,n) for(i = 0 ; i < n ; i++)
int factorial(int n)
{
    return (n==1 || n==0) ? 1: n * factorial(n - 1);
}

int main()
{
    fio
    int n,i,j,k,m,m1;
    cin>>n;
    ll sum = 0,s = 0;
    int a[n];
    fr(i,n)
    {cin>>a[i];
    s+=a[i];}
    m = s/n;
   // cout<<m<<endl;
    m1 = (s+n-1)/n;
   // cout<<m1<<endl;
   // m = (m+m1)/2;
   // cout<<m<<endl;
    /*
    sort(a,a+n);
    if(n%2)
        m = a[n/2];
    else{
        m = (a[n/2]+a[n/2 - 1])/2;
    }*/
    fr(i,n)
    {
        sum +=((a[i]-m)*(a[i]-m));
    }
    ll sum2=0;
    fr(i,n)
    {
        sum2 +=((a[i]-m1)*(a[i]-m1));
    }
    cout<<min(sum,sum2);
    return 0;
}


Measured memory_bytes: 256
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
# mod = 10**9 + 7

a = int(input())
b = int(input())
# s = deque(input())
# q = int(input())

# n, k = map(int, input().split())
# a = list(map(int, input().split()))
ans = -1
for i in range(1,4):
    if a != i and b != i:
        ans = i
        break
print(ans)

Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(void){
    int n, m;
    cin >> n >> m;
    int A[n][m];
    int b[m];
    int c[n];
    for (int i = 0; i < n; i++) {
        c[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> A[i][j];
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            c[i] += A[i][j] * b[j];
        }
    }
    for (int i = 0; i < n; i++) cout << c[i] << endl;
}

Measured memory_bytes: 3120
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var a = cin.nextInt();
            var b = cin.nextInt();

            Console.WriteLine(b<a? a-1:a);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


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

int main(){
  int n, h, now=-1, x=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> h;
    if(h>=now){
      now=h;
      x++; 
    }
  }
  cout << x << endl;
}

Measured memory_bytes: 256
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <bits/stdc++.h>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout << endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i++)
#define revn(i, n, x) for(long long i = n; i >= x; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define debug(x)      cout << x << endl;
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll bS(ll l, ll r, ll x, vll arr) {
	while (l <= r) {
		ll m = l + (r - l) / 2;

		if (arr[m] == x)
			return m;

		if (arr[m] < x)
			l = m + 1;

		else
			r = m - 1;
	}

	return -1;
}

void primeFactors(ll n) {
	while (n % 2 == 0) {
		//cout << 2 << " ";
		n = n / 2;
	}

	for (ll i = 3; i <= sqrt(n); i += 2) {
		while (n % i == 0) {
			//cout << i << " ";
			n = n / i;
		}
	}

	if (n > 2)
		cout << n << " ";
}

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	while (t--) {
		ll n, k;
		cin >> n >> k;
		ll count = 0, count1 = 0;
		forn(i, 1, n + 1) {
			if (i % k == 0) {
				count++;
			}
			if (k % 2 == 0 && i % k == k / 2)
				count1++;
		}
		cout << count1*count1*count1 + count*count*count << endl;
	}
	CLOCK
	return 0;
}
//Credits: Editorial
//Credits: https://www.whitman.edu/mathematics/higher_math_online/section03.01.html
//Credits: https://www.programmersought.com/article/18961901649/



Measured memory_bytes: 3792
#include <cstdio>

int main(){
    char a,b;
    scanf("%c %c",&a,&b);
    int A,B;
    if(a == 'H'){
        A = 1;
    }else{
        A = -1;
    }
    if(b == 'H'){
        B = 1;
    }else{
        B = -1;
    }
    if(A * B == 1){
        printf("H\n");
    }else{
        printf("D\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int dp[3][d5];
    for(int i=0;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        if(i==0){
            dp[0][0]=a;
            dp[1][0]=b;
            dp[2][0]=c;
        }
        else{
            dp[0][i]=max(dp[1][i-1]+a,dp[2][i-1]+a);
            dp[1][i]=max(dp[0][i-1]+b,dp[2][i-1]+b);
            dp[2][i]=max(dp[0][i-1]+c,dp[1][i-1]+c);
        }
    }
    cout<<max({dp[0][n-1],dp[1][n-1],dp[2][n-1]})<<endl;
}

Measured memory_bytes: 2560
object Main {
  def main(args: Array[String]): Unit = {
    // var prev_place = Array(0, 0, 0)
    val n = io.StdIn.readLine().toInt

    val inputs = Stream.continually(io.StdIn.readLine().split(' ').map { _.toInt }) take n

    val ls = Array(0,0,0) +: inputs

    val diff = (inputs zip ls) map {
      case (x,y) => (x zip y) map {
        case (a,b) => a-b
      }
    }

    def check(x:Array[Int]): Boolean = {
      return x(1) + x(2) <= x(0) && (x sum) % 2 == 0
    }

    if (diff.forall(check))
      println("Yes")
    else
      println("No")

/*
    var result = true
    var i = 0
    while (i < n && result == true) {
      val place = io.StdIn.readLine().split(' ').map({ _.toInt })
      val time = place(0) - prev_place(0)
      val move = place.zip(prev_place).map({ case (x, y) => x-y }).drop(1)

      if (move.sum > time)
        result = false

      if ((time + move.sum) % 2 == 1)
        result = false

      prev_place = place
      i += 1
    }

    if (result == true)
      println("Yes")
    else
      println("No")
*/
  }
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N + 1);
  for (int i = 0; i < N + 1; i++) {
    scanf("%lld", &A[i]);
  }
  std::vector<long long> B(N + 1);
  for (int i = 1; i < N + 1; i++) {
    scanf("%lld", &B[i]);
  }
  B.pb(0);

  ll ans = 0;
  rep(i, 0, N + 1) {
    if (A[i] >= B[i]) {
      ans += B[i];
      A[i] -= B[i];
    } else {
      ans += A[i];
      A[i] = 0;
    }

    if (A[i] >= B[i + 1]) {
      ans += B[i + 1];
      A[i] -= B[i + 1];
      B[i + 1] = 0;
    } else {
      ans += A[i];
      B[i + 1] -= A[i];
      A[i] = 0;
    }
  }

  cout << ans << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 2560