akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int, input().split()))
cnt = 0
 
def marge(A, left, mid, right):
    global cnt
    n1 = mid - left
    n2 = right - mid
    L = [0]*(n1+1) 
    R = [0]*(n2+1)
    
    for i in range(n1):
        L[i] = A[left + i]
    for i in range(n2):
        R[i] = A[mid + i]
    L[n1] = pow(10,10)
    R[n2] = pow(10,10)
     
    l = 0
    r = 0
    for k in range(left, right):
        if L[l] <= R[r]:
            A[k] = L[l]
            l += 1
        else:
            A[k] = R[r]
            r += 1
            cnt += n1 - l
            
def margeSort(A, left, right):
    if 2 <= right - left:
        mid = (left + right)//2
        margeSort(A, left, mid)
        margeSort(A, mid, right)
        marge(A, left, mid, right)
     
         
margeSort(a, 0, len(a))
print(cnt)


Measured memory_bytes: 27476
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

void DFS(int cur, bool* visit, vector<int>* adj, int * cnt)
{
  visit[cur] = true;
  for(int next: adj[cur])
  {
    if(!visit[next])
    {
      (*cnt)++;
      DFS(next, visit, adj, cnt);
    }
  }
}

int component(int n, vector<int>* adj)
{
  int size = 0;
  int cnt = 1;
  bool*visit = new bool[n+1];
  memset(visit, false, sizeof(bool) * (n+1));

  for(int i = 1; i<n+1; i++)
  {
    if(!visit[i])
    {
      DFS(i, visit, adj, &cnt);
      if(cnt > size)
        size = cnt;
      cnt = 1;
    }
  }
  delete[] visit;
  return size;
}


int main()
{
  int N, M, f, t;
  scanf("%d %d", &N, &M);
  bool* visit = new bool[N+1];
  memset(visit, false, sizeof(bool)*(N+1));
  vector<int> *adj = new vector<int>[N+1];
  vector<int> size;

  for(int i = 0; i<M; i++)
  {
    scanf("%d %d", &f, &t);
    adj[f].push_back(t);
    adj[t].push_back(f);
  }

  printf("%d", component(N, adj));
  delete[] visit;
}

Measured memory_bytes: 23568
// Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	for(int i=0; i<9; i++){
		string name;
		int am, pm;
		cin >> name >> am >> pm;

		cout << name << ' ' << am+pm << ' ' << 200*am+300*pm << '\n';
	}

	return 0;
}

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

long gcd(long a, long b){
    if(a==0) return b;
    if(b==0) return a;
    do{
        long t=a%b;
        a=b;
        b=t;
    }while(b!=0);
    return a;
}

int main(void){
    long n, s;
    scanf("%ld %ld\n", &n, &s);
    long g=0;
    for(long i=0; i<n; i++){
        long t;
        scanf("%ld", &t);
        g=gcd(labs(t-s), g);
    }
    printf("%ld\n", g);
    return 0;
}


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

int a[101]={0};

int main()
{
	int n,x,s=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=1;
	}
	for(int i=1;i<=100;i++)
	{
		if(a[i]==1) s++;
	}
	cout<<s;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main(){
int sheep;
int wolf;
cin >> sheep;
cin >> wolf;

if(wolf >= sheep){
    cout<< "unsafe" << endl;
}
else
{
    cout << "safe" << endl;
}

return 0;
}

Measured memory_bytes: 3580
def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split(sep)))

def main():
    n, a = reads()
    x = reads()
    s = sum(x)
    dp = [[[0]*3500 for j in range(n+1)] for i in range(n+1)]
    dp[0][0][0] = 1
    for i in range(n):
        for j in range(n):
            for k in range(s):
                dp[i][j+1][k] += dp[i][j][k]
                dp[i+1][j+1][k+x[j]] += dp[i][j][k]
    r = 0
    for j in range(1, n+1):
        r += dp[j][n][j*a]
    print(r)

main()


Measured memory_bytes: 111836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int mod = 998244353;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
vector<int> v[5];
int main(){
	int n;
	scanf("%d",&n);
	string s;
	cin >> s;
	ll ans = 0;
	for(int i = 0;i < s.size();i++){
		if(s[i] == 'R') v[1].push_back(i);
		if(s[i] == 'G') v[2].push_back(i);
		if(s[i] == 'B') v[3].push_back(i);
	}
//	cout << v[1].size() <<" "<< v[2].size() <<" "<< v[3].size()<<endl;
	ans = v[1].size() * v[2].size() * v[3].size();
	for(int i=0;i<n;i++){
		int j=1;
		while(i+j*2<s.size()){
			if(s[i]!=s[i+j] && s[i+j]!=s[i+j+j] && s[i]!=s[i+j+j]){
				ans--;
			}
			j++;
		}	
	}	
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 3700
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int main(void){
    int n;
    cin >> n;
    map<int, int> p;
    long long ans = 0;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        ans += a;
        p[a]++;
    }
    int q;
    cin >> q;
    for(int i=0;i<q;i++){
        int b, c;
        cin >> b >> c;
        int cnt = p[b];
        p.erase(b);
        ans += (long long) (c-b)*cnt;
        p[c] += cnt;
        cout << ans << endl;
    }
}


