akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

int main(void) {
    string S;
    ll count = 0;
    ll ten = 1;
    ll current = 0;
    map<ll, ll> m;
    cin >> S;
    reverse(S.begin(), S.end());
    m[0] = 1;
    for(auto &c: S) {
        current = (current + (c - '0') * ten) % 2019;
        ten *= 10;
        ten %= 2019;
        m[current]++;
    }
    for(auto &i: m) {
        count += i.second * (i.second - 1) / 2;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3732
#include<cstdio>
#include<algorithm>
#define N 100000
#define MAX (1<<31)-1
using namespace std;
long long A[N+1], T[4*N+1];

void build(int l, int r, int k) {
    if (l == r) {
        T[k] = A[l];
        return;
    }
    int mid = (l + r) / 2;
    build(l, mid, k * 2);
    build(mid + 1, r, k * 2 + 1);
    T[k] = T[2 * k] + T[2 * k + 1];
}
void updata(int in, int data ,int l, int r ,int k) {
    if (l == r) {
        A[l] += data;
        T[k] += data;
        return;
    }
    int mid = (l + r) / 2;
    if (in <= mid) updata(in, data, l, mid, k * 2);
    else updata(in, data, mid + 1, r, k * 2 + 1);
    T[k] = T[2 * k] + T[2 * k + 1];
}
long long find(int L, int R, int l, int r, int k) {
    if (L <= l && r <= R) return T[k];
    int mid = (l + r) / 2;
    long long ans = 0;
    if (mid >= L) ans += find(L, R, l, mid, k * 2);
    if (mid < R) ans += find(L, R, mid + 1, r, k * 2 + 1);
    return ans;
}
int main() {
    int n, q;
    scanf("%d%d", &n, &q);
    for (int i = 1; i <= n; i++)
        A[i] = 0;
    build(1, n, 1);
    int com, x, y;
    while (q--) {
        scanf("%d%d%d", &com, &x, &y);
        if (com == 0) updata(x, y, 1, n, 1);
        else printf("%ld\n", find(x, y, 1, n, 1));
    }
    return 0;
}


Measured memory_bytes: 5580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int last,x,n,c[200019];
ll ans;

int main() {
  cin >> n;
  ans=1;
  last=-1;
  
  for(int i=0; i<n; i++){
    cin >> x;
    if(x==last){continue;}
    last=x;
    ans = (ans+c[x])%1000000007;
    c[x]=ans;
  }

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

Measured memory_bytes: 1024
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
//~ #pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));


using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<
T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (3e5)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //

LL sil[maxn];
LL odw[maxn];
LL dp[maxn], dp2[maxn];

LL pot(LL a, LL w)
{
  if(w == 0) return 1;
  LL b = pot(a, w / 2);
  b = b * b % mod;
  if(w & 1) return a * b % mod;
  return b;
}

LL net(LL n, LL k)
{
  if(n < 0 || n < k || k < 0) return 0;
  return sil[n] * odw[k] % mod * odw[n - k] % mod;
}

int main()
{
	_upgrade
  sil[0] = odw[0] = 1;
  for(int i = 1;i < maxn;i++)
  {
    sil[i] = (sil[i - 1] * (LL) i) % mod;
    odw[i] = pot(sil[i], mod - 2);
  }
  int a, b;
  cin>>a>>b;
  int n = a + b;
  for(int i = 1;i <= n;i++)
  {
    dp[i] = (dp[i - 1] + net(i - 1, a - 1) * pot(2, mod - 1 - i)) % mod;
    dp2[i] = (dp2[i - 1] + net(i - 1, b - 1) * pot(2, mod - 1 - i)) % mod;
  //  cerr<<i<<" "<<dp[i]<<" "<<dp2[i]<<endl;
  }
  for(int i = 1;i <= n;i++)
  {
    LL res = (1 - dp[i - 1] + dp2[i - 1]) * pot(2, mod - 2);
    res %= mod;
    res += mod;
    res %= mod;
    cout<<res<<"\n";
  }

	return 0;
}


Measured memory_bytes: 11136
while true
  pts = []

  while true
    line = gets
    exit if line.nil?

    p0, p1 = line.chomp.split(" ").map{|s| s.to_i}
    break if p0 == 0 && p1 == 0

    p0 -= 1
    p1 -= 1

    pts[p0] = pts[p0].nil? ? 1 : (pts[p0] + 1)
    pts[p1] = pts[p1].nil? ? 1 : (pts[p1] + 1)
  end
  #p pts

  ok = true

  if pts[0] % 2 == 0 || pts[1] % 2 == 0
    ok = false
  else
    for i in (2...pts.length)
      if pts[i] % 2 != 0
        ok = false
        break
      end
    end
  end

  puts ok ? "OK" : "NG"
end

Measured memory_bytes: 6112
#include <bits/stdc++.h>
#include <numeric>
#include <iterator>
#include <stdio.h>
#define ll long long
#define ull unsigned long long int
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define sz(a) int((a).size())
#define all(a) (a).begin(),(a).end()
#define fr(i,p,n) for(int i=p;i<n;i++)
#define precise cout << std::setprecision(10) << std::fixed;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
ll M=1000000007;
//ll M=  998244353;
typedef pair<int, int> pairs;

int main()
{
    fastio; precise;
    int T=1;
    //cin>>T;
    while(T--){
        int n,m;
        cin>>n>>m;
        string s[n];
        fr(i,0,n) cin>>s[i];
        ll r=1,c=1;
        ll a[n][m];
        fr(i,0,n){
        fr(j,0,m){
        if(i==0) { if(s[i][j]=='#') r=0;
         a[i][j]=r; }
        else if(j==0){
            if(s[i][j]=='#') c=0;
            a[i][j]=c;
        }
        else if(s[i][j]=='#') a[i][j]=0ll;
        else a[i][j]=(a[i-1][j]+a[i][j-1])%M;
        }
        }
        cout<<a[n-1][m-1];

    }
     return 0;
}


Measured memory_bytes: 12500
/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX)
{return uniform_int_distribution<int>(l,r)(rng);}

template <typename T,typename G>
ostream& operator << (ostream& out, const pair<T,G> &a) 
{return out<<"( "<<a.x<<", "<<a.y<<")";}

template <typename T>
ostream& operator << (ostream& out, const vector<T> &a) 
{out<<"[ ";for(const auto &i:a)out<<i<<", ";return out<<"]"<<endl;}

template <typename T>
ostream& operator << (ostream& out, const set<T> &a) 
{out<<"{ ";for(const auto &i:a)out<<i<<", ";return out<<"}"<<endl;}

template <typename T,typename G>
ostream& operator << (ostream& out, const map<T,G> &a) 
{out<<"< ";for(const auto &i:a)out<<i<<", ";return out<<">"<<endl;}

template<typename T, size_t N>
typename enable_if<!is_same<typename remove_cv<T>::type, char>::value,
ostream&>::type operator<<(ostream& out, T(&a)[N])
{out<<"[ ";for(size_t i=0;i<N;++i)out<<a[i]<<", ";out <<"]"<<endl;return out;}

void debug_out(){cerr<<endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr<<(H)<<" ";debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr<<"#"<<#__VA_ARGS__<<":\n",debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

vector<int> vis,tim,a;
int t;

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,i,k;
	cin>>n>>k;
	a.resize(n+1);
	vis.assign(n+1,0);
	tim.resize(n+1,0);
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	int st=1;
	if(k<=3*n){
		while(k--){
			st=a[st];
		}
		cout<<st<<"\n";
		return 0;
	}
	vector<int> cyc;
	t=0;
	while(!vis[st]){
		cyc.push_back(st);
		tim[st] = t++;
		vis[st]=1;
		st=a[st];
	}
	debug(cyc);
	int cs=tim[st],ce=cyc.size()-1,ans=-1;
	if(k<cs)
		ans=cyc[k];
	k-=cs;
	k%=(ce-cs+1);
	ans=cyc[cs+k];
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 10068
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
int gcd(int one,int two) {
	while (one != 0 && two != 0) {
		if (one > two) {
			one = one % two;

		}
		else {
			two = two % one;
		}

	}

	return std::max(one,two);
	
}
int main()
{
	using namespace std;
	int a = 0, b = 0, c = 1, d = 0, e = 0, min = 0, ma = 0, ans = 0, count = 0, nagax = 0, nagay = 0, size = 0;
	int sa[100020] = {}, info[100020] = {};
	std::string str[150], strs;
	int thou = 0;
	bool okada = false;

	cin >> a>>b;
	for (int i = 0; i <= b/10000; i++) {
		for (int j = 0; j <= (b-i*10000) / 5000;j++) {
		
			thou = a - i - j;
			
			if (thou * 1000 + j * 5000 + 10000 * i == b) {
				cout << i <<" "<<j <<" "<< thou << endl;
				okada = true;
				return 0;
			}
		}

	}

	if (!okada) {
		cout <<"-1 -1 -1" << endl;
	}


	return 0;

}





Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

const int MAX_M = 50;
long long memo[MAX_M + 1][MAX_M + 1];
long long combination(int n, int k) {
	if(k == 0 || k == n)
		return 1;

	if(k * 2 > n)
		k = n - k;

	if(memo[n][k] > 0)
		return memo[n][k];

	return memo[n][k] = combination(n - 1, k - 1) + combination(n - 1, k);
}

int main() {
	int n, m, l;
	scanf("%d %d %d", &n, &m, &l);

	vector<int> t(n), v(n);
	vector<double> p(n);
	for(int i = 0; i < n; ++i) {
		scanf("%lf %d %d", &p[i], &t[i], &v[i]);
		p[i] /= 100.0;
	}

	vector<vector<double>> time(n, vector<double>(m + 1));
	for(int i = 0; i < n; ++i) {
		time[i][0] = static_cast<double>(l) / v[i];
		for(int j = 1; j <= m; ++j) {
			time[i][j] = time[i][j - 1] + t[i];
		}
	}

	vector<vector<double>> probability(n, vector<double>(m + 1));
	for(int i = 0; i < n; ++i) {
		const double q = 1.0 - p[i];
		for(int j = 0; j <= m; ++j) {
			probability[i][j] = combination(m, j) * pow(p[i], j) * pow(q, m - j);
		}
	}

	vector<vector<double>> sum(probability);
	for(int i = 0; i < n; ++i) {
		for(int j = m - 1; j >= 0; --j) {
			sum[i][j] += sum[i][j + 1];
		}
	}

	for(int i = 0; i < n; ++i) {
		double ans = 0.0;
		for(int j = 0; j <= m; ++j) {
			double tmp = probability[i][j];
			for(int k = 0; k < n; ++k) {
				if(i == k) continue;

				const int idx = upper_bound(time[k].begin(), time[k].end(), time[i][j]) - time[k].begin();
				tmp *= sum[k][idx];
			}
			ans += tmp;
		}

		printf("%.8lf\n", ans);
	}

	return EXIT_SUCCESS;
}

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

const int a[7] = {1, 2, 4, 8, 16, 32, 64};

int main()
{
	int n;
	cin>>n;
	for(int i=6;i>=0;i--)
	{
		if(n >= a[i])
		{
			cout<<a[i]<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int i=0 ; i<b ; i++)scanf("%d",&a[i])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	int a;
	scd(a);
	for(int i=1 ; i<=a ; i++)
	{
		int x=i;
		if(x%3==0)
		{
			printf(" %d",i);
			continue;
		}
		else if(x%10==3)
		{
			printf(" %d",i);
			continue;
		}
		else
		{
			x/=10;
			while(x>0)
			{
				if(x%10==3)
				{
					printf(" %d",i);
					break;
				}
				x/=10;
			}
		}
	}
	newline;
	return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    bool is=true;
    string s,t;
    cin>>s>>t;
    for(int i=s.size()-t.size();i>=0;i--){
        bool judge=true;
        for(int j=0;j<t.size();j++){
            judge&=(s[i+j]=='?' || s[i+j]==t[j]);
        }
        if(judge){
            s.replace(i,t.size(),t);
            is=false;
            break;
        }
    }
    if(is){
        cout<<"UNRESTORABLE";
    }else{
        replace(s.begin(),s.end(),'?','a');
        cout<<s;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double a = sc.nextInt();
        double b = sc.nextInt();
        double C = sc.nextInt() / 180.0 * Math.PI;
        double h = b * Math.sin(C);
        double S = a * h / 2.0;
        double r = b * Math.cos(C);
        double q = a - r;
        double p = Math.sqrt(h * h + q * q);
        double L = a + b + p;
        System.out.println(S);
        System.out.println(L);
        System.out.println(h);
    }
}



Measured memory_bytes: 26200
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define PI 3.1415926
#define MAX 100000
#define M 1e18

using namespace std;

int main() {
	int a, b;
	sfd(a);
	sfd(b);
	if( b<10 ) {
		a = a*10 + b;
	}else if( b<100 ) {
		a = a*100 + b;
	}else {
		a = a*1000 + b;
	}
	int i;
	for( i=1; i<320; i++ ) {
		if( i*i==a ) {
			break;
		}
	}
	if( i>=320 ) {
		pf("No");
	}else {
		pf("Yes");
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

int K, N;
int A[200000 + 100];

int main() {
	int saichou = 0;

	cin >> K >> N;
	for (int i = 0; i < N; i++)cin >> A[i];

	saichou = K + A[0] - A[N - 1];
	for (int i = 1; i < N; i++) {
		saichou = max(saichou, A[i] - A[i - 1]);
	}

	cout << K - saichou << endl;
	return 0;
}

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	vector <int> a(3); cin >>a[0]>>a[1]>>a[2];
	sort (a.begin(),a.end());
	cout << (a[0]*a[1]/2) << "\n" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int data[100]={};
int mini;
int n;
int SUM;



int main() {
    string s;
    while(1){
        getline(cin,s);
        if(s=="END OF INPUT")break;
        
        string ans="";
        int now=0;
        rep(i,s.size()){
            if(s[i]==' '){
                ans+=now+'0';
                now=0;
            }
            else{
                now++;
            }
        }
        ans+=now+'0';
        
        cout<<ans<<endl;
        
    }

    return 0;
}

Measured memory_bytes: 1192
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        int x= sc.nextInt();
        int n = sc.nextInt();
        int p[] = new int[n];
        for(int i = 0;i<n;i++){
            p[i] = sc.nextInt();
        }
        int ans = 0;


        for(int i = 0;i<105;i++){
            int tmp = x + i;
            int tmpp = x - i;
            boolean tmplus  = true;
            boolean tmpminus = true;
            int j = 0;
            while (tmplus||tmpminus){
                if(j == n){
                    break;
                }
                if(p[j]==tmp){
                    tmplus =false;
                }
                if(p[j]==tmpp){
                    tmpminus = false;

                }

                j++;
            }
            if(tmplus&&tmpminus){
                System.out.println(x-i);
                System.exit(0);
            }
            else if(tmplus&&!tmpminus){
                System.out.println(x+i);
                System.exit(0);
            }
            else if(!tmplus&&tmpminus){
                System.out.println(x-i);
                System.exit(0);
            }



        }

    }

}


Measured memory_bytes: 35788
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}


int main(int argc, char const* argv[])
{
  list<ll> l;
  auto itr = l.end();
  int q;
  cin >> q;
  rep(i, q){
    int x;
    cin >> x;
    if(x == 0){
      ll y;
      cin >> y;
      itr = l.insert(itr, y);
    }else if(x == 1){
      int y;
      cin >> y;
      if(y > 0)rep(i, y)itr++;
      else rep(i, -y)itr--;
    }else{
      itr = l.erase(itr);
    }
  }
  for(auto itr = l.begin(); itr != l.end(); ++itr){
    cout << *itr << endl;
  }
	return 0;
}



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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for(int y = sy; y < ty; y++) cout << "U";
  for(int x = sx; x < tx; x++) cout << "R";
  for(int y = ty; y > sy; y--) cout << "D";
  for(int x = tx; x > sx; x--) cout << "L";
  cout << "L";
  for(int y = sy; y < ty+1; y++) cout << "U";
  for(int x = sx-1; x < tx; x++) cout << "R";
  cout << "D";
  cout << "R";
  for(int y = ty; y > sy-1; y--) cout << "D";
  for(int x = tx+1; x > sx; x--) cout << "L";
  cout << "U";

  cout << endl;
  
  return 0;
}


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

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    int h, w;
    cin >> h >> w;
    string s[h];
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    int b = 0;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
        if (s[i][j] == '#') b++;
    }

    int d[h][w];
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) d[i][j] = -1;
    int dy[] = {-1, 1, 0, 0};
    int dx[] = {0, 0, -1, 1};
    queue<pii> q;
    q.push(make_pair(0, 0));
    d[0][0] = 1;
    while (q.size() > 0) {
        pii p = q.front();
        q.pop();
        int y = p.first, x = p.second;
        for (int j = 0; j < 4; j++) {
            int ny = y + dy[j], nx = x + dx[j];
            if (0 <= ny && ny < h && 0 <= nx && nx < w && s[ny][nx] == '.' && d[ny][nx] == -1) {
                q.push(make_pair(ny, nx));
                d[ny][nx] = d[y][x] + 1;
            }
        }
    }
    if (d[h - 1][w - 1] > 0) cout << h * w - d[h - 1][w - 1] - b << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//l={1,2,3,4}
