akhauriyash/Code-Regression huggingface dataset:
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double

#define pll pair<ll,ll>
#define ff first
#define ss second

#define pb push_back
#define all(x) x.begin(),x.end()

#define MOD  1000000007
const int N = 1000005; 

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
ll spf[N];
void solve()
{
    ll n;
    cin >> n;
    ll a[n];
    ll gcdi=0;
    for(ll i=0;i<n;i++)   cin >> a[i];
    for(ll i=0;i<n;i++)
    {
        gcdi = __gcd(gcdi,a[i]);
    }
    map<ll,ll> primes;
    for(ll i=1;i<N;i++)   spf[i] = i;
    for(ll i=2;i<N;i++)
    {
        if(spf[i]==i)
        {
            for(ll j=i+i;j<N;j+=i)  spf[j] = min(spf[j],i);
        }
    }
    for(ll i=0;i<n;i++)
    {
        ll temp = a[i];
        while(temp>1)
        {
            ll p = spf[temp];
            primes[p]++;
            while(temp%p==0)   
            {
                temp /= p;
            }
        }
    }
    ll chk = 1;
    for(ll i=0;i<n;i++)
    {
        ll temp = a[i];
        while(temp>1)
        {
            ll p = spf[temp];
            if(primes[p]>1)   
            {
                chk = 0;
                break;
            }
            while(temp%p==0)  temp /= p;
        }
        if(chk==0)  break;
    }
    if(chk)       cout<<"pairwise coprime";
    else if(gcdi==1)  cout<<"setwise coprime";
    else         cout<<"not coprime";
}

int main()
{
    FAST;
    int t = 1;
 // cin >> t;
    for(int i=1;i<=t;i++)
    {
        solve();
    }
}

