akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  1000000007;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}
  void init(int n) { par.assign(n, -1); }

  int root(int x) {
    if (par[x] < 0)
      return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y)
      return;
    if (par[x] > par[y])
      swap(x, y);
    par[x] += par[y];
    par[y] = x;
  }

  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { return -par[root(x)]; }
};


int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}


signed main() {
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<map<int, ll>> a(n);
  REP(i, n) a[i][i] = 0;
  UnionFind tree(n);
  REP(i, m) {
    ll l, r, d;
    cin >> l >> r >> d;
    l--;r--;
    if(tree.same(l, r)) {
      int root = tree.root(l);
      if(a[root][r] - a[root][l] != d) {
        cout << "No" << endl;
        return 0;
      }
      continue;
    }
    if(tree.size(l) < tree.size(r)) {
      swap(l, r);
      d = -d;
    }
    int root_l = tree.root(l);
    ll base = a[tree.root(l)][l] - a[tree.root(r)][r] + d;
    for(const auto value: a[tree.root(r)]) {
      a[tree.root(l)][value.first] = value.second + base;
    }
    tree.unite(l, r);
    if(root_l != tree.root(l)) {
      a[tree.root(l)] = a[root_l];
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 48256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b;
  cin >> a >> b;
  
  if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i,N)cin >> d[i];
    if(N%2==1){
        cout << 0 << endl;
        return 0;
    }
    sort(d.begin(),d.end());
    cout << d[N / 2] - d[N / 2 - 1] << endl;

    return 0;
}

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

a = []
b = []
for i in range(m):
    aa,bb = list(map(int,input().split()))
    a.append(aa)
    b.append(bb)
c = []
d = []
for i in range(m):
    if a[i] == 1:
        c.append(b[i])
    elif a[i] == n:
        d.append(b[i])
    elif b[i] == n:
        d.append(a[i])

ans = 'IMPOSSIBLE'
c = set(c)
d = set(d)

if len(c&d) >= 1:
    ans = 'POSSIBLE'
print(ans)

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

map<llong, int> PrimeFact(llong n){
	map<llong, int> ret;
	while(n % 2 == 0){
		ret[2]++;
		n /= 2;
	}
	for(llong i = 3; i*i <= n; i += 2){
		while(n%i == 0){
			ret[i]++;
			n /= i;
		}
	}
	if(n != 1)
	ret[n]++;

	return ret;
}

int main(){
	int N;
	llong ans = 1;

	cin >> N;
	map<llong,int> marge;
	for(int i = 1; i <= N; i++){
		auto m = PrimeFact(i);
		for(auto it = m.begin(); it != m.end(); it++)
			marge[it->first] += it->second;
	}
	for(auto it = marge.begin(); it != marge.end(); it++){
		// cerr << it->first << " " << it->second << endl;
		(ans *= it->second + 1) %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define maxn 100005
using namespace std;
typedef struct node{
  double x;
  double y;
}node;
double getlen(node a,node b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int main()
{
     int n;
     cin>>n;
     node   point[n];
     for(int i=0;i<n;i++)
     scanf("%lf%lf",&point[i].x,&point[i].y);
     int tem=1;
     for(int i=1;i<=n;i++)
         tem*=i;
     double ans=0;
     for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
     {
         if(i!=j)
            ans+=sqrt(getlen(point[i],point[j]));
     }
     ans/=n;
     /*ans*=(tem/n);
     ans/=tem;*/
     printf("%.7f",ans);
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#define INF 0x3f3f3f3f;

using namespace std;

int a[105];

int main() {
    int n,i,j;
    long long m=10000000;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<=100;i++){
        long long sum=0;
        for(j=0;j<n;j++){
            sum+=(a[j]-i)*(a[j]-i);
        }
        m=min(sum,m);
    }
    printf("%lld\n",m);
}


Measured memory_bytes: 128
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#include "bits/stdc++.h"

namespace adaptor = boost::adaptors;

bool binarySearch(int64_t A[], int64_t n, int64_t key) {
    int64_t left = 0;
    int64_t right = n;
    int64_t mid;

    while (left < right) {
        mid = (left + right) / 2;
        if (key == A[mid]) return true;
        if (key > A[mid]) left = mid + 1;
        if (key < A[mid]) right = mid;
    }
    return false;
}

void solve() {
    int64_t n, A[100000], q, key, sum = 0;
    std::cin >> n;
    for (int64_t i = 0; i < n; i++) {
        std::cin >> A[i];
    }
    std::cin >> q;
    for (int64_t i = 0; i < q; i++) {
        std::cin >> key;
        if (binarySearch(A, n, key)) sum++;
    }

    std::cout << sum << std::endl;
    return;
}

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



Measured memory_bytes: 3932
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int n;
	cin >> n;
	vi v(n - 1);
	rep(i, n - 1) cin >> v[i];
	int ans = v.front() + v.back();
	rep(i, n - 2) {
		ans += min(v[i], v[i + 1]);
	}
	cout << ans << endl;
}

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

	solve();
}


Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))