//greater<int>()
//sort(l,l+n)

int main(void)
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = 0;
	if (a > b)
		ans += b;
	else
		ans += a;
	if (c > d)
		ans += d;
	else
		ans += c;
	cout << ans << endl;
}


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

#define show(x) cerr << #x << " = " << x << endl

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

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll sum = 0;
    for (int i = 0; i < N; i++) {
        const ll mid = B[i];
        const ll a = lower_bound(A.begin(), A.end(), mid) - A.begin();
        const ll c = C.end() - upper_bound(C.begin(), C.end(), mid);
        sum += a * c;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int H = sc.nextInt();
        final int W = sc.nextInt();

        int[][] kinds = new int[H][W];
        int[][] costs = new int[H][W];
        String row = sc.next();
        for (int j = 0; j < W; j++) {
            kinds[0][j] = '.' == row.charAt(j) ? 0 : 1;
            if (j == 0) {
                costs[0][0] = kinds[0][0];
            } else {
                if (kinds[0][j] == 0 || kinds[0][j] == kinds[0][j - 1]) {
                    costs[0][j] = costs[0][j - 1];
                } else {
                    costs[0][j] = costs[0][j - 1] + 1;
                }
            }
        }
        for (int i = 1; i < H; i++) {
            row = sc.next();
            for (int j = 0; j < W; j++) {
                kinds[i][j] = '.' == row.charAt(j) ? 0 : 1;
                if (j == 0) {
                    costs[i][j] = costs[i - 1][j] + (kinds[i][j] == 0 || kinds[i][j] == kinds[i - 1][j] ? 0 : 1);
                } else {
                    int rCost = costs[i - 1][j] + (kinds[i - 1][j] == kinds[i][j] || kinds[i][j] == 0 ? 0 : 1);
                    int cCost = costs[i][j - 1] + (kinds[i][j - 1] == kinds[i][j] || kinds[i][j] == 0 ? 0 : 1);
                    costs[i][j] = rCost < cCost ? rCost : cCost;
                }
            }
        }
        System.out.println(costs[H - 1][W - 1]);
    }
}

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

