akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;

ll gcd(ll N, ll M){

if(N%M == 0)return M;

else return gcd(M, N%M);

}

int main(){
ll N, X, Ans = 0;cin >> N >>X;

if(N == 1){
ll a;cin >> a;
cout << abs(X - a);
exit(0);
}

rep(i, 0, N - 1){

if(i == 0){
ll a, b;cin >> a >> b;
Ans = gcd( abs(X - a), abs(X - b) );
}

else{
ll a;cin >> a;
Ans = gcd( Ans, abs(X - a) );
}

}


cout << Ans;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define reset(X) memset(X, 0, sizeof(X))
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif

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

	ll n;
	cin >> n;
	ll arr[n];

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

	ll a = 0;
	for (ll i = 0; i < n; i++)
	{
		a ^= arr[i];
	}
	//cout << a << endl;
	for (ll i = 0; i < n; i++)
	{
		ll x = a ^ arr[i];
		cout << x << " ";
	}
	cout << endl;
}



Measured memory_bytes: 5132
#include <stdio.h>
int main()
{
    int A,B,k,p,d,g,integer;
scanf("%d%d",&A,&B);
p=A+B;
k=p/2;
if(p%2==0) {
        printf("%d\n",k);
}
else{
    printf("IMPOSSIBLE\n");
}
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    string s;
    cin >> s;
    int n = s.size();
    int ans = INF;
    REP(i,n-1) if(s[i] != s[i+1]) chmin(ans, max(i+1, n-i-1));
    if(ans == INF) ans = n;
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(void){
  string s;
  cin>>s;
  int len=s.length();
  for(int i=0;i<(len-1);i++){
    if(s[i]=='A' && s[i+1]=='C'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

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

using namespace std;

int main() {
	int N, K, ride = 0;
	cin >> N >> K;
	for(int i = 0; i < N; i++) {
		int height;
		cin >> height;
		if(height >= K) ride++;
	}
	
	cout << ride << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;

int main(){

	int n, h, m;
	double deg_l, deg_s, deg;
	string str;

	cin >> n;
	
	for(int i=0; i<n; i++){
		cin >> str;
		
		h = (str[0] - '0') * 10 + (str[1] - '0');
		m = (str[3] - '0') * 10 + (str[4] - '0');
		deg_l = 360.0 * (m / 60.0);
		deg_s = 360.0 * (h / 12.0) + 30.0 * (m / 60.0);
		
		deg = min(abs(deg_l - deg_s), 360.0 - abs(deg_l - deg_s));
		
		if(deg < 30.0) cout << "alert" << endl;
		else if(deg < 90.0) cout << "warning" << endl;
		else cout << "safe" << endl;
	}

	return 0;

}

Measured memory_bytes: 1196
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;

string s;
int cnt[N];

int main() {
    ios::sync_with_stdio(false);
    cin>>s;
    int ans=0,num=0,res=1;
    cnt[0]=1;
    for(int i=s.size()-1;i>=0;--i){
        num=(num+(s[i]-'0')*res)%2019;
        ans+=cnt[num]++;
        res=res*10%2019;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 3780
from itertools import accumulate


def solve():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    L = list(map(int, input().split()))

    ans = -float("inf")
    for i in range(N):
        score_acc = [L[i]]
        cur = P[i] - 1
        while cur != i:
            score_acc.append(L[cur])
            cur = P[cur] - 1
        score_acc = list(accumulate(score_acc))
        M = len(score_acc)
        if M < K and score_acc[-1] > 0:
            res = K // M * score_acc[-1]
            if K % M:
                res += max(score_acc[: K % M])
            else:
                res += -score_acc[-1] + max(score_acc)
            ans = max(ans, res)
        else:
            res = max(score_acc[:K])
            ans = max(ans, res)
    return ans


print(solve())


Measured memory_bytes: 99092
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

ll n,k,x,y;

int main(){
  ll ans=0;

  cin >> n;
  
  vvvi data = vvvi(n, vvi(3, vi(4)));

  if (n==1){
    cout<<0<<endl;
    return 0;
  }
  
  if (n==2){
    cout<<2<<endl;
    return 0;
  }


  for(ll i=0;i<3;i++){
    if ((i!=0)&(i!=2)){
      data[0][i][0]=1;
    }
    
    if (i==0){
      data[0][i][1]=1;
    }
    
    if (i==2){
      data[0][i][2]=1;
    }

  }


  for(ll i=0;i<n-1;i++){
    ll j=0;
    ll x;
    //j=0 1
    x=data[i][j][1]%MOD;
    for(ll k=0;k<=1;k++){
      data[i+1][k][1]+=x;
    }
    data[i+1][2][3]+=x;

    //j=0 3
    x=data[i][j][3];
    for(ll k=0;k<3;k++){
      data[i+1][k][3]+=x;
    }


    for(j=1;j<2;j++){
      x=data[i][j][0]*8%MOD;
      //j=1-9  0
      for(ll k=1;k<=1;k++){
        data[i+1][k][0]+=x;
      }
      data[i+1][0][1]+=x;
      data[i+1][2][2]+=x;

      x=data[i][j][1]*8%MOD;
      //j=1-9  1
      for(ll k=0;k<=1;k++){
        data[i+1][k][1]+=x;
      }
      data[i+1][2][3]+=x;

      x=data[i][j][2]*8%MOD;
      //j=1-9  2
      for(ll k=1;k<=2;k++){
        data[i+1][k][2]+=x;
      }
      data[i+1][0][3]+=x;


      x=data[i][j][3]*8%MOD;
      //j=1-9  3
      for(ll k=0;k<=2;k++){
        data[i+1][k][3]+=x;
      }
    }

    
    

    j=2;
    //j=9 2
    x=data[i][j][2]%MOD;
    for(ll k=1;k<=2;k++){
      data[i+1][k][2]+=x;
    }
    data[i+1][0][3]+=x;

    //j=9 3
    x=data[i][j][3]%MOD;
    for(ll k=0;k<3;k++){
      data[i+1][k][3]+=x;
    }

    
    /*
    for(ll k=0;k<4;k++){
      data[i+1][1][k]=data[i+1][1][k]*8%MOD;
    }
    */
    


  }


  ans=0;
  ans+=data[n-1][0][3];
  ans+=data[n-1][1][3]*8;
  ans+=data[n-1][2][3];
  ans%=MOD;

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

Measured memory_bytes: 245164
#include<bits/stdc++.h>
using namespace std;
const int MAX=303;
string s[MAX];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int cnt=0;
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<n;k++)
            {
                if(s[j][k]==s[k][j])
                {
                    cnt++;
                }
            }
        }

        if(cnt==(n*n))
        {
            ans++;
        }
        for(int j=0;j<n;j++)
        {
            s[j]=s[j].substr(1)+s[j][0];
        }   
    }
    printf("%d\n",ans*n);
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	long long n,s,t,m=0,a;
	scanf("%lld",&n);
	s=n/500;
	m+=s*1000;
	t=n%500;
	a=t/5;
	m+=a*5;
	printf("%lld\n",m);
	return 0;
}

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

int main()
{
  long long n;
  cin>>n;
  long long arr[n],dp[n];
  for(int i=0; i<n; ++i)
  {
    cin>>arr[i];
  }
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(int i =2;i<n;++i)
  {
    	dp[i] = min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1]));		
  }
  cout<<dp[n-1];
  return 0;
}

Measured memory_bytes: 1792
s = gets.chomp.split('')
half = (s.length - (s.length % 2)) / 2
s1 = s[0 .. half - 1]
s2 = s[half .. s.length - 1].reverse

hug = 0
half.times{|i|
  if s1[i] != s2[i]
    hug += 1
  end
}
puts hug


Measured memory_bytes: 1788
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    val x = readLine()!!.split(' ').map(String::toInt)
    var count = 0
    for (i in 0..(n - 1)) {
        count += 2 * Math.min(Math.abs(x[i]), Math.abs(k - x[i]))
    }
    println(count)
}

