akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(x, y) pb(mp(x, y))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(VECTOR) (VECTOR).begin(), (VECTOR).end()

int sixPow[7];
int ninePow[6];
int sixTimes[7];
int nineTimes[6];

void powInit(){
	sixPow[6] = 6;
	for(int i = 5; i >= 0; i --)sixPow[i] = sixPow[i + 1] * 6;
	ninePow[5] = 9;
	for(int i = 4; i >= 0; i --)ninePow[i] = ninePow[i + 1] * 9;
}
void sixTimesInitByZero(){
	for(int i = 0; i < 7; i ++)sixTimes[i] = 0;
}
void nineTimesInitByZero(){
	for(int i = 0; i < 6; i ++)nineTimes[i] = 0;
}

int sixMoneySum(){
	int ret = 0;
	for(int i = 0; i < 7; i ++)ret += sixPow[i] * sixTimes[i];
	return ret;
}
int nineMoneySum(){
	int ret = 0;
	for(int i = 0; i < 6; i ++)ret += ninePow[i] * nineTimes[i];
	return ret;
}

int sixTimesSum(){
	int ret = 0;
	for(int i = 0; i < 7; i ++)ret += sixTimes[i];
	return ret;
}
int nineTimesSum(){
	int ret = 0;
	for(int i = 0; i < 6; i ++)ret += nineTimes[i];
	return ret;
}

void sixTimesNext(){
	sixTimes[6] ++;
	if(sixTimes[6] == 6){
		sixTimes[6] = 0;
		sixTimes[5] ++;
	}
	if(sixTimes[5] == 6){
		sixTimes[5] = 0;
		sixTimes[4] ++;
	}
	if(sixTimes[4] == 6){
		sixTimes[4] = 0;
		sixTimes[3] ++;
	}
	if(sixTimes[3] == 6){
		sixTimes[3] = 0;
		sixTimes[2] ++;
	}
	if(sixTimes[2] == 6){
		sixTimes[2] = 0;
		sixTimes[1] ++;
	}
	if(sixTimes[1] == 6){
		sixTimes[1] = 0;
		sixTimes[0] ++;
	}
}
void nineTimesNext(){
	nineTimes[5] ++;
	if(nineTimes[5] == 9){
		nineTimes[5] = 0;
		nineTimes[4] ++;
	}
	if(nineTimes[4] == 9){
		nineTimes[4] = 0;
		nineTimes[3] ++;
	}
	if(nineTimes[3] == 9){
		nineTimes[3] = 0;
		nineTimes[2] ++;
	}
	if(nineTimes[2] == 9){
		nineTimes[2] = 0;
		nineTimes[1] ++;
	}
	if(nineTimes[1] == 9){
		nineTimes[1] = 0;
		nineTimes[0] ++;
	}
}