using namespace std;

vector<bool> dp, searched;

bool isprime(int n, int k);

bool is_prime(int n)
{
	if (searched[n])
	{
		return dp[n];
	}

	if (n % 2 == 0)
	{
		return false;
	}

	return isprime(n, 3);
}

bool isprime(int n, int k)
{
	if (n < k * k)
	{
		searched[n] = true;
		
		dp[n] = true;
		
		return true;
	}

	if (n % k == 0)
	{
		searched[n] = true;
		
		dp[n] = false;
		
		return false;
	}

	return isprime(n, k + 2);
}

int main()
{
	int N;

	dp = searched = vector<bool>(10000001, false);

	while (true)
	{
		cin >> N;

		if (N == 0) { break; }

		int Ans = 1145141919;

		if (N % 2 == 0)
		{
			N -= 1;
		}

		if (N % 3 == 0)
		{
			N -= 2;
		}

		for (int i = N;;)
		{
			if (is_prime(i - 8) && is_prime(i - 6) && is_prime(i - 2) && is_prime(i))
			{
				Ans = i; break;
			}

			if (i % 6 == 1)
			{
				i -= 2;
			}
			else
			{
				i -= 4;
			}
		}
		
		cout << Ans << endl;
	}

	return 0;
}

Measured memory_bytes: 5076
#include<cstdio>
#include<algorithm>
int main(){
	int n;
	scanf("%d",&n);
	long long int a[n+1]={};
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		a[i]+=a[i-1];
	}
	long long int ans=0;
	std::sort(a,a+(n+1));
	long long int u=0;
	for(int i=1;i<=n;i++){
		if(a[i]==a[i-1]){
			u++;
		}else{
			ans+=(u*(u+1))/2;
			u=0;
		}
	}
	ans+=(u*(u+1))/2;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
