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

int main()
{
    int i,alphabet_count[30];
    char c;

    for (i = 0; i < 26; i++)alphabet_count[i] = 0;

    while(scanf("%c", &c) != EOF){
     
        if ('a' <= c && c <= 'z') {
            alphabet_count[c - 'a']++;
        }
        else if ('A' <= c && c <= 'Z'){
            alphabet_count[c - 'A']++;
        }
        
    }

    for (i = 0; i < 26; i++) {
        std::cout << char('a'+i) << " : " << alphabet_count[i] << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 3132
local n, m = io.read("*n", "*n", "*l")
local s = io.read()
local v = {}
local edge = {}
local acnt, bcnt = {}, {}
for i = 1, n do
  v[i] = s:byte(i) - 64
  edge[i] = {}
  acnt[i], bcnt[i] = 0, 0
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  table.insert(edge[a], b)
  table.insert(edge[b], a)
  if v[a] == 1 then
    acnt[b] = acnt[b] + 1
  else
    bcnt[b] = bcnt[b] + 1
  end
  if v[b] == 1 then
    acnt[a] = acnt[a] + 1
  else
    bcnt[a] = bcnt[a] + 1
  end
end
local tasks = {}
for i = 1, n do
  if acnt[i] * bcnt[i] == 0 then
    table.insert(tasks, i)
  end
end
local done = 0
while done < #tasks do
  done = done + 1
  local src = tasks[done]
  local cnttbl = v[src] == 1 and acnt or bcnt
  for j = 1, #edge[src] do
    local dst = edge[src][j]
    if 0 < acnt[dst] and 0 < bcnt[dst] then
      cnttbl[dst] = cnttbl[dst] - 1
      if cnttbl[dst] == 0 then
        table.insert(tasks, dst)
      end
    end
  end
end
print(#tasks == n and "No" or "Yes")


Measured memory_bytes: 27268
#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <time.h>
#include <cstdio>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */
int main(void)
{
  int test = 1;
  int i,j,k,l;
  int n;
  int min = INT_MAX;
  int rep = INT_MIN;
  static int a[200005];
  scanf("%d",&n);
  rep(i,n) {
    scanf("%d",&a[i]);
    if(a[i] - min > rep) rep = a[i] - min;
    if(min > a[i]) min = a[i];
  }
  printf("%d\n",rep);
  return 0;
}

Measured memory_bytes: 3980
#include<stdio.h>
int main(){

  int a,b;
  scanf("%d %d", &a, &b);

  if ( a < b ){
    printf("a < b\n");
  } else if ( a > b ){
    printf("a > b\n");
  } else {
    printf("a == b\n");
  }

  return 0;

}

Measured memory_bytes: 580
package main

import (
	"fmt"
	"math"
	"strings"
)

// 文字列 S に 0 も 1 も 1 つ以上残っている場合、どこかで 0 と 1 が隣り合っています。従って、与えら
// れた文字列 S に含まれる 0 の個数と 1 の個数を数え、それぞれ C0, C1 とすると、どのような順番で取り
// 除いても min(C0, C1) 回取り除く操作ができます。よって、答え (取り除けるキューブの個数の最大値) は
// 2 × min(C0, C1) になります。このアルゴリズムは O(|S|) で動作します。

func main() {
	s := SingleStr()
	ss := strings.Split(s, "")

	var oneC, zeroC int
	for _, item := range ss {
		if item == "0" {
			zeroC++
		} else {
			oneC++
		}
	}

	if zeroC == len(ss) || oneC == len(ss) {
		fmt.Println(0)
		return
	}

	fmt.Println(Min(oneC, zeroC) * 2)
}

func SingleStr() string {
	var s string
	fmt.Scan(&s)
	return s
}

func Min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 2944
def main():
    #N,K=map(int,input().split())
    N=int(input())
    A=list(map(int,input().split()))
    t=[A[0]]
    bef=A[0]
    flag=1
    for i in range(1,N):
        if flag==1:
            if bef > A[i]:
                t.append(bef)
                bef=A[i]
                flag=-1
            else:
                bef=A[i]
        elif flag==-1:
            if bef < A[i]:
                t.append(bef)
                bef=A[i]
                flag=1
            else:
                bef=A[i]
    if flag==1:
        t.append(bef)
    money=1000
    while t:
        b=t.pop(0)
        a=t.pop(0)
        cn=money//b
        money=money%b
        money+=cn*a
    print(money)

main()

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

int n, m, vc, ans;
const int MAX = 55;
int A[MAX], B[MAX];
bool used[MAX], G[MAX][MAX];

void dfs(int now){
    used[now] = true;
    for(int i = 0; i < n; i++){
        if(!used[i] && G[now][i]){
            dfs(i);
        }
    }
    return;
}

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

    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        G[A[i]][B[i]] = true;
        G[B[i]][A[i]] = true;
    }

    int ans = 0;
    for(int i = 0; i < m; i++){
        G[A[i]][B[i]] = false;
        G[B[i]][A[i]] = false;
        for(int j = 0; j < n; j++){
            used[j] = false;
        }

        dfs(0);

        bool f = true;
        for(int j = 0; j < n; j++){
            if(used[j]);
            else f = false;
        }

        if(!f) ans++;

        G[A[i]][B[i]] = true;
        G[B[i]][A[i]] = true;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,m=0;
	cin>>n;
	vector<int> a(n+1),b(n+1,0);
	rep(i,n){
		cin>>a[i+1];
	}
	for(int i=n;i>=1;i--){
		int cnt=0;
		for(int j=2*i;j<=n;j+=i){
			cnt+=b[j];
		}
		if(cnt%2!=a[i]){
			b[i]=1;
			m++;
		}
	}
	cout<<m<<endl;
	FOR(i,1,n+1){
		if(b[i]) cout<<i<<endl;
	}
}

Measured memory_bytes: 2560
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n, 0);
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int b;
            cin >> b;
            b--;
            a[b]++;
        }
    }
    int ans = 0;
    rep(i, n) {
        if(a[i] == 0)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int gcd(int,int);

ll lcm(int a, int b) {
return (ll)a / gcd(a, b) * (ll)b;
};

int gcd(int a, int b) {
return b ? gcd(b, a%b) : a;
};

int main(){
    int a , b;
    cin >> a >> b;

    cout << lcm(a,b) << endl;





}

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

int main( int argc, char *argv[] )
{
int W;
int a;
int b;
int i;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> W;
	cin >> a;
	cin >> b;

	i = abs( a - b ) - W;
	if( i <= 0 )
		cout << 0 << endl;
	else
		cout << i << endl;

	return 0;
}


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

using namespace std;

int main() {
	int N;
	string s;
	cin >> N >> s;

	string ABC = "ABC";
	int ans = 0;
	for (int i = 0; i + 2 < N; ++i) {
		if (s.substr(i, 3) == ABC) { ++ans; }
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
    int K; cin >> K;
    if (K % 2 == 0) {
        cout << (K / 2) * (K / 2) << endl;
    } else {
        cout << (K / 2 + 1) * (K / 2) << endl;
    }
}


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

#define xx first
#define yy second

typedef pair<int,int> pii;
typedef long long LL;

const int N = 1100;
int vis[N];

void div(int x) {
	for (int i = 2; i * i <= x; i++) if (x % i == 0) {
		while (x % i == 0) {
			vis[i]++;
			x /= i;
		}
	}
	if (x > 1) vis[x]++;
}

const int mod = 1e9 + 7;

int main() {
  //freopen("in", "r", stdin);
  int n;
	cin >> n;
	for (int i = 1; i <= n; i++) div(i);
	LL res = 1;
	for (int i = 2; i < N; i++) (res *= (vis[i] + 1)) %= mod;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <ctime>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#pragma comment(linker, "/STACK:256000000")
using namespace std;

#define in(s) freopen(s, "r", stdin)
#define out(s) freopen(s, "w", stdout)
#define forn(i, n) for (int i = 0; i < n; i++)
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef long double ld;

int main()
{
	//in("input.txt");
	//out("output.txt");
	srand(1373737);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n;
	cin >> n;

	vector < pair<string, int> > arr(n);
	forn(i, n)
		cin >> arr[i].first >> arr[i].second;
	string s;
	cin >> s;

	bool flag = false;
	int ans = 0;
	forn(i, n) {
		if (flag)
			ans += arr[i].second;
		flag |= (s == arr[i].first);
	}
	cout << ans;

	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 1e6 + 5;
const ll mod = 998244353;
ll sum[N];
ll sqsum[N];
ll f[N];
ll inv[N];

ll add(ll x, ll y) {
  x = (x + y);
  if(x >= mod) x -= mod;
  return x;
}

ll sub(ll x, ll y) {
  x = x - y;
  x %= mod;
  if(x < 0) x += mod;
  return x;
}

ll mult(ll x, ll y) {
  x = (x * y) % mod;
  if(x < 0) x += mod;
  return x;
}

ll get(int x) {
  return sub(mult(sum[x], sum[x]), sqsum[x]);
}

ll bigmod(ll a, ll b) {
  ll res = 1LL;
  while(b) {
    if(b & 1LL) res = mult(res, a);
    b >>= 1LL;
    a = mult(a, a);
  }
  return res;
}

int main() {
  for(ll i = 1; i < N; i++) {
    inv[i] = bigmod(i, mod - 2);
  }
  int n; scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    ll x;
    scanf("%lld", &x);
    sum[x] = add(sum[x], x);
    sqsum[x] = add(sqsum[x], mult(x, x));
    //cout << sum[x] << ' ' << sqsum[x] << '\n';
  }
  for(int i = 1; i < N; i++) {
    for(int j = i + i; j < N; j += i) {
      sum[i] = add(sum[i], sum[j]);
      sqsum[i] = add(sqsum[i], sqsum[j]);
    }
    f[i] = get(i);
  }
  ll sum = 0;
  for(int i = N - 1; i >= 1; i--) {
    for(int j = i + i; j < N; j += i) {
      f[i] = sub(f[i], f[j]);
    }
    sum = add(sum, mult(f[i], inv[i]));
  }
  sum = mult(sum, inv[2]);
  printf("%lld\n", sum);
}

Measured memory_bytes: 31488
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

N = int(input())
S = input()

ans = []
for c in S:
    hoge = ((ord(c) - ord("A") + N) % 26) + ord("A")
    ans.append(chr(hoge))

print("".join(ans))


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

int main() {
    int n, m;
    cin >> n;
    int t[n];
    int sum = 0;
    rep(i, n) cin >> t[i];
    rep(i, n) sum += t[i];
    cin >> m;

    rep(i, m) {
        int p, x;
        cin >> p >> x;
        p--;

        int time = sum - t[p];
        cout << time + x << endl;
    }

    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int N;
  cin>>N;

  cout << 800*N - 200*(N/15) <<"\n";
}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

int f(int x) {
    if (x == 0) return 0;
    return f(x % __builtin_popcount(x)) + 1;
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> x(n);
    rep(i, n) x[i] = s[i] - '0';

    int p = 0;
    vector<int> ans(n);
    rep(i, n) p += x[i];

    rep(b, 2) {
        int np = p;
        b == 0 ? np++ : np--;
        if (np <= 0) continue;

        int r0 = 0;
        rep(i, n) {
            r0 = (r0 * 2) % np;
            r0 += x[i];
        }

        int k = 1;
        for (int i = n - 1; i >= 0; i--) {
            if (x[i] == b) {
                int r = r0;
                if (b == 0)
                    r = (r + k) % np;
                else
                    r = (r - k + np) % np;
                ans[i] = f(r) + 1;
            }
            k = (k * 2) % np;
        }
    }

    rep(i, n) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 5148
#include<cstdio>
#include<algorithm>
#include<queue>
const int MAXN = 2e5 + 5;
using namespace std;

struct Node
{
	int l,r;
	friend bool operator < (const Node &a,const Node &b){ return a.r>b.r;}
}a[MAXN],b[MAXN];
int bcnt=0;
inline bool cmp(Node a,Node b){ return a.l<b.l;}

bool vis[MAXN];
priority_queue<Node> q;

int main(void)
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; ++i) scanf("%d%d",&a[i].l,&a[i].r);
	
	sort(a+1,a+n+1,cmp);
	for(int i=1, cnt=0; i<=n; ++i)
	{
		q.push(a[i]);
		if(cnt >= a[i].l)
			b[++bcnt] = q.top(),
			q.pop();
		else
		{
			++cnt;
			if(cnt>m)
			{
				for(; i<=m; ++i) b[++bcnt]=a[i];
				break;
			}
			vis[cnt]=1;
		}
	}
	
	sort(b+1,b+bcnt+1);
	int ans=0;
	for(int i=1, cnt=0; i<=bcnt; ++i)
	{
		if(cnt > m-b[i].r) ++ans;
		else
		{
			++cnt;
			if(vis[m-cnt+1] || m-cnt+1 < 1)
			{
				ans += bcnt-i+1;
				break;
			}
			vis[m-cnt+1]=1;
		}
	}
	
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 4468
#include<iostream>

using namespace std;

typedef long long llint;

const int MAXN = 55;

llint n, sol;
llint l[MAXN], d[MAXN];

void f () {
	llint sum=0;
	for (int i=0; i<n; i++) {
		d[i]=l[i]/n;
		sol+=d[i];
		sum+=d[i];
		l[i]%=n;
	}
	for (int i=0; i<n; i++) {
		l[i]+=sum-d[i];
	}
}

bool ok () {
	for (int i=0; i<n; i++) {
		if (l[i]>=n) return 0;
	}
	return 1;
}

int main () {
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> l[i];
	}
	while (!ok()) f();
	cout << sol;
	return 0;
}

Measured memory_bytes: 256
s = list(map(int,list(input())))

counter = 0
if len(s) == 1:
    print(0)
else:
    for i in range(1,len(s)):
        if s[i] == s[i-1]:
            s[i] = int(int(s[i-1]) ==  0)
            counter += 1
    print(counter)

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

int main(void){
    int n,x=0,ans=0;
    string s;
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='I'){
            x ++;
            ans = max(ans,x);
        }else{
            x --;
        }
    }
    cout<<ans<<endl;
}

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