int main(){

	powInit();

	int N;
	cin >> N;
	int ans = 100005;
	sixTimesInitByZero();
	while(true){
		nineTimesInitByZero();
		/*while(true){
			ans = min(ans, sixTimesSum() + nineTimesSum() + (N - sixMoneySum() - nineMoneySum()));
			nineTimesNext();
			if(sixMoneySum() + nineMoneySum() > N)break;
		}*/
		int tmp = N - sixMoneySum();
		for(int i = 0; i < 6; i ++){
			nineTimes[i] = tmp / ninePow[i];
			tmp %= ninePow[i];
		}
		ans = min(ans, sixTimesSum() + nineTimesSum() + (N - sixMoneySum() - nineMoneySum()));
		sixTimesNext();
		if(sixMoneySum() > N)break;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce

n = int(input())

clock_list = []
for i in range(n):
    a = int(input())
    clock_list.append(a)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


print(lcm_list(clock_list))

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

int main() {
  int n, m; cin >> n >> m;
  vector<int> dp(n+1);
  vector<bool> vv(n+1, true);
  for (int i = 0; i < m; i++) {
    int tmp; cin >> tmp;
    vv[tmp] = false;
  }
  dp[0] = 1; dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (vv[i-2]) dp[i] += dp[i-2];
    if (vv[i-1]) dp[i] += dp[i-1];
    dp[i] %= 1000000007;
  }
  cout << dp[n];
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
int main(){
  int R[MAX],n;

  cin >> n;
  for(int i= 0; i< n; i++)
    cin >> R[i];
  int maxv = -2000000000;
  int minv = R[0];
  for(int i=1; i< n; i++){
    maxv=max(maxv,R[i]-minv);
    minv=min(minv,R[i]);
  }
  cout << maxv << endl;
  
  return 0;
}

Measured memory_bytes: 1940
local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    local cnt = bls(1, i - 1)
    for j = 1, cnt do
      self.stage[i][j] = self.func(self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2])
    end
  end
end
SegTree.create = function(self, n, func, emptyvalue)
  self.func, self.emptyvalue = func, emptyvalue
  local stagenum, mul = 1, 1
  self.stage = {{}}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.stage[stagenum] = {}
  end
  self.stagenum = stagenum
  self.left_stage = {}
  for i = 1, n do
    local sp, sz = 1, bls(1, stagenum - 1)
    while(i - 1) % sz ~= 0 do
      sp, sz = sp + 1, brs(sz, 1)
    end
    self.left_stage[i] = sp
  end
  self.sz_stage = {}
  local tmp, sp = 1, stagenum
  for i = 1, n do
    if tmp * 2 == i then tmp, sp = tmp * 2, sp - 1 end
    self.sz_stage[i] = sp
  end
  for i = 1, mul do self.stage[stagenum][i] = emptyvalue end
  self:updateAll()
end
SegTree.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local stagenum = self.stagenum
  local ret = self.emptyvalue
  while left <= right do
    local stage = mma(self.left_stage[left], self.sz_stage[right - left + 1])
    local sz = bls(1, stagenum - stage)
    ret = self.func(ret, self.stage[stage][1 + brs(left - 1, stagenum - stage)])
    left = left + sz
  end
  return ret
end
SegTree.addValue = function(self, idx, value)
  self.stage[self.stagenum][idx] = self.stage[self.stagenum][idx] + value
  for i = self.stagenum - 1, 1, -1 do
    local dst = brs(idx + 1, 1)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.func(self.stage[i + 1][idx], self.stage[i + 1][rem])
    idx = dst
  end
end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local n, q = io.read("*n", "*n", "*l")
local t = {}
local s = io.read()
for w in s:gmatch("%d+") do
  table.insert(t, tonumber(w))
end
local ql, qr = {}, {}
local idx = {}
local ret = {}
for iq = 1, q do
  ql[iq], qr[iq] = io.read("*n", "*n")
  idx[iq] = iq
  ret[iq] = 0
end
table.sort(idx, function(a, b) return qr[a] < qr[b] end)
local p = {}
for i = 1, n do
  p[i] = 0
end
local st = SegTree.new(n, function(a, b) return a + b end, 0)
local ti = 1
for iq = 1, q do
  local l, r = ql[idx[iq]], qr[idx[iq]]
  while ti <= r do
    local v = t[ti]
    local old = p[v]
    if 0 < old then
      st:addValue(old, -1)
    end
    p[v] = ti
    st:addValue(ti, 1)
    ti = ti + 1
  end
  ret[idx[iq]] = st:getRange(l, r)
end
print(table.concat(ret, "\n"))


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

const char kUp = '/';
const char kDown = '\\';
const char kFlat = '_';

int calc_area(const vector<int>& height, const int first, const int last){
	int h = height[first];
	int ret = 0;
	for(int i = first + 1; i <= last; i++){
	    ret += h - height[i];
	}
	return ret;
}

int SumVec(const vector<int> &vec) {
	int sum = 0;
	for(auto num : vec){
        sum += num;
	}
	return sum;
}

vector<int> FindLakeAndCalcArea(const vector<int> &height) {
    vector<int> lake_area;
	for(int i = 0; i < (int)height.size() - 1; i++){
        if(height[i] <= height[i+1]) { // 隣と高さが一緒か、右隣のほうが高い時
            continue;
        }
        for(int j = i+1; j <= (int)height.size() - 1; ++j){
			if(height[i] == height[j]){ // 湖を発見
				lake_area.push_back(calc_area(height, i, j));
				i = j - 1;
				break;
			}
        }
	}	
	return lake_area;
}

int main() {	
    vector<char> shape;
    char c;
	while(cin >> c){
        shape.push_back(c);
	}
    
    vector<int> height(shape.size()+1);  
    // height[0] = 0 を基準に高さを求める
	for(int i = 1; i <= (int)shape.size(); i++){
		switch(shape[i-1]){
		case kUp:
			height[i] = height[i - 1] + 1;
			break;
		case kDown:
			height[i] = height[i - 1] - 1;
			break;
		case kFlat:
			height[i] = height[i - 1];
			break;
		}
	}

	// 面積を求める
    vector<int> lake_area = FindLakeAndCalcArea(height);

	cout << SumVec(lake_area) << endl;

	cout << lake_area.size();
	for(auto x : lake_area){
        cout << " " << x;
	}
    cout << endl;
	
	return 0;
}


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

int main() {
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    int count=0;
    for(int i=0;i <= A;i++){
        for(int j=0; j<= B;j++){
            for(int k=0 ;k <=C;k++){
                if(X== 50*k+100*j+500*i){
                    count++;
                    break;
                }
                else if(X < 50*k+100*j+500*i){
                    break;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTA(a,n) sort(a,a+n)
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
  string s;
  cin >> s;
    //処理
    //出力
	if(s[0]==s[2]) cout << "Yes" << ENT;
	else cout << "No" << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
int main(){
    int len,i=0,j,f=0,res;
    char str1[105],str2[105];
    scanf("%s %s",str1,str2);
    len=strlen(str1);
    for(i=0;i<len;i++){
        for(j=0;j<len;j++){
            if(str1[i]==str2[j]) f=1;
        }
        if(f==0) {
            printf("No\n");
            return 0;
        }
        f=0;
    }
   res=strcmp(str1,str2);
    if(res==0){
        printf("Yes\n");
        return 0;
    }
    for(i=0;i<len;i++){
        char temp;
        temp=str1[len-1];
        char str3[len];
        for(j=1;j<len;j++){
           str3[j]=str1[j-1];
        }
        str3[0]=temp;
        str3[j]='\0';
        strcpy(str1,str3);
        res=strcmp(str1,str2);
        if(res==0){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cmath>
#include<utility>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long int ll;
int main(void) {
	int n, k; cin >> n >> k;
	k--;
	string str; cin >> str;
	for (int i = 0; i < str.length(); i++) {
		if (i == k)printf("%c", str[i] + 0x20);
		else cout << str[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import fractions

N = int( input() ) # <= 10^5
A = list( map( int, input().split() ) ) # <= 10^9


"""
i番目の数を変更するとすると求めるべき最大公約数はi番目の数を除いた残りの数の最大公約数である
"""

"""
# i = 0 の場合
g = A[1]
g = gcd( g, A[2] )
g = gcd( g, A[3] )
...
g = gcd( g, A[N - 1] ) = R(0)

iを消すとして
iの左側の最大公約数をL(i) (0~i-1の最大公約数)
iの右側の最大公約数をR(i) (i+1からN-1の最大公約数)

i + 1 ~ N - 1
0 ~ N - 1 - (i + 1)

とするとiを消した時の求めるべき最大公約数は
gcd( L(i), R(i) )
であり
L(i + 1) = gcd( L(i), A[i] )
R(i)     = gcd( R(i + 1), A[i] )
という関係が成り立つ
ここで
L(0) = R(N-1) = 0
gcd(0, X) = X
と定義する

L_0を求めて残りは漸化式より順に求める
R_N-1を求めて残りは漸化式より順に求める
"""
def gcd(x, y):
    if x == 0:
        return y
    
    if y == 0:
        return x

    return fractions.gcd(x, y)

# def L(i):
#     if i == 0:
#         return 0
    
#     g = 0
#     for t in range(i):
#         g = gcd( g, A[t] )
#     return g

# def R(i):
#     if i == N - 1:
#         return 0
    
#     g = 0
#     for t in range(N - i - 1):
#         g = gcd( g, A[i + 1 + t] )
#     return g

G = [0] * N # i番目の要素はA_iを除いた時の最大公約数

L_buf = 0
R_buf = 0
tmp1 = 0
tmp2 = 0

for i in range(N):
    if i == 0:
        G[0] = L_buf
        G[N-1] = R_buf
        continue

    tmp1 = gcd( L_buf, A[i-1] )
    # G[i] = G[i] + tmp1
    G[i] = gcd(G[i], tmp1)
    L_buf = tmp1

    tmp2 = gcd( R_buf, A[N - 1 - i + 1] )
    # G[N - 1 - i] = G[N - 1 - i] + tmp2
    G[N - 1 - i] = gcd(G[N - 1 - i], tmp2)
    R_buf = tmp2

print(max(G))

Measured memory_bytes: 16152
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
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...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
//#########################################
const int mod = 1000000007;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
vector<int> f = {1},fi = {1};
int fact(int x){
	while((int)f.size() <=x)f.push_back((f.back()*f.size())%mod);
	return f[x];
}
int ifact(int x){
	return modpow(fact(x),mod-2,mod);
}
int C(int x,int y){
	if(x < y)return 0;
	return fact(x)*ifact(y)%mod*ifact(x-y)%mod;
}
int P(int x,int y){
	if(x < y)return 0;
	return fact(x)*ifact(x-y)%mod;
}
signed main(){
	int n,m;cin >> n >> m;
	int ret = 0;
	rep(i,n+1){
		int tmp = P(m,i);
		tmp = (tmp*P(m-i,n-i))%mod;
		tmp = (tmp*P(m-i,n-i))%mod;
		tmp = (tmp*C(n,i))%mod;
		if(i%2== 0){
			ret = (ret + tmp)%mod;
		}	
		else{
			ret -= tmp;
			ret = (ret%mod + mod)%mod;
		}	
	}
	cout << ret%mod << endl;

	return 0;
}

Measured memory_bytes: 7448
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int main() {
  int n;
  cin >> n;
  vs s(n);
  vi t(n);
  string x;
  rep(i, n) cin >> s[i] >> t[i];
  cin >> x;
  int res = 0;
  bool flag = false;
  rep(i, n) {
    if(flag)
      res += t[i];
    if(s[i] == x)
      flag = true;
  }
  cout << res << endl;
}

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

const int maxn=50+10;
int n,a[maxn],minn=1e9,maxx=-1e9,minp,maxp;
int m,ansx[maxn<<1],ansy[maxn<<1];

int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]<minn)
			minn=a[i],minp=i;
		if(a[i]>maxx)
			maxx=a[i],maxp=i;
	}
	if(-minn>maxx){
		for(int i=1;i<=n;++i)
			if(a[i]>0)
				++m,ansx[m]=minp,ansy[m]=i;
		for(int i=n-1;i;--i)
			++m,ansx[m]=i+1,ansy[m]=i;
	}
	else{
		for(int i=1;i<=n;++i)
			if(a[i]<0)
				++m,ansx[m]=maxp,ansy[m]=i;
		for(int i=1;i<n;++i)
			++m,ansx[m]=i,ansy[m]=i+1;
	}
	cout<<m<<endl;
	for(int i=1;i<=m;++i)
		cout<<ansx[i]<<' '<<ansy[i]<<endl;
	return 0;
}

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

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

const int MAX = 200010;
const int INF = 2e9 + 10;
const int MOD = 1e9 + 7;
const lint LNF = 2e18 + 10;

int n;
vector<int> G[MAX];

int dfs(int v, int p=0){
	int res = 0;
	for(int x:G[v]) if(x!=p) res ^= 1+dfs(x,v);
	return res;
}

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

	cin>>n;
	for(int i=1; i<n; i++){
		int u,v; cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	cout<<(dfs(1) == 0 ? "Bob" : "Alice")<<'\n';

	return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int MOD = 1000000007;
const int INF = 2000000000;
const long double PI = acosl(-1);
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}
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; }

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int N, M;
    cin >> N >> M;

    int ans = 0;
    ans = N*(N-1)/2+M*(M-1)/2;
    pa;
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc159/abc159_a && sh test.sh
cd ~/Desktop/Programming/AtCoder/contest/abc159/abc159_a && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/abc159/abc159_a && sh submit.sh
*/


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

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; }
const long long LINF = 1e18;

int dp[3010][3010] = {};

int main()
{
  string s, t; cin >> s >> t;

  for (int s_i = 0, s_length = s.length(); s_i < s_length; ++s_i) {
    for (int t_i = 0, t_length = t.length(); t_i < t_length; ++t_i) {
      if (s[s_i] == t[t_i]) {
        chmax(dp[s_i+1][t_i+1], dp[s_i][t_i] + 1);
      }

      chmax(dp[s_i+1][t_i+1], dp[s_i][t_i+1]);
      chmax(dp[s_i+1][t_i+1], dp[s_i+1][t_i]);
    }
  }


  // 復元
  string result = "";
  for (int s_i = s.length(), t_i = t.length(); s_i > 0 and t_i > 0;) {
    if (dp[s_i][t_i-1] == dp[s_i][t_i]) {
      t_i--;
    }
    else if (dp[s_i-1][t_i] == dp[s_i][t_i]) {
      s_i--;
    }
    else {
      result = s[s_i-1] + result;
      s_i--, t_i--;
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	long long int n;
	cin >> n;
	vector<long long int> a(n);
	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	long long int sum = 0;
	for (long long int i = 0; i < n; i++) {
		long long int b = 1;
		long long int c = a[i];
		for (int j = i + 1; j < n; j++) {
			if (c == a[j]) {
				b++;
				i++;
			}
			else {
				break;
			}
		}
		b %= 2;
		sum += b;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const ll INF = 1e18;

int main() {
    long double a, b;
    cin >> a >> b;
    ll p = floor(a * b);
    cout << p << endl;
}

Measured memory_bytes: 3752
inputs = []
for i in range(5):
    tmp = int(input())
    inputs.append(tmp)

tmp = 999
minidx = 0
for idx, i in enumerate(inputs):
    if tmp > (i % 10) and (i % 10) > 0:
        minidx = idx
        tmp = i % 10

ans = 0
for idx, i in enumerate(inputs):
    if idx == minidx:
        ans += i
    else:
        if i % 10 != 0:
            ans += i + (10 - (i % 10))
        else:
            ans += i
        
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
using namespace std;

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


int main() {
	int A[3];
	rep(i, 3) cin >> A[i];
	sort(A, A+3);

	int z = 3 * A[2] - (accumulate(A, A+3, 0));
	if (z % 2 == 0) {
		cout << z /2 << endl;
	}
	else {
		cout << (z+3) / 2 << endl;
	}
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

dp = [100000] * n

dp[0] = 0

for i in range(0, n):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(h[i-1] - h[i])
    else:
        a = dp[i-1] + abs(h[i] - h[i-1])
        b = dp[i-2] + abs(h[i] - h[i-2])
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])


Measured memory_bytes: 13784
#include <iostream>
#include <vector>
#include <limits>

using Bool = bool;
using Int = long long int;
template <class T>
using Vector = std::vector<T>;
template <class T>
using Matrix = Vector<Vector<T>>;

constexpr Int INF = std::numeric_limits<Int>::max() / 3;

constexpr Int K = 1000;
constexpr Int H = K * 2 + 1, W = K * 2 + 2;
Matrix<Int> holes(H, Vector<Int>(W));
const Vector<Int> dx{0, -1, 0, 1}, dy{1, 0, -1, 0};

Vector<Bool> isprime(H* W + 1, true);

void init() {
    Int x = K, y = K;
    Int step = 0, cnt = 1;
    for (Int n = 0;; ++n) {
        if (n % 2 == 0) ++step;
        for (Int i = 0; i < step; ++i) {
            holes[x][y] = cnt++;
            x += dx[n % 4], y += dy[n % 4];
        }
        if (x < 0 || y < 0) break;
    }

    isprime[1] = false;
    for (Int p = 2; p * p <= H * W; ++p) {
        for (Int q = p; p * q <= H * W; ++q) {
            isprime[p * q] = false;
        }
    }
}

Matrix<Int> dp(H, Vector<Int>(W));
Matrix<Int> last(H, Vector<Int>(W));
Matrix<Int> hit(H, Vector<Int>(W));

Bool solve() {
    Int m, n;
    std::cin >> m >> n;
    if (m == 0) return false;

    for (Int x = 0; x < H; ++x) {
        for (Int y = 0; y < W; ++y) {
            hit[x][y] = (isprime[holes[x][y]] && holes[x][y] <= m);
            dp[x][y] = (holes[x][y] == n ? hit[x][y] : -INF);
            last[x][y] = 0;
        }
    }

    for (Int x = 1; x < H; ++x) {
        for (Int y = 0; y < W; ++y) {
            for (Int d = -1; d <= 1; ++d) {
                Int px = x - 1, py = y + d;
                if (py < 0 || W <= py) continue;

                Int score = dp[px][py] + hit[x][y];
                if (dp[x][y] < score ||
                    (dp[x][y] == score &&
                     last[x][y] < last[px][py])) {
                    dp[x][y] = score;
                    last[x][y] = last[px][py];
                }
            }

            if (hit[x][y]) last[x][y] = holes[x][y];
        }
    }

    Int ans = 0, p = 0;
    for (Int y = 0; y < W; ++y) {
        if (dp[H - 1][y] > ans ||
            (dp[H - 1][y] == ans && p < last[H - 1][y])) {
            ans = dp[H - 1][y];
            p = last[H - 1][y];
        }
    }

    std::cout << ans << ' ' << p << std::endl;
    return true;
}

int main() {
    init();
    while (solve()) {}
    return 0;
}



Measured memory_bytes: 128588
import re
def insertionSort(A,n,g):
	cnt=0
	for i in range(g,n):
		v = A[i]
		j = i-g
		while(j>=0 and A[j]>v):
			A[j+g] = A[j]
			j = j-g
			cnt+=1
		A[j+g]=v
	return cnt

def shellSort(A,n):
	cnt=0
#	m=n//2
#	print(m)
#	G=[]
#	while(m>0):
#		G.append(m)
#		m//=2

	G=[]
	v=1
	c=1
	while(v<=n):
		G.append(v)
		v+=3**c
		c+=1
	G=list(reversed(G))
	m=len(G)
	print(m)

	print(re.sub("[\[\]\,]","",str(G)))
	for i in range(len(G)):
		cnt+=insertionSort(A,n,G[i])
	print(cnt)
		

n=int(input())
a=[]
for i in range(n):
	a.append(int(input()))

shellSort(a,n)

for i in range(len(a)):
	print(a[i])


Measured memory_bytes: 46312
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){

	int n,x,result[30000],count;
	int i,j,k,sum;

	count = 0;
	for(;;){
		sum = 0;
		cin >> n >> x;
		if(n == 0 && x == 0)
			break;

		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				for(k=1;k<=n;k++){
					if(i != j && j != k && k != i && i < j && j < k){
						//cout << i+j+k << endl;
						if(i+j+k == x)sum++;
					}
				}
			}
		}
		result[count] = sum;
		count++;
	}
	
	for(i=0;i<count;i++){
		cout << result[i] << endl;
	}

	return 0;
}


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

#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 10000000;
//int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem0151 : Grid **/
bool grid[256][256];
const int dx[8]={-1, 0, 1, -1, 1, -1, 0, 1}, dy[8]={-1, -1, -1, 0, 0, 1, 1, 1};
int N;

int search(int x, int y, int i)
{
	int num=1;
	while (1) {
		x+=dx[i]; y+=dy[i];
		if_range(x, y, N, N) {
			if (grid[x][y]) {
				num++;
				continue;
			}
		}
		break;
	}
	return num;
}

int main()
{
	while (cin>>N, N) {
		rep(i, N) {
			rep(j, N) {
				char c; cin>>c;
				if (c=='1')
					grid[j][i]=true;
				else
					grid[j][i]=false;
			}
		}
		
		int ans=0;
		rep(i, N) {
			rep(j, N) {
				if (grid[j][i]) {
					rep(k, 8) {
						ans = max(ans, search(j, i, k));
					}
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1224
#include <iostream>
#include<bits/stdc++.h>
#include <string>
#include <stdlib.h>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<fstream>
#include<typeinfo>
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define repi(i,a,b)  for(ll i=a;i<b;i++)
#define repj(j, a, b) for (ll j = a; j < b;j++)
#define vi vector<int>
#define pii pair<int, int>
#define vpii vector< pii >
#define mod 1000000007
#define lim 100001
 
using namespace std;
ll factorial(ll n){return (n==1 || n==0) ? 1: n * factorial(n - 1); }
int max3(int a,int b,int c){ return max(a, max(c, b));}
int gcd(int a,int b){if(a==0){return b;}else{return gcd(b % a, a);}}
ll power(ll a, ll n){if(n==1) return a; else if(n==0) return 1; else{ ll r = power(a, n / 2); if(n%2==0) return r * r; else return r * a * r;}}
ll nCr(ll n, ll r) { return ((factorial(n)) / (factorial(n - r) * factorial(r))); }
void dfs(vector< vector<int > >& v,vi& check,int start){check[start - 1] = 1;repj(j, 0, v[start-1].size()){if(!check[v[start-1][j]-1]){dfs(v, check, v[start - 1][j]);}}}
bool isPrime(ll n) { if (n <= 1) return false;if (n <= 3)return true; if (n % 2 == 0 || n % 3 == 0)return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
//works under 2 till 1e12
 
int i, j;
 
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int a;
   cin>>a;
   int ans = a + a*a + a*a*a;
   cout<<ans;
   return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    int cnt=0;
    rep(i,10)if(i>=1 && i<=n)cnt++;
    rep(i,1000)if(i>=100 && i<=n)cnt++;
    rep(i,100000)if(i>=10000 && i<=n)cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6005;
const int INF = 1e5;
int A[MAXN], nxt[MAXN], dp[MAXN][MAXN], ans = 0, base = 0, N;
inline int Cost(int a, int b, int c) { return A[a] == A[b] && A[b] == A[c]; }
void chmax(int &x, int val) { x = max(x, val); }
inline void Transition(int i, int j, int cur) {
  if (cur > 3 * N) return;
  if (cur == 3 * N)
    return void(chmax(ans, dp[i][j] + Cost(i, j, cur)));
  for (int u = 1; u <= 3; ++u)
    for (int v = u + 1; v <= 3; ++v)
      chmax(dp[cur + u - 1][cur + v - 1], dp[i][j] + Cost(i, j, cur + (u ^ v) - 1));
  for (int c : {i, j}) {
    chmax(dp[c][cur + 0], dp[i][j] + Cost(i ^ j ^ c, cur + 1, cur + 2));
    chmax(dp[c][cur + 1], dp[i][j] + Cost(i ^ j ^ c, cur + 0, cur + 2));
    chmax(dp[c][cur + 2], dp[i][j] + Cost(i ^ j ^ c, cur + 0, cur + 1));
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> N;
  for (int i = 1; i <= 3 * N; i++) {
    cin >> A[i];
    if (i % 3 == 2 && i >= 5 && Cost(i, i - 1, i - 2)) i -= 3, --N, ++base;
  }
  vector<int> last(3 * N + 1, 3 * N + 1);
  for (int i = 3 * N; i > 0; i--) nxt[i] = last[A[i]], last[A[i]] = i; 
  for (int i = 0; i < MAXN; i++)
    for (int j = 0; j < MAXN; j++)
      dp[i][j] = -INF;
  dp[1][2] = 0;
  for (int i = 1; i <= 3 * N; i++) {
    for (int j = i + 1; j <= 3 * N; j++) {
      Transition(i, j, (j + 3) / 3 * 3);
      if (j / 3 * 3 < nxt[i] / 3 * 3)
        Transition(i, j, nxt[i] / 3 * 3);
      if (j / 3 * 3 < nxt[j] / 3 * 3)
        Transition(i, j, nxt[j] / 3 * 3);
    }
  }
  cout << ans + base << "\n";
  return 0;
}


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

typedef long long ll;
# define  pii pair<ll,ll> 
# define pb push_back
# define f first 
# define s second 








int main() {


ll a,b,c,d;
cin>>a>>b>>c>>d;

ll mx=-1e18;

ll x1= a*c;

mx = max(x1,mx);

ll x2 = b*c;

mx = max(x2,mx);

ll x3 = a*d;

mx= max(x3,mx);

ll x4 = b*d;

mx = max(mx,x4);


cout<<mx<<endl;



}


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

int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) cout << 1 << endl;
  else if (a != b && b != c && c != a) cout << 3 << endl;
  else cout << 2 << endl;

  return 0;
}

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

void solve(long long A, long long B) {
  if (A < B * 2) {
    cout << 0 << endl;
    return;
  }
  cout << A - (B * 2) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  solve(A, B);
  return 0;
}


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

int main() {
    int n, k, ans = 0;
    cin >> n >> k;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
        cin >> l[i];
    sort (l.begin(), l.end() );
    reverse (l.begin(), l.end() );
    for (int i = 0; i < k; i++)
        ans += l[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
typedef long long ll;
using namespace std;
struct edge {int cost, value;}; 
int N, W;
edge L[103];
int DP[103][100003]; // 日数, 取り得るvalue。 resは最小の重さ

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

  cin >> N >> W;
  int w, v;
  rep(i, N) {
    cin >> w >> v;
    edge e = {w, v};
    L[i] = e;
  }
  fill(DP[0], DP[0]+100003, 1000000007);
  DP[0][0] = 0;

  // i-1番目の品物から価値の総和がjとなるように選ぶ
  // i-1番目の品物から価値の総和がjーv[i]となるように選び、i番目の品物を加える。
  rep(i, N) {
    int v = L[i].value;
    int w = L[i].cost;
    rep(j, 100003) {
      if (j < v) {
        DP[i+1][j] = DP[i][j];
      } else {
        DP[i+1][j] = min(DP[i][j], DP[i][j-v] + w);
      }
    }
  }

  int res = 0;
  rep(i, 100003){
    if (DP[N][i] <= W) res = i;
  }

  cout << res << endl;;
  return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
class SegmentTree{
	T def_value;
	int last_num;
	vector<T> element,lazy;
	vector<bool> lazy_flag;
public:
	SegmentTree(vector<T>& vec,T def):def_value(def){
		int N=vec.size();
		last_num=1;
		while(last_num<N) last_num <<= 1;
		element.resize(2*last_num-1,def);
		lazy.resize(2*last_num-1,0);
		lazy_flag.resize(2*last_num-1,false);

		for(int i=0;i<N;i++){
			element[i+last_num-1] = vec[i];
		}
		for(int i=last_num-2;i>=0;i--){
			element[i] = min(element[2*i+1],element[2*i+2]);
		}
	}
	void Evaluate(int index,int left,int right){
		if(!lazy_flag[index]) return;
		element[index] = lazy[index];
		if(right-left>1){
			lazy[2*index+1] = lazy[index];
			lazy[2*index+2] = lazy[index];
			lazy_flag[2*index+1] = lazy_flag[2*index+2] = true;
		}
		lazy[index] = 0;
		lazy_flag[index] = false;
	}
	void UpdateRange(int left,int right,T x,int index=0,int vleft=0,int vright=-1){
		if(vright<0) vright = last_num;
		Evaluate(index,vleft,vright);

		if(vright<=left || right<=vleft) return;
		if(left<=vleft && vright<=right){
			lazy[index] = x;
			lazy_flag[index] = true;
			Evaluate(index,vleft,vright);
		}
		else{
			UpdateRange(left,right,x,2*index+1,vleft,(vleft+vright)/2);
			UpdateRange(left,right,x,2*index+2,(vleft+vright)/2,vright);
			element[index] = min(element[2*index+1],element[2*index+2]);
		}
	}
	void Update(int index,T x){
		int i=last_num+index-1;
		element[i] = x;
		while(i>0){
			i = (i-1)/2;
			element[i] = element[2*i+1]+element[2*i+2];
		}
	}
	// left<right
	T Find(int left,int right,int index=0,int vleft=0,int vright=-1){
		if(vright<0) vright = last_num;
		if(vright<=left || right<=vleft) return def_value;

		Evaluate(index,vleft,vright);
		if(left<=vleft && vright<=right) return element[index];

		T res_left = Find(left,right,2*index+1,vleft,(vleft+vright)/2);
		T res_right = Find(left,right,2*index+2,(vleft+vright)/2,vright);
		return min(res_left,res_right);
	}
};

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

	auto N=in(),Q=in();
	vector<ll> A(N,(1LL<<31)-1);
	SegmentTree<ll> tree(A,(1LL<<31)-1);

	REP(i,Q){
		int q=in();
		if(q==1){
			int x=in(),t=in();
			out(tree.Find(x,t+1));
		}
		else{
			int s=in(),x=in();
			tree.UpdateRange(s,s+1,x);
		}
	}

	return 0;
}



Measured memory_bytes: 7956
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

struct Factorization {
    vector<pair<ll, int>> factors;
    void factoring(ll n) {
        ll sqrt_n = (ll)(sqrt(n) + 1e-6);
        vector<ll> primes;
        vector<bool> isPrime(sqrt_n + 1, true);
        for (ll k = 2; k <= sqrt_n; ++k) {
            if (!isPrime[k]) continue;
            primes.push_back(k);
            for (ll l = k * 2; l <= sqrt_n; l += k) isPrime[l] = false;
        }
        for (ll i = 0; i < primes.size() && n > 1;) {
            if (n % primes[i] == 0) {
                n /= primes[i];
                if (!factors.empty() && factors.back().first == primes[i]) factors.back().second++;
                else factors.emplace_back(primes[i], 1);
            }
            else i++;
        }
        if (n > 1) factors.emplace_back(n, 1);
    }
    pair<ll, int> operator [](int i) { return factors[i]; }
    size_t size() const { return factors.size(); }
};

int main() {
    ll A, B;
    cin >> A >> B;

    Factorization af, bf;
    af.factoring(A);
    bf.factoring(B);

    int ans = 1;
    for (int i = 0, j = 0; i < af.size() && j < bf.size(); ) {
        if (af[i].first == bf[j].first) {
            ans++;
            i++;
            j++;
        }
        else if (af[i].first < bf[j].first) {
            i++;
        }
        else {
            j++;
        }
    }

    write(ans);
}

Measured memory_bytes: 2072
def array_split(array):
    array_len=len(array)
    res=[];ans=[]
    s=0 # 0:傾き不明 1:単調非減少 2:単調非増加
    roop=0
    while roop!=array_len:
        if ans==[]:
            ans.append(array[roop])
            roop+=1
        elif s==0 and ans[-1]>array[roop]:
            ans.append(array[roop])
            s=2
            roop+=1
        elif s==0 and ans[-1]<array[roop]:
            ans.append(array[roop])
            s=1
            roop+=1
        elif s==0 and ans[-1]==array[roop]:
            ans.append(array[roop])
            roop+=1
        elif s==1:
            if ans[-1]<=array[roop]:
                ans.append(array[roop])
                roop+=1
            else:
                res.append(ans)
                s=0
                ans=[]
        elif s==2:
            if ans[-1]>=array[roop]:
                ans.append(array[roop])
                roop+=1
            else:
                res.append(ans)
                s=0
                ans=[]
    res.append(ans)
    return res
n=int(input())
a=list(map(int,input().split()))
print(len(array_split(a)))

Measured memory_bytes: 63468
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

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

	ll n, k;
	cin >> n >> k;

	ll t = n / k;
	ll ans = t * t * t;
	if (k % 2 == 0) {
		k /= 2;
		ll x = n / k - t;
		ans += x * x * x;
	}

	cout << ans << "\n";

	return 0;
}



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

int main(){
    string div[4] = {"dream", "dreamer", "eraser", "erase"};

    string S;
    cin >> S;

    reverse(S.begin(), S.end());
    for(int i = 0; i < 4; i++) reverse(div[i].begin(), div[i].end());

    bool ans = true;
    for(int i = 0; i < S.size();){
        bool flag = false;
        for(int j = 0; j < 4; j++){
            string d = div[j];
            if(S.substr(i, d.size()) == d){
                flag = true;
                i += d.size();
            }
        }

        if(!flag){
            ans = false;
            break;
        }
    }

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

void Main() {
  int N;
  cin >> N;
  int A[N][N];
  long long dist[N][N];

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
      dist[i][j] = A[i][j];
    }
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (dist[i][j] < A[i][j]) {
        cout << -1 << endl;
        return;
      }
      bool shortest = true;
      for (int k = 0; k < N; k++) {
        if (k != i && k != j && dist[i][j] == dist[i][k] + dist[k][j]) {
          shortest = false;
        }
      }
      if (shortest) ans += A[i][j];
    }
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



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

using namespace std;

int INF = 2147483646 / 2;

int main() {
  int H, W;

  cin >> H >> W;
  vector<string> S(H);

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

  vector<vector<int>> dist(H * W, vector<int>(H * W, 0));

  for (int hi = 0; hi < H; hi++) {
    for (int wi = 0; wi < W; wi++) {
      for (int hj = 0; hj < H; hj++) {
        for (int wj = 0; wj < W; wj++){
          if (S[hi][wi] == '.' && S[hj][wj] == '.'
              && ((abs(hi-hj) <= 1 && abs(wi-wj) == 0) || (abs(hi-hj) == 0 && abs(wi-wj) <= 1))
              ) {
            dist[W * hi + wi][W * hj + wj] = abs(hi - hj) + abs(wi - wj);
          } else {
            dist[W * hi + wi][W * hj + wj] = INF;
          }
        }
      }
    }
  }

  for (int k = 0; k < H * W; k++) {
    for (int i = 0; i < H * W; i++) {
      for (int j = 0; j < H * W; j++) {
        if (dist[i][j] > (dist[i][k] + dist[k][j])) {
          dist[i][j] = dist[i][k] + dist[k][j];
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < H * W; i++) {
    for (int j = 0; j < H * W; j++) {
      if (dist[i][j] < INF) {
        ans = max(ans, dist[i][j]);
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip> 
#include <cstring>
#include <queue>
#include <stack> 
#include <vector>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
double a,b,c,d;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> a >> b >> c >> d;
	int cnt = 1;
	while(a > 0 && c > 0){
		if(cnt & 1){
			c -= b;
		}else{
			a -= d;
		}
		cnt++;
	}
	if(a > 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


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

int main()
{

    int N;
    cin >> N;
    string S;
    cin >> S;
    for (int i = 0; i < S.size(); i++)
    {
        S[i] = S[i] + N;
        if(S[i] > 'Z'){
            S[i] = S[i] - 26;
        }
    }
    cout << S << endl;
    return 0;
}

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

int T[1500][1500];
struct rect {
    int h;
    int p;
};

int main() {
    int H, W; cin >> H >> W;
    rep(i, H){
        rep(j, W){
            cin >> T[i][j];
            T[i][j] = (T[i][j]+1) % 2;
        }
    }

    for (int i = 1; i < H; i++){
        for (int j = 0; j < W; j++){
            if(T[i][j] != 0){
                T[i][j] = T[i-1][j]+1;
            }
        }
    }

    int ans = 0;
    rep(i, H){
        stack<rect> S;
        rep(j, W+1){
            rect r = {T[i][j], j};
            if(S.empty()){
                S.push(r);
            } else if(S.top().h < r.h){
                S.push(r);
            } else if(S.top().h == r.h){
                continue;
            } else {
                int nowp;
                while(!S.empty() && S.top().h > r.h){
                    rect r2 = S.top(); S.pop();
                    int men = r2.h * (j - r2.p);
                    ans = max(ans, men);
                    nowp = r2.p;
                }
                r.p = nowp;
                S.push(r);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11300
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  int N;
  string s,l;
  cin>>N>>s>>l;
  const int INF=1e9+7;
  int i;
  int ans;
  if(s[0]==l[0]){
    ans=3;
    i=1;
  }
  else{
    ans=6;
    i=2;
  }
  for(i;i<N;i++){
    if(s[i]==l[i]){
      if(s[i-1]==l[i-1])ans*=2;
      else ans*=1;
    }
    else{
      if(s[i-1]==l[i-1])ans*=2;
      else ans*=3;
      i++;
    }
    ans%=INF;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int N;
    int A[200005];
    int Box[200005];
    memset(A,0,sizeof(A));
    memset(Box,0,sizeof(Box));
    cin >> N;
    //bool can=true;
    bool last=false;
    int lastindex;
    int inbox=0;
    for(int i=1;i<=N;i++) cin >> A[i];
    for(int i=N;i>=1;i--)
    {
        if(i>(N/2) && A[i]==1) 
        {
            Box[i]=1,inbox++;
            if(!last) lastindex=i,last=true;
            //cout << "i: " <<i << "Box[i]: " << Box[i] << endl;
        }
        else
        {
            //cout << "i: " << i << endl;
            int sum=0;
            for(int j=2*i;j<=N;j+=i)
            {
                sum+=Box[j];
            }
            //cout << "sum: " << sum << endl;
            if(A[i]==(sum%2)) Box[i]=0;
            else 
            {
                Box[i]=1,inbox++;
                if(!last) lastindex=i,last=true;
            }
        }
        
    }
    cout << inbox << endl;
    for(int i=1;i<=N;i++)
    {
        if(Box[i]==1 && i!=lastindex) cout << i <<  ' ';
        else if(Box[i]==1 && i==lastindex) cout << i << endl;
    }
}

Measured memory_bytes: 2688