ll pt[21];
int main() {
	ll d;
	cin >> d;
	ll tp = 1;
	for(int i=0;i<=20;i++) {
		pt[i] = tp;
		if(i < 18) {
			tp *= 10;
		}
	}
	ll tot = 0;
	for(int i=2;i<=20;i++) {
		ll ct = 1;
		ll b = pt[i-1]-1;
		ll dv = d;
		map<ll,ll> bs,nu;
		bs[0] = 1;
		if(i >= 18) {
			b = 0;
			for(int j=0;j<17;j++) {
				if(i-j <= 18) {
					b += 9*pt[j];
				} else {
					ll q = 10;
					if(j == 0) q--;
					bs[0] *= q;
				}
			}
		}
		for(int j=max(i-18,0);j<(i+1)/2;j++) {
			nu.clear();
			ll sub = 10;
			if(j == 0) sub--;
			for(auto& it: bs) {
				if(b > 0) {
					ll ml = ((d-it.first)/b);
					if(it.first+ml*b > d) {ml--;}
					if(abs(ml) > sub) {continue;}
					ll lb = it.first+ml*b;
					ll ub = lb+b;
					nu[lb] += max(sub-abs(ml),0LL)*it.second;
					nu[ub] += max(sub-abs(ml+1),0LL)*it.second;
					//cout << "add " << lb << ", " << ub << '\n';
				} else {
					nu[it.first] += 10*it.second;
				}
			}
			b /= 10;
			b = (b/pt[j+1])*pt[j+1];
			bs = nu;
		}
		ct = bs[d];
		tot += ct;
	}
	cout << tot << '\n';
}

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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

