akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A, B;
    cin >> A >> B;

    if (A - 2 * B > 0) {
        cout << A - 2 * B << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF 0x3f3f3f3f3f3f3f3f
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x)h & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;

const int N = 1e6 + 5;
const LL mod = 998244353;

void solve() {

    int a, b, c, k;

    scanf("%d %d %d %d", &a, &b, &c, &k);

    int sum = 0;

    if(k >= a) k -= a, sum = a;

    else {

        printf("%d\n", k);

        return ;

    }

    if(k >= b) k -= b;

    else {

        printf("%d\n", sum);

        return ;

    }

    sum -= k;

    printf("%d\n", sum);

}

int main() {

//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=100000+5;

int a[N];
int b[N];

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

    memset(b,0x3f,sizeof(b));
    int ans=0;
    for(int i=0;i<n;++i)
    {
        int pos=upper_bound(b,b+N,a[i])-b;
        b[pos]=a[i];
        ans=max(ans,pos);
    }
    cout<<ans+1;
    return 0;
}
/*

*/


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
 
#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;
 
ll mod = 1e9 + 7ll;
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; }
const ll inf = 1ll << 60;

int n, m;
vector<vector<int>> graph(101010);
vector<int> g(101010);
int group = 1;

void DFS(int a){
    g.at(a) = group;
    for(auto x: graph.at(a)){
        if(g.at(x) == 0) DFS(x);
    }
}

int main(){
    cin >> n >> m;
    rp(i, 0, m){
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        graph.at(x).emplace_back(y);
        graph.at(y).emplace_back(x);
    }
    rp(i, 1, n+1){
        if(g.at(i) == 0){
            DFS(i);
            group++;
        }
    }
    printf("%d", group-1);
    return 0;

}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll INF = 1LL << 60;

vector<ll> dp(100100,0);

int main(){
  int n,m; cin >> n >> m;
  dp[0] = 1;
  for (int i = 0; i < m; i++) {
    int a; cin >> a;
    dp[a] = -1;
  }
  for (int i = 0; i < n; i++) {
    if (dp[i] == -1) continue;
    if (dp[i+1] != -1) dp[i+1] = (dp[i+1] + dp[i])%MOD;
    if (dp[i+2] != -1) dp[i+2] = (dp[i+2] + dp[i])%MOD;
  }

  std::cout << dp[n] << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for (int i = A; i <= B; i++)
  {
    string s = to_string(i);
    if (s[0] == s[4] && s[1] == s[3])
      ans++;
  }
  cout << ans << endl;
  return 0;
}


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

//{{{
/********************************************************************/
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define reps(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) reps(i, 0, n)
#define REPS(i, a, b) reps(i, a, b)
#define REP(i, n) rep(i, n)
#define deps(i, a, b) for (int i = a; i >= b; --i)
#define dep(i, n) deps(i, n, 0)
#define DEPS(i, a, b) deps(i, a, b)
#define DEP(i, n) dep(i, n)

#define pf push_front
#define pb push_back
#define mp make_pair
#define fst first
#define FST fst
#define sec second
#define SEC sec
#define sz(obj) ((int)(obj).size())
#define all(v) (v).begin(), (v).end()
#define ALL(v) all(v)
#define endl "\n"

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

//vector<string> split(const string &s, char delim) {
//  vector<string> elems;
//  string item;
//  for (char ch: s) {
//    if (ch == delim) {
//      if (!item.empty()) elems.push_back(item);
//      item.clear();
//    }
//    else item += ch;
//  }
//  if (!item.empty()) elems.push_back(item);
//  return elems;
//}

inline bool inside(int y, int x, int H, int W) { return y >= 0 && x >= 0 && y < H && x < W; }
inline int in() { int x; std::cin >> x; return x; }
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

/****************************************************************/
//}}}

int h, w;

int func1(int y, bool f, int a[15][10005]) {
  if (y >= h) return 0;
  int ans = 0, res = max(func1(y + 1, true, a), func1(y + 1, false, a));
  if (f) {
    rep(i, w) a[y][i] = abs(a[y][i] - 1);
  }
  rep(i, w) {
    int cnt = 0;
    rep(j, h) cnt += a[j][i];
    ans += (cnt > h / 2) ? cnt : h - cnt;
  }
  return max(ans, res);
}

signed main()
{
  while (cin >> h >> w, h + w) {
    int table[15][10005];
    rep(i, h) rep(j, w) cin >> table[i][j];
    print(max(func1(0, true, table), func1(0, false, table)));
  }

  return (0);
}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
#define ll long long
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
using namespace std;