tmp = [0] * N
for i in range(N):
    tmp[i] = X[i]

tmp.sort()
mid_left = tmp[N // 2 - 1]
mid_right = tmp[N // 2]



for i in X:
    if i <= mid_left:
        print(mid_right)
    else:
        print(mid_left)


Measured memory_bytes: 26772
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    deque<char> dS(S.size());
    for(int i=0;i<S.size();i++)dS[i]=S[i];
    int Q;cin>>Q;
    int rev=0;
    for(int i=0;i<Q;i++){
        int type;cin>>type;
        if(type==2){
            int f;char c;
            cin>>f>>c;--f;
            if(rev)f=1-f;
            if(f==0)dS.push_front(c);
            else dS.push_back(c);
        }

        else rev=1-rev;
    }
    if(rev)reverse(dS.begin(),dS.end());
    for(auto c:dS)cout<<c;
    cout<<endl;
}

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

#define ll long long
#define mod 1000000007

ll n;
double prob[3003], dp[3003][3003];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> prob[i];
	}
	//memset (dp, -1, sizeof dp);
	dp[0][0] = 1;
	dp[0][1] = 0;
	dp[1][0] = 1;

	for (int i = 1; i <= n; i++) {
		for (int heads = 0; heads <= i; heads++) {
			if (heads == 0) {
				dp[i][heads] = 1;
				continue;
			}
			dp[i][heads] = prob[i] * dp[i - 1][heads - 1] + (1 - prob[i]) * dp[i - 1][heads];
		}
	}
	cout << setprecision(10) << dp[n][(n + 1) / 2] << "\n";
	return 0;
}

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

using namespace std;