Measured memory_bytes: 6124
# 入力
N = int(input())
L = list(map(int, input().split()))

if(len(L) < 3):
    print(0)
    exit(0)
count = 0

for i in range(0,N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if(L[i] != L[j] and L[j] != L[k] and L[k] != L[i]):
                if(L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j]):
                    count += 1

print(count)

Measured memory_bytes: 9100
n=int(input())
a=[int(j) for j in input().split()]
dp=[[0]*(n+1) for i in range(n+1)]

for i in range(n)[::-1]:
    for j in range(i,n):
        if (n+i-j-1)%2==0:
            dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j])
        else:
            dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j])
print(dp[0][n-1])



Measured memory_bytes: 112604
#include <bits/stdc++.h>
#define N 1000500
using namespace std;
map<int,int> F;
int a[N],b[N],n,ans;
inline int rd() {int r;scanf("%d",&r);return r;}
int main() {
	n = rd();
	for (int i=1;i<=n;i++) a[i] = rd();
	for (int i=1;i<=n;i++) b[i] = a[i];
	sort(b+1, b+n+1);
	for (int i=1;i<=n;i++) F[b[i]] = i&1;
	for (int i=1;i<=n;i++) if (i%2 == 0 && F[ a[i] ]) ans++;
	cout << ans << endl;
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
  

int main()
{
  int n; cin >> n;
  map<string, int> mp;
  rep(i, n) {
    string s; cin >> s;
    ++mp[s];
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

int main(){
    std::vector<int> a;
    for(int i = 0; i < 3; i++){
        int x;
        std::cin >> x;
        a.push_back(x);
    }
    std::sort(a.begin(),a.end());
    std::cout << a[0] + a[1];
    return 0;

}



Measured memory_bytes: 256
import sys
from copy import deepcopy
N, W = map(int, raw_input().split())
pre = []
V = 0
for i in range(N):
    w, v = map(int, raw_input().split())
    V += v
    pre.append((w, v))
minw = min(pre)[0]
items1 = []
items2 = []
items3 = []
items4 = []
for w, v in pre:
    if w == minw:
        items1.append((w, v))
    elif w == minw + 1:
        items2.append((w, v))
    elif w == minw + 2:
        items3.append((w, v))
    else:
        items4.append((w, v))
items1.sort(reverse=True)
items2.sort(reverse=True)
items3.sort(reverse=True)
items4.sort(reverse=True)
items = [items1, items2, items3, items4]
memo = {}

def dfs(indice, W, value):
    if W < 0:
        return -(10**9)
    if W < minw or W == 0:
        return value
    if indice in memo:
        return memo[indice]
    outOfAmmo = True
    indicel = list(indice)
    sofar = -(10**9)
    for i in range(4):
        if indice[i] < len(items[i]):
            outOfAmmo = False
            new_indice = deepcopy(indicel)
            new_indice[i] += 1
            current_item = items[i][indice[i]]
            sofar = max(sofar, dfs(tuple(new_indice), W-current_item[0], value+current_item[1]))
    memo[indice] = sofar
    if outOfAmmo:
        return value
    return sofar
print dfs((0, 0, 0, 0), W, 0)


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

int main(){
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	
	if( x-r < 0 ) cout << "No" << endl;
	else if( y-r < 0 ) cout << "No" << endl;
	else if( x+r > H ) cout << "No" << endl;
	else if( y+r > H ) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 1160
n = int(input())
a = list(map(int, input().split()))
m = max(a)
mod = 1000000007
memo = [[] for i in range(m+1)]
d = {-1: 3}
ans = 1
for ai in a:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1
    if ai - 1 in d:
        memo[ai].append(d[ai-1])
    else:
        ans  = 0
for l in memo:
    i = 0
    for li in l:
        ans = ans * (li - i) %  mod
        i += 1
print(ans)


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

using namespace std;


int main(){

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int h1, s1, h2, s2;
    cin>>h1>>s1>>h2>>s2;
    while(true){
        h2 -= s1;
        if (h2<=0) {
            cout<<"Yes"; return 0;
        }
        h1 -= s2;
        if (h1<=0) {
            cout<<"No"; return 0;
        }
    }
}

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

int main(){
  int N; cin >> N;
  long long Tp=1,Ap=1;
  for(int i=0; i<N; i++){
    long long T,A;
    cin >> T >> A;
    long long temp=max((Tp+T-1)/T,(Ap+A-1)/A);
    Tp=temp*T;
    Ap=temp*A;
  }
  cout << fixed << setprecision(0) << Tp+Ap << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define eps 1e-8
#define all(v) (v.begin(),v.end())
#define db double
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const double pi=acos(-1.0);
const double inf = 1e100;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
ll inv[500010],f[500010];
int n,m;
ll quick_pow(ll r,ll k){
	ll ret=1;
	while(k){
		if(k&1) ret=(ret*r)%mod;
		r=(r*r)%mod;
		k>>=1;
	}
	return ret;
}
void init(){
	f[0]=1,f[1]=1;
	for(int i=2;i<=500000;i++){
		f[i]=(1ll*f[i-1]*i)%mod;
	}
	for(int i=2;i<=500000;i++){
		inv[i]=quick_pow(f[i],mod-2);
	}
}
ll A(int n,int m){
	return f[m]*quick_pow(f[m-n]%mod,mod-2)%mod;
}
ll C(int n,int m){
	return f[m]*quick_pow((f[n]*f[m-n])%mod,mod-2)%mod;
}
ll cal(){
	ll ans=0;
	ll mul=1;
	for(int i=0;i<=n;i++){
		ll cur=mul*C(i,n)*C(n-i,m-i)%mod*f[n-i]%mod;
		ans=(ans+cur+mod)%mod;
		mul*=(-1);
	}
	return ans*A(n,m)%mod;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    init();
    cin>>n>>m;
    cout<<cal();
    return 0;
}



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

int main(){
    int n;
    scanf("%d",&n);
    map<string,long int> mp;
    long int ans=0;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        auto itr=mp.find(s);
        if(itr!=mp.end()){
            mp[s]++;
            ans+=mp[s];
        }
        else mp[s]=0;

    }

    printf("%ld\n",ans);
}

Measured memory_bytes: 11136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
      
        {
          
            var abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];
            if (a<b && b<c)
            {
                Console.WriteLine("Yes");
               }
            else
                Console.WriteLine("No");
             }
     }
 }
           
          
     

Measured memory_bytes: 9312
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    foreach (i; 0..10) {
        foreach (j; i..10) {
            if (N == i*j) {
                writeln("Yes");
                return;
            }
        }
    }
    writeln("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
#define MIN(vec) *min_element(vec.begin(), vec.end())
using namespace std;
typedef long long LL;
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class Key,class Value> ostream& operator << (ostream &s, map<Key,Value> M)
{ for ( auto itr = begin(M); itr != end(M); ++itr) { s << itr->first << ":" << itr->second; } return s;}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int L;
    cin >> L;
    vector<LL>  A(L);
    REP(i, L) cin >> A[i];
    vector<vector<LL> > DP(L,vector<LL> (5,0));
    // <通らない(Z)> [A_D <偶数回通る>] [A_S <奇数回数通る>] [A_G <偶数回通る>] [A_U <通らない>]
    constexpr int Z = 0,D = 1,S = 2,G = 3,U = 4;
    DP[0][Z] = A[0];
    DP[0][D] = A[0] != 0 ? A[0] % 2 : 2;
    DP[0][S] = (A[0] % 2 == 0) ? 1 : 0;
    DP[0][G] = A[0] != 0 ? A[0] % 2 : 2;
    DP[0][U] = A[0];
    REP(i,L-1) {
        DP[i+1][Z] = DP[i][Z] + A[i+1];
        DP[i+1][D] = min(DP[i][Z],DP[i][D]) + ((A[i+1] != 0) ? A[i+1] % 2 : 2);
        DP[i+1][S] = min({DP[i][Z],DP[i][D],DP[i][S]}) + ((A[i+1] % 2 == 0) ? 1 : 0);
        DP[i+1][G] = min({DP[i][Z],DP[i][D],DP[i][S],DP[i][G]}) + ((A[i+1] != 0) ? A[i+1] % 2 : 2);
        DP[i+1][U] = min({DP[i][Z],DP[i][D],DP[i][S],DP[i][G],DP[i][U]}) + A[i+1];
    }
    cout << MIN(DP[L-1]) << endl;
}


Measured memory_bytes: 15872
//
//  main.cpp
//  ALDS1_7_D
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
vector<int> pre,in,post;
int pos;
int n;
void rec(int l,int r){
    if(l>=r) return;
    int root=pre[pos];
    pos++;
    int m=(int)distance(in.begin(),find(in.begin(),in.end(),root));
    rec(l,m);
    rec(m+1,r);
    post.push_back(root);
}
void solve(){ // preとinからpostを作る
    pos=0;
    rec(0,(int)pre.size());
    rep(i,n){
        if (i) cout<<" ";
        cout<<post[i];
    }
    cout<<endl;
}
int main(int argc, const char * argv[]) {
    cin>>n;
    int k;
    rep(i,n){
        cin>>k;
        pre.push_back(k); // 先行順のデータ
    }
    rep(i, n){
        cin>>k;
        in.push_back(k); // 中間順のデータ
    }
    solve(); // 後行順のデータを作る
    return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
  int N,M; cin>>N>>M;
  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin>>H[i];
  }
  vector<int> c(0);
  ll ans=0;
  for(int i=0; i<M; i++){
    int a,b;
    cin>>a;
    cin>>b;
    if(H[a-1]==H[b-1]){
      c.push_back(a); 
      c.push_back(b);
    }
    else if(H[a-1]>H[b-1])c.push_back(b);
    else c.push_back(a);
  }
  sort(c.begin(), c.end());
  for(int i=0;i<c.size();i++){
    if(c[i+1]-c[i]>1)ans+=c[i+1]-c[i]-1;
  }
  ans+= c[0]- 1 + N - c[c.size()-1];
  cout<< ans <<endl;
  return 0;
}

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