constexpr long long INF = 1LL << 60;

struct Edge {
  int to;
  Edge(int _to) : to(_to) {
  }
};
using Graph = vector<vector<Edge>>;

int cycle_node = -1; // 閉路上に存在するノードのid
vb seen;             // 探索済みフラグ
vb finished;         // 探索済みで、絶対にサイクルがないノード
vi history;

void dfs(const Graph& g, int idx) {
  if (finished[idx]) {
    return;
  }

  history.push_back(idx);

  // 探索終了していないけど訪問済みなノードに到達
  if (seen[idx]) {
    // それは閉路である
    cycle_node = idx;
    return;
  }

  seen[idx] = true;

  for (const auto& e : g[idx]) {
    if (finished[e.to])
      continue;

    dfs(g, e.to);

    if (cycle_node != -1)
      return;
  }

  finished[idx] = true;
  history.pop_back();
}

// 閉路のパス
// 戻り値: 0→閉路なし 1→閉路あり
// cycle: 閉路のpath
int find_cycle(const Graph& g, vector<int>& cycle) {
  ll n = g.size();

  // init
  cycle_node = -1;
  seen.assign(n, false);
  finished.assign(n, false);
  cycle.clear();

  // 全ての頂点を確認する
  rep(i, n) {
    dfs(g, i);
    // サイクルが見つかった時点でループを抜ける
    if (cycle_node != -1) {
      break;
    }
  }

  if (cycle_node == -1) {
    return 0;
  }

  // historyの始めにあるサイクルと無関係なデータを削除
  cycle.push_back(cycle_node);
  for (auto it = history.rbegin() + 1; it != history.rend(); it++) {
    if (*it == cycle[0]) {
      break;
    }
    cycle.push_back(*it);
  }
  reverse(all(cycle));

  return 1;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll v, e;
  cin >> v >> e;

  Graph g(v);

  rep(i, e) {
    ll x, y;
    cin >> x >> y;
    g[x].emplace_back(y);
  }

  vi cycle_path;
  cout << find_cycle(g, cycle_path) << endl;

  return 0;
}