using ll = long long int;
using ld = long double;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	int b1 = 0, b2 = 0, b4 = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 4 == 0) {
			b4++;
		} else if (a % 2 == 0) {
			b2++;
		} else {
			b1++;
		}
	}

	if (b2 == 0) {
		cout << (b1 <= b4 + 1 ? "Yes" : "No") << endl;
	} else {
		cout << (b1 <= b4 ? "Yes" : "No") << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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 ll INF=1e18;
const int mx=200005;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll k;
    cin>>k;
    if(k%2==0||k%5==0)cout<<-1<<endl;
    else{
        ll ans=0;
        ll cnt=0;
        while(true){
            ans++;
            cnt=(cnt*10+7LL)%k;
            if(cnt==0)break;
        }
        cout<<ans<<endl;
    }
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
vi mk_bits(int bit,int n){
    vi S;
    rep(i,n){
        if(bit & (1 << i)){
            S.pb(1);
        }
        else{S.pb(0);}
    }
    return S;
}



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

	int d, g;
	cin >> d >> g;
	vi p(d);
	vl c(d);
	ll ans = INF;

	rep(i,d){
		cin >> p[i] >> c[i];
	}


	for(int bit = 0;bit < (1<<d);++bit){
		vi bits = mk_bits(bit,d); //n bitの01からなる数列
		ll tot=0;
		ll kosuu=0;
		rep(i,d){
			if(bits[i]==1){
				tot += (p[i]* 100*(i+1) + c[i]);
				kosuu += p[i];
			}
		}
		if(tot>=g) ans = min(ans,kosuu);
		else{
			for(int i = d-1; i>=0 ; --i){
				if(bits[i]==1)continue;
				rep(j,p[i]){
					if(tot >= g)break;
					tot += 100*(i+1);
					kosuu++;
				}
			}
			ans = min(ans,kosuu);
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 最大公約数 - 取得
int
fGetGcd(
	int piVal1					// <I> 値１
	, int piVal2				// <I> 値２
)
{
	int liWork;

	// ユークリッドの互除法
	if (piVal1 < piVal2) {
		liWork = piVal1;
		piVal1 = piVal2;
		piVal2 = liWork;
	}
	while (piVal2 > 0) {
		liWork = piVal1 % piVal2;
		piVal1 = piVal2;
		piVal2 = liWork;
	}

	return piVal1;
}

// 最小公倍数 - 取得
int
fGetLcm(
	int piVal1					// <I> 値１
	, int piVal2				// <I> 値２
)
{
	// 最大公約数 - 取得
	int liGcd = fGetGcd(piVal1, piVal2);

	// 約数
	int liVal1 = piVal1 / liGcd;
	int liVal2 = piVal2 / liGcd;

	return liVal1 * liVal2 * liGcd;
}

// 実行メイン
int
fMain(
)
{
	char lc1Buf[1024];

	// X - 取得
	int liX;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &liX);

	// 最小公倍数 - 取得
	int liLcm = fGetLcm(liX, 360);

	return liLcm / liX;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 1708
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
#include <bitset>
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


ll a[4];

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

    rep(i, 6){
        ll inp;
        cin >> inp;
        inp--;
        a[inp]++;
    }
    ll o = 0;
    ll t = 0;

    rep(i, 4){
        if(a[i] == 1) o++;
        if(a[i] == 2) t++;
    }

    if(o==t && t==2) cout << "YES" << endl;
    else cout << "NO" << endl;

    //cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
N = len(S)
K = ii()
cnt = 0
#for i in range(1, N):
i = 1
flag = 0

if S.count(S[0]) == N:
    print(N * K // 2)
    exit()

while i < N:
    if S[i] == S[i-1]:
        cnt += 1
        if i + 1 < N and S[i] == S[i+1]:
            i += 1
        if i == N-1:
            flag = 1
    i += 1

if flag and S[0] == S[-1]:
    cnt += 1
    cnt_sub = 0
    S = S[1:] + S[0]
    i = 1
    flag = 0
    while i < N:
        if S[i] == S[i-1]:
            cnt_sub += 1
            if i + 1 < N and S[i] == S[i+1]:
                i += 1
        i += 1
    print(cnt + cnt_sub * (K-2) + cnt_sub - 1)

else:
    print(cnt * K)

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    string a,b;
    cin >>a>>b;
    ll co=0;
    if(a.size()>b.size()){
        co=1;
    }
    else if(a.size()<b.size())co=2;
    else {
        for (int i = 0; i < a.size(); ++i) {
            int an=a[i]-'0';
            int bn=b[i]-'0';
            if(an>bn){
                co=1;
                break;
            }
            if(an<bn){
                co=2;
                break;
            }
        }
    }
    if(co==0){
        puts("EQUAL");
    }
    if(co==1){
        puts("GREATER");
    }
    if(co==2){
        puts("LESS");
    }
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string> 
typedef long long ll;
using namespace std;

int main() {
    
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll ac = a * c;
    ll ad = a * d;
    ll bc = b * c;
    ll bd = b * d;
    ll res = max({ ac, ad, bc, bd });
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define nmax 2e+5


int main()
{
	int N; cin >> N;
	vector<int> P(nmax+1),place(nmax+2);
	set <int> order;
	long long ans=0;
	P[0]=0;
	P[N+1]=N+1;
	for (int i=1;i<N+1;i++)
	{
		cin >> P[i];
		place[P[i]]=i;
	}
	order.insert(place[N]);
	order.insert(N+1);
	order.insert(0);
	decltype(order)::iterator x,y,w,z;
	for (long long i=N-1;i>0;i--)
	{
	
		x=order.upper_bound(place[i]);
		if (*x!=N+1) y=order.upper_bound(*x);
		else y=x;
		w=order.lower_bound(place[i]);
		if (*w!=0) 
		{
			w--;
			z=order.lower_bound(*w);
			if (*z!=0) z--;
		}
		else z=w;
		ans+=i*((long long)*y-(long long)*x)*(place[i]-(long long)*w);
		ans+=i*((long long)*w-(long long)*z)*((long long)*x-place[i]);
		order.insert(place[i]);
	}
	cout << ans << endl;
return 0;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> v(n + 1), w(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> v[i] >> w[i];
  }
  constexpr int th = 4096;
  vector<vector<pair<int, int>>> a(th);
  a[0] = {{0, 0}};
  for (int i = 1; i <= min(th - 1, n); ++i) {
    a[i] = a[i / 2];
    int sz = size(a[i]);
    a[i].reserve(2 * sz);
    for (int j = 0; j < sz; ++j) {
      a[i].emplace_back(a[i][j].first + w[i], a[i][j].second + v[i]);
    }
    inplace_merge(begin(a[i]), begin(a[i]) + sz, end(a[i]));
    for (int j = 1; j < 2 * sz; ++j) {
      a[i][j].second = max(a[i][j].second, a[i][j - 1].second);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int i, l;
    cin >> i >> l;
    if (i < th) {
      auto it = prev(lower_bound(begin(a[i]), end(a[i]), make_pair(l + 1, 0)));
      cout << it->second << '\n';
    } else {
      vector<pair<int, int>> b(1);
      while (i >= th) {
        int sz = size(b);
        b.reserve(2 * sz);
        for (int j = 0; j < sz; ++j) {
          b.emplace_back(b[j].first + w[i], b[j].second + v[i]);
        }
        inplace_merge(begin(b), begin(b) + sz, end(b));
        i >>= 1;
      }
      int res = 0;
      for (auto [sw, sv] : b) {
        if (sw > l) break;
        auto it = prev(lower_bound(begin(a[i]), end(a[i]), make_pair(l - sw + 1, 0)));
        res = max(res, sv + it->second);
      }
      cout << res << '\n';
    }
  }
}


Measured memory_bytes: 92940
#include <iostream>
using namespace std;
int coaster[1001][1001];
int main(void){
    int c,n,x,y,d,temp;
    char a;
    int cut=0;
    int ans=0;
    cin>>c>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a;
            if(a=='1'){
                coaster[i][j]=1;
            }
            else{
                coaster[i][j]=0;
            }
        }
    }
    for(int i=1;i<=n/2;i++){
        for(int j=1;j<=n/2;j++){
            if(coaster[i][j]!=coaster[n-i+1][j]||coaster[i][j]!=coaster[i][n-j+1]||coaster[i][j]!=coaster[n-i+1][n-j+1]){
                cut++;
            }
        }
    }
    if(cut==0){
        ans++;
    }
    for(int i=2;i<=c;i++){
        cin>>d;
        for(int j=0;j<d;j++){
            cin>>y>>x;
            if(coaster[y][x]==0){
                coaster[y][x]=1;
                temp=0;
            }
            else{
                coaster[y][x]=0;
                temp=1;
            }
            if((temp==coaster[n-y+1][x]&&temp==coaster[y][n-x+1]&&temp==coaster[n-y+1][n-x+1])&&(coaster[y][x]!=coaster[n-y+1][x]||coaster[y][x]!=coaster[y][n-x+1]||coaster[y][x]!=coaster[n-y+1][n-x+1])){
                cut++;
            }
            else if((temp!=coaster[n-y+1][x]||temp!=coaster[y][n-x+1]||temp!=coaster[n-y+1][n-x+1])&&(coaster[y][x]==coaster[n-y+1][x]&&coaster[y][x]==coaster[y][n-x+1]&&coaster[y][x]==coaster[n-y+1][n-x+1])){
                cut--;
            }
        }
        if(cut==0){
            ans++;
        }
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 7004
from collections import defaultdict

def main():
    H, W, N = map(int, input().split())
    d = defaultdict(int)
    dt = [-1,0,1]
    for _ in range(N):
        a, b = map(int, input().split())
        for i in dt:
            if 2 <= a + i <= H-1:
                for j in dt:
                    if 2 <= b + j <= W-1:
                        # 正方形の中点をkeyとして持つ
                        d[(a+i,b+j)] += 1
    
    ans = [0] * 10
    ans[0] = (H-2) * (W-2)
    for i in d.values():
        ans[i] += 1
        ans[0] -= 1

    for a in ans:
        print(a)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 181592
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 10000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int a,b,q;
	cin>>a>>b>>q;
	set<int> s,t;
	vector<int> que;
	for(int i=0;i<a;i++){
		int x; cin>>x; s.insert(x);
	}
	for(int i=0;i<b;i++){
		int x; cin>>x; t.insert(x);
	}
	for(int i=0;i<q;i++){
		int x; cin>>x; que.pb(x);
	}
	s.insert(-LINF); s.insert(LINF);
	t.insert(-LINF); t.insert(LINF);
	for(int i=0;i<q;i++){
		ll ans = LINF;
		set<int>::iterator its = s.upper_bound(que[i]);
		set<int>::iterator itt = t.upper_bound(que[i]);
		int s1 = *its; its--;
		int s2 = *its;
		int t1 = *itt; itt--;
		int t2 = *itt;
		int ans1 = max( que[i]-s2, que[i]-t2 );
		int ans2 = max( s1-que[i], t1-que[i]);
		int ans3 = (que[i]-s2) + (t1-que[i]) + min( (que[i]-s2) , (t1-que[i]) );
		int ans4 = (que[i]-t2) + (s1-que[i]) + min( (que[i]-t2) , (s1-que[i]) );
		cout<< min( ans1 ,min(ans2, min(ans3,ans4) ) ) <<endl;
	}
	return 0;
}

Measured memory_bytes: 11640
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll x,y,a,b,c;cin>>x>>y>>a>>b>>c;
    V<ll>p(a),q(b),r(c);
    for(ll i=0;i<a;i++)cin>>p[i];
    for(ll i=0;i<b;i++)cin>>q[i];
    for(ll i=0;i<c;i++)cin>>r[i];
    ll ans=0;
    sort(all(p));
    sort(all(q));
    sort(all(r));
    reverse(all(p));
    reverse(all(q));
    reverse(all(r));
    ll total=x+y;
    ll p1=0,q1=0,r1=0;
    for(ll i=0;i<total;i++){
        ll aa=0,bb=0,cc=0;
        if(p1<a&&x)aa=p[p1];
        if(q1<b&&y)bb=q[q1];
        if(r1<c)cc=r[r1];
        ll maxm=mmax(mmax(aa,bb),cc);
        //cout<<x<<" "<<y<<endl;
        if(aa==maxm){
            x--;
            p1++;
            ans+=maxm;
        }
        else if(q[q1]==maxm){
            y--;
            q1++;
            ans+=maxm;
        }
        else{
            ans+=maxm;
            r1++; 
        }
    }
    cout<<ans<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





























Measured memory_bytes: 2560
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = list(map(int,readline().split()))

mx = 0
ans = 0
for i in lst1:
    if i < mx:
        ans += mx-i
    else:
        mx = max(mx,i)

print(ans)

Measured memory_bytes: 92824
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; scanf("%lld", &x); return x;}
ld fin(){double x; scanf("%lf", &x); return x;}
char yuyushiki[1000010]; string stin(){scanf( "%s", yuyushiki ); return yuyushiki;}

// head

struct Unionfind{
  vector<int> size, par;
  Unionfind(){}
  Unionfind(int n) :  size(n, 1), par(n){
    for(int i = 0; i < n; i++){
      par[i] = i;
    }
  }
  int find(int x){
    if(par[x] == x){
      return x;
    }
    return par[x] = find(par[x]);
  }
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y){
      return false;
    }
    if(size[y] < size[x]){
      swap( x , y );
    }
    par[x] = y;
    size[y] += size[x];
    return true;
  }
  bool same(int x, int y){
    return find(x) == find(y);
  }
};

using T = tuple<int, int, int>;
using pi = pair<int, int>;

vector<int> G[100010];
bool nr[100010];

int ite;
int ord[100010];

int par[100010];

bool used[100010];

void dfs(int x){
  used[x] = true;
  YYS(w, G[x]){
    if(!used[w]){
      dfs(w);
    }
  }
  ord[x] = ite++;
}

int main(){

  int n = in();
  int m = in();
  vector<pi> es(0);
  REP(i, n - 1 + m){
    int a = in() - 1;
    int b = in() - 1;
    es.pb(a, b);
    G[a].pb(b);
    nr[b] = true;
  }

  REP(i, n){
    if(!used[i]){
      dfs(i);
    }
  }

  vector<T> ess(0);
  
  YYS(w, es){
    int a = w.fi;
    int b = w.se;
    // cout << a << " " << b << " " << ord[a] << " " << ord[b] << endl;
    assert(ord[a] > ord[b]);
    ess.pb(ord[a] - ord[b], a, b);
  }

  sort(ess.begin(), ess.end());
  
  Unionfind uf(n);

  YYS(w, ess){
    int c, a, b;
    tie(c, a, b) = w;
    if(!uf.same(a, b)){
      uf.unite(a, b);
      par[b] = a + 1;
    }
  }

  REP(i, n){
    printf("%d\n", par[i]);
  }
  
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int s[N];
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> s[i];
    sum += s[i];
  }
  sort(s, s + N);
  int ans = 0;
  if (sum % 10 != 0) {
    ans = sum;
  } else {
    for (int i = 0; i < N; i++) {
      if (s[i] % 10 != 0) {
        ans = sum - s[i];
        break;
      }
    }
  }
  // 解答
  cout << ans << endl;
  return 0;
}


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

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)
//ll MLG(ll n,ll b){ll a=0;while(n)a++,n/=b;return a-1;}

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
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...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble
    int a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
    return 0;
}


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