using namespace std;
int main()
{
    long int N, M, a, ans = 0;
    cin >> N >> M;
    priority_queue<int> q;

    for(int i=0;i<N;i++){
        cin >> a;
        q.push(a);
    }

    while (M != 0) {
        a = q.top();
        q.pop();
        a /= 2;
        q.push(a);
        M--;
    }

    while (!q.empty()) {
        ans += q.top();
        q.pop();
    }

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

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;

int x[100001],a[100001],n,q,sum[100001],tmp;
vector<int> v;
int cf;
int main(void){
    string str;
    cin>>str;
    rep(i,str.size()){
        rep(j,str.size()){
            if(i>j)continue;
            //cout<<str.substr(0,i)+str.substr(j,str.size())<<endl;
            if(str.substr(0,i)+str.substr(j,str.size())=="keyence"){cout<<"YES"<<endl;return 0;}
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


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

using namespace std;
using ll=long long;

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cint int t;cin>>t;while(t--)
#define rep(i,a,b) for(int i=a;i<b;i++)

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

    set<int> s;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(s.find(x)==s.end()) s.insert(x);
        else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int a; cin >> a;
	cout << (a + (a * a) + (a * a * a)) << endl;
	return;
}
int main() {
	solve();
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

ll n, b, base;

int main() {
    string ans = "";
    cin >> n;
    base = 2;
    if (n == 0) {
        cout << 0 << endl;
        exit(0);
    }

    while (n) {
        if (n % base) {
            ans = '1' + ans;
            ll v = pow(2, b);
            if (b & 1) {
                n += v;
            } else {
                n -= v;
            }
        } else {
            ans = '0' + ans;
        }
        ++b;
        base *= 2;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4000
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//あー結局わからない

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), M = getint();

	ll lcm = getint();

	bool dame = 0;
	ll a, g, bai;

	rep1(i, N - 1) {
		a = getint();
		g = __gcd(lcm, a);
		bai = a / g;
		if (lcm > 2e9 || !(bai & lcm / g & 1)) {
			dame = 1;
			break;
		}
		lcm = lcm * bai;
	}

	if (dame) printf("0\n");
	else {
		ll kotae = (lcm / 2 + M) / lcm;
		printf("%lld\n", kotae);
	}

	Would you please return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
 int H,W;
  cin>>H>>W;
  vector<string> a(H); 
  int i;
  for(i=0;i<H;i++){
      cin>>a.at(i);
  }
  for(i=0;i<W+2;i++){
  cout<<'#';
  }
  cout<<endl;
  for(i=0;i<H;i++) cout<<'#'<<a.at(i)<<'#'<<endl;
  for(i=0;i<W+2;i++){
  cout<<'#';
  }
  cout<<endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
string s,a,b,c;
int r;
int main()
{
	cin>>s;
	a=s;
	b=s;
	c=s;
	for(int q=0;q<a.size();q++)
	   {
	   	if(a[q]=='b')a[q]='d';
	   	if(a[q]=='p')a[q]='q';
	   	if(a[q]=='q')a[q]='p';
	   	if(a[q]=='d')a[q]='b';
	   	b[a.size()-1-q]=s[q];
	   }
	for(int q=0;q<a.size();q++)
	{
		if(b[q]=='b')c[q]='d';
	   	if(b[q]=='p')c[q]='q';
	   	if(b[q]=='q')c[q]='p';
	   	if(b[q]=='d')c[q]='b';
	}
	   if(b==s||a==s||c==s)r=1;
	   if(r==1)cout<<"Yes";
	   if(r==0)cout<<"No";
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int col(int n){
  if(n%2)
    return 3*n+1;
  else
    return n/2;
}
int main(){
  int n,s;
  while(true){
  cin>>n;
  if(!n)
    break;
  s = 0;
  while(n!=1){
    n = col(n);
    s++;
  }
  cout<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){

    int N, K;
    cin >> N;
    cin >> K;

    vector<int> h(N);
    for(int i=0; i<N; i++) cin >> h.at(i);

    int ans = 0;
    for(int i=0; i<N; i++){
        if(h.at(i) >= K) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  ans = LINF;
  rep(i, n - 1) {
    cnt += a[i];
    ans = min(ans, abs(cnt - (sum - cnt)));
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 1792
H,W,K = map(int,input().split())

import itertools
from collections import defaultdict
ZO = [0,1]

CHOCO = []
for i in range(H):
    s = input()
    CHOCO.append(s)

ans = 10**16
C = 0

for i in itertools.product(ZO,repeat = H-1):
    saki = 0
    To = defaultdict(int)
    To[0] = saki
    for j in range(H-1):
        if i[j]==0:
            To[j+1] = saki
        else:
            saki += 1
            To[j+1] = saki
    tmpans = saki
    #print(To,tmpans)
    NowWhite = [0]*(saki+1)
    preW = 0
    for w in range(W):
        h = 0
        while 1:
            C+= 1
            #print(NowWhite,h)
            #if C>10000:
              #break
            if CHOCO[h][w] == '1':
                NowWhite[To[h]] += 1
                if NowWhite[To[h]] > K:
                    #print('break')
                    tmpans += 1
                    NowWhite = [0]*(saki+1)
                    h = -1
                    if preW==w:
                        tmpans += 10**16
                        break
                    preW = w
            if h==H-1:
                #print('h==H-1')
                break
            h += 1
    ans = min(ans,tmpans)
print(ans)

Measured memory_bytes: 44380
def LIST():return list(map(int,input().split()))
def MAP():return map(int,input().split())

n,k=MAP()
a=LIST()
a=[0]+a
s=[0]
loca=1
begin=end=0
temp=[-1]*(2*10**5+1)
for i in range(1,n+1):
    s.append(a[loca])
    loca=a[loca]
    if k==i:
        print(s[i])
        exit()
    if temp[loca]==-1:
        temp[loca]=i
    else:
        begin=temp[loca]
        end=i-1
        break

if begin==0:print(s[(k-1)%n+1])
else:
    k=k-(begin-1)
    s=[0]+s[begin:]
    print(s[(k-1)%(end-begin+1)+1])


















Measured memory_bytes: 97488
#include<iostream>
using namespace std;
int main(){
  int n,i,j,k;
  cin >> n;
  while(n!=0){
    int map[101][101]={{}},left[101][101]={{}},right[101][101]={{}};

    for(i=0;i<n;i++)
      for(j=0;j<n;j++) cin >> map[i][j];

    int flag=0,f=0;
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	f=0;
	for(k=0;k<n;k++){
	  if(map[i][j]>map[i][k]) f=1;
	}
	//	cout << f << endl;
	if(f==0){
	  for(k=0;k<n;k++) {
	    if(map[i][j]<map[k][j]) f=1;
	  }
	}
	//	cout << f << endl; 
	if(f==0) {
	  if(flag==0){
	    cout << map[i][j];flag=1;
	  }
	  else {
	  }
	}
      }
    }
    
    
    if(flag==0) cout << 0 ;
    cout << endl;
    cin >> n;
  }
}

Measured memory_bytes: 1204
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var list = myconv(input[1],6);
  var tmpList = [list[0]];
  for(var i = 1; i < list.length; i++){
    var mae = list[i-1];
    var ato = list[i];
    if(mae == ato){
       
       }else{
        tmpList.push(list[i]); 
       }
  }
  myout(tmpList.length);
}

Main(myin());


Measured memory_bytes: 22088
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
 
int main(){
	int q; cin >> q;
	for (int i = 0; i < q; i ++) {
		long long a, b; cin >> a >> b;
		long long root = sqrt(a*b);
		long long ans = root + (a*b-1)/root - (a!=b);
		if (root >= a) ans --;
		if ((a*b-1)/root >= b) ans --;
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
H, W, A, B = map(int,input().split())
S = [1] * A + [0] * (W - A)
T = [0] * A + [1] * (W - A)
s = ""
t = ""
for a in S:
    s += str(a)
for b in T:
    t += str(b)
for _ in range(B):
    print(s)
for _ in range(H - B):
    print(t)

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

int main(){
    int n,ans=0;
    cin >> n;
    vector<int> v(n),c(n);
    for(int i = 0;i < n;i ++){
        cin >> v[i];
    }
    for(int i = 0;i < n;i ++){
        cin >> c[i];
    }
    for(int i = 0;i < n;i ++){
        ans += max(0,v[i]-c[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
    char num[1001];
    int sum, i;
     
    while(1) {
        sum=0;
        scanf("%s", num);
        if(num[0]=='0') break;
        for(i=0; num[i]!='\0'; i++) {
            sum+=num[i]-'0';
        }
    printf("%d\n", sum);
    }
     
    return 0;
}


Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define ALL(v) (v).begin(), (v).end()
#define INF 1000000000000000000

int main(){
    unsigned long long N;
    cin >> N;
    vector<unsigned long long> a(N);
    cin>>a[0];
    unsigned long long ans=a[0];
    rep(i,1,N){
        cin>>a[i];
        if(ans!=0)if(a[i]>INF/ans)ans=INF+2;
        else{ 
            ans*=a[i];
            if(ans>INF)ans=INF+2;
        }
    }
 
    if(ans<=INF)cout << ans << endl;
    else if(ans>INF) cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 4048
import java.util.*;

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

		int N = sc.nextInt();
		int K = sc.nextInt();

		Integer[] Ni = new Integer[N];

		for(int i =0; i<N; i++){
			Ni[i] = 0;
		}

		for(int i =0; i<K; i++){
			int tmpD = sc.nextInt();
			for(int j =0; j<tmpD; j++){
				int target = sc.nextInt();
				Ni[target-1] = 1;
			}
		}

		Integer cnt = 0;
		for(int i =0; i<N; i++){
			if(Ni[i]==0){
				cnt++;
			}
		}

		System.out.println(cnt);
		return;
	}
}


Measured memory_bytes: 46420
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad.State.Strict
import qualified Data.ByteString.Char8      as B
import qualified Data.ByteString.Unsafe     as B
import           Data.Char                  (isSpace)
import qualified Data.Vector.Unboxed        as V

main :: IO ()
main = do
  n <- readLn
  txys <- V.unfoldrN n parseInt3 <$> B.getContents
  putStrLn $ if solve n txys then "Yes" else "No"

solve :: Int -> V.Vector (Int, Int, Int) -> Bool
solve _ txys = V.all travelable $ V.zip ((0, 0, 0) `V.cons` txys) txys

travelable :: ((Int, Int, Int), (Int, Int, Int)) -> Bool
travelable ((t, x, y), (t', x', y')) = dx + dy <= dt && even (dt - dx - dy) where
  dx = x' - x
  dy = y' - y
  dt = t' - t

type Parser a = B.ByteString -> Maybe (a, B.ByteString)

parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
  (,,) <$> StateT (B.readInt . B.dropWhile isSpace)
  <*> StateT (B.readInt . B.unsafeTail)
  <*> StateT (B.readInt . B.unsafeTail)


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

using ll = long long;

template<class T> ostream &operator <<(ostream &os, const vector<T> &v) {
    for (T x : v) os << x << " ";
    return os;
}

vector<ll> restore(multiset<pair<int, ll>> st) {
    vector<ll> ans;
    int pre = 0;
    for (auto kv : st) {
        for (int i = 0; i < kv.first - pre; i++) {
            ans.push_back(kv.second);
        }
        pre = kv.first;
    }
    return ans;
}

int main() {
    int n, q;
    cin >> n >> q;

    multiset<pair<int, ll>> st; // sum, val
    const ll inf = ll(2e13) + 100;
    st.emplace(0, inf);
    st.emplace(n, 0);

    for (int i = 0; i < q; i++) {
        int a;
        ll b;
        scanf("%d %lld", &a, &b);

        while (b > 0) {
            auto cur = st.lower_bound(make_pair(a, -1));
            auto pre = prev(cur);

            int pre_sum = pre->first;
            int cnt = cur->first - pre->first;
            int front = a - pre->first;
            int back = cnt - front;
            ll val = cur->second;
            ll pre_val = pre->second;

            st.erase(cur);
            st.erase(pre);
            
            if (val + (b + front - 1) / front <= pre_val) {
                ll val0 = val + (b + front - 1) / front;
                ll val1 = val0 - 1;
                int cnt0 = b % front == 0 ? front : b % front;
                int cnt1 = front - cnt0;
                if (val0 < pre_val) {
                    st.emplace(pre_sum, pre_val);
                    if (cnt0 > 0) {
                        st.emplace(pre_sum + cnt0, val0);
                    }
                    if (cnt1 > 0) {
                        st.emplace(pre_sum + cnt0 + cnt1, val1);
                    }
                } else {
                    if (cnt0 > 0) st.emplace(pre_sum + cnt0, pre_val);
                    if (cnt1 > 0) st.emplace(pre_sum + cnt0 + cnt1, val1);
                }
                if (back > 0) st.emplace(pre_sum + cnt0 + cnt1 + back, val);
                b = 0;
            } else {
                b -= (pre_val - val) * front;
                if (front > 0) st.emplace(pre_sum + front, pre_val);
                if (back > 0) st.emplace(pre_sum + front + back, val);
            }
        }
    }

    auto ans = restore(st);
    for (int i = 0; i < ans.size(); i++) {
        printf("%lld\n", ans[i]);
    }
}

Measured memory_bytes: 14836
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;

	vector<int> p(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	sort(p.begin(), p.end());

	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans += p[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3196
n = int(input())
ac, wa, tle, re = 0, 0, 0, 0
for i in range(n):
    s = input()
    if s == "AC":
        ac += 1
    if s == "WA":
        wa += 1
    if s == "TLE":
        tle += 1
    if s == "RE":
        re += 1
print(f"AC x {ac}")
print(f"WA x {wa}")
print(f"TLE x {tle}")
print(f"RE x {re}")

Measured memory_bytes: 9168
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int n;

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while(c>'9'||c<'0')c=getchar();
   	if(c=='-')t=-1,c=getchar();
   	while(c>='0'&&c<='9')s=s*10+c-'0',c=getchar();
   	return s*t;
}

int main(void){
	scanf("%d",&n);
	printf("%d\n",n*n*n);
}

Measured memory_bytes: 128
#include <iostream>
#include <unordered_map>
#include <vector>
#include <cmath>

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


int wini(char c)
{
    if (c == 'r') return 2;
    else if (c == 's') return 0;
    else if (c == 'p') return 1;
    else return 3;
}

int main()
{
    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    int winpoint[] = {R, S, P, 0};

    vi winhands(N);
    for (int i = 0; i < N; i++)
    {
        winhands[i] = wini(T[i]);
    }

    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        if (i >= K && winhands[i-K] == winhands[i]) 
            winhands[i] = 3;

        ans += winpoint[winhands[i]];        
    }

    cout << ans << endl;    
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

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

  ll n; cin >> n;
  ll mn = 1e18;

  rep(i, 5) {
    ll x; cin >> x;
    chmin(mn, x);
  }

  cout << (n + mn - 1) / mn + 4 << endl;

  return (0);
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100005;
const int MOD = 1000000007;
int n, a[NMAX];
long long cnt[NMAX], ans = 1;
 
int main()
{
  	ios::sync_with_stdio(false);
  	cin.tie(0);
	cin >> n;
	for(int i=0;i<n;i++)
      cin >> a[i];
	cnt[0]=3;
	for(int i=0;i<n;i++)
	{
		int k=a[i];
		ans=ans*cnt[k]%MOD;
		cnt[k]--;
		cnt[k+1]++;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(){
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}
	return 0;
}


Measured memory_bytes: 2108
//Δ_C
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
int n,a,b,c,w;
string s;
int main()
{
	int i,j;
	cin>>n;
	for(j=1;j<=n;j=j+1){
		cin>>s;
		for(i=1;i<s.length();i=i+1)
			if(s[i-1]=='A'&&s[i]=='B')
				w++;
		if(s[s.length()-1]=='A'){
			if(s[0]=='B')
				c++;
			else
				a++;
		}
		else{
			if(s[0]=='B')
				b++;
		}
	}
	if(c>=2)
		w+=c-1,c=1;
	if(c){
		if(a&&b)
			w+=2,a--,b--,c--;
		else{
			if(a||b)
				w++;
		}
	}
	cout<<w+min(a,b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
const int maxn = 1000000;
ll mod = INF;


int main(){
    ll n,x,m;
    vector<ll> circle;
    ll ans=0;
    ll start=0;
    bool used[maxn+1];

    cin >> n>>x>>m;
    ll cpx=x;
    for(int i=1;i<=100000;i++){
        //cout << x<<" ";
        if(!used[x]){
            circle.push_back(x);
            used[x]=true;
        }else{
            start=x;
            break;
        }
        x=x*x%m;
    }
    //cout << endl;

    bool flag=false;
    ll headsize=0;
    ll headsum=0;
    ll circlesize=0;
    ll circlesum=0;
    rep(i,circle.size()){
        
        if(circle[i]==x)flag=true;
        if(flag){
            circlesize++;
            circlesum+=circle[i];
        }else{
            headsize++;
            headsum+=circle[i];
        }
    }
    // cout << endl;

    // cout << "circle size,sum= "<<circlesize<<" "<<circlesum<<endl;
    // cout << "head size,sum= "<<headsize<<" "<<headsum<<endl;

    if(headsize>=n){
        x=cpx;
        rep(i,n){
            ans+=x;
            x=x*x%m;
        }
    }else{
        //cout << "check"<<endl;
        ans+=headsum;
        n-=headsize;
        ans+=circlesum*(n/circlesize);
        //cout <<"Yes"<<endl;
        ll rest=n%circlesize;
        x=start;
        rep(i,rest){
            ans+=x;
            x=x*x%m;
        }
    }

    cout << ans<<endl;

    return 0;
}

Measured memory_bytes: 3992
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int c,t[3],i;
    cin>>c;
    while(c--){
        for(i=0;i<3;i++){
        cin>>t[i];
      }
      sort(t,t+3);
      if(t[0]*t[0]+t[1]*t[1]==t[2]*t[2]) {
        cout<<"YES"<<endl;
      }
      else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
		cout << "vowel" << endl;
	} else {
		cout << "consonant" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
P = gets.chomp.split.map(&:to_i)
Q = gets.chomp.split.map(&:to_i)
array = [*1..n]
arr = array.permutation(n).to_a
a=0
b=0
for i in 0..arr.length-1
    if P==arr[i]
        a = i
    end
    if Q==arr[i]
        b = i
    end
end 

puts (a-b).abs

Measured memory_bytes: 6780
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
#define INF (int(1e9) + 1)
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
int N, A, B, C;
vector<int> l;
int rec(int i, int a, int b, int c)
{
    if (i == N)
    {
        if (!a || !b || !c)
            return INF;
        return abs(a - A) + abs(b - B) + abs(c - C);
    }

    int res0 = rec(i + 1, a, b, c);

    int res1 = rec(i + 1, a + l[i], b, c) + (a ? 10 : 0);
    int res2 = rec(i + 1, a, b + l[i], c) + (b ? 10 : 0);
    int res3 = rec(i + 1, a, b, c + l[i]) + (c ? 10 : 0);
    return min(min(res0, res1), min(res2, res3));
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B >> C;
    l.resize(N);
    rep(i, N) cin >> l[i];
    int min = ll(1e18) + 1;
    cout << rec(0, 0, 0, 0) << endl;
 //   system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF (1<<28)

int n, m, a[64], b[64], c[64];
int dp[64][64][64];

int f(int k, int x, int y) {
    int ans = c[k];
    rep (i, x+1) rep (j, y+1) if (1 <= i+j && i+j <= 8) {
        ans = max(ans, a[k]*i + b[k]*j);
    }
    return ans;
}

int main() {
    scanf("%d%d", &n, &m);
    rep (i, n) scanf("%d%d%d", a+i, b+i, c+i);
    rep (i, 64) rep (j, 64) rep (k, 64) dp[i][j][k] = -INF;
    dp[0][0][0] = 0;
    rep (k, n) rep (x, m+1) rep (i, x+1) if (dp[k][x][i] > -INF) {
        rep (j, m-x+1) {
            dp[k+1][x+j][j] = max(dp[k+1][x+j][j], dp[k][x][i]+f(k, j, i));
        }
    }
    int ans = -INF;
    rep (x, m+1) rep (i, 64) ans = max(ans, dp[n][x][i]);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2052
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll a; cin>>a;
    vec<ll> m(a);
    ll xr =0 ;
    for(int q=0; q<a; q++){
        cin>>m[q];
        xr ^= m[q];
    }
    for(ll i : m) cout<<(xr^i)<<" ";
}

Measured memory_bytes: 4804
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int MX = 500001;
int n, l[MX], r[MX], lf[MX], depth[MX];
ll dp[2][MX];

inline void rec(int c, int d = 0){
	//if(c == n) return;
	//rec(l[c], d + 1); rec(r[c], d + 1);
	lf[c] += lf[l[c]] + lf[r[c]];
	dp[0][c] += dp[0][l[c]] + lf[l[c]];
	dp[0][c] += dp[0][r[c]] + lf[r[c]];
	
	dp[1][c] = min(lf[l[c]] + dp[0][l[c]] + dp[1][r[c]], lf[r[c]] + dp[1][l[c]] + dp[0][r[c]]) + 1;
	dp[1][c] = min(dp[1][c], 2 + d + dp[1][l[c]] + dp[1][r[c]]);
}

int main(){
	cin >> n;
	rep(i, n - 1) cin >> l[i + 1] >> r[i + 1];
	
	vi ord;
	queue<pi> q;
	q.push(mp(1, 0));
	while(!q.empty()){
		int c = q.front().first, d = q.front().second; q.pop();
		ord.pb(c);
		depth[c] = d;
		if(l[c] < n) q.push(mp(l[c], d + 1));
		if(r[c] < n) q.push(mp(r[c], d + 1));
	}
	reverse(all(ord));
	
	lf[n] = 1;
	rep(i, n - 1) rec(ord[i], depth[ord[i]]);
	cout << dp[1][1] << endl;
	/*
	rep(i, n) cerr<<dp[0][i + 1] << " " << dp[1][i + 1] << endl;
	rep(i, n) dbg(lf[i + 1]);
	*/
	return 0;
}

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

using namespace std;

const int N=3e5+7,MOD=1e9+7;

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

typedef long long ll;


int v,p,n,tc,q,k,c,m,b[N],cnt,curr,ans,calc[N];

bool sum[N],bad[N];
  
string s;
 
ll dp[N][2][2];

int power(int x,int p){
    if (p==0)
        return 1;
    if (p==1)
        return x;
    int r=power(x,p/2);
    return (((ll)r*r)%MOD*power(x,p&1))%MOD;
}

ll solve(int indx,int rem,bool low){
	if(!indx){
		if(low){
			if(rem){
				return 0;
			}
			else{
				return 1;
			}
		}	
		else{
			if(rem){
				return 0;
			}
			else{
				return 3;
			}
		}
	}
 
	ll &ret = dp[indx][rem][low];
 
	if(~ret)return ret;
 
	ret = 0;
 
	if(s[indx]=='1'){
		if(rem){
 
			return 0;
		}
		else{
 
			ret+=(2*solve(indx-1,0,low)%MOD);// 01 10
			ret%=MOD;
 
			ret+=(solve(indx-1,0,0)+solve(indx-1,1,0))%MOD;// 00 11
			ret%=MOD;
 
		}
	}
	else{
		if(rem){
			return 0;	
		}
		else{
 
			ret+=(2*solve(indx-1,0,1)%MOD);//01 10
			ret%=MOD;
 
			ret+=(solve(indx-1,0,low)+solve(indx-1,1,low))%MOD; //00 11
			ret%=MOD;
		}
 
	}
 
	return ret;
}
int main()
{	
 
 
 	cin>>s;
 
 	reverse(s.begin(),s.end());
 
 	while(s.back()=='0')s.pop_back();
 	reverse(s.begin(),s.end());
 	memset(dp,-1,sizeof(dp));
 	cout<<solve(s.size()-1,0,0)<<"\n";

}


Measured memory_bytes: 18560
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

int INF = 9999999;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vi lis(n, INF);
  rep (i, m) {
    int a, b;
    scanf("%d %d", &a, &b);
    a -= 1;
    b -= 1;
    lis[a] = min(lis[a], b);
    /*
    if (lis[a] == -1) {
      lis[a] = b;
    } else {
      lis[a] = min(lis[a], b);
    }
    */
  }
  int mi = n;
  for (int i = n-1; i >= 0; --i) {
    if (lis[i] < mi) {
      mi = lis[i];
    } else {
      lis[i] = INF;
    }
  }

  vvi ab;
  rep (i, n) {
    if (lis[i] == INF) {
      continue;
    }
    ab.push_back((vi){i, lis[i]});
  }
  m = ab.size();
  int ma_cut = -1;
  int cnt = 0;
  rep (i, m) {
    if (ma_cut >= ab[i][0]) {
      continue;
    }
    cnt += 1;
    ma_cut = ab[i][1] - 1;
  }
  printf("%d\n", cnt);

  return 0;
}


Measured memory_bytes: 8372