Measured memory_bytes: 3240
N, M = list(map(int,input().split()))
A = []
B = []
for i in range(M):
    A1,B1=[int(i) for i in input().split()]
    A.append(A1)
    B.append(B1)
A.reverse()
B.reverse()

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n+1)]
        self.rank = [0 for _ in range(n+1)]
        self.size = [1 for _ in range(n+1)]
    
    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            x_size = self.size[x]
            y_size = self.size[y]
            sum_size = x_size + y_size
            self.size[x] = sum_size
            self.size[y] = sum_size
            
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
    
    def get_size(self, a):
        x = self.find(a)
        return self.size[x]

uf = UnionFind(N)
anses = []
ans = int(N * (N-1) / 2)
anses.append(ans)

for k in range(len(A)-1):
    if uf.is_same(A[k], B[k]):
        anses.append(anses[k])
    else:
        N1 = uf.get_size(A[k])
        N2 = uf.get_size(B[k])
        ans = anses[k] - (N1 * N2)
        if ans < 0:
            ans = 0
        uf.union(A[k], B[k])
        anses.append(ans)
        
for ans in reversed(anses):
        print(ans)

Measured memory_bytes: 21628
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main(){
  int A,B; cin >>A >>B;
  if (10<=A+B) {
    cout <<"error" <<endl;
    return 0;
  } else {
    cout <<A+B <<endl;
    return 0;    
  }
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int N, X, D1 = 0, D2=1, L;

    scanf("%d %d", &N, &X);

    for(int i=1; i<=N; i++)
    {
        scanf("%d", &L);

        D1 = D1 + L;

        if(D1 <= X)D2++;
    }

    printf("%d", D2);

    return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
     string S,T,U;
     int A,B;
     cin>>S>>T>>A>>B>>U;
     if(U==S){A--;}
      else{B--;}
      cout<<A<<" "<<B<<endl;
      return 0;
    }

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int ii = 0; ii < n; ii++)
		cin >> a[ii];

	bool check=1;

	for (int i = 0; i < n; i++) {
		if (a[i] % 2 != 0) {
			continue;
		}
		else {
			if (a[i] % 3 == 0 || a[i] % 5 == 0) {
				continue;
			}
			else {
				check = 0;
				break;
			}
		}
	}

	if (check)
		cout << "APPROVED" << endl;
	else
		cout << "DENIED" << endl;


}

Measured memory_bytes: 256
N = eval(input())
num = []
flag = {}
for i in range(N):
    num.append(eval(input()))
for i in num:
    if i not in flag.keys():
        flag[i] = False
    else:
        flag[i] = not flag[i]
sum = 0
for i in flag.keys():
    if not flag[i]:
        sum = sum + 1
print(sum)


Measured memory_bytes: 16380
import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
def YesNo(x):print("Yes")if x==True else print("No")
n,m=NM()
edge=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    c=1
    edge[a].append((b,c))
    edge[b].append((a,c))
pre=[-1]*(n+1)
from heapq import *
def dijkstra(s,n):
    d = [float('inf') for i in range(n+1)]
    pq = []
    d[s]=0
    heappush(pq,(0,s))
    while pq:
        dist,u = heappop(pq)
        for v,cost in edge[u]:
            if d[v]<=dist+cost:
                continue
            d[v]=dist+cost
            pre[v]=u
            heappush(pq,(d[v],v))
    return d
dijkstra(1,n)
if -1 in pre[2:]:
    print("No")
else:
    print("Yes")
    for i in pre[2:]:
        print(i)

Measured memory_bytes: 110980
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#define N 1001

using namespace std;