class Edge
{
	public:
	int from,to,cost,index;
	Edge(int f,int t,int c,int i)
	{
		from=f;
		to=t;
		cost=c;
		index=i;
	}
};

bool comp(Edge &lhs, Edge &rhs)
{
	return lhs.cost<rhs.cost;
}

class UF
{
	public:
	int s;
	vector<int> par;
	vector<int> dep;
	vector<int> size;

	UF(int n)
	{
		s=n;
		par.resize(s);
		dep.resize(s);
		size.resize(s);
		for(int i=0;i<n;i++)
		{
			par[i]=i;
			dep[i]=0;
			size[i]=1;
		}
	}

	int find(int x)
	{
		if(par[x]==x)
			return x;
		else
			return par[x]=find(par[x]);
	}

	void unite(int x,int y)
	{
		x=find(x);
		y=find(y);
		if(x==y)
			return;
		if(dep[x]<dep[y])
		{
			par[x]=y;
			size[y]+=size[x];
		}else{
			par[y]=x;
			size[x]+=size[y];
			if(dep[x]==dep[y])
				dep[x]++;
		}
	}

	bool same(int x,int y)
	{
		return find(x)==find(y);
	}

	int getSize(int x)
	{
		return size[find(x)];
	}
};

vector<Edge> v;
vector<int> nouseind;
bool use[50000];
int mst(int n,int nouse)
{
	int ret=0;
	UF u=UF(n);
	for(int i=0;i<v.size();i++)
	{
		Edge e=v[i];
		if(!u.same(e.from,e.to) && i!=nouse)
		{
			u.unite(e.from,e.to);
			ret+=e.cost;
			use[i]=true;
		}
		if(u.getSize(0)>=n)
			break;
	}
	if(u.getSize(0)<n)
		return -1;
	else
		return ret;
}