Measured memory_bytes: 24116
#include<stdio.h>
int main(void){
  char s[10],t[10];
  int ans=0;
  scanf("%s %s",s,t);
  if(s[0]==t[0]) ans++;
  if(s[1]==t[1]) ans++;
  if(s[2]==t[2]) ans++;
  printf("%d\n",ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<map>
#include<vector>
 
using namespace std;
unsigned long long n,a,b,c,d;
map<unsigned long long,unsigned long long> dp;

unsigned long long get(unsigned long long x){
	if(x==1)
		return d;
	if(x==0)
		return 0;
	if(dp.count(x)>0)
		return dp[x];
	unsigned long long best=x*d;
	vector<unsigned long long> val{2,3,5};
	vector<unsigned long long> cost{a,b,c};
	for(int i=0;i<3;++i){
		if(x%val[i]==0){
			best=min(best,get(x/val[i])+cost[i]);
		}
		else{
			unsigned long long up=x/val[i]+1;
			unsigned long long down=x/val[i];
			unsigned long long up_dist=0;
			unsigned long long up_cost=(up*val[i]-x)*d+cost[i]+get(up);
			unsigned long long down_cost=(x-down*val[i])*d+cost[i]+get(down);
			best=min(best,min(up_cost,down_cost));
		}
	}
	dp[x]=best;
	return best;
}

int main(){
	int t;
	cin>>t;
	
	while(t--){
		dp.clear();
		cin>>n>>a>>b>>c>>d;
		cout<<get(n)<<"\n";
	}
	return 0;
}

Measured memory_bytes: 4464
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;

int main(){
  int N;
  int a;
  int d[2][100];
  cin >> N >> a;
  d[0][0]=a;
  FOR(i,1,N){
    cin >> a;
    d[0][i]=a+d[0][i-1];
  }
  cin >> a;
  d[1][0]=d[0][0]+a;// a(2,1)
  FOR(i,1,N){
    cin >> a;
    d[1][i]=max(d[1][i-1],d[0][i])+a;
  }
  cout << d[1][N-1] << endl;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    cout << (b-a)*(b-a+1)/2-b << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
M = [list(map(int, input().split())) for _ in range(N)]

xnow, ynow = 0, 0
tnow = 0
ans = "Yes"
for m in M:
    t, x, y = m
    min_len = abs(x - xnow) + abs(y - ynow)
    time_len = t - tnow
    if time_len >= min_len:
        if (time_len - min_len) % 2 == 0:
            xnow, ynow = x, y
            tnow = t
            continue
        else:
            ans = "No"
            break
    else:
        ans = "No"
        break

print(ans)

Measured memory_bytes: 27324
S = input()
flag = (S[0] == "A")
flag = flag and (S[2:-1].count("C") == 1)
if flag:
    s = S[1:]
    i = s.index("C")
    s = s[:i] + s[i+1:]
    flag = flag and (s == s.lower())
if flag:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

// doot diddly donger cuckerino Hahahahahah

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef unsigned int UINT;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef tuple<int, int, int> TPL;
typedef priority_queue<int> pqueue;
typedef priority_queue<int, VI, greater<>> pdqueue;

#define sim             template<class T
#define MP              make_pair
#define MT              make_tuple
#define PB              push_back
#define EB              emplace_back
#define F               first
#define S               second
#define ALL(a)          std::begin(a), std::end(a)
#define Sort(X)         sort(ALL(X))
#define UNIQUE(X)       Sort(X); (X).erase(unique(ALL(X)),(X).end())
#define SZ(x)           (int)(x).size()
#define IN_REP          int _t; cin >> _t ; while(_t--)
#define IOS             ios::sync_with_stdio(false);cin.tie(NULL)
#define FOR(i, a, b)    for(int i=(a);i<(b);i++)
#define REP(i, n)       FOR(i,0,n)
#define FORR(i, n)      for(int i=(n);i>=0;i--)
#define EPS             (LD) 1e-9
#define MOD             (LL)(1e9+ 7)
#define cerr2(x,y)      cerr << (x) << " " << (y) << endl;
#define cout2(x,y)      cout << (x) << " " << (y) << endl;
const LD PI = acos(-1);
sim>T gcd(T x, T y) {return (y==0)?x:gcd(y, x % y);}
sim>void mini(T &a, T b) { a = min(a, b); }
sim>void maxi(T &a, T b) { a = max(a, b); }
sim>inline void add(T &x, T y) {x += y;if (x >= MOD) x -= MOD;}
sim>inline void sub(T &x, T y) {x -= y;if (x < 0) x += MOD;}
sim>inline T mul(T a, T b) {LL x = (long long) a * b;x %= MOD;return x;}
sim>inline T power(T base, T exp) {T result = 1; while (exp) {if (exp & 1)result *= base;exp >>= 1;base *= base;}return result;}
sim>inline T power(T a, T b, T mod) {T res = 1;while (b > 0) {if (b & 1) { res = mul(res, a); }a = mul(a, a);b >>= 1;}return res%mod;}
sim>inline T modInverse(T n, T p) { return power(n, p - 2, p)%p; }
sim, class U>string to_string(pair<T, U> p) {return "" + to_string(p.F) + " " + to_string(p.S) + "";}


double n, k;

double get(int x) {
    double res = 1 / n;
    while (x < k) {
        res /= 2;
        x *= 2;
    }
    return res;
}

class CDiceAndCoin {
public:
    static void solve(std::istream &cin, std::ostream &cout) {
        cout << setprecision(12);
        cin >> n >> k;
        double res = 0;
        for (int i = 1; i <= n; ++i) {
            res += get(i);
        }
        cout << res << endl;
    }
};


int main() {
    IOS;
	CDiceAndCoin solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	CDiceAndCoin::solve(in,out);
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init,ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T> &v) {
	T ans = -INF;
	rep(i,0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}
/*
ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}
*/
bool sortreverse(ll a, ll b) {
	return a > b;
}

bool kansu(pll a, pll b) {
	return a.first < b.first;
}

ll kiriage(ll a, ll b) {
	if (a % b == 0)return a / b;
	return a / b + 1;
}

double dp[310][310][310];
ll n;

double solv(ll i,ll j,ll k) {
	if (i < 0 || j < 0 || k < 0)return 0.0;
	if (dp[i][j][k] >= 0) return dp[i][j][k];
	dp[i][j][k] = (double)solv(i - 1, j + 1, k) * i + solv(i, j - 1, k + 1) * j + solv(i, j, k - 1) * k + n;
	dp[i][j][k] /= (double)i + j + k;
	return dp[i][j][k];
}


int main() {
	cin >> n;
	vl a(n); vl count = vl{ 0,0,0 };
	rep(i, 0, n) {
		cin >> a[i];
		count[a[i] - 1]++;
	}
	rep(i, 0, 302) {
		rep(j, 0, 302) {
			rep(k, 0, 302) {
				if (i > n)dp[i][j][k] = 0;
				else if (j > n)dp[i][j][k] = 0;
				else if (k > n)dp[i][j][k] = 0;
				else dp[i][j][k] = -1;
			}
		}
	}
	dp[0][0][0] = 0;
	//printf("#");
	printf("%.16f\n", solv(count[2], count[1], count[0]));
}

Measured memory_bytes: 227584
A, B, C = map(int,input().split())
ans = 0
while True:
  if A & 1 or B & 1 or C & 1: break 
  elif A == B and B == C:
    ans = -1
    break  
  else: 
    ans += 1
    A, B, C = (B + C) // 2, (A + C) // 2, (A + B) // 2
print(ans)

Measured memory_bytes: 38256
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

from collections import deque

N = int(input())
S = [input() for _ in range(N)]

def bfs(start):
    res = 0
    dist = [-1] * N
    dist[start] = 1
    q = deque()
    q.append([start, 1])
    st = set()
    st.add((start, 1))

    while q:
        i, d = q.popleft()
        if dist[i] == -1:
            dist[i] = d
            res = max(res, d)
        elif dist[i] != d:
            res = -1
            break
        for j in range(N):
            if S[i][j] == '1' and dist[j] != d-1:
                if (j, d+1) not in st:
                    q.append([j, d+1])
                    st.add((j, d+1))
    return res

ans = -1
for i in range(N):
    k = bfs(i)
    if k == -1:
        break
    else:
        ans = max(ans, k)

print(ans)

Measured memory_bytes: 3436
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	long long ans=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(__gcd(i,j)==1){
				ans+=n;
			}else{
				for(int k=1;k<=n;k++){
					ans+=__gcd(__gcd(i,j),k); 
				}
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(ll i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(ll i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

ll lt[200010], rev[200010], n, m, a, b, res, f[200010];

ll mu(ll a, ll b)
{
    if (b == 0) return 1;
    if (b == 1) return a%base;
    ll p = mu(a,b/2);
    if (b&1) return (((p*p)%base)*a)%base;
    return (p*p) % base;
}

ll C(ll n, ll k)
{
    return (((lt[n]*rev[n-k]) % base) * rev[k]) % base;
}

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    lt[0] = 1;
    rev[0] = mu(1,base-2);
    FOR(i,1,200000) {
        lt[i] = (lt[i-1]*i) % base;
        rev[i] = mu(lt[i], base-2);
    }
    cin >> n >> m >> a >> b;
    FOR(i,1,n-a) f[i] = C(b+i-2, i-1);
    FOR(i,1,n-a) res = (res + (f[i]*C(m-b+n-i+1-2, m-b-1))%base) % base;
    cout << res;
    return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=100010,mod=998244353;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,a[maxn],c;
bool hhh[maxn];
ll ans;
int main(){
	n=read();
	FOR(i,1,n) a[i]=read();
	sort(a+1,a+n+1);
	for(int i=2;i<=n;i+=2) ans+=abs(a[i]+a[i-1]);
	if(n&1) ans+=a[n];
	printf("%lld\n",ans);
}

Measured memory_bytes: 640
#include <stdio.h>
#define N 44
int fib(int);
int F[N];
int main(){
int n,i;
for( i=0;i<N;i++){
F[i] = 0;
}
scanf("%d",&n);
printf("%d\n",fib(n));
}

int fib(int n){
if(n == 0 || n ==1){
return F[n] =1;
}
if(F[n] != 0){
return F[n];
}
return F[n] = fib(n-2) +fib(n-1);
}





Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int INFTY=1e9;
const int N=25000;

int p[N], a[N], b[N];

int main() {
    int i, t, n;
    scanf("%d", &n);
    for(i=1; i<=n; i++) a[i]=b[i]=1;
    for(i=1; i<=n; i++) {
        scanf("%d", &t);
        a[t]+=i;
        b[t]+=i;
    }
    for(i=1; i<=n; i++) a[i]+=a[i-1];
    for(i=n; i>=1; i--) b[i]+=b[i+1];
    for(i=1; i<=n; i++) printf(i==n? "%d\n":"%d ", a[i]);
    for(i=1; i<=n; i++) printf(i==n? "%d\n":"%d ", b[i]);
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;

int main() {
	int N;
	cin>>N;
	vector<int> v1,v2;
	std::map<ll, ll> map1,map2;
	rep(i,N){
		int v;
		cin>>v;
		if(i%2 == 0){
			v1.push_back(v);
			map1[v]++;
		}
		else{
			v2.push_back(v);
			map2[v]++;
		}
	}
	vector<P> cnt1,cnt2;
	//個数、keyのPairのベクター
	for(auto x :  map1){
		cnt1.push_back({x.second,  x.first});
	}
	for(auto x :  map2){
		cnt2.push_back({x.second,  x.first});
	}
	cnt1.push_back({0,0});
	cnt2.push_back({0,0});
	sort(all(cnt1));
	sort(all(cnt2));
	int ans  = N;
	int N1 = cnt1.size();
	int N2 = cnt2.size();
	if(cnt1[N1-1].second==cnt2[N2-1].second){
		ans -= max(cnt1[N1-1].first+cnt2[N2-2].first,cnt1[N1-2].first+cnt2[N2-1].first);
	}
	else{
		ans -= cnt1[N1-1].first+cnt2[N2-1].first;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 60; //10e18+10e17ちょっとくらい
const int MOD = 1000000007;
const int MAX_N = 200100;

bool mp[25][25];
int memo[25][25];
void solve(int h, int w)
{
    queue<pair<int, int>> q;
    memo[h][w] = 0;
    q.push(make_pair(h, w));
    while (!q.empty())
    {
        h = q.front().first;
        w = q.front().second;
        q.pop();
        if (!mp[h - 1][w] && memo[h - 1][w] == -1)
        {
            memo[h - 1][w] = memo[h][w] + 1;
            q.push(make_pair(h - 1, w));
        }
        if (!mp[h + 1][w] && memo[h + 1][w] == -1)
        {
            memo[h + 1][w] = memo[h][w] + 1;
            q.push(make_pair(h + 1, w));
        }
        if (!mp[h][w - 1] && memo[h][w - 1] == -1)
        {
            memo[h][w - 1] = memo[h][w] + 1;
            q.push(make_pair(h, w - 1));
        }
        if (!mp[h][w + 1] && memo[h][w + 1] == -1)
        {
            memo[h][w + 1] = memo[h][w] + 1;
            q.push(make_pair(h, w + 1));
        }
    }
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int h, w;
    cin >> h >> w;
    rep(i, h + 2)
    {
        mp[i][0] = true;
        mp[i][w + 1] = true;
    }
    rep(i, w + 2)
    {
        mp[0][i] = true;
        mp[h + 1][i] = true;
    }
    rep(i, h)
    {
        rep(j, w)
        {
            char c;
            cin >> c;
            if (c == '#')
                mp[i + 1][j + 1] = true;
        }
    }

    int ans = 0;
    rep(i, h)
    {
        rep(j, w)
        {
            if (mp[i + 1][j + 1] == false)
            {
                rep(ii, h)
                {
                    rep(jj, w)
                    {
                        memo[ii + 1][jj + 1] = -1;
                    }
                }
                solve(i + 1, j + 1);
                int tmp = 0;
                rep(ii, h)
                {
                    rep(jj, w)
                    {
                        tmp = max(tmp, memo[ii + 1][jj + 1]);
                    }
                }
                ans = max(ans, tmp);
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(ll i = (ll)a; i < (ll)b; i++)
using namespace std;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n*a, b) << "\n";
}


Measured memory_bytes: 3604
w = list(input())
S = set(w)
L = []
T = sorted(S)
for i in range(0,len(S)):
  L.append(w.count(T[i]))

flag = True  
for a in L:
  if (a % 2 != 0):
    flag = False
    
if flag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e8)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
 int a,p;
   cin>>a>>p;
  int res = a*3+p;
  cout<<res/2;
  
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int MOD = 1000000007;

int main(void){
    ll N, K; cin >> N >> K;
    
    int cnt = 0;
    while(N > 0){
        cnt++;
        N /= K;
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 256
// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
#ifdef __MINGW32__
typedef double rn;
#else
typedef long double rn;
#endif

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

string s;

int main(){
	cin>>s;
	int c = 0;
	REP(i,s.size()-1){
		if(s[i]!=s[i+1])c++;
	}
	cout<<c<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN

 main() {
string s;
cin >> s;
for(int i=0;i<4;i++){
   cout << s.at(i);
}
cout <<" ";
for(int i=4;i<s.size();i++){
   cout << s.at(i);
}
cout << endl;
 }


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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main(void){
    int i, j, n, judge=0;
    scanf("%d", &n);
    int array[n];
    for (i=0; i < n; i++){
        scanf("%d", &array[i]);
    }
    qsort(array, n, sizeof(int), compare_int);
    for (i=0;i<n-1;i++){
        if (array[i]==array[i+1]){
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}

Measured memory_bytes: 1788
if __name__ == "__main__":
    N, K = [int(x) for x in input().split(" ")]
    arr = []
    for _ in range(N):
        a, b = [int(x) for x in input().split(" ")]
        arr.append((a, b))
    arr.sort()

    k = 0
    for a, b in arr:
        if k + b < K:
            k = k + b
        else:
            print(a)
            break



Measured memory_bytes: 79240
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //cout<<"bismillahhir rahmanir rahim"<<endl;
    double n, m, a;
    cin>>n>>m;
    for(int i=0; i<m; i++){
        double x;
        cin>>x;
        a += x;
    }
    (n-a > -1)? (cout<<n-a<<endl) : (cout<<"-1"<<endl);

    return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MAX = 7 + 1000000000;
signed main(){
    int n;
    cin >> n;
    vector<int> prime;
    prime.push_back(2);
    for(int i=3; i<=n; i+=2){
        bool undivisable = false;
        for(int j=0; j<prime.size(); ++j){
            if(i % prime[j] == 0) undivisable = true;
        }
        if(undivisable) continue;
        else prime.push_back(i);
    }
    vector<int> count(prime.size(),1);
    for(int i=1; i<=n; ++i){
        for(int j=0; j<prime.size(); ++j){
            int m = i;
            while(m % prime[j] == 0){
                count[j]++;
                m /= prime[j];
            }
        }
    } 
    int ans = 1;
    for(int item: count){
        ans *= item;
        ans %= MAX;
    } 
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  int N;
  cin >> N;
  int ans = 0;
  int sum = 0;
  vector<int> tako(N);
  for(int i = 0; i < N; i++){
    cin >> tako.at(i);
    sum += tako.at(i);
  }
  for(int i = 0; i < N-1; i++){
    sum -= tako.at(i);
    ans += tako.at(i) * sum;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,x = map(int, input().split())
    #b[i]:レベルiバーガーの層数(max:n)
    b = [1]
    for i in range(n):
        b.append(b[i]*2+3)

    #p[i]:レベルiバーガーのパティの数
    p = [1]
    for i in range(n):
        p.append(p[i]*2+1)

    #n:レベル　x:層数
    def solve(n, x):
        if n==0:
            if x==0:
                return 0
            else:
                return 1
        res = 0
        if b[n]//2 == x:
            res += p[n-1]
        elif b[n] == x:
            res += p[n-1]*2 + 1
        elif x == 0:
            res = 0
        elif b[n]//2 < x:
            res += p[n-1] + 1 + solve(n-1, x-b[n]//2-1)
        else:
            res += solve(n-1, x-1)
        return res

    print(solve(n, x))

if __name__ == '__main__':
    main()

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;


main()
{
        set<int> s;
        rep(i,3)
        {
                int a; cin>>a;
                s.insert(a);
        }
        if(s.size()==1)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
}

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

int main(){
    int N;
    cin>>N;
    bool ans = 0;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(i*j==N)ans = 1;
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){
  int n;
  cin>>n;
  vector <int> b(n);
  for (int i=0;i<n;i++) cin>>b.at(i);
  
  sort(b.begin(),b.end(),greater<int>());
  int temp=0,ans=0;
  for(int i=0;i<n;i++){
    if(temp==b.at(i)) continue;
    temp=b.at(i);
    ans++;
  }
  cout<<ans<<endl;  
}

Measured memory_bytes: 3624
#include <stdio.h>

//問題文より、入力される文字列の最大の長さ
#define MAXLENGTH 1200

int main(void)
{
	int i;
	char str[MAXLENGTH];

	//\n(改行文字)以外を読み込む(ホワイトスペース対策)
	scanf("%[^\n]", str);

	//添字は0から
	i = 0;
	//文字列の最後まで繰り返す
	while(str[i] != '\0'){
		//大文字なら小文字へ変換
		if((str[i] >= 'A') && (str[i] <= 'Z')){
			str[i] += ('a' - 'A');
		}
		//小文字なら大文字へ変換
		else if((str[i] >= 'a') && (str[i] <= 'z')){
			str[i] -= ('a' - 'A');
		}
		//添字を一つ進める
		i++;
	}

	//結果を出力
	printf("%s\n", str);

	return 0;
}


Measured memory_bytes: 2112
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int K=sc.nextInt();
        String s="";
        while(N>=1){
            s+=(N%K);
            N/=K;
        }
        System.out.println(s.length());



    }
}


Measured memory_bytes: 23380
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include <iomanip>
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int H,M;
    while(1){
        cin >> H >> M;
        if(H==0&&M==0) break;
        REP(i,H){
            REP(j,M){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;

double area(double a, double b, double c)
{
	double s = (a+b+c)/2;
	return sqrt(s*(s-a)*(s-b)*(s-c));
}
double distance(double x1, double y1, double x2, double y2)
{
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
bool isInTriangle(double x[3], double y[3], double xp, double yp)
{
	double edge[3];
	for (int i = 0; i < 3; ++i)
		edge[i] = distance(x[i], y[i], x[(i+1)%3], y[(i+1)%3]);
	double correctArea = area(edge[0], edge[1], edge[2]);
	double totalArea = 0;
	for (int i = 0; i < 3; ++i)
	{
		totalArea += area(distance(x[i], y[i], xp, yp)
			, distance(x[(i+1)%3], y[(i+1)%3], xp, yp), edge[i]);
	}
	return abs(correctArea - totalArea) < 0.0001;
}

int main()
{
	double x[4], y[4];
	while (true)
	{
		for (int i = 0; i < 3; ++i)
			scanf("%lf,%lf,", x+i, y+i);
		if (scanf("%lf,%lf", x+3, y+3) == EOF)
			break;

		bool isConvace = false;
		for (int i = 0; i < 4; ++i)
		{
			double xp = x[i];
			double yp = y[i];
			double tx[3], ty[3];
			for (int j = 0; j < 3; ++j)
			{
				tx[j] = x[(i+j+1)%4];
				ty[j] = y[(i+j+1)%4];
			}
			isConvace |= isInTriangle(tx, ty, xp, yp);
		}
		if (isConvace)
			puts("NO");
		else
			puts("YES");
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <utility>
#include <algorithm>
using std::cin;
using std::cout;
using std::endl;

int main(void)
{
    double n, m, d;
    cin >> n >> m >> d;
    double answer;
    if (d == 0)
    {
        answer = 1.0 / n * (m - 1);
    }
    else
    {
        answer = 2.0 * (n - d) * (m - 1) / n / n;
    }

    //
    //＿Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^＿
    //＞  cout << answer << endl; ＜
    //￣Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^￣
    //Why this code makes WA!!!!????
    //

    printf("%f\n", answer);

    return 0;
}


Measured memory_bytes: 256
import collections
def gcd(m,n):
    if min(m,n) == 0:
        return(max(m,n))
    else:
        return(gcd(min(m,n),max(m,n)%min(m,n)))
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
a,b = list(map(int,input().split()))
c = gcd(a,b)
d = collections.Counter(prime_factorize(c))
print(len(d)+1)

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
#define int lint
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int n, A, B, C;
vi l;
int dfs(int i, int a, int b, int c)
{
    if (i == n)
    {
        if (a == 0 || b == 0 || c == 0)
        {
            return INT_MAX;
        }
        else
        {
            return abs(A - a) + abs(B - b) + abs(C - c) - 30;
        }
    }
    int o = dfs(i + 1, a, b, c);
    int p = dfs(i + 1, a + l[i], b, c) + 10;
    int q = dfs(i + 1, a, b + l[i], c) + 10;
    int r = dfs(i + 1, a, b, c + l[i]) + 10;
    return min({o, p, q, r});
}
signed main()
{
	fastio();
    cin >> n >> A >> B >> C;
    l.resize(n);
    rep(i, n)
    {
        cin >> l[i];
    }
    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan2, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def main():
    a, b, x = MAP()
    if x > (a*a*b) / 2:
        x = a*a*b - x
        c =  (x * 2) / (a * a)
        print(90 - degrees(atan2(a, c)))
    else:
        c =  (x * 2) / (a * b)
        print(degrees(atan2(b, c)))

if  __name__=='__main__':
    main()


Measured memory_bytes: 5328
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

using namespace std;

int main(){
  
    int a,b,c,d;

    cin >> a >> b >> c >> d;

    cout << (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d) ? "Yes" : "No") << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<set>
using namespace std;
int main(){
	int n,k,num1,num2;
	set<int> st;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&k);
		num1=st.size();
		st.insert(k);
		num2=st.size();
		if(num1==num2)
		{
			st.erase(k);
		}
	}
	printf("%d",st.size());
	return 0;
}

Measured memory_bytes: 4864
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  ll n, k;
  cin >> n >> k;
  ll m = n % k;
  cout << min(m, k - m) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 1e17;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
// #define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,ans,a,b,c,d,e,h,r,l,q;
ll k;
ll x[500005], y[500005], z[500005];
char s[500005], t[500005];



int main(){
    cin >> h >> a;
    p((h + a - 1) / a);
    return 0;
}


















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

int main(){
	int x,n;
	cin >> x >> n;
	int p[n];
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
	}

	int m = -1000;
	for (int i = -1; i <= 101; i++)
	{
		int c = 0;
		for (int j = 0; j < n; j++)
		{
			if(i == p[j]) c = 1;
		}
		if(c == 0){
			if(abs(m - x) > abs(i - x)) m = i;
		}
	}
	cout << m << endl;
}


Measured memory_bytes: 3616
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{
	char p[5];
	scanf("%s",p);
	
	if(p[1]==p[2] &&(p[0]==p[1] || p[2]==p[3]))
		printf("Yes");
	else
		printf("No");
	return 0;
 } 

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
using ll = long long;

class UFDS {
public:
    std::vector<ll> size, ps;
    ll ans;
    UFDS(ll N) : size(N + 1, 1), ps(N + 1), ans(1) {
        iota(ps.begin(), ps.end(), 0);
    }

    ll find_set(ll x) const {
        return x == ps[x] ? x : find_set(ps[x]);
    }

    bool same_set(ll x, ll y) {
        return find_set(x) == find_set(y);
    }

    void union_set(ll x, ll y)
    {
        if (same_set(x, y)) return;

        ll p = find_set(x);
        ll q = find_set(y);

        if (size[p] < size[q])
            std::swap(p, q);

        ps[q] = p;
        size[p] += size[q];

        ans = max(ans, size[p]);
    }
};

int main()
{
    ll n, m;
    cin >> n >> m;

    UFDS union_find(n);

    while(m--)
    {
        ll a, b;
        cin >> a >> b;

        union_find.union_set(a, b);
    }

    cout << union_find.ans << '\n';


    return 0;
}


Measured memory_bytes: 6428
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

def get_point(x):
    if x == 'r':
        return P
    if x == 's':
        return R
    if x == 'p':
        return S

# think each mod K
ans = 0
for i in range(K):
    dp = [0] * 2
    pre = ''
    for j in range(i, N, K):
        dp2 = dp[:]
        dp2[0] = max(dp)
        if pre == T[j]:
            dp2[1] = dp[0] + get_point(T[j])
        else:
            dp2[1] = max(dp) + get_point(T[j])
        pre = T[j]
        dp = dp2
    ans += max(dp)

print(ans)

Measured memory_bytes: 9580
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int n,m,a[1010];
ll dp[2555][55],ret;
int main() {
	scanf("%d%d",&n,&m);
	rep(i,0,n) scanf("%d",a+i);
	dp[0][0]=1;
	int s=0;
	rep(i,0,n) {
		per(j,0,s+1) per(k,0,i+1) dp[j+a[i]][k+1]+=dp[j][k];
		s+=a[i];
	}
	rep(k,1,n+1) ret+=dp[m*k][k];
	printf("%lld\n",ret);
}


Measured memory_bytes: 1280
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()



def main():
	n,x,t=MI()
	y=(n-1)//x+1
	print(y*t)







if __name__ == "__main__":
	main()


Measured memory_bytes: 61992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
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; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    iosetup;
    string S; cin >> S;
    int N = S.size();
    string T = S;
    sort(ALL(T), greater<char>());
    int cnt = N - 1;
    ll ans = 0;
    rrep(i, 0, N){
        if(S[i] == 'B'){
            ans += cnt - i;
            cnt--;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 788
#include <iostream>
#include <set>
#include <vector>
#include <iomanip>
#include <numeric>
#include <cfenv>
#include <cmath>
typedef long long int ll;

using namespace std;

void dfs(vector<vector<int>> X, vector<vector<int>> &G, vector<bool> &visit, int i, int k, int &count, vector<ll> &high, vector<ll> H)
{

    if (visit[i] == 0)
    {


        G[k].push_back(i);

        high[k] = max(high[k], H[i]);

        count++;

        visit[i] = 1;

        if (X[i].size() > 0)
        {

            for (int visiter : X[i])
            {

                dfs(X, G, visit, visiter, k,  count, high, H);
            }
        }
    }
}

int main()
{

    int N, M;

    cin >> N >> M;

    vector<ll> H(N);

    vector<vector<int>> X(N, vector<int>(0));
    vector<vector<int>> G(N, vector<int>(0));

    vector<ll> high(N, 0);

    for (int i = 0; i < N; i++)
    {

        cin >> H[i];
    }

    for (int i = 0; i < M; i++)
    {

        ll A, B;

        cin >> A >> B;

        X[A - 1].push_back(B - 1);
        X[B - 1].push_back(A - 1);
    }

    vector<bool> visit(N, 0);

    int count = 0;

    for (int i = 0; i < N; i++)
    {


         int hantei =0;


        for (int j : X[i]){


           


            if(H[j]>=H[i]){


                hantei =1;
            }
        }

        if(hantei ==0){


            count++;
        }

    }


    cout << count << endl;


    



    return 0;
}

Measured memory_bytes: 12216
def m(L,R):
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):
 l=len(A);global c;c+=l
 s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A
def s():
 print(*d(list(map(int,input().split()))))
 print(c)
if'__main__'==__name__:c=-int(input());s()



Measured memory_bytes: 63432
def restore(s, t):
    orig_s = s
    for i in range(len(s) - len(t), -1, -1):
        s = list(orig_s)
        ok = True
        for j in range(len(t)):
            if s[i+j] != t[j] and s[i+j] != '?':
                ok = False
                break
            s[i+j] = t[j]
        if ok:
            for i in range(len(s)):
                if s[i] == '?':
                    s[i] = 'a'
            return "".join(s)
    return "UNRESTORABLE"


S = input()
T = input()

print(restore(S, T))


Measured memory_bytes: 9080
using System;
using System.Collections.Generic;
using System.Linq;

namespace StringsLength
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var st = Console.ReadLine().Split();
            char[] S = st[0].ToCharArray();
            char[] T = st[1].ToCharArray();
            var output = "";
            for (int i = 0; i < N; i++)
            {
                output += S[i].ToString() + T[i].ToString();
            }
            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    string S;
    cin >> S;
    ll N=S.size();
    ll i;
    ll cnt=0;
    for(i=0;i<N-1;i++){
        if(S[i]!=S[i+1])cnt++;
    }
    cout << cnt <<endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

typedef long long int64;


int main() {
    int k,x;
    cin >> k >> x;
    cout << (500*k>=x? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
# (c) midandfeed
from functools import cmp_to_key
def func(*a):
	q = ['S', 'H', 'C', 'D']	
	return(q.index(a[0][0]))

n = int(input())
cards = []
for i in range(1, 14):
	cards.append(('S', i))
	cards.append(('H', i))
	cards.append(('C', i))
	cards.append(('D', i))
cards.sort(key = func)	

q = []
for _ in range(n):
	a, b = [x for x in input().split()]
	q.append((a,int(b)))
	
for x in cards:
	if (x not in q):
		print("{} {}".format(x[0], x[1]))

Measured memory_bytes: 8368
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int long long int
using namespace std;

void desperate_optimization(bool submitting=true,int precision=10)
{
  if(!submitting) return;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}
int mod=1e9+7;
void add_self(int& a,int b)
{
  a+=b;
  if(a>=mod) a-=mod;
}

int n;
struct M
{
  vector<vector<int>> t;
  M()
  {
    t.resize(n,vector<int>(n));
  }
  M operator* (const M& b) const
  {
     M c=M();
     for(int i=0;i<n;i++)
     {
      for(int j=0;j<n;j++)
      {
        for(int k=0;k<n;k++)
        {
          add_self(c.t[i][k],(t[i][j]*b.t[j][k])%mod);
        }
      }
     }
     return c;
  }
};

int32_t main()
{
  desperate_optimization(true);
  //freopen("input.txt","r",stdin);
  int k;
  cin>>n>>k;
  M answer=M();
  for(int i=0;i<n;i++) answer.t[i][i]=1;
  vector<vector<int>> can(n,vector<int>(n));
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>can[i][j];
  M m=M();
  m.t=can;
  while(k)
  {
    if(k%2)
    {
      answer=answer*m;
    }
    m=m*m;
    k/=2;
  }
  int total=0;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<n;j++)
    {
      add_self(total,answer.t[i][j]);
    }
  }
  cout<<total;


  return 0;
}


Measured memory_bytes: 384