Measured memory_bytes: 36316
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<utility>
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
	ll n,m,d;cin>>n>>m>>d;
	m--;
	ll t = 0;
	if(n>=d)
		t = n-d;
	else t = 0;
	if(d)t *= 2;
//	cout<<"!"<<t<<endl;
	double ans = (0.0+t)/(n*n);
	ans *= m;
	printf("%.9f",ans); 
	return 0;
}

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

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

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i], a[i] *= 2;

  ll o = 0;
  rep(i, 0, n) {
    // test
    o = a[i] - o;
  }
  ll x = o / 2;

  ll now = x;
  rep(i, 0, n) {
    if (i > 0)
      cout << " ";
    cout << now;
    now = a[i] - now;
  }
  cout << endl;
}


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

int main()
{
    int n, sum;
    cin >> n >> sum;
    sum /= 1000;
    int x, y, z;
    for (x = 0; x <= n; ++x)
    {
        for (y = 0; y <= n - x; ++y)
        {
            z = n - x - y;
            if (x * 10 + y * 5 + z == sum)
            {
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
ans = 0
s = 0

for i in range(0,len(A)-1):
    if(A[i]>A[i+1]):
        s = A[i]-A[i+1]
        ans += s
        A[i+1]=A[i]
    
print(ans)

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

using namespace std;

const int N = 10;

int n, tot = 1;
int x[N], y[N], p[N];
double sum;

inline double dis(int i, int j) {
    return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", x+i, y+i);
        p[i] = i;
        tot *= (i+1);
    }
    do {
        for (int i = 1; i < n; ++i)
            sum += dis(p[i-1], p[i]);
    } while (next_permutation(p, p+n));
    printf("%10lf\n", sum/tot);
    return 0;
}



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

const int N = 2e3 + 10, mod = 1e9 + 7;

pair<int, int> arr[N];
long long dp[N][N];
int n;

long long solve(int i, int l) {
    if(!arr[i].first) return 0;
    if(dp[i][l] != -1) return dp[i][l];
    int r = n - (i - l);
    long long ret = solve(i + 1, l + 1) + 1ll * arr[i].first * abs(arr[i].second - l);
    ret = max(ret, solve(i + 1, l) + 1ll * arr[i].first * abs(arr[i].second - r));
    return dp[i][l] = ret;
}

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    //scanf("%d", &tc);
    while(tc--) {
        scanf("%d", &n);
        for(int i = 0; i < n; i++) {
            scanf("%d", &arr[i].first);
            arr[i].second = i + 1;
        }
        sort(arr, arr + n, greater<pair<int, int>>());
        //for(int i = 1; i <= n; i++) cout << arr[i].first << ' ' << arr[i].second << '\n';
        //memset(dp, -1, sizeof(dp));
        //cout << solve(1, 1);
        for(int i = 0; i < n; i++) {
            for(int l = 1; l < i + 2; l++) {
                int r = n - (i - l + 1);
                //cout << i << ' ' << l << ' ' << r << '\n';
                dp[i + 1][l + 1] = max(dp[i + 1][l + 1], dp[i][l] + 1ll * abs(arr[i].second - l) * arr[i].first);
                dp[i + 1][l] = max(dp[i + 1][l], dp[i][l] + 1ll * abs(arr[i].second - r) * arr[i].first);
            }
        }
        //cout << dp[1][2] << ' ' << dp[2][2] << ' ' << dp[3][3] << ' ' << dp[4][4] << '\n';
        long long ans = 0;
        for(int l = 1; l <= n + 1; l++) ans = max(ans, dp[n][l]);
        printf("%lld\n", ans);
    }    
    return 0;
}

Measured memory_bytes: 26452
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{int n,a,b=0,sum=0,i,w=1;
while(cin>>n)
{  w=1;b=0;
    for(i=1;i<=n;i++)
   {a=i;

    sum=0;
    while(a%2==0&&a)
  {

sum++;a=a/2;}
    if(sum>b)
        {b=sum;w=i;}
    }
   if(n==1)
    w=1;
cout<<w<<endl;

}
return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
ll N, W;
vector<pair<double, double>> pack;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> W;
    pack.resize(N);
    rep(i, N)
    {
        double v, w;
        cin >> v >> w;
        pack[i].first = v / w;
        pack[i].second = w;
    }

    sort(pack.rbegin(), pack.rend());
    double sum_w = 0, sum_v = 0;
    rep(i, N)
    {
        if (W - (sum_w + pack[i].second) > 0) {
            sum_v += pack[i].first * pack[i].second;
            sum_w += pack[i].second;
        } else if (W - sum_w > 0) {
            sum_v += pack[i].first * (W - sum_w);
            sum_w = W;
        }
    }
    printf("%lf\n", sum_v);

    return 0;
}


Measured memory_bytes: 4424
#include <iostream>
#include <vector>
#define INF 50000000000000
std::vector<int> G[100000];
struct edge{int from,to,cost;};
int V,E,r;
bool negativeflag=false;
bool possiblity[100000];
edge es[500000];
long long int d[100000];
void shortest_path(int s);
bool negative_path(int s);
bool reachable(int v);
int main(void){
	std::cin>>V>>E>>r;
	for(int i=0;i<E;i++){
		int from,to,cost;
		std::cin>>from>>to>>cost;
		G[from].push_back(to);
		//G[t].push_back(s);
		es[i].from=from;
		es[i].to=to;
		es[i].cost=cost;
	}
	negativeflag=negative_path(r);
	if(!negativeflag){
		shortest_path(r);
	}
	if(negativeflag){
		std::cout<<"NEGATIVE CYCLE"<<std::endl;
	}else {
		for(int i=0;i<V;i++){
			if(d[i]!=INF){
				std::cout<<d[i]<<std::endl;
			}else {
				std::cout<<"INF"<<std::endl;
			}
		}
	}
	return 0;
}
void shortest_path(int s){
	for(int i=0;i<V;i++){
		d[i]=INF;
	}
	d[r]=0;
	while(1){
	//for(int j=0;j<V;j++){
		bool flag=true;
		for(int i=0;i<E;i++){
			if(d[es[i].from]!=INF){
				if(d[es[i].to]>d[es[i].from]+es[i].cost){
					d[es[i].to]=d[es[i].from]+es[i].cost;
					flag=false;
				}
			}
		}
		if(flag){
			break;
		}
	}
}
bool negative_path(int s){
	bool flag=false;
	for(int i=0;i<V;i++){
		d[i]=INF;
		possiblity[i]=false;
	}
	d[r]=0;
	for(int j=0;j<V;j++){
		for(int i=0;i<E;i++){
			if(d[es[i].from]!=INF){
				if(d[es[i].to]>d[es[i].from]+es[i].cost){
					d[es[i].to]=d[es[i].from]+es[i].cost;
					if(j==V-1){
						flag=true;
					}
				}
			}
		}
	}
	return flag;
	/*for(int i=0;i<V;i++){
		std::cout<<d[i]<<std::endl;
	}
	if(flag==false){
		return false;
	}else {
		flag=reachable(r);
		return flag;	
	}*/
}
bool reachable(int v){
	possiblity[v]=true;
	if(d[v]<0){
		return true;
	}else {
		for(int i=0;i<G[v].size();i++){
			if(possiblity[G[v][i]]==false){
				return reachable(G[v][i]);
			}
		}
	}
	return false;
}

Measured memory_bytes: 5532
#include "bits/stdc++.h"
using namespace std;

int n,withdraw;
vector<pair<int,int>> sixNine;
vector<int> six, nine;
set<int> moves;

int sixYen(int current){
	if(pow(6,current) > 100000){
		return current;
	}
	else{
		six.push_back(pow(6,current));
		sixYen(current+1);
	}
}

int nineYen(int current){
	if(pow(9,current) > 100000){
		return current;
	}
	else{
		nine.push_back(pow(9,current));
		nineYen(current+1);
	}
}

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

	sixYen(0); nineYen(0);
	cin>>n;

	for(int i=0;i<=n;i++){
		sixNine.push_back(make_pair(i,n-i));
	}

	for(int i=0;i<sixNine.size();i++){
		withdraw=0;
		while(sixNine[i].first > 0){
			if(sixNine[i].first <= 5){
				withdraw+=sixNine[i].first;
				sixNine[i].first=0;
			}
			else{
				int power = log(sixNine[i].first)/log(6)+0.00001;
				sixNine[i].first -= six[power];
				withdraw++;
			}
		}
		while(sixNine[i].second > 0){
			if(sixNine[i].second <= 8){
				withdraw+=sixNine[i].second;
				sixNine[i].second=0;
			}
			else{
				int power = log(sixNine[i].second)/log(9)+0.00001;
				sixNine[i].second -= nine[power];
				withdraw++;
			}
		}
		moves.insert(withdraw);
	}

	cout<<*moves.begin();
	return 0;
}

Measured memory_bytes: 1400
t,r=[],[]
while gets
  q=$_.split(",").map(&:to_i)
  break if q==[0,0]
  t<<q
end
t.sort!{|i,j| j[1]<=>i[1]}.each{|i,j| r<<j}
while gets
  q=$_.chomp.to_i
  t.each do |i,j|
    if i==q
      p r.uniq.index(j)+1
      break
    end
  end
end

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int> v(200000);
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		v.at(A - 1)++;
	}

	sort(v.begin(), v.end());
	//for (int i = 0; i < 3; i++) cout << v.at(i) << endl;

	int ans = 0;
	for (int i = v.size() - K - 1; i >= 0; i--) {
		if (!v.at(i)) break;
		else ans += v.at(i);
	}

	cout << ans << endl;
}