int main(){
  ll A,B,C,D,E,F,ans1,ans2;
  double ans=0.0;
  cin>>A>>B>>C>>D>>E>>F;
  vector<ll> wa,su;
  for(ll i=0;i*A*100<=F;i++){
    for(ll j=0;i*A*100+j*B*100<=F;j++) wa.push_back(i*A*100+j*B*100);
  }
  sort(wa.begin(),wa.end());
  
  for(ll i=0;i*C*100<=F*E;i++){
    for(ll j=0;100*(i*C+j*D)<=F*E;j++) su.push_back(i*C+j*D);
  }
  sort(su.begin(),su.end());

  for(ll i=0;i<wa.size();i++){
    for(ll j=0;j<su.size();j++){
      if(wa[i]+su[j]<=F&&su[j]*100<=wa[i]*E){
        if(ans<=(double)su[j]/wa[i]){
          ans=(double)su[j]/wa[i];
          ans1=su[j]+wa[i];
          ans2=su[j];
        }
      }
    }
  }
  cout<<ans1<<" "<<ans2<<endl;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>

int count_digit(const int n) {
	return (n == 0) ? 0 : 1 + count_digit(n / 10);
}
int power(const int digit) {
	return (digit == 1) ? 1 : 10 * power(digit - 1);
}
int main() {
	int n; std::cin >> n;
	auto digit = count_digit(n);
	if (digit % 2 == 1) {
		auto result = n - power(digit) + 1;
		for (auto d = 1; d < digit; d += 2) {
			result += power(d) * 9;
		}
		std::cout << result << std::endl;
	}
	else {
		auto result = 0;
		for (auto d = 1; d < digit; d += 2) {
			result += power(d) * 9;
		}
		std::cout << result << std::endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(i,a,b) for(long long i=a;i<b;i++)
#define pb(i) push_back(i)
#define mk(x,y) make_pair(x,y)
#define F first
#define S second
#define accu(i) fixed<<setprecision(i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
using namespace std;


int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    string s;cin>>s;
    ll flag=0;
    f(i,0,s.size()){
    	if( (i+1)%2!=0 and s[i]=='L' ){
    		flag=1;break;
		}
		if( (i+1)%2==0 and s[i]=='R' ){
			flag=1;break;
		}
	}
	if(flag==1) cout<<"No\n";
	else cout<<"Yes\n";
	return 0;
}

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

int main()
{
  string s;
  cin >> s;
  int n = s.size();
  
  ll res = 0, cnt = 0;
  rep(i, n-1)
  {
    if(s[i] == 'A')
    {
      cnt++;
      //continue;
    }
    else if(s[i] == 'B' && s[i+1] == 'C')
    {
      res += cnt;
      i++;
    }
    else
    {
      cnt = 0;
    }
  }
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>

int main(){
  char b;
  std::cin >> b;

  char ret;
  if(b == 'A') ret = 'T';
  else if (b == 'T') ret = 'A';
  else if (b == 'C') ret = 'G';
  else if (b == 'G') ret = 'C';

  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cerr<<elem;}cerr<<endl;}

/*二項係数(mod付き)*/
struct Combination{
	const int num=51e4;			//要素数(適宜変更する).
	const int mod=1e9+7;
	vector<llong> fact,inv,finv;//階乗,逆元,逆元の階乗.
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){//nが大きい場合に使用.
		llong res=1LL;
		REP(i,k) res=res*(n-i)%mod;
		res=res*finv[k]%mod;
		return res;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};

template<class Type_k,class Type_p>
Type_p mod_pow(long long n,Type_k k,Type_p p){//n^k(mod p).
	if(k==0) return 1;
	long long res=mod_pow(n*n%p,k/2,p);
	if(k&1) res=res*n%p;
	return res;
}

int main(){
	int n,a,b;
	cin>>n>>a>>b;
	
	Combination ob;
	
	llong ans=(MOD+mod_pow(2LL,n,MOD)-1)%MOD;
	llong tmp=ob.big_nCk(n,a);
	llong tmpp=ob.big_nCk(n,b);
	ans=(2*MOD+ans-tmp-tmpp)%MOD;
	
	cout<<ans<<endl;
}

Measured memory_bytes: 15140
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define mod 1000000007

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    map<ll,ll> m;
    ll sum=0;
    REP(i,n){
        ll temp;
        cin>>temp;
        sum+=temp;
        m[temp]++;
    }
    ll q;
    cin>>q;
    while(q--){
        ll b,c;
        cin>>b>>c;
        ll x=m[b];
        m[b]=0;
        sum-=x*b;
        sum+=x*c;
        m[c]+=x;
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 9524
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int N;

int main(){
    cin>>N;

    int ans=0;
    for(int i=0;i<=5;i++){
        if(i%2==0 && pow(10,i)<=N && N<pow(10,i+1)){
            ans+=N-pow(10,i)+1;
            break;
        }else if(i%2==0 && pow(10,i+1)<=N){
            ans+=pow(10,i+1)-pow(10,i);
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
array = [int(i) for i in input().split()]
ans_array = [0]*8
upper_num = 0

for i in array:
  if 1 <= i <= 399:
    ans_array[0] =  1
  elif 400 <= i <= 799:
    ans_array[1] =  1
  elif 800 <= i <= 1199:
    ans_array[2] =  1
  elif 1200 <= i <= 1599:
    ans_array[3] =  1
  elif 1600 <= i <= 1999:
    ans_array[4] =  1
  elif 2000 <= i <= 2399:
    ans_array[5] =  1
  elif 2400 <= i <= 2799:
    ans_array[6] =  1
  elif 2800 <= i <= 3199:
    ans_array[7] =  1
  else:
    upper_num += 1
    
min_num = max(sum(ans_array),1)
max_num = sum(ans_array) + upper_num

print(min_num, max_num)

Measured memory_bytes: 3064
#include<iostream>
#include<functional>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

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

	if (A <= B) {
		cout << A << endl;
	}
	else {
		cout << A-1 << endl;
	}

	

	
	return 0;
}


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

vector<pi> pts;

int main()
{
  int n,k;cin>>n>>k;
  for(int i=0;i<n;i++)
    {
      int x,y;cin>>x>>y;
      pts.push_back({x,y});
    }
  ll res=0;
  sort(pts.begin(),pts.end());
  for(int xlo=0;xlo<n;xlo++)
    for(int xhi=xlo;xhi<n;xhi++)
      {
	ll h = pts[xhi].first - pts[xlo].first;
	vector<int> todo;
	for(auto p : pts)
	  if(p.first>=pts[xlo].first && p.first<=pts[xhi].first)
	    todo.push_back(p.second);
	sort(todo.begin(),todo.end(),greater<int>());
	deque<int> deq;
	while(!todo.empty())
	  {
	    deq.push_back(todo.back());
	    todo.pop_back();
	    if(deq.size()>k)deq.pop_front();
	    if(deq.size()==k)
	      {
		ll w = abs(deq.back()-deq.front());
		if(!res || w*h<res){
		  res=w*h;
		}
	      }
	  }
      }
  cout<<res<<endl;
  return 0;
}


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

int main() {
  vector<vector<int>>data(3,vector<int>(3));
  vector<vector<bool>>ans(3,vector<bool>(3,false));
  for(int i = 0;i < 3;i++){
    for(int j = 0;j < 3;j++){
      cin >> data[i][j];
    }
  }
  int n;
  cin >> n;
  for(int i = 0;i < n;i++){
    int b;
    cin >> b;
    for(int j = 0;j < 3;j++){
      for(int k = 0;k < 3;k++){
        if(b == data[j][k]) ans[j][k] = true;
      }
    }
  }
  bool flag = false;
  if(ans[0][0]&&(ans[0][1]&&ans[0][2])){
    flag = true;
  }
  else if(ans[1][0]&&(ans[1][1]&&ans[1][2])){
    flag = true;
  }
  else if(ans[2][0]&&(ans[2][1]&ans[2][2])){
    flag = true;
  }
  else if(ans[0][0]&&(ans[1][0]&&ans[2][0])){
    flag = true;
  }
  else if(ans[0][1]&&(ans[1][1]&&ans[2][1])){
    flag = true;
  }
  else if(ans[0][2]&&(ans[1][2]&&ans[2][2])){
    flag = true;
  }
  else if(ans[0][0]&&(ans[1][1]&&ans[2][2])){
    flag = true;
  }
  else if(ans[2][0]&&(ans[1][1]&&ans[0][2])){
    flag = true;
  }
  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
import Control.Applicative
import Control.Monad

shapingData :: String -> [[Int]]
shapingData = map (map read . words) . takeWhile ( /= "0 0") . lines

addReturn :: String -> String
addReturn x = x ++ "\n"

makeFrame :: [Int] -> String
makeFrame all@[h, w] = unlines $ [replicate w '#'] ++ makeContents all ++ [replicate w '#'] 

makeContents :: [Int] -> [String]
makeContents [h, w] = replicate (h-2) $ makeLine w

makeLine :: Int -> String
makeLine w = "#" ++ replicate (w-2) '.' ++ "#"

main = do
    line <- getContents
    mapM_ putStrLn (map makeFrame (shapingData line))


Measured memory_bytes: 4240
N = int(input())
A = [input() for _ in range(N)]

n = 0
Acount, Bcount,both = 0,0,0
for a in A:
    n += a.count("AB")
    if (a[0]=="B")&(a[-1]=="A"):both+=1
    elif a[0] == "B":Bcount+=1
    elif a[-1] == "A":Acount+=1

# print(n,Acount,Bcount,both)
n += min(Acount,Bcount)
if Acount+Bcount>0:n += both
elif both>0:n += both-1
print(n)


Measured memory_bytes: 9788
#include<iostream>
main(){int n,m,i,a,c[1000001];for(std::string s;std::cin>>n>>m>>s,n;printf("%d\n",a))for(a=0,i=m;--i;a+=c[i]>=n)c[i]=s.substr(i,3)=="IOI"?c[i+2]+1:0;}

Measured memory_bytes: 5676
import Control.Applicative
import Control.Monad
 
main :: IO ()
main = do
    x:xs <- getLine
    putStrLn $ solve (filter (/= x) xs)

solve :: String -> String 
solve xs = if length xs == 2 then 
              if head xs == last xs then "Yes"
              else "No"
           else "No"

Measured memory_bytes: 380
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int N, T;
  cin >> N >> T;
  int c[1000], t[1000];
  int min_cost = -1;
  rep(i, N) {
    cin >> c[i] >> t[i];
    if (t[i] > T) continue;
    if (min_cost == -1) min_cost = c[i];
    min_cost = min(min_cost, c[i]);
  }
  if (min_cost == -1) cout << "TLE" << endl;
  else cout << min_cost << endl;
  return 0;
}


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }

  int res = -1;
  int cur = 0;
  int cnt = 0;
  while (true) {
    if (cur == 1) {
      res = cnt;
      break;
    }
    if (cnt >= n) {
      break;
    }
    cur = a[cur];
    cnt++;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

vector<int> init(int size){
  vector<int> par(size,-1);
  return par;
}

int root(int x, vector<int>& par){
  if(par[x] < 0){
    return x;
  }else{
    return par[x] = root(par[x],par);
  }
}

bool same(int x, int y, vector<int>& par){
  return root(x, par) == root(y, par);
}

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

int size(int x, vector<int>& par){
  return -par[root(x, par)];
}

int pow(int x, int n){
  if(n == 0)return 1;
  if(n % 2 == 0)return pow(x * x % MOD, n/2);
  else return x * pow(x, n-1) % MOD;
}

int n;vector<int> v[110000];int c[110000],ans[110000];pair<int,int> dig[110000];
int cind,ansM;

void f(int ver){
  //cout << "ver : " << ver << endl;
  vector<int> next;
  for(int nver : v[ver]){
    if(ans[nver] != -1)continue;
  //cout << "nver : " << nver << " " << cind << endl;
    next.push_back(nver);
    ans[nver] = c[cind];
    ansM += c[cind];
    cind++;
  }
  for(int nver : next){
    f(nver);
  }
}
signed main(){
  int n,m;cin>>n>>m;int dp[110000];rep(i,110000)dp[i] = 0;
  bool a[110000];rep(i,110000)a[i] = true;
  rep(i,m){
    int aa;cin>>aa;a[aa] = false;
  }
  dp[0] = 1;dp[1] = 1;
  if(!a[1])dp[1] = 0;
  repd(i,2,n+1){
    if(!a[i])dp[i] = 0;
    else dp[i] = (dp[i-1]+dp[i-2])%MOD;
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 5248
#include <stdio.h>

int n, T;

int Binary_Search(int a[],int key) {
    int left = 0;
    int right = n;
    while (left < right) {
        int mid = (left + right) / 2;
        if (a[mid] == key) {
            return 1;
        } else if (key < a[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    return 0;
}

int main() {
    scanf("%d",&n);
    int a[n+1];
    for (int i = 0; i < n; ++i) {
        scanf("%d",&a[i]);
    }
    scanf("%d",&T);
    int b;
    int ans=0;
    for (int i = 0; i < T; ++i) {
        scanf("%d",&b);
        if (Binary_Search(a,b)) ans++;
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 2148
from numba import jit
N = int(input())

"""nを素因数分解"""
"""2以上の整数n => [(素因数, 指数), ...]の2次元リスト"""
@jit
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(n**0.5)+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

li = factorization(N)
ans = 0
for i in li:
    k = i[1]
    loop = 1
    while True:
        k -= loop
        if k>=0:
            ans += 1
        else:
            break
        loop += 1
if N==1:
    print(0)
else:
    print(ans)
        

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

class Progaram
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var n = l[0]; var m = l[1];
        var res = 0;
        res += (n * (n - 1)) / 2;
        res += (m * (m - 1)) / 2;
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 13396
class Main{public static void main(String[]z)throws Exception{byte[]b=new byte[81],c=b.clone();System.in.read(b);String s="";int t,j,i,x;for(t=0;t++<3;b=c.clone())for(s+=t*90+"\n",j=-1;j++<7;s+="\n")for(i=8;i-->0;s+=(char)c[x])c[x=j*9+7-i]=b[i*9+j];System.out.print(s);}}

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

int ans[1000000];

char check(int a, int b, int c) {
	if((a == c) ^ b) return 'o';
	return 'x';
}

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

	int N;
	string s;
	cin >> N >> s;

	for(int i = 0; i < 2; i++) {
		for(int j = 0; j < 2; j++) {
			for(int k = 0; k < 2; k++) {
				ans[0] = i;
				ans[1] = j;
				ans[2] = k;
				if(check(i, j, k) == s[1]) {
					for(int l = 2; l < N - 1; l++) {
						if(check(ans[l - 1], ans[l], 0) == s[l]) ans[l + 1] = 0;
						else ans[l + 1] = 1;
					}
					if(check(ans[N - 2], ans[N - 1], ans[0]) == s[N - 1] &&
					   check(ans[N - 1], ans[0], ans[1]) == s[0]) {
						for(int l = 0; l < N; l++) {
							if(ans[l] == 0) cout << 'S';
							else cout << 'W';
						}
						cout << endl;
						return 0;
					}
				}

			}
		}
	}
	cout << -1 << endl;
}

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

int main (void) {
    long int K, a = 7;
    scanf("%ld", &K);
    for (long long int i = 1; i <= K; i++) {
        if (a % K == 0) {
            printf("%lld\n", i);
            return 0;
        }
        a = 10 * (a % K) + 7;
    }
    printf("-1\n");
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <numeric>

int main()
{
	int n;
	std::cin >> n;
	
	for (int i = 3; i < n+1; ++i)
	{
		if (i % 3 == 0 || std::to_string(i).find("3") != std::string::npos)
		{
			std::cout << " " << i;
		}
	}
	std::cout << std::endl;

	return 0;
}


Measured memory_bytes: 3268
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N,K; cin >> N>>K;
    vector<int>h(N);
    int ans = 0;
    rep(i, N) {
        cin >> h[i];
        if (K <= h[i])ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}




int atcoder(){
  string b;
  cin>>b;
  string x;
  if(b=="A"){x="T";}
  if(b=="T"){x="A";}
  if(b=="C"){x="G";}
  if(b=="G"){x="C";}
	cout<<x<<endl;
    return 0;
}


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




Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i=0; i < (n); i++)
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    rep(i,n) cin >> a[i];
    int count = 0;
    if(k >= n) cout << 1 << endl;
    else{
        n -= k;
        count++;
        while (n > 0){
            n -= k-1;
            count++;
        }
        cout << count << endl;
    }
    return 0;
}

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

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

int main(){
    int n, k;
    cin >> n >> k;
    int h[n];
    rep(i,n) cin >> h[i];
    vector<int> dp(n,1001001001);
    dp[0]=0;

    rep(i,n){
        rep1(j,k){
            if(i+j>=n) break;
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
            //cout << i+j << ":" << dp[i+j] << endl;
        }
    }
    //rep(i,n) cout << dp[i] << endl;
    cout << dp[n-1] << "\n";

}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
int dp[100000][3];
int rec(int mat[][3],int n,int p,int r)
{
	if(r>=n)
		return 0;
	
	int mx=0;
	for(int i=0;i<3;i++)
	{
		if(dp[r][i]==-1)
			dp[r][i]=rec(mat,n,i,r+1)+mat[r][i];
		if(i!=p)
			mx=max(mx,dp[r][i]);
	}
	return mx;
	
}
int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
	ll T=1;
//	cin>>T;
	while(T--)
	{
		int x,n;
		cin>>x>>n;
		vll v(n);
		for(int i=0;i<n;i++)
			cin>>v[i];
		sort(all(v));
		int res=x;
		int diff=INT_MAX;
		for(int i=0;i<=101;i++)
		{
			if(!binary_search(all(v),i))
			{
				if(diff>abs(x-i))
				{
					diff=abs(x-i);
					res=i;
				}
			}
		}
		cout<<res<<endl;
		
		
		
	
	}
	return 0;
}





Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<iomanip>
using namespace std;

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

    long x=A*B;
    if(A<B){
        int n=A;
        A=B;
        B=n;
    }
    int r=A%B;
    while(r!=0){
        A=B;
        B=r;
        r=A%B;
    }
    cout<<x/B<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    static String jadg(int n){
        for(int i = 1; i <= 9; i++){
            for(int j = 1; j <= 9; j++){
                if(n == i * j){
                    return "Yes";
                }
            }
        }
        return "No";
    }

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();

        String ans = jadg(n);

        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define maxn 100000
int a[maxn+5];
int main(){
	int n,k,q,x;scanf("%d%d%d",&n,&k,&q);
	k=q-k+1;
	for(int i=0;i<q;i++)scanf("%d",&x),a[x]++;
	for(int i=1;i<=n;i++)if(a[i]>=k)puts("Yes");else puts("No");
	return 0;
}

Measured memory_bytes: 1024
function main(input) {
    const args = input.split(' ');
    const a = parseInt(args[0], 10);
    const b = parseInt(args[1], 10);
  if(a*b%2==0){
    console.log("Even"); 
  }else{
    console.log("Odd"); 
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] A = new int[N+1];
            for (var i = 0; i < N; i++)
            {
                int o = int.Parse(input[i]);
                A[o] = i+1;
            }
            for (var i = 1; i <= N; i++)
            {
                Console.Write(A[i]+" ");
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 26712
#include <iostream>
#include <stdlib.h>
using namespace std;

int find(long k,long* A,int n);

int main(void){
  int n;
  cin>>n;
  long A[n];
  for(long i=0;i<n;i++){
    cin>>A[i];
  }

  int m;
  cin>>m;
  long k;
  int retval=0;
  for(int i=0;i<m;i++){
    cin>>k;
    retval+=find(k,A,n);
  }
  if(retval==m){
    cout<<1<<endl;
  }
  else{
    cout<<0<<endl;
  }
}

int find(long k, long* A,int n){
  long low = 0;
  long high = n-1;
  long mid;
  while (high-low>10){
    mid = (high+low)/2;
    if(A[mid]>k){
      high=mid;
    }
    else{
      low=mid;
    }
  }

  for(long i=low;i<=high;i++){
    if(A[i]==k){
      return 1;
    }
  }
  return 0;
}



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

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 1e6 + 5, A = 26;
int to[N][A], a[N], ct[N][A];
string s[N];
int cv = 1;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> s[i];
        a[i] = i;
    }

    sort(a, a + n, [](const int &x, const int &y) {
        return s[x].size() < s[y].size();
    });

    memset(to, -1, sizeof(to));

    int first_occ[A];

    ll ans = 0;

    for (int i = 0; i < n; i++) {
        fill(first_occ, first_occ + A, -1);
        int ind = a[i];

        for (int j = s[ind].size() - 1; j >= 0; j--) {
            first_occ[s[ind][j] - 'a'] = j;
        }

        // if (i == 4)
        //     cout << first_occ[1] << "\n";

        int v = 0;
        for (int j = s[ind].size() - 1; j >= -1; j--) {
            if (v == -1)
                break;

            for (int k = 0; k < A; k++) {
                if (first_occ[k] != -1 && first_occ[k] <= j) {
                    // if (i == 4)
                    //     cout << v << " " << k << " " << ct[v][k] << "\n";
                    // if (i == 1)
                    
                    ans += ct[v][k];
                }
            }

            if (j == -1)
                break;

            v = to[v][s[ind][j] - 'a'];
        }

        v = 0;
        for (int j = s[ind].size() - 1; j > 0; j--) {
            int c = s[ind][j] - 'a';
            if (to[v][c] == -1) {
                to[v][c] = cv++;
            }
            v = to[v][c];
        }

        ct[v][s[ind][0] - 'a']++;

        // cout << ans << "\n";
    }

    cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 190872
#include<stdio.h>

int  scan_sentence(char * str, int length_max);
void count_alphabet(char * str, int * num_check, int length);
void print_result(int * num_check);

int main(){

	int length;
	char str[1200];
	int num_check[26];
	int i;
	
	for(i = 0;i < 1200;i++){
		str[i] = 0;
	}
	for(i = 0;i < 26;i++){
		num_check[i] = 0;
	}
	
	length = scan_sentence(str, 1200);
	
	count_alphabet(str, num_check, length);
	
	print_result(num_check);
	
	return 0;
}

int scan_sentence(char * str, int length_max)
{
	int count_text = 0;
	int i;

	for(i = 0;i < length_max;i++){
		scanf("%c", str + i);
		if(*(str + i) == EOF){
			break;
		}
		count_text++;
	}

	return count_text;
}

void count_alphabet(char * str, int * num_check, int length)
{
	int i;
	char alphabet;
	for(i = 0;i < length;i++){
		if(((65 <= *(str + i)) && (*(str + i) <= 90)) || ((97 <= *(str + i)) && (*(str + i) <= 122))){
			alphabet = *(str + i) & 0x1F;
			*(num_check + (alphabet - 1)) += 1;
		}
	}
}

void print_result(int * num_check)
{
	int i;
	for(i = 0;i < 26;i++){
		printf("%c : %d\n", (i + 97), *(num_check + i));
	}
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    string ans = "APPROVED";
    REP(i,N){
        if(A[i] % 2 == 0){
            if(A[i] % 3 == 0 || A[i] % 5 == 0) continue;
            else ans = "DENIED";
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
#define ll long long int
#define gc getchar_unlocked
#define pc putchar_unlocked
const long long int size=1000003;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#ifdef _WIN32
// no getchar_unlocked on Windows so call _getchar_nolock
inline int gc() { return getchar(); }
inline int pc(ll n) { return putchar(n);}
#endif
// //ll f[size];
// vector<bool>isPrime(size,1);
// //bool isPrime[size];
// ll p[size];
// void fact()
// {f[0] = 1;ll i = 1;while(i<size){f[i] = f[i-1]*i;f[i] = f[i]%MOD;i++;}}
// //use when mod is prime no
// ll fast_pow(ll a,ll n)
// {ll result = 1;while(n>0){if(n&1){result = result*a;result = result%MOD;}a = (a*a)   %MOD;n/= 2;}return result;}
// ll inv(ll x)
// {return fast_pow(x,MOD-2);}
// void sieve()
// {//for(ll i = 0; i <= size;++i) {isPrime[i] = true;}
// isPrime[0] = false;isPrime[1] = false;
// for(ll i = 2; i * i <= size; ++i) {if(isPrime[i] == true) {
// for(ll j = i * i; j <= size ;j += i)isPrime[j] = false;}}

//  p[1]=0;p[0]=0;
//     for(ll i=2;i<=size-1;i++)
//     {
//         if(isPrime[i])
//         p[i]=i+p[i-1];
//         else
//         p[i]=p[i-1];
//     }
// }
// vector<ll> factorize(ll n) {vector<ll> res;
// for (ll i = 2; i * i <= n; ++i) {while (n % i == 0) {res.push_back(i);n /= i;}}
// if (n != 1) {res.push_back(n);}return res;}
ll phi(ll n)
{
	ll result = n;
	for (ll p = 2; p * p <= n; ++p) {
		if (n % p == 0) {
			while (n % p == 0)
				n /= p;
			result -= result / p;
		}
	}
	if (n > 1)
		result -= result / n;
	return result;
}
inline void in(ll &x)
{
	register char c = gc();
	while(c<'0' || c>'9')
		c = gc();

	x=0;
	while(c>='0' && c<='9')
	{
		x = 10 * x + c - 48;
		c = gc();
	}

}
inline void out( ll &b)
{
	char snum[20];
	ll i=0;
	do
	{
		snum[i++]=b%10+'0';
		b=b/10;
	}while(b);
	i=i-1;

	while (i>=0)
	{
		pc(snum[i--]);
	}
   pc('\n');
}
int main()
{
    string s;cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
    
}

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

#define rep(i, b, e) for(i = b; i < e; ++i)
#define ull unsigned long long int

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, i, j;
    ull s = 0;
    cin >> n;
    vector<int> tako(n);
    rep (i, 0, n) cin >> tako[i];

    rep (i, 0, n - 1)
        rep (j, i + 1, n)
            s += tako[i] * tako[j];

    cout << s;
    
    return 0;
}


Measured memory_bytes: 256
//The Number of Inversions
#include <iostream>
#include <climits>

using namespace std;

long long int cnt = 0;

void merge(int A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1 + 1], R[n2 + 1];
    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] = INT_MAX;
    R[n2] = INT_MAX;
    int l = 0, r = 0;
    for (int i = left; i < right; i++) {
        if (L[l] <= R[r]) A[i] = L[l++];
        else {
            A[i] = R[r++];
            cnt += n1 - l;
        }
    }
}

void mergeSort(int A[], int left, int right) {
    if(right > 1 + left) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main() {
    int n;
    cin >> n;
    int A[n];
    for(int i = 0; i < n; i++) cin >> A[i];

    mergeSort(A, 0, n);

    cout << cnt << endl;
}


Measured memory_bytes: 4640
// https://atcoder.jp/contests/abc150/tasks/abc150_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  VL ps(N);
  VL qs(N);
  rep(i, N) cin >> ps[i];
  rep(i, N) cin >> qs[i];

  VL a(N);
  rep(i, N) a[i] = i + 1;

  ll pi;
  ll qi;

  ll ct = 0;
  do {
    if (a == ps) pi = ct;
    if (a == qs) qi = ct;
    ct++;
  } while (next_permutation(all(a)));

  cout << abs(pi - qi) << endl;
}

struct Fenwick {
  vector<ll> tree;

  Fenwick(ll n) : tree(vector<ll>(n, 0)) {}

  // sum of [0, i)
  ll sum(ll i) {
    ll res = 0;

    for (i--; i >= 0; i = (i & (i + 1)) - 1) {
      res += tree[i];
    }

    return res;
  }

  void add(ll i, ll n) {
    for (ll len = tree.size(); i < len; i |= i + 1) {
      tree[i] += n;
    }
  }
};

void solve2() {
  ll N;
  cin >> N;

  VL ps(N);
  VL qs(N);
  rep(i, N) cin >> ps[i];
  rep(i, N) cin >> qs[i];

  auto fact = [](ll a) -> ll {
    ll res = 1;

    while (a > 0) {
      res *= a;
      a--;
    }

    return res;
  };

  auto get_index = [&](VL& vs) -> ll {
    ll smaller_ct = 0;

    Fenwick bit(N + 1);

    rep(i, N) {
      ll v = vs[i];
      ll rest_ct = N - i - 1;
      ll used_smaller_num_ct = bit.sum(v);
      smaller_ct += (v - 1 - used_smaller_num_ct) * fact(rest_ct);
      bit.add(v, 1);
    }

    return smaller_ct;
  };

  cout << abs(get_index(ps) - get_index(qs)) << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve2();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
      using namespace std;
      #define ll long long
      #define pb push_back
      #define pll  pair <long long,long long>
      #define mp make_pair
      #define ss second
      #define ff first
      #define maa 1000000007
      #define endl '\n'
      #define ld long double
      #define all(x) x.begin(),x.end()
      ll  power(ll  i,ll  j)
      {
        if(j==0)
        return 1 ;
        ll t=power(i,j/2)%maa ;
        if(j%2==0)
        return (t%maa*t%maa)%maa ;
        else
        return ((t%maa*t%maa)%maa*(i%maa)%maa)%maa ;
      }
      bool is(ll  i)
      {
        if(i==1)
            return 0 ;
        ll  f=0 ;
        for(ll  j=2;j<=sqrt(i);j++)
        {
            if(i%j==0)
            {
                f=1 ;
                break ;
            }
        }
        return !f ;
      }
      int main()
      {

        /// 50-4
        /// freopen("input.txt","r",stdin);
        /// freopen("output.txt","w",stdout);
        ll n ;
        cin>>n ;
        ll r[n][n] ;
        for(ll i=0;i<n;i++)
        {
            for(ll j=0;j<n;j++)
            cin>>r[i][j] ;
        }
        ll dp[(1<<n)] ;
        memset(dp,0,sizeof(dp)) ;
        dp[0]=1 ;
        for(ll i=0;i<n;i++)
        {
            for(ll mask=0;mask<(1<<n);mask++)
            {
                bitset<30>bb(mask) ;
                if(bb.count()!=i)
                continue ;
                
                for(ll j=0;j<n;j++)
                {
                    if(r[i][j]==1&&((mask&(1<<j))==0))
                    {
                        //cout<<dp[mask]<<" "<<dp[mask|(1<<j)]<<endl;
                        dp[mask|(1<<j)]+=dp[mask] ;
                        dp[mask|(1<<j)]%=maa ;
                    }
                }
            }
        }
        cout<<dp[(1<<n)-1]%maa ;
       
        
        

      }








Measured memory_bytes: 16640
// Problem : B - 1%
// Contest : AtCoder - AtCoder Beginner Contest 165
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
#define pb push_back
#define PI acos(-1.0)
#define EPS 1e-4
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fout(S,x)            cout<<fixed<<setprecision(x)<<(S)<<endl
#define present(c,x) ((c).find(x) != (c).end())
#define T() ll t;cin>>t;while(t--)
#define mem(input,b) memset(input,b,sizeof(input))
#define ff first
#define ss second
#define fread(input) freopen("input","r",stdin)
#define fwrite(b) freopen("b","w",stdout)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define FOREACH(i,c) for (__typeof ((c).begin()) i = (c).begin() ; i != (c).end() ; i++)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int main(){
    fastio;
    ll init = 100;
    ll x;
    cin>>x;
    int cnt = 0;
    while(init<x){
    	init += init/100;
    	cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}    


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

char map1[60][60];
int from[60][60];
typedef pair <int, int> P;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

void bfs(P s){
    deque <P> todo{s};
    map1[s.first][s.second] = 'c';
    while(!todo.empty()){
        P now = todo.front();
        todo.pop_front();
        for(int k = 0;k < 4;++k){
            P next(now.first + dx[k], now.second + dy[k]);
            if(map1[next.first][next.second] == '.'){
                map1[next.first][next.second] = 'c';
                from[next.first][next.second] = k;
                todo.push_back(next);
            }
        }
    }
}

void trackback(P s,P g){
    map1[g.first][g.second] = 'p';
    P now(g);
    while(now != s){
        int k = from[now.first][now.second];
        now = P(now.first - dx[k], now.second - dy[k]);
        map1[now.first][now.second] = 'p';
    }
}

int main(){
    int H,W;
    int count = 0;
    cin >> H >> W;
    for(int i=0;i<60;++i){
        for(int j=0;j<60;++j){
            map1[i][j] = '#';
        }
    }
    for(int i=1;i<=H;++i){
        for(int j=1;j<=W;++j){
            cin >> map1[i][j];
        }
    }
    P s(1,1);
    P g(H,W);
    bfs(s);
    if(map1[g.first][g.second] == 'c'){
        trackback(s,g);
        for(int i=1;i<=H;++i){
            for(int j=1;j<=W;++j){
                if(map1[i][j] == 'c' || map1[i][j] == '.'){
                       count ++;
                }
            }
        }
        cout << count << endl;
    }
    else cout << -1 << endl;
    int a;
    cin >>a;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  
  n=n%10;
  if(n==2 || n==4 || n==5 || n==7||n==9)cout<<"hon"<<endl;
  
  else if(n==0 || n==1 || n==6 || n==8)cout<<"pon"<<endl;
  
  else if(n==3) cout<<"bon"<<endl;
}

Measured memory_bytes: 3596