int main(){
  int dp[N];
  dp[0] = 1; dp[1] = 2;
  for(int i=2; i<N; ++i) dp[i] = (dp[i-1]+dp[i-2])%N;
  int v, d;
  while(cin >> v >> d){
    vector<int> data;
    for(int i=1; i<=v; ++i) data.push_back(dp[i]);
    sort(data.begin(), data.end());
    int ans=1;
    for(int i=1; i<data.size(); ++i){
      if(abs(data[i]-data[i-1]) >= d) ++ans;
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 1001001001;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);

int main(){
    ld a,b;
    cin >> a >> b;
    ld P = a*b;
    if(P-ll(a*b) >= 0.5){
        cout << ll(a*b) << endl;
    }else{
        cout << ll(a*b) << endl;
    }

}

Measured memory_bytes: 3756
#include<stdio.h>
	int main(){
		int H,A;
		
		scanf ("%d %d", &H, &A);
		
		if (H%A == 0){
			printf ("%d",H/A);
		}else if (H%A != 0){
			printf ("%d",H/A+1);
		}
		return 0;
	}


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

const int N = 110;
int A[N][N], d[N];
int cnt[N]; 
int n, k;

int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= k; i++) {
		scanf("%d", &d[i]);
		for(int j = 1; j <= d[i]; j++) {
			int x; scanf("%d", &x);
			cnt[x]++;
		} 
	}	
	
	int res = 0;
	for(int i = 1; i <= n; i++) if(cnt[i]) res++;
	printf("%d\n", n - res);
	
}

Measured memory_bytes: 3812
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

s = inputSL()

print("A"+s[1][0]+"C")

Measured memory_bytes: 63980
#include <iostream>

using namespace std;

#define SENTINEL 2000000000
typedef long long llong;

llong merge(int A[], int left, int mid, int right) {
    llong cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1];
    int R[n2];
    for (int i = 0; i < n1; ++i) {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; ++i) {
        R[i] = A[mid + i];
    }
    L[n1] = SENTINEL;
    R[n2] = SENTINEL;
    int i = 0;
    int j = 0;
    for (int k = left; k < right; ++k) {
        if (L[i] <= R[j]) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
            cnt += n1 - i;
        }
    }
    return cnt;
}

llong mergeSort(int A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        llong v1 = mergeSort(A, left, mid);
        llong v2 = mergeSort(A, mid, right);
        llong v3 = merge(A, left, mid, right);
        return v1 + v2 + v3;
    }
    return 0;
}