Measured memory_bytes: 4020
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int A; long long B, N;
	cin >> A >> B >> N;
	long long x = min(N, B - 1);
	cout << A * x / B - A * (x / B) << endl;
	return 0;
}

Measured memory_bytes: 3640
// AUTHOR : RUTVIK KOTHARI
// DA-IICT

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

#define ll long long int 
#define ull unsigned long long
#define pll pair<ll,ll>
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define INFL 10000000000000000
#define pb push_back
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll N = 2e5 + 5;
const ll M = 1e5 + 5;
const ll mod = 1e9 + 7;
const ll m1 = 1e9 + 7;
const ll m2 = 1e9 + 9;
const ll p1 = 402653189;
const ll p2 = 1610612741;
const int LN = 61;

ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

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

ll pw[LN],fact[N],invfact[N];

void pre()
{
    fact[0]=1;
    for(int i=0;i<LN;i++)pw[i]=power(2,i);
    for(int i=1;i<N;i++)fact[i]=(i*fact[i-1])%mod;
    for(int i=0;i<N;i++)invfact[i]=powermodm(fact[i],mod-2,mod);
}


int main()
{
    FIO;
    //pre();

    ll i,j;
    
    ll n,h,w;
    cin>>n>>h>>w;
    
    if(h>n || w>n)
    {
        cout<<"0";
        return 0;
    }
    
    ll ans=(n-h+1)*(n-w+1);
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
using namespace std;

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

  stack<int> bs_index;          // Index of backslash(\)
  stack<pair<int, int>> puddle; // (index, area)

  int total_area = 0;
  for (int i = 0; i < (int)str.length(); ++i)
  {
    switch (str[i])
    {
      case '\\':
      {
        bs_index.push(i);
        break;
      }
      case '/':
      {
        if (!bs_index.empty()) // Corresponding backslach(\) is found
        {
          int j = bs_index.top();
          int area = i - j;
          bs_index.pop();

          while (!puddle.empty() && j < puddle.top().first) // Integratable puddle is found
          {
            area += puddle.top().second; // Integrate the puddle
            puddle.pop();
          }

          puddle.push(pair<int, int>(j, area)); // Add new puddle
          total_area += (i - j);                 // Add to total area
        }
        break;
      }
      default:
        break;
    }
  }

  cout << total_area << endl;

  int num_of_puddles = puddle.size();

  string result;
  for (int i = 0; i < num_of_puddles; ++i)
  {
    result = ' ' + to_string(puddle.top().second) + result;
    puddle.pop();
  }
  cout << num_of_puddles << result << endl;

  return 0;
}