int main() {
    int N, A, B;
    int ans = 0;
    cin >> N >> A >> B;
    for (int i = 1; i <= N; i++) {
        int sum = 0;
        int tmp = i;
        while (tmp > 0) {
            sum += tmp % 10;
            tmp /= 10;
        }
        if (A <= sum && sum <= B) ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
6 9
0 1 1
0 2 3
1 2 1
1 3 7
2 4 1
1 4 3
3 4 1
3 5 1
4 5 6

output:
5
"""

import sys
import heapq as hp

WHITE, GRAY, BLACK = 0, 1, 2


def generate_adj_table(v_table):
    for each in v_table:
        v_from, v_to, edge_weight = map(int, each)
        init_adj_table[v_from][v_to] = edge_weight
        init_adj_table[v_to][v_from] = edge_weight

    return init_adj_table


def prim_span_tree():
    distance[init_v] = 0
    parent[init_v] = -1
    path_heap = []
    hp.heappush(path_heap, (distance[init_v], init_v))

    while len(path_heap) >= 1:
        current_vertex = hp.heappop(path_heap)[1]

        color[current_vertex] = BLACK

        for adj_vertex, adj_weight in adj_table[current_vertex].items():
            if color[adj_vertex] is not BLACK:
                if adj_weight < distance[adj_vertex]:
                    distance[adj_vertex] = adj_weight
                    parent[adj_vertex] = current_vertex
                    color[adj_vertex] = GRAY
                    hp.heappush(path_heap, (distance[adj_vertex], adj_vertex))

    return distance


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])

    parent = [-1] * vertices
    distance = [float('inf')] * vertices
    color = [WHITE] * vertices
    init_v = 0

    init_adj_table = tuple(dict() for _ in range(vertices))
    adj_table = generate_adj_table(v_info)
    print(sum(prim_span_tree()))

Measured memory_bytes: 38888
#include <bits/stdc++.h>
const int N = 1e5 + 54;
int n, m;
namespace Tree {
	struct node { int u, v; } edge[N << 1];
	int head[N], v[N], col[N], cnt;
	long long sum, ans;
	inline void add(int x, int y) { edge[cnt].u = head[x], edge[cnt].v = y, head[x] = cnt++; }
	void dfs(int x, int fa) {
		int i;
		for (i = head[x]; ~i; i = edge[i].u) {
			int y = edge[i].v;
			if (y == fa) continue;
			col[y] = 1 - col[x], dfs(y, x);
		}
	}
	void solve(int x, int fa) {
		int i;
		for (i = head[x]; ~i; i = edge[i].u) {
			int y = edge[i].v;
			if (y == fa) continue;
			solve(y, x);
			v[x] += v[y];
		}
	}
	void SOLVE() {
		int x, y, i;
		memset(head, -1, sizeof head);
		for (i = 1; i <= m; ++i) scanf("%d%d", &x, &y), add(x, y), add(y, x);
		col[1] = 1, dfs(1, 0);
		for (i = 1; i <= n; ++i) {
			if (col[i]) v[i] = 1;
			else v[i] = -1;
			sum += v[i];
		}
		if (sum) {
			puts("-1");
			return;
		}
		solve(1, 0);
		for (i = 1; i <= n; ++i) ans += abs(v[i]);
		printf("%lld\n", ans);
	}
}

namespace BRT {
	struct Edge { int id, x, y; } E;
	struct node { int u, v; } edge[N << 1];
	int head[N], v[N], col[N], cnt, tot, p[N], vis[N], f[N];
	long long sum, ans;
	inline void add(int x, int y) { edge[cnt].u = head[x], edge[cnt].v = y, head[x] = cnt++; }
	void dfs(int x, int fa) {
		int i;
		vis[x] = 1;
		for (i = head[x]; ~i; i = edge[i].u) {
			int y = edge[i].v;
			if (y == fa) continue;
			if (vis[y]) E.id = i, E.x = x, E.y = y;
			else col[y] = 1 - col[x], dfs(y, x);
		}
	}
	void solve(int x, int fa) {
		int i;
		for (i = head[x]; ~i; i = edge[i].u) {
			int y = edge[i].v;
			if (y == fa || i == E.id || (i ^ 1) == E.id) continue;
			solve(y, x), v[x] += v[y], f[x] += f[y];
		}
	}
	void SOLVE() {
		memset(head, -1, sizeof head);
		int x, y, i;
		for (i = 1; i <= m; ++i) scanf("%d%d", &x, &y), add(x, y), add(y, x);
		col[1] = 1, dfs(1, 0);
		for (i = 1; i <= n; ++i) {
			if (col[i]) v[i] = 1;
			else v[i] = -1;
			sum += v[i];
		}
		if (col[E.x] == col[E.y]) {
			if (abs(sum) & 1) {
				puts("-1");
				return;
			}
			v[E.x] -= sum / 2, v[E.y] -= sum / 2, ans += abs(sum / 2);
		} else {
			if (sum) {
				puts("-1");
				return;
			}
			f[E.x] = 1, f[E.y] = -1;
		}
		solve(1, 0);
		if (col[E.x] == col[E.y]) {
			for (i = 1; i <= n; ++i) ans += abs(v[i]);
			printf("%lld\n", ans);
			return;
		}
		for (i = 1; i <= n; ++i)
			if (f[i] == 0) ans += abs(v[i]);
			else p[++tot] = f[i] * v[i];
		p[++tot] = 0;
		std::sort(p + 1, p + tot + 1);
		int mid = p[(tot + 1) >> 1];
		for (i = 1; i <= tot; ++i) ans += abs(p[i] - mid);
		printf("%lld\n", ans);
	}
}
int main() {
	scanf("%d%d", &n, &m);
	if (m == n - 1) Tree::SOLVE();
	else BRT::SOLVE();
}

 

Measured memory_bytes: 9344
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main(){
  string str;
  int m, h;

  while (1) {
    cin >> str;
    if (str == "-") {
      break;
    }
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> h;
      string head = str.substr(0, h);
      string tail = str.substr(h, str.size() - h);
      str = tail + head;
    }
    cout << str << endl;
  }

  return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int main(void)
{
    ll n,x, m;
    cin >> n >> x >> m;
    vector<int> id(m, -1);
    vector<int> a;
    int length = 0;
    ll total = 0;
    while (id[x] == -1 && length !=n)
    {
        a.push_back(x);
        id[x] = length;
        length++;
        total += x;
        x = (x * x) % m;
    }
    if(length==n){
        cout<<total<<endl;
        return 0;
    }

    int circleLength=length-id[x];
    ll oneCircleSum=0;
    for(int i=id[x];i<length;i++){
        oneCircleSum+=a[i];
    }

    ll ans=total;
    n-=length;
    ans +=oneCircleSum*(n/circleLength);//一周回った回数分
    n%=circleLength;//回りきらなかった余り
    rep(i,n) ans+=a[id[x]+i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define FOR(i, s, n) for(int i=(int)(s); i<(int)(n); ++i)
#define ALL(n) (n).begin(), (n).end()
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;

const ll MAX_V = 100000;
const ll INF = 1e9;
const ll MOD = 998244353;

int main(){
    string s; cin >> s;
    bool fg = true;
    int cnt = 0;
    int idx = s.size()-3;

    if (s[0] != 'A') fg = false;

    string sub = s.substr(2, idx);
    REP(i, sub.size()){
        if (sub[i] == 'C') cnt++;
    }
    if (cnt != 1) fg = false;

    int cnt2 = 0;
    REP(i, s.size()){
        if(!islower(s[i])) cnt2++;
    }
    if (cnt2 != 2) fg = false;

    if (fg) cout << "AC" << endl;
    else cout << "WA" << endl;
}

Measured memory_bytes: 256
let scan_words () = Scanf.scanf "%d %d\n" (fun a b -> (a, b))
let n, m = scan_words ()
let h = Hashtbl.create m
let ans = ref 0

let rec search found visited now =
  if List.exists ((=) now) visited then ()
  else if found = n then incr ans
  else
    let found' = found + 1 in
    let visited' = now :: visited in
    match Hashtbl.find_all h now with
    | [] -> ()
    | next_nodes -> List.iter (search found' visited') next_nodes

let () =
  for i = 1 to m do
    let a, b = scan_words () in
    Hashtbl.add h a b ;
    Hashtbl.add h b a
  done ;
  search 1 [] 1 ;
  Printf.printf "%d\n" !ans

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

/* constant */
const int N = 3;

/* main */
int main(){

    //データ定義
    int numList[N];

    //データ取得
    for(int i = 0; i < N; i++){
        cin >> numList[i];
    }

    //並び替え
    sort(numList, numList + N);

    //結果表示
    for(int i = 0; i < N; i++){
        if(i) cout << " ";

        cout << numList[i];
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 3148
#include<cstdio>
using namespace std;
#define N 5050
#define mod 1000000007
int n,sz[N],dp[N][N],f[N],head[N],cnt,a,b;
struct edge{int t,next;}ed[N*2];
void adde(int f,int t){ed[++cnt]=(edge){t,head[f]};head[f]=cnt;ed[++cnt]=(edge){f,head[t]};head[t]=cnt;}
void dfs(int u,int fa)
{
	sz[u]=1;dp[u][1]=1;
	for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)
	{
		dfs(ed[i].t,u);
		for(int j=sz[u];j>=1;j--)
		{
			for(int k=1;k<=sz[ed[i].t];k++)
			dp[u][j+k]=(dp[u][j+k]+1ll*dp[u][j]*dp[ed[i].t][k])%mod;
			dp[u][j]=1ll*dp[u][j]*dp[ed[i].t][0]%mod;
		}
		sz[u]+=sz[ed[i].t];
	}
	for(int i=1;i<=sz[u];i++)dp[u][0]=(dp[u][0]-1ll*dp[u][i]*f[i])%mod;
}
int main()
{
	scanf("%d",&n);
	f[0]=1;for(int i=2;i<=n;i+=2)f[i]=1ll*f[i-2]*(i-1)%mod;
	for(int i=1;i<n;i++)scanf("%d%d",&a,&b),adde(a,b);
	dfs(1,0);printf("%d\n",(mod-dp[1][0])%mod);
}

Measured memory_bytes: 98432
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int count = Integer.parseInt(sc.nextLine());
        for (int i=0; i<count; i++) {
            String  request = sc.next(); //命令
            int a = sc.nextInt();
            int b = sc.nextInt();
            if (request.equals("print")) {
                System.out.println(str.substring(a, b+1));
            } else if (request.equals("reverse")) {
                StringBuffer sb = new StringBuffer(str.substring(a, b+1));
                String rs = sb.reverse().toString();
                str = str.substring(0, a) + rs + str.substring(b+1, str.length());
            } else if (request.equals("replace")) {
                String p = sc.next();
                str = str.substring(0, a) + p + str.substring(b+1, str.length());
            }
        }
    }
}



Measured memory_bytes: 29364
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner sc = new Scanner(is);

        int N = sc.nextInt();
        int K = sc.nextInt();
        int P[] = new int[N];
        int C[] = new int[N];

        for(int i = 0; i < N; i++) {
            P[i] = sc.nextInt()-1;
        }
        for(int i = 0; i < N; i++) {
            C[i] = sc.nextInt();
        }

        long ans = Integer.MIN_VALUE;
        if(K <= N) {
            for(int i = 0; i < N; i++) {
                long max = getMax(P, C, i, K);
                ans = Math.max(ans, max);
            }
        } else {
            for(int i = 0; i < N; i++) {
                boolean visited[] = new boolean[N];
                int times[] = new int[N];
                long totalScore[] = new long[N];
                int pos = i;
                long sum = 0;
                int period = 1;
                for(int j = 0; j < K; j++) {
                    pos = nextKoma(P, pos);
                    if(visited[pos]) {
                        period = j - times[pos];
                        break;
                    }
                    visited[pos] = true;
                    long score = getScore(C, pos);
                    sum += score;
                    totalScore[pos] = sum;
                    times[pos] = j;
                }
                int lastTime = K - times[pos]-1;
                long diff = getScore(C, pos) + sum - totalScore[pos];
                if(diff > 0) {
                    long max = Math.max(0, getMax(P, C, pos, lastTime%period));
                    ans = Math.max(ans, totalScore[pos] + (lastTime/period) * diff + max);
                }
                ans = Math.max(ans, getMax(P, C, i, times[pos]+period));
            }
        }

        os.println(ans);
    }


    static int nextKoma(int P[], int now){
        return P[now];
    }
    static int getScore(int C[], int now) {
        return C[now];
    }


    static long getMax(int P[], int C[], int start, int K) {
        long max = Integer.MIN_VALUE;
        long sum = 0;
        int pos = start;
        for(int j = 0; j < K; j++) {
            //move
            pos = nextKoma(P, pos);
            long score = getScore(C, pos);
            sum += score;
            max = Math.max(max, sum);
        }
        return max;
    }
}

Measured memory_bytes: 49060
import math
n, m = map(int, input().split())

if n >= 2:
    odd = math.factorial(n) // math.factorial(n-2) // 2
else:
    odd = 0
if m >= 2:
    even = math.factorial(m) // math.factorial(m-2) // 2
else:
    even = 0

print( odd + even )

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define repprev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) repprev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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 (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
struct UnionFind {
    vector<ll> par;
 
    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }
 
    int root(ll x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
 
    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }
 
    bool merge(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
 
    int size(ll x) {
        return -par[root(x)];
    }
};
 
int main(){
    ll N,M;
  	cin >> N >> M;
  	vector<ll> A(M), B(M);
  	rep(i,M){
      cin >> A[i] >> B[i];
      A[i]--;
      B[i]--;
    }
  
  	vector<ll> ans(M);
  	ans[M-1] = N * (N - 1) / 2;
  
  	UnionFind Uni(N);
  
  	repprev(i, 1, M){
      //繋がってなかったのが繋がった時
      	if(Uni.root(A[i]) != Uni.root(B[i])){
          ans[i - 1] = ans[i] - Uni.size(A[i]) * Uni.size(B[i]);
          Uni.merge(A[i],B[i]);
        }
      else ans[i - 1] = ans[i]; 
    }
  
  rep(i,M){
    cout << ans[i] << endl;
  }
  	
}

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

struct edge {
	int to, cost;
};
class dijkstra {
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<P>> que;
	void update(int s, vector<edge> G[]) {
		fill(d, d + V + 1, 100000000000ll);
		d[s] = 0;
		que.push(make_pair(0, s));
		while (!que.empty()) {
			P p = que.top();
			que.pop();
			int v = p.second;
			if (d[v] < p.first) continue;
			rep(i, G[v].size()) {
				edge e = G[v][i];
				if (d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					que.push(make_pair(d[e.to], e.to));
				}
			}
		}
	}

  public:
	dijkstra(int v, int s, vector<edge> G[]) {
		V = v;
		update(s, G);
	}
	int find(int e) {
		return d[e];
	}
};
int gcd(int a, int b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
bool prime(int a) {
	if (a == 1) return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0) return false;
	}
	return true;
}
class Union_Find {
  private:
	vector<int> t, s;

  public:
	Union_Find(int max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}
	void Union(int x, int y) {
		if (same(x, y)) return;
		int tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}
	int Find(int n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}
	bool same(int x, int y) {
		return Find(x) == Find(y);
	}
	int get_Size(int a) {
		return s[a];
	}
};
int memo[200000];
signed main() {
	int n,m;
	cin>>n>>m;
	rep(i,m){
		int l,r;
		cin>>l>>r;
		memo[l]++;
		memo[r+1]--;
	}
	int ans=0;
	if(memo[1]==m)ans++;
	REP(i,2,n+1){
		memo[i]+=memo[i-1];
		if(memo[i]==m)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>

int gcd(int a, int b, int c) {
	// a is the biggest
	for (int i = c; i > 0; i--) {
		if ((a % i) + (b % i) + (c % i) == 0) {
			return i;
		}
	}

	return 1;
}


int sumOfgcd(int n) {
	if (n == 1) {
		return 1;
	} else {
		int count = 0;
		for (int i = 1; i < n; i++) {
			for (int j = i; j < n; j++) {
				if (j != i) {
					count += 6 * gcd(n, j, i);
				} else {
					count += 3 * gcd(n, j, i);
				}
			}
			count += 3 * gcd(n, n, i);
		}
		return sumOfgcd(n-1) + count + n;
	}
}


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

	std::cout << sumOfgcd(N) << std::endl;
}


Measured memory_bytes: 3636
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long n=sc.nextLong();
        long a=sc.nextInt();
        long b=sc.nextInt();
        n%=12;
        for(int i=1;i<n+1;i++){
            if(i%2==1)a=a-b;
            else b=a+b;
        }
        System.out.println(a+" "+b);
    }
    
}


Measured memory_bytes: 26396
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int A[100010], B[100010];
pair<int, pair<int, int>> p[100010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 0;
    rep(i, N) cin >> A[i] >> B[i];
    rep(i, N) {
        p[i].first = A[i] + B[i];
        p[i].second.first = A[i];
        p[i].second.second = B[i];
    }
    sort(p, p + N, greater<pair<int, pair<int, int>>>());
    int X = 0, Y = 0;
    rep(i, N) {
        if (i % 2 == 0) X += p[i].second.first;
        else Y += p[i].second.second;
    }
    cout << X - Y << endl;

    return 0;
}


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

int main() {
    ll X;
    cin >> X;

    int h500 = X / 500;
    int h5 = (X % 500) / 5;

    cout << h500 * 1000 + h5 * 5 << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(ReadLine());
        }

        public static long[] Reads()
        {
            return ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x,long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }

        public static long C(long n,long k)
        {
            long x=1;
            for (long i = 1; i <=k; i++)
            {
                x *= n - i + 1;
                x /= i;
            }
            return x;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var p = Reads();
            long ans = 0;
            for (int i = 0; i < n-1; i++)
            {
                if (p[i] == i + 1)
                {
                    var x = p[i];
                    p[i] = p[i + 1];
                    p[i + 1] = x;
                    ans++;             
                }
            }
            if (p[n - 1] == n) ans++;
            WriteLine(ans);
            
            


            Console.Out.Flush();
        }
    }
}


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

#define ll long long
#define mp make_pair
#define pb push_back

const int LOG = 1500;

int n;
char a[1 << 20];

int main() {
	ios :: sync_with_stdio(0);
	cin >> n >> a;
	for (int i = 0; i < n; ++ i) a[i] -= '3';
	int level = 0;
	bool ok0, ok1;
	while (n > 1) {
		++ level;
		if (level >= LOG) {
			cout << 0 << endl;
			return 0;
		}
		for (int i = 0; i + 1 < n; ++ i)
			a[i] = abs(a[i] - a[i + 1]);
		n --;
		ok0 = 1;
		for (int i = 0; i < n; ++ i)
			if (a[i] == 2) {ok0 = 0; break;}
		if (ok0) break;
		ok1 = 1;
		for (int i = 0; i < n; ++ i)
			if (a[i] == 1) {ok1 = 0; break;}
		if (ok1) break;
	}
	if (n == 1) {
		cout << int(a[0]) << endl;
		return 0;
	}
	if (!ok0) {
		for (int i = 0; i < n; ++ i) a[i] /= 2;
	}
	int C = 0, ans = 0;
	for (int i = 0; i < n; ++ i) {
		if (!C) ans ^= a[i];
		if (i + 1 == n) break;
		int cnt;
		{cnt = 0; int x = n - i - 1; while (x % 2 == 0) x /= 2, cnt ++; C += cnt;}
		{cnt = 0; int x = i + 1; while (x % 2 == 0) x /= 2, cnt ++; C -= cnt;}
	}
	if (!ok0) {
		ans *= 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const int maxn = 3e5 + 5;
const ll mod = 1e9 + 7;
ll n;
ll a[maxn];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	ll mx = 0;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		mx = max(mx , a[i]);
	}
	int lim = log2(mx);
	ll ans = 0;
	for(int i = 0; i <= lim; ++i) {
		ll cnt = 0;
		for(int j = 1; j <= n; ++j) 
			if(a[j] & ((ll)1 << i)) cnt++;
		ll sum = (n - cnt) * cnt % mod;
		for(int j = 0; j < i; ++j)
			sum = (sum * 2) % mod;
		ans = (ans + sum) % mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(int argc, char** argv)
{
	int i, j, in_num, total;
	char kind[1];

	unsigned char ar[4][13] = { { 0 } };
	scanf("%d", &total);

	for (i = 0; i < total; i++) {
		scanf("%s%*c%d", &kind, &in_num);

		if (kind[0] == 'S') {
			ar[0][in_num-1] = 1;
		}
		else if (kind[0] == 'H') {
			ar[1][in_num-1] = 1;
		}
		else if (kind[0] == 'C') {
			ar[2][in_num-1] = 1;
		}
		else if (kind[0] == 'D') {
			ar[3][in_num-1] = 1;
		}
	}

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			if (ar[i][j] == 0) {
				char k = '\0';
				switch (i) {
				case 0:
					k = 'S';
					break;
				case 1:
					k = 'H';
					break;
				case 2:
					k = 'C';
					break;
				case 3:
					k = 'D';
					break;
				}
				printf("%c %d\n", k, j+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

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

  cin>>x;
  int ans = 1, i = 2;

  while(ans < x){
    ans += i;
    i ++;
  }

  cout<<i-1<<endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.reverse()
cum = []
cumsum = 0
for i in A:
    cum.append(cumsum+i)
    cumsum+=i
ans = 0
for j in range(N-1):
    ans += A[N-j-1]*cum[N-j-2]
    ans = ans%1000000007
print(ans)

Measured memory_bytes: 101884
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
 
using namespace std;
using ll = long long;
 
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
 
#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
 
// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(string, n, s);
    For(i, n) Sort(s[i]);

    unordered_map<string, int> m;
    For(i, n) m[s[i]] ++;
    
    ll ans = 0;
    for(const auto &e : m){
        ll k = e.second;
        ans += k*(k-1)/2;
    }
    Cout(ans);
}


Measured memory_bytes: 17700
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

char buf[1 << 20];

int main()
{
	scanf("%s", buf);
	int n = strlen(buf);

	int i;
	int cnt = 0;
	Int res = 0;
	FOR(i, 0, n)
	{
		if (buf[i] == 'B') ++cnt;
		else res += cnt;
	}
	printf("%lld\n", res);
	return 0;
};


Measured memory_bytes: 384
def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    visited = [0 for i in range(n)]
    visit = [0]
    visited[0]=1
    s = 0
    while True:
        s = a[s]-1
        if visited[s]==1:
            x = visit[0:visit.index(s)]
            y = visit[visit.index(s):]
            break
        visit.append(s)
        visited[s]=1

    if k<len(x):
        print(x[k]+1)
    else:
        k = k-len(x)
        print(y[k%len(y)]+1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 32260
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, k;
i64 f(i64 n) {
  if (n == 0) return 1;
  i64 x = f(n - 1);
  return min(2 * x, x + k);
}

int main() {
  cin >> n >> k;
  cout << f(n) << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		//入力A(モンスター体力)
		int a = sc.nextInt();

		//入力B(サーバルの攻撃値)
		int b = sc.nextInt();

		int attacked = 0;

		//モンスターの体力を0以下にする
		for (int i = 1; a > 0; i++) {

			a = a - b;

			attacked = i;
		}

		System.out.println(attacked);

	}
}


Measured memory_bytes: 23892
/*
	Name:
	Author: xiaruize
	Date:
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define sz(a) int((a).size())

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ll a;
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;
	return 0;
}


Measured memory_bytes: 3636