int main() {
    int n;
    scanf("%d", &n);
    int A[n];
    for (int i = 0; i < n; ++i) {
        scanf("%d", &A[i]);
    }

    llong ans = mergeSort(A, 0, n);
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 4744
# -*- coding: utf-8 -*-
def get_input() -> str:
    """
    標準入力の取得.

    Returns:\n
        str: 標準入力
    """
    s = input()
    return s


def main(s: str) -> None:
    """
    求解処理.\n
    順番に処理を行う.

    Args:\n
        s (str): しぐが押したキーを順番に記録した文字列
    """
    result = str()
    for s_i in s:
        if s_i == "0":
            result += "0"
        elif s_i == "1":
            result += "1"
        elif s_i == "B":
            result = result[:-1]

    # 結果出力
    print(result)


if __name__ == "__main__":
    s = get_input()
    main(s)


Measured memory_bytes: 3064
#include <algorithm>
#include <complex>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::cerr;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::stack;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;
const int MOD = 1e9 + 7;

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

    vector<int> a('z' + 1);
    for (size_t i = 0; i < w.length(); i++) {
        a[w[i]]++;
    }

    bool beautiful = true;
    for (int c : a) {
        if(c % 2 != 0){
            beautiful = false;
            break;
        }
    }

    cout << (beautiful ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
ans, cnt = 0, 0
while (True):
    cnt = ans
    for i in range(N):
        if(A[i] % 2 == 1): break
        A[i] //= 2
        if (i == N - 1): ans += 1
    if (cnt == ans): break
print(ans)


Measured memory_bytes: 2940
W,H,N = gets.chomp.split(" ").map(&:to_i)
x,y,a = N.times.map{gets.split.map(&:to_i)}.transpose
x0 = 0
y0 = 0
x1 = W
y1 = H
N.times do |i|
  if a[i] == 1
    x0 = x[i] if x0 < x[i]
  elsif a[i] == 2
    x1 = x[i] if x1 > x[i]
  elsif a[i] == 3
    y0 = y[i] if y0 < y[i]
  else
    y1 = y[i] if y1 > y[i]
  end
end
width = [x1 - x0,0].max
height = [y1 - y0,0].max
puts width*height

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

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

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

  ll tmp = 0, cur = 5;
  while (cur <= n)
  {
    tmp += n / (cur*2);
    cur *= 5;
  }

  cout << tmp << endl;

  return 0;
}

Measured memory_bytes: 256
N=int(input())
A =list(map(int,input().split()))
B =list(map(int,input().split()))
START = sum(A)

for i in range(N):
    if A[i] <= B[i]:
        sa =(B[i]-A[i])
        if A[i+1] >= sa:
            A[i+1] -= sa
        else:
            A[i+1] = 0
        A[i]=0
    else:
        A[i] -= B[i]
END=sum(A)
print(START-END)

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

int main(){
  int N,K;
  cin >> N >> K;
  int count = 0;
  vector<int> height(N);
  for(auto& h : height){
    cin >> h;
    if(h>=K){
      count ++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 640
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int K = int.Parse(input[1]);
    input = Console.ReadLine().Split(' ');
    int[] arr = new int[N];
    for (int i = 0; i < N; i++) {
      arr[i] = int.Parse(input[i]);
    }
    Array.Sort(arr);
    Array.Reverse(arr);
    int sum = 0;
    for (int i = 0; i < K; i++) {
      sum += arr[i];
    }
    Console.WriteLine(sum);
  }
}

Measured memory_bytes: 11220
import math
n = int(input())
for i in range(n):
    a, b = map(int, input().split())
    if a == b:
        print(2 * a - 2)
    elif max(a, b) - min(a, b) == 1:
        print(2 * min(a, b) - 2)
    else:
        c = math.floor(math.sqrt(a * b))
        if c == math.sqrt(a*b):
            c -= 1
        if c * (c + 1) >= a * b:
            print(2 * c - 2)
        else:
            print(2 * c - 1)

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

using namespace std;

typedef long long int lli;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vii;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<b;i++)

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

int main() {
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
//	#endif
	
	FASTIO

	int T=1;
//	cin >> T;

	while(T--) {
		int x[5];
		REP(i,0,5) {
			cin >> x[i];
			if(x[i]==0) {
				cout << i+1 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
using namespace std;
typedef long long int LL;
const LL MAX=998244353;
LL comb[300005];

LL ex(LL a,LL n){
	LL i,j;
	LL s=1;
	for(i=0;(1<<i)<=n;i++){}
	i--;
	for(;i>=0;i--){
		s=(s*s)%MAX;
		if(n&(1<<i))s=(s*a)%MAX;
	}
	return s;
}

void init(LL n){
	LL s=1;
	comb[0]=s;
	for(LL i=1;i<=n;i++){
		s=(s*(n-i+1))%MAX;
		s=(s*ex(i,MAX-2))%MAX;
		comb[i]=s;
	}
}

int main(){
	LL n;
	LL s=0;
	LL i,j,k;
	LL a,b,c;
	LL x,y;
	cin>>n>>a>>b>>c;
	init(n);
	for(i=0;i<=n;i++){
		x=c-a*i;
		if(x<0)break;
		if(x%b!=0 || x/b>n)continue;
		x/=b;
		s+=comb[i]*comb[x];
		s%=MAX;
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	Solver() {
		ios::sync_with_stdio( false );
		cout << fixed << setprecision( 10 );
	}

	void solve() {
		int K;
		cin >> K;

		queue<long> q;
		for( int i = 1; i <= 9; ++i ) {
			q.push( i );
		}

		long ans = 0;
		while( K-- ) {
			ans = q.front();
			q.pop();

			for( int i = -1; i <= 1; ++i ) {
				int d = ans % 10 + i;
				if( d < 0 || d > 9 ) { continue; }

				q.push( 10*ans + d );
			}
		}

		cout << ans << endl;
	}
};

int main() {
	Solver().solve();
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
	long long i,n,l,r,s=0,k=0,j1=0;
	cin>>n>>l>>r;
	for(int j=1;j<=n;j++){
		j1=j;
		for(i=1;i<=5;i++){
			s+=j1%10;
			j1/=10;
		}
		if(s>=l && s<=r){
			k+=j;
			s=0;
		}	
		else{
			s=0;
		}
	}
	cout<<k;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) FOR(i,0,n)

void swapString(string &str, int a1, int a2, int b1, int b2, int c1, int c2, int d1, int d2, int e1, int e2) {
	swap(str[a1-1], str[a2-1]);
	swap(str[b1-1], str[b2-1]);
	swap(str[c1-1], str[c2-1]);
	swap(str[d1-1], str[d2-1]);
	swap(str[e1-1], str[e2-1]);
}

int main() {
	int n;
	cin >> n;
	
	string ans_str = "111111111222444666555333333333";
	
	while (n--) {
	
		string str = "";
		
		REP(i, 30) {
			int in;
			cin >> in;
			str.push_back(in + '0');
		}
		
		int ans = 0;
		queue<pair<string, int> > que;
		set<string> s;
		
		que.push(make_pair(str, 0));
		while (!que.empty()) {
			string now = que.front().first;
			int cnt = que.front().second;
			que.pop();
			
			if (s.find(now) != s.end()) continue;
			s.insert(now);
			
			if (now == ans_str) {
				ans = cnt;
				break;
			}
			
			string next;
			
			next = now;
			swapString(next, 7, 22, 8, 23, 9, 24, 18, 13, 10, 12);
			que.push(make_pair(next, cnt + 1));
			
			next = now;
			swapString(next, 1, 28, 2, 29, 3, 30, 16, 15, 21, 19);
			que.push(make_pair(next, cnt + 1));

			next = now;
			swapString(next, 1, 24, 4, 27, 7, 30, 21, 10, 16, 18);
			que.push(make_pair(next, cnt + 1));

			next = now;
			swapString(next, 3, 22, 6, 25, 9, 28, 19, 12, 13, 15);
			que.push(make_pair(next, cnt + 1));
		}
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1292