Measured memory_bytes: 3320
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

const int MAX_N = 2000000;
vector<int> prime;
bool is_prime[MAX_N + 1];
void sieve(int n){
    rep(i, 0, n + 1) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    rep(i, 2, n + 1){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j = 2*i; j <= n; j += i) is_prime[j] = false;
        }
    }
}

signed main(){
    sieve(MAX_N);
    int n;
    while(cin >> n, n){
        if(is_prime[n]){
            cout << 0 << endl;
            continue;
        }
        int ind = upper_bound(all(prime), n) - prime.begin();
        cout << prime[ind] - prime[ind - 1] << endl;
    }
}

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

int f[102][6][3]={0}, p[102][11]={0}, c[102]={0};

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i)
        for(int j=0;j<5;++j)
            for(int k=0;k<2;++k)
                cin >> f[i][j][k];
    for(int i=0;i<n;++i)
        for(int j=0;j<=10;++j)
            cin >> p[i][j];

    int ans = INT_MIN;
    for(int i=1;i<(1<<10);++i){
        memset(c, 0, sizeof(c));
        for(int j=0;j<10;++j){
            if((i>>j)&1){
                int day = j / 2, t = j & 1;
                for(int k=0;k<n;++k){
                    if(f[k][day][t])c[k]++;
                }
            }
        }
        int sum = 0;
        for(int j=0;j<n;++j)sum += p[j][c[j]];
        ans = max(ans, sum);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   int ans = 0;
   for (int num = 1; num <= n; num += 2) {
      int cnt = 0;
      rep(i, 1, num + 1) {
         if (num % i == 0) cnt++;
      }
      if (cnt == 8) ans++;
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int w[2001], b[2001];
int cw[2001][2001], cb[2001][2001], f[2001][2001];

int main(){
  memset(cw, 0, sizeof(cw));
  memset(cb, 0, sizeof(cb));
  memset(f, 0, sizeof(f));
  
  int N;cin>>N;
  for (int i=1;i<=2*N;++i){
    char c;cin>>c;int a;cin>>a;
    if(c=='W') w[a]=i;
    else b[a]=i;
  }

  for (int i=1;i<=N;++i){
    for (int j=1;j<i;++j){
      cw[i][0]+=(w[j]>w[i]);
    }

    for (int j=1;j<=N;++j){
      cw[i][j]=cw[i][j-1]+(w[i]<b[j]);
    }
  }

  for (int i=1;i<=N;++i){
    for (int j=1;j<i;++j){
      cb[0][i]+=(b[j]>b[i]);
    }

    for (int j=1;j<=N;++j){
      cb[j][i]=cb[j-1][i]+(b[i]<w[j]);
    }
  }

  for (int i=1;i<=N;++i){
    f[i][0]=f[i-1][0]+cw[i][0];
  }
  for (int i=1;i<=N;++i){
    f[0][i]=f[0][i-1]+cb[0][i];
  }

  for (int i=1;i<=N;++i){
    for (int j=1;j<=N;++j){
      f[i][j]=min(f[i-1][j]+cw[i][j], f[i][j-1]+cb[i][j]);
    }
  }

  cout << f[N][N] << endl;
  return 0;
}

Measured memory_bytes: 47232
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int n, m;
    cin >> n >> m;
    cout << (n == m ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<char> vi;
int main()
{
    // freopen("B.04.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q=0;
    cin >> n;
    vi a(n);
    vi colors(4, 0);
    trav(it, a)
    {
        cin >> it;
    }
    rep(i, 0, n)
    {
        if (a[i] == 'P')
        {
            colors[0]++;
        }
        if (a[i] == 'W')
        {
            colors[1]++;
        }
        if (a[i] == 'G')
        {
            colors[2]++;
        }
        if (a[i] == 'Y')
        {
            colors[3]++;
        }
    }
    rep(i, 0, 4){
        if(colors[i]!=0){
            q++;
        }
    }
    if(q==3){
        cout << "Three" << endl;
    }
    else{
        cout << "Four" << endl;
    }
    return 0;
}

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

static const int NMAX = 50000;
static const int INFTY = (1<<29);

int main(){
    int n,m;
    int C[21];
    int T[NMAX+1];
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        cin >> C[i];
    }
    
    for(int i=0; i<=NMAX; i++) T[i] = INFTY;
    T[0] = 0;
    for(int i=1; i<=m; i++){
        for(int j=C[i]; j<=n; j++){
            T[j] = min(T[j],T[j-C[i]]+1);
        }
    }
    cout << T[n] << endl;
}

Measured memory_bytes: 3280
import sys
sys.setrecursionlimit(2147483647)
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
for i in range(n-k):
    if t[i] == t[i+k]:
        t[i+k] = "d"

t = "".join(t)
t = t.replace("r", "{}+".format(p)).replace("p", "{}+".format(s)).replace("s", "{}+".format(r)).replace("d", "0+") + "0"
print(eval(t))


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

int main() {
  int N, a, b, c, tmp1, tmp2;
  cin >> N;
  int happy[N+1][3] = {};
  for (int i=1; i<=N; i++) {
    cin >> a >> b >> c;
    tmp1 = happy[i-1][1] + a;
    tmp2 = happy[i-1][2] + a;
    if (tmp1 > tmp2) happy[i][0] = tmp1;
    else happy[i][0] = tmp2;
    tmp1 = happy[i-1][0] + b;
    tmp2 = happy[i-1][2] + b;
    if (tmp1 > tmp2) happy[i][1] = tmp1;
    else happy[i][1] = tmp2;
    tmp1 = happy[i-1][0] + c;
    tmp2 = happy[i-1][1] + c;
    if (tmp1 > tmp2) happy[i][2] = tmp1;
    else happy[i][2] = tmp2;
  }
  int max_h = happy[N][0];
  if (happy[N][1] > max_h) max_h = happy[N][1];
  if (happy[N][2] > max_h) max_h = happy[N][2];
  cout << max_h << endl;
}


Measured memory_bytes: 1408
#include<stdio.h>
int main() 
{
    long long n,x,tmp,ans=0,last=0;
    scanf("%lld %lld",&n,&x);
    for(long i=1;i<=n;++i) 
    {scanf("%lld",&tmp);
    if(last+tmp>x) 
    {ans+=last+tmp-x;
    tmp=x-last;}
    last=tmp;}
    printf("%lld\n", ans);
}


Measured memory_bytes: 128
n,input = gets.chomp.split("\n");
input = gets.chomp.split(" ").map(&:to_i);
count = 0
while input.any? {|e| e.even?} do
    input = input.map do |i|
        if i.even? then
            count += 1
            # puts count
            next i/2
        end
    end.compact
end
puts count

Measured memory_bytes: 6908
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

int main() {
	int N;
	cin >> N;
	N %= 1000;

	if (N == 0) cout << 0 << endl;
	else cout << 1000 - N << endl;

	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n; string s;
    cin >> n >> s;
    vector<pair<char, int>> c;
    c.emplace_back(s[0], 1);
    for (int i = 1; i < n; ++i) {
        if(s[i] == c.back().first){
            c.back().second++;
        }else {
            c.emplace_back(s[i], 1);
        }
    }
    cout << c.size() << "\n";
    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define MAXN 200005
#define INT_SIZE 32
#define debug cout<<"we are debugging"<<endl;
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main(){
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
          cin>>a[i];
   sort(a,a+n);
   int s=0;
   for(int i=0;i<k;i++)
     s+=a[i];
   cout<<s;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
vector<int> a[N];
int f[N], c[N];

void DFS(int u, int parent) {
  f[u] = parent;
  for (auto& v : a[u]) {
    if (v == parent) continue;
    DFS(v, u);
  }
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  DFS(0, -1);
  vector<int> A;
  for (int u = n - 1; u != 0; u = f[u]) {
    A.push_back(u);
  }
  A.push_back(0);
  fill(c, c + n, -1);
  queue<int> Q;
  for (int i = 0; i < A.size(); ++i) {
    c[A[i]] = i < A.size() / 2;
    Q.push(A[i]);
  }
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (auto& v : a[u]) {
      if (c[v] < 0) {
        c[v] = c[u];
        Q.push(v);
      }
    }
  }
  vector<int> cnt(2);
  for (int i = 0; i < n; ++i) {
    cnt[c[i]]++;
  }
  puts(cnt[0] > cnt[1] ? "Fennec" : "Snuke");
  return 0;
}


Measured memory_bytes: 12024
n, m = map(int, input().split())

yd = {}
i = 2
while m != 1:
  while m % i == 0:
    if i in yd:
      yd[i] += 1
    else:
      yd[i] = 1
    m //= i
  i += 1

ans = 1
for v in yd.values():
  start = v + n - 1
  c = 1
  for _ in range(v):
    c *= start
    start -= 1
  d = 1
  for _v in range(v):
    d *= (_v + 1)
  ans *= (c // d)
print(ans % 1000000007)


Measured memory_bytes: 40044
N, M = map(int, input().split())

height1 = input().split()
height2 = []


for i in range(len(height1)):
    height2.append(int(height1[i]))


point = []
for j in range(len(height2)):
    point.append(0)

for k in range(M):
    A, B = map(int, input().split())
    if height2[A-1] > height2[B-1]:
        point[B-1] += 1
    elif height2[A-1] < height2[B-1]:
        point[A-1] += 1
    else:
        point[A-1] += 1
        point[B-1] += 1


count = 0
for l in range(len(point)):
    if point[l] == 0:
        count = count + 1
print(count)

Measured memory_bytes: 20924
#include <bits/stdc++.h>
#define MOD (long long)(1e9 + 7)
using namespace std;

long long ssize = 0;
long long dp[200005][2] = {0}, sum[200005][2] = {0};
string s, t;

long long solve();

int main() {
  cin >> s >> t;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  ssize = s.size();
  dp[0][0] = 1;
  for(int i = 0; i < ssize; ++i) {
    int nums = s[i] - '0', numt = t[i] - '0';
    if(t[i] != '?') {
      if(nums == numt) {
        (dp[i + 1][1] += dp[i][1]) %= MOD;
        (dp[i + 1][0] += dp[i][0]) %= MOD;

        sum[i + 1][1] +=
            (sum[i][1] * 10 % MOD + dp[i][1] * numt % MOD) %
            MOD;
        sum[i + 1][1] %= MOD;
        sum[i + 1][0] +=
            (sum[i][0] * 10 % MOD + dp[i][0] * numt % MOD) %
            MOD;
        sum[i + 1][0] %= MOD;
      }
      else if(nums < numt) {
        dp[i + 1][1] += dp[i][1];
        dp[i + 1][1] %= MOD;

        sum[i + 1][1] +=
            (sum[i][1] * 10 % MOD + dp[i][1] * numt % MOD) %
            MOD;
        sum[i + 1][1] %= MOD;
      }
      else {
        dp[i + 1][1] += dp[i][1];
        (dp[i + 1][1] += dp[i][0]) %= MOD;

        sum[i + 1][1] +=
            (sum[i][1] * 10 % MOD + dp[i][1] * numt % MOD) %
            MOD;
        sum[i + 1][1] %= MOD;
        sum[i + 1][1] +=
            (sum[i][0] * 10 % MOD + dp[i][0] * numt % MOD) %
            MOD;
        sum[i + 1][1] %= MOD;
      }
    }
    else {
      for(int k = 0; k < 10; ++k) {
        numt = k;
        if(nums == numt) {
          (dp[i + 1][1] += dp[i][1]) %= MOD;
          (dp[i + 1][0] += dp[i][0]) %= MOD;

          sum[i + 1][1] += (sum[i][1] * 10 % MOD +
                            dp[i][1] * numt % MOD) %
                           MOD;
          sum[i + 1][1] %= MOD;
          sum[i + 1][0] += (sum[i][0] * 10 % MOD +
                            dp[i][0] * numt % MOD) %
                           MOD;
          sum[i + 1][0] %= MOD;
        }
        else if(nums < numt) {
          dp[i + 1][1] += dp[i][1];
          dp[i + 1][1] %= MOD;

          sum[i + 1][1] += (sum[i][1] * 10 % MOD +
                            dp[i][1] * numt % MOD) %
                           MOD;
          sum[i + 1][1] %= MOD;
        }
        else {
          dp[i + 1][1] += dp[i][1];
          (dp[i + 1][1] += dp[i][0]) %= MOD;

          sum[i + 1][1] += (sum[i][1] * 10 % MOD +
                            dp[i][1] * numt % MOD) %
                           MOD;
          sum[i + 1][1] %= MOD;
          sum[i + 1][1] += (sum[i][0] * 10 % MOD +
                            dp[i][0] * numt % MOD) %
                           MOD;
          sum[i + 1][1] %= MOD;
        }
      }
    }
  }

  return (sum[ssize][1] + sum[ssize][0]) % MOD;
}


Measured memory_bytes: 9724
import itertools

N = int(input())
count = [0,0,0,0,0]
total = 0

for _ in range(N):
    S = input()
    if S[0] == 'M':
        count[0] += 1
    elif S[0] == 'A':
        count[1] += 1
    elif S[0] == 'R':
        count[2] += 1
    elif S[0] == 'C':
        count[3] += 1
    elif S[0] == 'H':
        count[4] += 1
count = [i for i in count if i != 0]

for v in itertools.combinations(count, 3):
    total += v[0]*v[1]*v[2]
print(total)

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

#define fastio 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define forn(low,high,i) for(i = low; i < high; i++)
#define forrev(high,low,i) for(i = high; i >= low; i--)
#define all(v) v.begin(),v.end()
#define decimal_digits cout << fixed << setprecision(15);

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(long long a, long long b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(long long a, long long b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(long long a, long long b){a %= mod; b %= mod; return (int)((long long) a * b % mod);}
inline int modexpo(long long a, long long b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(long long a, long long b){return mul(a, modexpo(b, mod - 2));}
inline int inv(long long a){return modexpo(a, mod - 2);}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  long long n, k, i, j;
  cin >> n >> k;
  long long ans = 0;
  long long all = (n * (n + 1)) / 2;
  for(i = k; i <= n + 1; i++){
    long long minVal = (i * (i - 1)) / 2;
    long long maxVal = all - ((n - i) * (n - i + 1)) / 2;
    ans = add(ans, (maxVal - minVal + 1) % mod);
  }
  cout << ans << '\n';
}

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

  pre();

  int t = 1, T;
  // cin >> t;
  T = t;
  while(t--){
    // cout << "Case #" << T - t << ": ";
    solve();
  }

  ktj();
}


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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<ll> cost(100, LONG_LONG_MAX);
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll N;
vector<ll> A;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // Globalなvectorのリサイズ
  //A.resize(N);

  ll n;
  cin >> n;
  vector<ll> x(n);
  rep(i, n) cin >> x[i];
  rep1(p, 100) {
    ll tmp =0;
    rep(i, n) {
      tmp += pow(x[i]-p, 2);
    }
    cost[p] = tmp;
  }
  sort(cost.begin(), cost.end());
  cout << cost[0] << endl;
  return 0;
}


Measured memory_bytes: 256
S = input()
mod = 10 ** 9 + 7

a = b = ans = 0
a_old = b_old = ans_old = 0

q = 1 
for s in S:
    if s == "A":
        a = (a_old + q) % mod
        b = b_old
        ans = ans_old
    elif s == "B":
        a = a_old
        b = (b_old + a_old) % mod
        ans = ans_old
    elif s == "C":
        a = a_old
        b = b_old
        ans = (ans_old + b_old) % mod
    else:
        a = (3 * a_old + q) % mod
        b = (3 * b_old + a_old) % mod
        ans = (3 * ans_old + b_old) % mod
        q = q * 3 % mod
    a_old = a
    b_old = b
    ans_old = ans
    # print(a, b, ans)

print(ans)


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

int main() {
    string S, T; cin >> S >> T;
    bool ok = true;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) ok = false;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  char c;
  cin >> c;
  switch (c) {
    case 'a':
    case 'i':
    case 'u':
    case 'e':
    case 'o':
      cout << "vowel" << endl;
      break;
    default:
      cout << "consonant" << endl;
  }
}

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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}

int main(){
    double p = 3.14159265358979323846264338327950288419716939937510;
    double n;
    cin >> n;
    printf ("%.20f\n", 2 * n * p);
    return 0;
}

Measured memory_bytes: 3788
def solve():
    A = [list(map(int, input().split())) for _ in range(3)]
    N = int(input())
    b = [int(input()) for _ in range(N)]
    
    bingo = [[False] * 3 for _ in range(3)]
    for bi in b:
        for i in range(3):
            for j in range(3):
                if A[i][j] == bi:
                    bingo[i][j] = True
    
    for i in range(3):
        cnt = 0
        for j in range(3):
            cnt += bingo[i][j]
        if cnt == 3:
            print('Yes')
            exit()
    for i in range(3):
        cnt = 0
        for j in range(3):
            cnt += bingo[j][i]
        if cnt == 3:
            print('Yes')
            exit()
    cnt = 0
    for i in range(3):
        cnt += bingo[i][i]
    if cnt == 3:
        print('Yes')
        exit()
    cnt = 0
    for i, j in [[0, 2], [1, 1], [2, 0]]:
        cnt += bingo[i][j]
    if cnt == 3:
        print('Yes')
        exit()
    print('No')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
//in the name of god
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)1e5+20
#define INF 1e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int,int> pii;
const int delta=(int)1e9+7;
LL n,x,y,ans,dp[MAX_N]; vector<int>a,b,c;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>x; a.pb(x);
	} sort(a.begin(),a.end());
	for(int i=0;i<n;++i){
		cin>>x; b.pb(x);
	} sort(b.begin(),b.end());
	for(int i=0;i<n;++i){
		cin>>x; c.pb(x);
	} sort(c.begin(),c.end());
	for(int i=b.size()-1;i>=0;--i){
		x=c.end()-(upper_bound(c.begin(),c.end(),b[i]));
		y=(lower_bound(a.begin(),a.end(),b[i]))-a.begin();
		ans+=x*y;
	}
	//ans=(upper_bound(a.begin(),a.end(),4))-a.begin();
	cout<<ans;
	return cout<<endl,0;
}

