akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int N, D;
    cin >> N >> D;
    int X[N][D];
    for(int i = 0; i < N; i++){
        cins(X[i], X[i] + D);
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            int dist = 0;
            for(int k = 0; k < D; k++){
                dist += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            int root = round(sqrt(dist));
            ans += (dist == root * root);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
import bisect
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
cnt = 0
a.sort()
c.sort()
for i in range(n):
    cnt += (bisect.bisect_left(a, b[i])) * (n-bisect.bisect_right(c, b[i]))
print(cnt)

Measured memory_bytes: 23268
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    const MOD: i64 = 1000000007;
    input! {
        n: usize,
    }
    let mut dp: [[[i64; 4]; 4]; 4] = [[[1; 4]; 4]; 4];
    dp[0][1][2] = 0;
    dp[1][0][2] = 0;
    dp[0][2][1] = 0;
    for _ in 3..n {
        let mut ndp: [[[i64; 4]; 4]; 4] = [[[0; 4]; 4]; 4];
        for i in 0..4 {
            for j in 0..4 {
                for k in 0..4 {
                    for l in 0..4 {
                        if (j, k, l) == (0, 1, 2) ||
                            (j, k, l) == (1, 0, 2) ||
                            (j, k, l) == (0, 2, 1) ||
                            (i, j, l) == (0, 1, 2) ||
                            (i, k, l) == (0, 1, 2) {} else {
                            ndp[j][k][l] += dp[i][j][k];
                        }
                    }
                }
            }
        }
        dp = ndp;
        for i in 0..4 {
            for j in 0..4 {
                for k in 0..4 {
                    dp[i][j][k] %= MOD;
                }
            }
        }
    }
    let ans = dp.iter().fold(0, |s, a|
        (s + a.iter().fold(0, |t, b|
            (t + b.iter().fold(0, |u, c| (u + c) % MOD)) % MOD)) % MOD);
    println!("{}", ans)
}


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

using namespace std;

void makingfib(int);

int fib[2000];

int main(){

  int n, d;

  while(cin >> n >> d){
    makingfib(n);
    int sum = 1;
    for(int i = 2; i <= n; i++){
      if(fib[i] - fib[i-1] >= d){
	sum++;
	//	cout << fib[i] << "  " << fib[i-1] << endl;
      }

    }

    cout << sum << endl;
  }
}

void makingfib(int v){
  fib[0] = 1;
  fib[1] = 2;

  for(int i = 2; i <= v; i++){
    fib[i] = (fib[i-2]+fib[i-1])%1001;
  }
  sort(fib, fib+v+1);

  //for(int i = 0; i <= v; i++) cout << "  " << fib[i] <<endl;

}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <fstream>

using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, m;
    cin >> n >> m;
    vector<bool> used(n + 100);
    vector<pair<int, int>> v(m);
    for (int i = 0; i < m; i++) {
        cin >> v[i].first >> v[i].second;
        if (v[i].second == n) {
            used[v[i].first] = 1;
        }
    }
    for (int i = 0; i < m; i++) {
        if (v[i].first == 1 && used[v[i].second]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();
        final int M = sc.nextInt();

        int [] score = new int[N];
        int sum = 0;
        for (int i = 0; i < N; i++) {
            score[i] = sc.nextInt();
            sum += score[i];
        }
        sc.close();

        double border = (double)sum / (double)(4 * M);
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            if(score[i] >= border){
                cnt++;
                if(cnt >= M){
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0); cin.tie(0);
#define FL(i,a,n) for(ll i=a;i<n;i++)
#define even(x) (((x)%(2))==(0))
#define odd(x) (((x)%(2))==(1))
#define meme(x) memset(x, 0, sizeof(x))
#define mod 1000000007

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

ll claw[2000003];
ll infant[2000003];
 
int main() 
{
    string s,t;
    cin>>s>>t;
    int cnt=0;
    int x=s.length();
    for(int i=0;i<x;i++)
    {
        if(s[i]!=t[i])
        cnt++;
    }
    cout<<cnt;
}

Measured memory_bytes: 3912
#include<stdio.h>
#include<string.h>
#include<queue>
#include<utility>
#define MAX 0x3f3f3f3f
using namespace std;
int mat[1005][1005];
int visited[1005][1005];
int node[10][2];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int h,w,n,cur;
typedef pair<pair<int,int>,int> P;
int dfs(int no)
{
	int i,ni=node[no][0],nj=node[no][1];
	queue<P> que;
	P m;
	cur++;
	que.push(make_pair(make_pair(ni,nj),0));
	visited[ni][nj]=cur;
	int x,y;
	while(!que.empty())
	{
		
		m=que.front(),que.pop();
		for(i=0;i<4;i++)
		{
		
			x=m.first.first+dx[i];
			y=m.first.second+dy[i];
		
			if(x<0||x>=h||y<0||y>=w||visited[x][y]==cur||mat[x][y]=='X')continue;
			if(mat[x][y]-'0'==no+1)
				return m.second+1;
			que.push(make_pair(make_pair(x,y),m.second+1));
			visited[x][y]=cur;
		}
		
	}
	return -1;
}
int main()
{
	int i,j,si,sj,no=0;
	scanf("%d%d%d",&h,&w,&n);
	getchar();
	for(i=0;i<h;i++)
	{
		for(j=0;j<w;j++)
		{
			mat[i][j]=getchar();
			if(mat[i][j]=='S')
			{
				node[0][0]=i;
				node[0][1]=j;
			}
			else if(mat[i][j]>'0'&&mat[i][j]<='9')
			{
				node[mat[i][j]-'0'][0]=i;
				node[mat[i][j]-'0'][1]=j;
			}
		
		}
		getchar();
	}

	int sum=0;
	for(i=0;i<n;i++)
	{
	
		sum+=dfs(i);
	}
	printf("%d\n",sum);
	return 0;
} 


Measured memory_bytes: 10472
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1000000000
typedef long long ll;


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

	int a, b, cnt=0;
	cin >> a >> b;

	for (int i = a; i <= b; i++) {
		int digit[5], num = i;
		for (int j = 4; j >= 0; j--) {
			digit[j] = num % 10;
			num /= 10;
		}

		if (digit[0] == digit[4] && digit[1] == digit[3]) cnt++;
	}
	
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vi vector<int>
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
#define er(x) cout << x << " "
#define err(x,y) cout << x << " "<<y
using namespace std;
const int dx[] = { 1, -1 , 0 , 0  };
const int dy [] = { 0 ,0 , 1 , -1  };
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int N = 1000+5 ;
const int INF = INT_MAX ;
const int M = 200005;
char a[N][N]; 
int main ( ){
fast_io();
string s ;
cin >> s ;
map<int , int >mp ; 
for(char &x : s )
mp[x]++ ;
cout << ( mp.size() == 1 ? "No":"Yes") ,br 	
 
return 0 ;
 
}


Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int m,f,r;
    char grade;
    while(true){
        scanf("%d %d %d",&m,&f,&r);
        if(m == -1 && f == -1 && r == -1) break;
        if(m == -1 || f == -1){
            grade = 'F';
        }else if(m+f >= 80){
            grade = 'A';
        }else if(m+f >= 65){
            grade = 'B';
        }else if(m+f >= 50){
            grade = 'C';
        }else if(m+f >= 30){
            grade = (r >= 50)? 'C':'D';
        }else{
            grade = 'F';
        }
        printf("%c\n",grade);
    }
}


Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string m;
    char f[7],l[7];
    cin>>f>>m>>l;
    f[0]='A';
    char ch = m[0];
    l[0]='C';
        printf("%c%c%c",f[0],ch,l[0]);
    return 0;
}


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

int main(int argc, const char * argv[]) {
    int N, K;
    string S;
    
    cin >> N >> K;
    cin >> S;
    
    S[K - 1] = S[K - 1] + 32;
    
    cout << S << endl;
    
    return 0;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;




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


	int a,b;
	cin>>a>>b;

	writeln(max(a*b,max(a+b,a-b)));

}




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

int main(){

	int n;
	int a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;

	int cnt = 0;
	int k = 0;
	for(int i=0; i<n; i++){

		if( s[i] == 'a' ){
			if( cnt < a+b ){
				cnt++;
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
		}else if( s[i] == 'b' ){
			if( cnt < a+b && k < b ){
				cnt++;
				k++;
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
		}else{
			cout << "No" << endl;
		}
	}	

	return 0;

}

Measured memory_bytes: 896
# editorial,解説ブログを参考にした(偶数の場合の考え方)
N, K = map(int, input().split())
ans = 0
if K % 2 == 1:
    ans = (N // K) ** 3
else:
    ans += (N // K) ** 3
    ans += ((N+(K/2))//K) ** 3
print(int(ans))


Measured memory_bytes: 2940
//Youtube解説AC
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans = 0;
  rep(si,h)rep(sj,w){
      if(s[si][sj]=='#') continue;
      vector<vector<int>> dist(h,vector<int>(w,INF));
      queue<pair<int,int>> q;
      //幅優先のときはupdate関数を作ると楽
      auto update = [&](int i,int j,int x){
      if(dist[i][j]!=INF) return;
      dist[i][j] = x;
      q.push(pair<int,int>(i,j));  //make_pairと同じ?
    };
    update(si,sj,0);
    while(!q.empty()){
      int i = q.front().first;
      int j = q.front().second; q.pop();
      rep(dir,4){
        int ni = i+di[dir],nj = j+dj[dir];
        if(ni<0||ni>=h||nj<0||nj>=w) continue;
        if(s[ni][nj]=='#') continue;
        update(ni,nj,dist[i][j]+1);
      }
    }
    rep(i,h)rep(j,w){
      if(dist[i][j]==INF) continue;
      ans = max(ans,dist[i][j]);
      }
    }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int n;
	map<int,int> dic;
	int mx = 0;
	while( cin >> n ) dic[n]++,mx = max(dic[n],mx);
	for( auto x : dic ){
		if( x.second == mx ) cout << x.first << endl;
	}
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <map>
#include <list>
#include <queue>
#include <cstdlib>
#define INF (1000000007)
#define distance(x1,y1,x2,y2) sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
#define rep(i,N) for(ll i=0;i<N;i++)
#define rep2(i,j,k) for(ll i=j; i<k;i++)
typedef long long int ll;
using namespace std;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vs=vector<string>;
using vvs=vector<vector<string>>;

template <typename T>
void print(T v){
    for(size_t i=0;i<v.size();i++){
        cout<<i<<": "<<v[i]<<endl;}
}

template <typename T>
void print2(T v){
    for(size_t i=0;i<v.size();i++){
        cout<<i<<": ";
        for(size_t j=0;j<v[0].size();j++){
            cout<<v[i][j]<<" ";
        }
        cout<<endl;
    }
}

template <typename T>
T slice(T v,ll left,ll right){
    T ret(0);
    copy(v.begin()+left,v.begin()+right,back_inserter(ret));
    return ret;
}

bool func(vl s,vl t){
    return s[1]<t[1];
}

int main(){
    
    vl vec(5);
    ll k;
    rep(i,5){
        cin>>vec[i];
    }
    cin>>k;
        
    if(*max_element(vec.begin(),vec.end())-*min_element(vec.begin(),vec.end())>k){
        cout<<":("<<endl;
    }
       
    else{
        cout<<"Yay!"<<endl;
    }
    
    return 0;
}

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

using namespace std;

int main()
{
    int a,b,h,s;
    while(scanf("%d%d%d",&a,&b,&h)==3)
    {
        s=(a+b)*h/2;
        printf("%d\n",s);
    }
    return 0;
}


Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << 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...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

const int N = 2e5 + 10;
int64 a[N];
int64 dp[N][2];
bool visit[N][2];
int n;

int64 solve(int pos, int rem) {
  if (pos >= n) return 0;
  int64& ret = dp[pos][rem];
  if (visit[pos][rem]) return ret;
  visit[pos][rem] = true;
  ret = -(1LL << 60);
  for (int i = 0; i <= rem; ++i) {
    ret = max(ret, a[pos + i] + solve(pos + i + 2, rem - i));
  }
  // trace(pos, rem, ret);
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }
  memset(visit, 0, sizeof(visit));
  int64 ret = solve(0, n % 2 + 1);
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 16660
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <functional>

using namespace std;

int main(void){
    int N;
    string S;
    cin>>N>>S;
    int blackSeq=0;
    int whiteSeq=0;
    bool isIgnoBlack=true;
    int ans=0;
    for(int i=N-1;i>=0;i--){
        if(S[i]=='#'&&isIgnoBlack){continue;}
        
        if(S[i]=='.'){
            isIgnoBlack=false;
            whiteSeq++;
        }
        if(S[i]=='#'&&!isIgnoBlack){
            blackSeq++;
        }
        if(blackSeq>=whiteSeq){
            ans+=whiteSeq;
            whiteSeq=0;
            blackSeq=0;
            isIgnoBlack=true;
        }
    }
    ans+=blackSeq;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int main(){
  ll x;
  cin>>x;
  ll a;
  if(x%11==0) a=0;
  else if(x%11<=6) a=1;
  else a=2;
  ll res=(x/11)*2+a;
  prin(res);
  return 0;
}


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

int main(void) {
  int n, a = 0, b = 0;
  vector<pair<int, int>> zohe[2];
  
  cin >> n;
  
  zohe[0].resize(100000);
  zohe[1].resize(100000);
  
  for (int i = 0; i < 100000; i++) {
    zohe[0][i].first = 0;
    zohe[0][i].second = i;
    zohe[1][i].first = 0;
    zohe[1][i].second = i;
  }
  
  for (int i = 0; i < n; i++) {
    int in;
    cin >> in;
    zohe[i % 2][in - 1].first++;
  }

  sort(zohe[0].begin(), zohe[0].end(), greater<pair<int, int>>());
  sort(zohe[1].begin(), zohe[1].end(), greater<pair<int, int>>());
  
  a = zohe[0][0].first;
  b = zohe[1][0].first;
  
  if (zohe[0][0].second == zohe[1][0].second) {
    if (zohe[0][0].first + zohe[1][1].first >= zohe[0][1].first + zohe[1][0].first)
      b = zohe[1][1].first;
    else
      a = zohe[0][1].first;
  }
  
  cout << (n + 1) / 2 - a + n / 2 - b << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define F first
#define S second
#define INF 1<<28
using namespace std;


int n, m;
typedef pair < int, int > P;
vector < P > g[222222];
int ans[111111];
int ans2[111111];

void solve(int a){

  priority_queue < P, vector<P>, greater<P> > que;
  fill(ans, ans+n+1, INF);

  ans[a] = 0;
  que.push( P(0, a) );

  while(!que.empty()){
    P p = que.top(); que.pop();

    if(ans[p.S] < p.F) continue;
    for(long long int i=0;i<g[p.S].size();i++){
      P pp = g[p.S][i];
      if(ans[pp.F] > ans[p.S] + pp.S){
	       ans[pp.F] = ans[p.S] + pp.S;
         ans2[pp.F] = p.S;
	       que.push( P(ans[pp.F], pp.F) );
      }
    }
  }

}

int main(){

  cin >> n >> m;

  for(int i=0;i<m;i++){
    int a, b;
    cin >> a >> b;
    g[a].push_back( P(b, 1) );
    g[b].push_back( P(a, 1));
  }

  solve(1);

  bool ok = true;
  for(int i=2;i<=n;i++) if(ans[i] >= INF) ok = false;

  if(!ok) cout << "No\n";
  else{
    cout << "Yes\n";
    for(int i=2;i<=n;i++) cout << ans2[i] << endl;
  }

}


Measured memory_bytes: 16536
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  vector<int> v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, 28, 30, 32, 35, 36, 40, 42, 45, 49, 56, 63, 64, 72, 81};
  int n;
  cin >> n;
  rep(i, 0, 34){
    if(n == v[i]){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No";
}
  
  
  

Measured memory_bytes: 3584
#include<stdio.h>
int main(){
  int array[5];
  int i,k,p,j;
  p=0;
  for(i=0;i<5;i++){
    scanf("%d",&array[i]);
  }
  scanf("%d",&k);
  for(i=0;i<5;i++){
    for(j=i;j<5;j++){
      if(k<array[j]-array[i]){
        p+=1;
      }
    }
  }
  if(p==0){
    printf("Yay!\n");
  }else{
    printf(":(\n");
  }
}

Measured memory_bytes: 128
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
 
	public static void main(String[] args) {
		new Main();	
	}
 
	public Main() {
		new aoj510().doIt();
	}
	class aoj510{
		void doIt(){
			int S = 0,T = 0;
			for(int i = 0;i < 4;i++)S = S + sc.nextInt();
			for(int i = 0;i < 4;i++)T = T + sc.nextInt();
			System.out.println(Math.max(S,T));
		}
	}
}

Measured memory_bytes: 26268
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)



int main(){ FastIO;

string s;cin>>s;
int f=1;
for(int i=0;i<s.length();i++)
{
	if(s[i]=='7') f=0;
}
if(f) cout<<"No";
else cout<<"Yes";




return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
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;};

bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}

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

  int n;
  while(true) {
    cin >> n;
    if(n == 0) break;
    for(int i = n; i >= 0; i--) {
      if(IsPrime(i) && IsPrime(i - 2)) {
        cout << i - 2 << " " << i << endl;
        break;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <math.h>

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define vstr vector<string>
#define vb vector<bool>
using namespace std;



ll brute_cols(vstr& board, vb &rows, vb &cols, ll curCol, ll h, ll w, ll k)
{
	if (curCol == w)
	{
		/*
		cout << "rows: ";
		for (ll i = 0; i < rows.size(); i++) cout << rows[i] << " ";
		cout << endl;
		cout << "cols: ";
		for (ll i = 0; i < cols.size(); i++) cout << cols[i] << " ";
		cout << endl;*/
		ll blacks = 0;
		for (ll i = 0; i < h; i++)
		{
			for (ll j = 0; j < w; j++)
			{
				if (rows[i] == false && cols[j] == false)
				{
					if (board[i][j] == '#') blacks++;
				}
			}

		}
		if (blacks == k)
		{
			//cout << "ans: 1" << endl;
			return 1;
		}
		//cout << "ans: 0" << endl;
		return 0;
	}

	ll ans = 0;
	ans += brute_cols(board, rows, cols, curCol + 1, h, w, k);
	cols[curCol] = true;
	ans += brute_cols(board, rows, cols, curCol + 1, h, w, k);
	cols[curCol] = false;
	return ans;
}

ll brute_rows(vstr& board, vb &rows, ll curRow, ll h, ll w, ll k)
{
	if (curRow == h)
	{
		vb cols(w);
		return brute_cols(board, rows, cols, 0, h, w, k);
	}

	ll ans = 0;
	ans += brute_rows(board, rows, curRow + 1, h, w, k);
	rows[curRow] = true;
	ans += brute_rows(board, rows, curRow + 1, h, w, k);
	rows[curRow] = false;
	return ans;
}


int main()
{
	ll h, w, k;
	cin >> h >> w >> k;
	vstr board(h);
	for (ll i = 0; i < h; i++) cin >> board[i];
	vb rows(h);
	ll ans = brute_rows(board, rows, 0, h, w, k);
	cout << ans << endl;
	

}

Measured memory_bytes: 3196
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

typedef long long ll;

ll encode(int* state)
{
	ll res = 0;
	for (int i = 0; i < 13; ++i)
		res = res << 4 | state[i];
	return res;
}
void decode(int* d, ll e)
{
	for (int i = 12; i >= 0; --i, e >>= 4)
		d[i] = e & 15;
}

map<ll, int> minSteps;
int dir[] = { -1, 1, -2, 2, -4, 4 };
map<int, bool> ok[3];

const int InitialDepth = 13;
map<ll, int> problemSteps;

int start_from_initial(ll current, ll next)
{
	bool newState = minSteps.count(next) == 0;
	if (newState)
		minSteps[next] = minSteps[current] + 1;

	return newState && minSteps[next] < InitialDepth ? 0 : -1;
}
int start_from_problem(ll current, ll next)
{
	bool newState = problemSteps.count(next) == 0;
	if (newState)
		problemSteps[next] = problemSteps[current] + 1;

	if (minSteps.count(next))
		return problemSteps[next] + minSteps[next];

	return newState && problemSteps[next] < 20 - InitialDepth ? 0 : -1;
}
int bfs(ll initial, int (*f)(ll, ll))
{
	queue<ll> q;
	q.push(initial);

	while (!q.empty())
	{
		ll e = q.front();
		q.pop();
		int d[13];
		decode(d, e);

		int zero_pos[2];
		for (int i = 0, j = 0; j < 2; ++i)
			if (!d[i])
				zero_pos[j++] = i;

		for (int i = 0; i < 2; ++i)
		{
			for (int j = 0; j < 6; ++j)
			{
				int a = zero_pos[i];
				int b = a + dir[j];
				if (a > b)
					swap(a, b);
				if (a < 0 || b > 12 || !d[a] && !d[b] || !ok[j/2][a])
					continue;

				int copy[13];
				memcpy(copy, d, sizeof(copy));
				swap(copy[a], copy[b]);
				ll next = encode(copy);

				int r = f(e, next);
				if (r == 0)
					q.push(next);
				else if (r > 0)
					return r;
			}
		}
	}

	return -1;
}

int main()
{
	int o[][9] = {
		{ 1, 2, 4, 5, 6, 7, 9, 10, -1 },
		{ 0, 10, -1 },
		{ 1, 2, 3, 5, 6, 7, -1 }
	};
	for (int i = 0; i < 3; ++i)
		for (int j = 0; o[i][j] != -1; ++j)
			ok[i][o[i][j]] = true;

	int initial[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0 };
	ll t = encode(initial);
	minSteps[t] = 0;

	bfs(t, start_from_initial);

	while (true)
	{
		int d[13];
		for (int i = 0; i < 13; ++i)
			scanf("%d", d + i);
		if (d[0] == -1)
			break;

		int ans = -1;
		ll s = encode(d);
		if (minSteps.count(s))
			ans = minSteps[s];
		else
		{
			problemSteps.clear();
			ans = bfs(s, start_from_problem);
		}

		if (ans != -1)
			printf("%d\n", ans);
		else
			puts("NA");
	}

	return 0;
}

Measured memory_bytes: 3244
#include <iostream>
#include <utility>
#include <stdint.h>
#include <string>
#include <map>

using namespace std;

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

  map<char,int> m;
  for (char c : s) {
    if (m.count(c) == 0)
      m[c] = 1;
    else
      ++m[c];
  }

  bool flag = m.size()==2;
  for (auto mm : m)
    flag = flag && mm.second==2;
  
  cout << (flag ? "Yes" : "No") << endl;

  return 0;
}


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

class Program
{
    public static void Main()
    {
        string s = Read();
        Console.WriteLine(s + ((s[^1] == 's') ? "es" : "s"));
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
    public static IEnumerable<long> ReadLong(long n) => Read(n).Select(long.Parse);
}


Measured memory_bytes: 26692
#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() {
  string S;
  cin >> S;
  string T = S.at(S.length() - 1) == 's' ? "es" : "s";
  cout << S << T << endl;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(){
char s[4];
int i,a[100]={0};
scanf("%s",s);
for(i=0;i<3;i++){
a[s[i]]++;
}
if(a['a']==1&&a['b']==1&&a['c']==1){
printf("Yes\n");
return 0;
}
printf("No\n");
return 0;
}

Measured memory_bytes: 128
from collections import deque

n = int(input())
adj = [list(map(int, input().split(' '))) for i in range(n)]

class Node:
  def __init__(self, id, ck):
    self.id = id
    self.ck = ck
    self.depth = -1

  def __str__(self):
    return '{} {}'.format(self.id, self.depth)

class Graph:
  def __init__(self):
    self.map = {}

  def get(self, id):
    return self.map[id]

  def set(self, id, ck):
    self.map[id] = Node(id, ck)

  def bfs(self):
    root = self.get(1)
    root.depth = 0
    queue = deque()
    queue.append(root)
    while(len(queue) > 0):
      node = queue.popleft()
      for id in node.ck:
        target = self.get(id)
        if target.depth != -1: continue
        target.depth = node.depth + 1
        queue.append(target)

  def __str__(self):
    return '\n'.join(map(str, [self.get(i + 1) for i in range(len(self.map))]))

graph = Graph()
for data in adj:
  id = data[0]
  ck = data[2:]
  graph.set(id, ck)

graph.bfs()
print(graph)



Measured memory_bytes: 6052
N,Y = map(int, input().split())
for a in range(N+1):
  for b in range(N+1):
    if N-a-b<0:
      continue
    #print(a,b,N-a-b)
    if (10000*a) + (5000*b) + 1000*(N-a-b) == Y:
      print(a,b,N-a-b)
      exit()
print(-1,-1,-1)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

template<int mod>
struct ModInt {
    int64_t value;

    ModInt() : value(0) {}
    ModInt(int64_t x) : value(x >= 0 ? x % mod : (mod - ((-x) % mod) % mod)) {}

    ModInt &operator+=(const ModInt &input) {
        value += input.value;
        if (value >= mod) value -= mod;
        return *this;
    }    

    ModInt &operator-=(const ModInt &input) {
        value += (mod - input.value);
        if (value >= mod) value -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &input) {
        value = value * input.value % mod;
        return *this;
    }

    ModInt &operator/=(const ModInt &input) {
        *this *= input.inverse();
        return *this;
    }

    ModInt inverse() const {
        int64_t base = value, p = mod;
        pair<int64_t, int64_t> save = {1, 0};
        while (p) {
            int64_t temp = base / p;
            swap(base -= temp * p, p);
            swap(save.first -= temp * save.second, save.second);
        }
        return ModInt(save.first);
    }

    ModInt operator-() const { return ModInt(-value); }

    ModInt operator-(const ModInt &input) const { return ModInt(*this) -= input; }

    ModInt operator+(const ModInt &input) const { return ModInt(*this) += input; }

    ModInt operator*(const ModInt &input) const { return ModInt(*this) *= input; }

    ModInt operator/(const ModInt &input) const { return ModInt(*this) /= input; }

    bool operator==(const ModInt &comparsion) const { return value == comparsion.value; }

    bool operator!=(const ModInt &comparsion) const { return value != comparsion.value; }

    friend istream &operator>>(istream &stream, ModInt &input) {
        int64_t temp;
        stream >> temp;
        input = ModInt<mod>(temp);
        return stream;
    }

    friend ostream &operator<<(ostream &stream, const ModInt &input) {
        return stream << input.value;
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), x(value);
        while (n > 0) {
            if (n and 1) ret *= x;
            x *= x;
            n >>= 1;
        }
        return ret;
    }
};

using modint = ModInt<MOD>;

int main() {
    int N, K;
    cin >> N >> K;
    modint ans = 0;
    ll left = 0, right = 0;
    auto update = [&](int input) {
        left += input;
        right += N - input;
    };
    for (int i = 0; i <= N + 1; i++) {
        if (i >= K) ans += (right - left + 1);
        update(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3680
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <set>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<int> st;
    REP(i,3){
        int a;
        cin >> a;
        st.insert(a);
    }
    int ans = (int)st.size();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3560
using System;

namespace ITP1_8_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string ring = Console.ReadLine();
            string word = Console.ReadLine();
            bool isexist = false;

            for(int i = 0; i < ring.Length; i++)
            {
                string r_word = null;
                if ((ring.Length - i) >= word.Length)
                    r_word = ring.Substring(i, word.Length);
                else
                    r_word = ring.Substring(i) + ring.Substring(0, word.Length - (ring.Length - i));

                if (word.CompareTo(r_word) == 0)
                    {
                        isexist = true;
                        Console.WriteLine("Yes");
                        break;
                    }
            }
            if (!isexist) Console.WriteLine("No");            
        }
    }
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(NULL); cout.tie(NULL); 
  ll i,n,x,y,z,t,j;
  cin>>n; t=n;
  ll arr[n],dp[n][n];
  for(i=0;i<n;i++)cin>>arr[i];
  for(t=0;t<n;t++)
    for(i=0,j=t;j<n;j++,i++){
       x=(i+1<=j-1)?dp[i+1][j-1]:0ll;
       y=(i+2<=j)?dp[i+2][j]:0ll;
       z=(i<=j-2)?dp[i][j-2]:0ll;
       dp[i][j]=max(arr[i]+min(x,y),arr[j]+min(x,z));
    }
  //  cout<<dp[0][n-1];
  cout<<2*dp[0][n-1]-accumulate(arr,arr+n,0ll);
}

Measured memory_bytes: 70272
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    while(A>=B){
        B=B*2;
        K=K-1;
    }
    while(B>=C){
        C=C*2;
        K=K-1;
    }
    if (K>=0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
  int E, Y;
  cin >> E >> Y;

  switch(E){
    case 0:
            if(1868<=Y && Y<=1911){
              cout << 'M' << Y-1867 << endl;
            }
            else if(1912<=Y && Y<=1925){
              cout << 'T' << Y-1911 << endl;
            }
            else if(1926<=Y && Y<=1988){
              cout << 'S' << Y-1925 << endl;
            }
            else if(1989<=Y && Y<=2016){
              cout << 'H' << Y-1988 << endl;
            }
            break;
    case 1:
            cout << Y+1867 << endl;
            break;
    case 2:
            cout << Y+1911 << endl;
            break;
    case 3:
            cout << Y+1925 << endl;
            break;
    case 4:
            cout << Y+1988 << endl;
            break;
  }
  return 0;
}



Measured memory_bytes: 3076
import java.util.*;
import java.util.stream.*;
class Main{
  private static Scanner sc = new Scanner(System.in);
  public static void main(String[] args){
	C();
  }
  
  private static void B(){
    int n = Integer.parseInt(sc.nextLine());
    String str = sc.nextLine();
    int ans = 0;
    for (int i = 0; i < n - 2;i++){
      if (str.substring(i,i+3).equals("ABC")) ans++;
    }
    System.out.println(ans);
  }
  
  
  public static void C(){
    int n = sc.nextInt();
      //Integer.parseInt(sc.nextLine());
    List<Integer> fst = new ArrayList<>();
    List<Integer> snd = new ArrayList<>();
    int[] nums = new int[n];
    for (int i = 0; i < n; i++){
      nums[i] = i + 1;
      fst.add(sc.nextInt());
    }
    for (int i = 0; i < n; i++){
      snd.add(sc.nextInt());
    }
    
    int a = 0, b = 0;
    List<List<Integer>> facs = new ArrayList<>();
    facs = perms(nums);
    
    for(int i = 0; i < facs.size(); i++){
      if (a != 0 && b != 0) break;
      if (fst.equals(facs.get(i))) a = i;
      if (snd.equals(facs.get(i))) b = i;
    }
    
   System.out.println(Math.abs(a - b));
  }
  public static List<List<Integer>> perms(int[] nums) {
    List<Integer> numbers = Arrays.stream(nums).boxed().collect(Collectors.toList());
    List<Integer> arr = new ArrayList<>();
    List<List<Integer>> facs = new ArrayList<>();
    return helper(numbers,arr,facs);
    }
  
  
  
   public static List<List<Integer>> helper(List<Integer> nums, List<Integer> arr,List<List<Integer>> result){
        
        if (nums.size() == 0 && (! arr.isEmpty())) {

          List<Integer> edge = new ArrayList<>();
          for (int i = 0; i < arr.size(); i++){
            edge.add(arr.get(i)); 
          }
          result.add(edge);
        }
        
        for (int i = 0; i < nums.size(); i++){
          int target = nums.get(i).intValue();
          List<Integer> newNums = nums.stream().filter(x -> x != target).collect(Collectors.toList());
          arr.add(target);
          helper(newNums, arr, result);
          arr.remove(arr.size()-1);
        }
     
        return result;
    }
  
 
}

Measured memory_bytes: 55104
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

a,b=map(int,input().split())
print(a-b)


Measured memory_bytes: 6312
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <bitset>
#include <string>
#include <cstdio>
#include <math.h>
using namespace std;

const long long int INF = 1000000007;

long long max4(long long a, long long b, long long c, long long d)
{
    return max(max(a, b), max(c, d));
}

int main(void)
{
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max4(a * c, a * d, b * c, b * d) << endl;
}

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

using namespace std;

typedef long long ll;

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

	int p;
	int diff = INT_MAX;
	unordered_set<int> s;
	for(int i = 0; i < n; i++)
	{
		int val;
		cin >> val;
		s.insert(val);
	}

	for(int i = -1; i <= 101; i++)
	{
		if(abs(i - x) < diff && s.find(i) == s.end())
		{
			diff = abs(i - x);
			p = i;
		}
	}

	cout << p << endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll h,n;cin>>h>>n;
    ll a[n],b[n];
    f(i,0,n)cin>>a[i]>>b[i];
    ll dp[10004];
    f(i,0,h+1)dp[i]=__LONG_LONG_MAX__;
    dp[0]=0;
    for(ll i=0;i<=h;i++){
        for(ll j=0;j<n;j++){
            dp[i]=min(dp[max(0LL,i-a[j])]+b[j],dp[i]);
        }
    }
    cout<<dp[h];
    return 0;  
} 

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

using P = pair<int, int>;

template <class T>
struct fenwick_tree {
  vector<T> x;
  fenwick_tree(int n) : x(n+1) { } 
  void add(int k, T a) { 
    for (++k; k < x.size(); k += k&-k) x[k] += a;
  }
  T sum(int k) {
    T s = 0;
    for (; k > 0; k &= k-1) s += x[k];
    return s;
  }
};

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, Q;
  while (~scanf("%d %d", &N, &Q)) {
    vector<int> colors(N);
    for (auto& x : colors) scanf("%d", &x), --x;
    vector<P> queries(Q);
    for (auto& x : queries) scanf("%d %d", &x.fst, &x.snd), --x.fst;
    vector<int> index(Q);
    iota(index.begin(), index.end(), 0);
    sort(index.begin(), index.end(), [&](auto i, auto j) {
      auto a = queries[i], b = queries[j];
      if (a.snd != b.snd) return a.snd < b.snd;
      return a.fst < b.fst;
    });
    fenwick_tree<int> bit(N);
    vector<int> pre(N, -1);
    int r = 0, cnt = 0;
    vector<int> res(Q, -1);
    for (auto qi : index) {
      auto q = queries[qi];
      while (r < q.snd) {
        int c = colors[r];
        int p = pre[c];
        if (p < 0) {
          ++cnt;
        } else {
          bit.add(p, -1);
        }
        bit.add(r, 1);
        pre[c] = r;
        ++r;
      }
      res[qi] = cnt - bit.sum(q.fst);
    }
    for (int x : res) printf("%d\n", x);
  }
  return 0;
}


Measured memory_bytes: 17376