int main()
{
	int n,m;
	int ans1=0;
	int ans2=0;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int s,d,c;
		cin>>s>>d>>c;
		s--;d--;
		v.push_back(Edge(s,d,c,i));
	}
	fill(use,use+50000,false);
	sort(v.begin(),v.end(),comp);
	for(int i=0;i<m;i++)
	{
		//cerr<<v[i].cost<<endl;
		v[i].index=i;
	}
	
	//start mst
	int init=mst(n,-1);
	for(int i=0;i<m;i++)
	{
		if(use[i])
			nouseind.push_back(i);
	}
	//cerr<<init<<" "<<nouseind.size()<<endl;
	for(int i=0;i<nouseind.size();i++)
	{
		if(init!=mst(n,nouseind[i]))
		{
			ans1++;
			ans2+=v[nouseind[i]].cost;
		}
	}
	cout<<ans1<<" "<<ans2<<endl;
	return 0;
}


Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll MOD = 1e9+7;
const static ll INF = 1e14;


int main() {
    ll a, b; cin >> a >> b;
    ll ans = a-1;
    if(b >= a) ans++;
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+18
#define MOD 1000000007
using namespace std;



int main(){
    int H,W;
    cin >> H >> W;
    char matrix[100][100];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> matrix[i][j];
        }
    }
    
    for(int i=0; i<H; i++){
        int f=1;
        for(int j=0; j<W; j++){
            if(matrix[i][j] == '#') f=0;
        }
        if(f){
            for(int j=0; j<W; j++){
                matrix[i][j] = '!';
            }
        }
    }
    
    for(int j=0; j<W; j++){
        int f=1;
        for(int i=0; i<H; i++){
            if(matrix[i][j] == '#') f=0;
        }
        if(f){
            for(int i=0; i<H; i++){
                matrix[i][j] = '!';
            }
        }
    }
    
    for(int i=0; i<H; i++){
        int f=1;
        for(int j=0; j<W; j++){
            if(matrix[i][j]!='!'){
                f=0;
                cout<<matrix[i][j];
            }
        }
        
        if(!f)cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.math.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			int m=sc.nextInt();
			for(int i=0;i<m;i++){
				n-=sc.nextInt();
			}
			System.out.println(n>=0?n:-1);
		}
	}
}