Measured memory_bytes: 1784
/**
 * Author: AcFunction
 * Date:   2019-02-24 19:56:49
 * Email:  3486942970@qq.com
**/

#include <bits/stdc++.h>
#define ll long long

using namespace std;
int n; double ans;  
int main() {
  cin >> n; 
  for(int i = 1; i <= n; i++) {
    double t; char s[5]; 
    cin >> t >> s; 
    if(s[0] == 'J') ans += t;
    else ans += 380000.0 * t; 
  } printf("%lf", ans); 
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int off = 300;
int n, m;
int dl[710][710], dr[710][710];
char s[310][310];
int get_dl(int idx, int l, int r) {
	if(l > r) return 0;
	if(idx < 0 || idx >= 710) return 0;
	l = max(l, 1); r = min(r, m);
	return dl[idx][r] - dl[idx][l-1];
}
int get_dr(int idx, int l, int r) {
	if(l > r) return 0;
	if(idx < 0 || idx >= 710) return 0;
	l = max(l, 1); r = min(r, m);
	return dr[idx][r] - dr[idx][l-1];
}
int get(int y, int x) {
	if(y<1 || x<1 || y>n || x>m) return 0;
	return s[y][x] == '#';
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i=1; i<=n; i++) scanf("%s", s[i]+1);
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(s[i][j] == '#') {
				dl[i+j][j]++;
				dr[i-j+off][j]++;
			}
		}
	}
	for(int i=0; i<700; i++) {
		for(int j=0; j<=700; j++) {
			dl[i][j+1] += dl[i][j];
			dr[i][j+1] += dr[i][j];
		}
	}
	ll r1 = 0, r2 = 0;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(s[i][j] != '#') continue;
			for(int k=2; k<=n+m; k+=2) {
				int c11 = get_dr(i-j+off-k, j+1, j+k/2-1);
				int c12 = get_dr(i-j+off-k, j+k/2+1, j+k-1);
				int c21 = get_dl(i+j+k, j+k/2+1, j+k-1);
				int c22 = get_dl(i+j+k, j+1, j+k/2-1);
				int c31 = get_dr(i-j+off+k, j-k/2+1, j-1);
				int c32 = get_dr(i-j+off+k, j-k+1, j-k/2-1);
				int c41 = get_dl(i+j-k, j-k+1, j-k/2-1);
				int c42 = get_dl(i+j-k, j-k/2+1, j-1);
				int ru = get(i-k/2, j+k/2);
				int rd = get(i+k/2, j+k/2);
				int ld = get(i+k/2, j-k/2);
				int lu = get(i-k/2, j-k/2);
				int u = get(i-k, j);
				int r = get(i, j+k);
				int d = get(i+k, j);
				int l = get(i, j-k);
				r1 += rd * (c12 + c31);
				r1 += ld * (c22 + c41);
				r1 += lu * (c32 + c11);
				r1 += ru * (c21 + c42);
				r2 += rd * (ld + r + d);
				r2 += ld * (lu + l + d);
				r2 += lu * (ru + l + u);
				r2 += ru * (rd + r + u);
				//printf("%d %d %d %d  %d %d %d %d\n", ru,rd,ld,lu,r,d,l,u);
				//printf("i:%d, j:%d, k:%d, r1:%d, r2:%d\n", i,j,k,r1,r2);
				//printf("i:%d, j:%d, k:%d, %d %d %d %d r1:%d, r2:%d\n", i, j, k, c1,c2,c3,c4,r1,r2);
			}
		}
	}
	printf("%lld", r1 / 2 + r2 / 3);
	return 0;
}


Measured memory_bytes: 4224
#include<cstdio>
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 100000
inline int z(int x){return x<0?-x:x;}
int main()
{
	int n=read(),nt=0,nx=0,ny=0,t,x,y,i;
	while(n--)
	{
		t=read();x=read();y=read();
		if(z(nx-x)+z(ny-y)>t-nt||(z(nx-x)+z(ny-y)+t-nt)&1)return 0*puts("No");
	}
	puts("Yes");
}

Measured memory_bytes: 128
N, K = map(int, input().split())

# あとで開区間な累積和を取るので、K+1。
want_white = [[0] * (K+1) for _ in range(K+1)]
want_black = [[0] * (K+1) for _ in range(K+1)]

for _ in range(N):
    x_str, y_str, c_str = input().split()
    x = int(x_str)
    y = int(y_str)
    c = 1 if c_str == 'B' else 0

    x %= 2 * K
    y %= 2 * K
    if x >= K:
        x -= K
        c ^= 1
    if y >= K:
        y -= K
        c ^= 1

    if c:
        want_black[x+1][y+1] += 1
    else:
        want_white[x+1][y+1] += 1

# 累積和
for i in range(K+1):
    for j in range(K):
        want_black[i][j+1] += want_black[i][j]
        want_white[i][j+1] += want_white[i][j]

for i in range(K):
    for j in range(K+1):
        want_black[i+1][j] += want_black[i][j]
        want_white[i+1][j] += want_white[i][j]

# (h, w)が黒の左下になるとして、全探索。
ans = 0
for h in range(K+1):
    for w in range(K+1):
        count = want_black[-1][-1] - want_black[h][-1] - want_black[-1][w] + 2 * want_black[h][w]
        count += want_white[h][-1] + want_white[-1][w] - 2 * want_white[h][w]
        ans = max(ans, count, N - count)

print(ans)    

Measured memory_bytes: 91116