Measured memory_bytes: 46412
//0:45
#include <stdio.h>
#include <string.h>
#include <algorithm>

typedef long long ll;
ll max(ll a, ll b){return(a>b)?a:b;}
ll min(ll a, ll b){return(a<b)?a:b;}
ll abs(ll a){return(a<0)?-a:a;}

ll gcd(ll a, ll b){
        if(b > a){
                ll tmp = b;
                b = a;
                a = tmp;
        }
        if(b == 0) return a;
        else return gcd(b, a%b);
}
ll lcm(ll a, ll b){
        ll gcdi = gcd(a,b);
        return a/gcdi*(b);
}
int main(){
        int N;
        scanf("%d",&N);
        ll tc,t;
        scanf("%lld",&tc);
        for(int i = 1; i < N; i ++){
                scanf("%lld",&t);
                tc = lcm(tc,t);
        }

        printf("%lld\n",tc);
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int A, B;
  while (cin >> A >> B) {
    int res = -1;
    for (int M = 1; M <= 20000; M++) {
      int p8 = M * 8 / 100;
      int p10 = M * 10 / 100;
      if (p8 == A && p10 == B) {
        res = M;
        break;
      }
    }
    cout << res << endl;
  }
  return 0;
}


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


int main(void) {
  string o, e;
  cin >> o >> e;
  string ans;
  rep(i, o.length()) {
    ans.push_back(o[i]);
    if (e.length() > i) {
      ans.push_back(e[i]);
    }
  }

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

Measured memory_bytes: 3580
N=int(input())
H=list(map(int,input().split()))
answer='Yes'
for i in range(N-1):
    left=H[N-2-i]
    right=H[N-1-i]
    if left<=right and answer=='Yes':
        answer='Yes'
    elif left==right+1 and answer=='Yes':
        H[N-2-i]-=1
    else:
        answer='No'
print(answer)

Measured memory_bytes: 14396
n, m = map(int, input().split())
h = list(map(int, input().split()))
edges = [tuple(map(int, input().split())) for _ in range(m)]

good_obs = [True] * n
for a, b in edges:
    if h[a - 1] >= h[b - 1]:
        good_obs[b - 1] = False
    if h[a - 1] <= h[b - 1]:
        good_obs[a - 1] = False
print(sum(good_obs))


Measured memory_bytes: 27404
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

string s;
char M[3][3];

int main(){
	while (cin >> s){
		char ans = 'd';
		REP(i, 3){
			if (s[0 + i] == 's')continue;
			if (s[0 + i] == s[3 + i] && s[3 + i] == s[6 + i])ans = s[0 + i];
		}
		for (int i = 0; i < 9; i += 3){
			if (s[i] == 's')continue;
			if (s[i] == s[i + 1] && s[i + 1] == s[i + 2])ans = s[i];
		}
		if (s[4] != 's'){
			if (s[0] == s[4] && s[4] == s[8])ans = s[0];
			if (s[2] == s[4] && s[4] == s[6])ans = s[2];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
#define ll                long long int
#define ld                long double
#define F                 first
#define S                 second
#define C                 continue
#define G                 goto done
#define pb                push_back
#define pf                push_front
#define ppb               pop_back
#define ppf               pop_front
#define sz                size()
#define pi                acos(-1.0)
#define mod               1000000007
#define maxe              *max_element
#define mine              *min_element
#define min3(a,b,c)       min(a,min(b,c))
#define max3(a,b,c)       max(a,max(b,c))
#define min4(a,b,c,d)     min(a,min(b,min(c,d)))
#define max4(a,b,c,d)     max(a,max(b,max(c,d)))
#define mem(a,b)          memset(a,b,sizeof(a))
#define all(a)            (a).begin(),(a).end()
#define gcd(a,b)          __gcd(a,b)
#define lcm(a,b)          ((a)*((b)/gcd(a,b)))
#define case(a)           cout<<"Case "<<(a)<<": "
#define point(a)          fixed<<setprecision(a)
#define get(a)            for(auto &x:a) cin>>x;
#define print(a)          for(auto x:a) cout<<x<<" "; cout<<endl;
#define uniq(a)           sort(all(a)); (a).erase(unique((a).begin(),(a).end()),(a).end())
#define big(a)            transform((a).begin(),(a).end(),(a).begin(),::toupper)
#define small(a)          transform((a).begin(),(a).end(),(a).begin(),::tolower)
#define ischar(a)         (('a'<=a&&a<='z')('A'<=a&&a<='Z'))
#define isvowel(a)        (a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U')
#define fast              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define tc                int test; cin>>test; while(test--)
using namespace std;
int main()
{
    ll n; cin>>n; ll a[n]; get(a);
    ll g=a[0],f=0;
    for(ll i=1;i<n;i++) g=gcd(g,a[i]);
    map<ll,ll>mp;
    for(ll i=0;i<n;i++)
    {
        ll k=a[i];
        for(ll j=1;j*j<=k;j++)
        {
            if(k%j==0)
            {
                ll x=j;
                ll y=k/j;
                if((mp[x]==1 && x!=1) || (mp[y]==1 && y!=1))
                {
                    f=1; break;
                }
                mp[x]=1;mp[y]=1;

            }
        }
    }


    //cout<<f<<endl;
    if(f==0) cout<<"pairwise coprime";
    else if(g==1) cout<<"setwise coprime";
    else cout<<"not coprime";
}




















Measured memory_bytes: 73900
#include "bits/stdc++.h"
#include <boost/range/irange.hpp>
//#include <boost/range/algorithm.hpp>
using namespace std;
using boost::irange;

// 定義
typedef long long           ll;
typedef pair<ll, ll>        P;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
const ll                    INF = 2e9;
const ll                    INF_LL = 1LL<<60;
const ll                    MOD = 1e9 + 7;

// ライブラリ
namespace {
	ll Ceil(ll val, ll div)   { return (val + div - 1) / div; };
	ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; };
	ll FloorN(ll x, ll n)     { return (x - x % n); };
	bool IsOdd(ll x)          { return ((x & 1) == 1); };
	bool IsEven(ll x)         { return ((x & 1) == 0); };
};

// 処理
void Solve()
{
	ll H, W;
	cin >> H >> W;
	vector<string> HW(H);
	for_each(ALL(HW), [](string &a){cin >> a;});

	vector<vector<ll>> dp(H, vector<ll>(W, INF));
	dp[0][0] = HW[0][0] == '#' ? 1 : 0;
	for(auto i : irange<ll>(0, H)) {
		for (auto j : irange<ll>(0, W)) {
			if (HW[i][j] == '.') {
				if (i + 1 < H) {
					if (HW[i + 1][j] == '.') {
						dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
					} else {
						dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
					}
				}
				if (j + 1 < W) {
					if (HW[i][j + 1] == '.') {
						dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
					} else {
						dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
					}
				}
			} else {
				if (i + 1 < H) {
					dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
				}
				if (j + 1 < W) {
					dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
				}
			}
		}
	}

	cout << dp[H - 1][W - 1] << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
#include <string>
#include <iterator>
#include <vector>
 
using namespace std;

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 1e6 + 5;
int n = 0, m = 0;
int a[MAXN];
int b[MAXN];


int largest(int a, int b){
	return (a<b)?b:a;
}


int main() {
	int n = 0;
	cin >> n;
	vector<int> a(n);
	int small = 100000, large = 0;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int var = a[n/2];
	cout << var - a[n/2-1] << endl;






    return 0;
} 

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

int main(){
	int matchCount = 0;
	int inputCount;
	int pointSumA[5] = {0}, pointSumB[5] = {0};
	
	while(cin >> inputCount){
		//cout << inputCount << endl;
		if (!inputCount) break;
		
		int cnt = 0;
		while (cnt++ < inputCount){
			int tempA, tempB;
			cin >> tempA >> tempB;
			if (tempA > tempB){
				pointSumA[matchCount] += (tempA + tempB);
			} else if (tempA == tempB) {
				pointSumA[matchCount] += tempA;
				pointSumB[matchCount] += tempA;
			} else {
				pointSumB[matchCount] += (tempA + tempB);
			}
		}
		matchCount++;
	}
	int cnt2 = 0;
	while(cnt2 < matchCount){
		cout << pointSumA[cnt2++] << " " << pointSumB[cnt2] << endl;
	}
	return 0;
}

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



int main() {
    int k, x;
    cin >> k >> x;
    
    k--;
    
    for(int i = x - k; i < x + k; i++) {
        cout << i << " ";
    }
    cout << x + k << endl;
    
    
    
    return 0;
}




Measured memory_bytes: 3616